Deep "automation regions" support.
[ardour.git] / libs / ardour / ardour / midi_region.h
1 /*
2     Copyright (C) 2000-2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id: midiregion.h 733 2006-08-01 17:19:38Z drobilla $
19 */
20
21 #ifndef __ardour_midi_region_h__
22 #define __ardour_midi_region_h__
23
24 #include <vector>
25
26 #include <pbd/fastlog.h>
27 #include <pbd/undo.h>
28
29 #include <ardour/ardour.h>
30 #include <ardour/region.h>
31 #include <ardour/gain.h>
32 #include <ardour/logcurve.h>
33 #include <ardour/export.h>
34 #include <ardour/midi_source.h>
35
36 class XMLNode;
37
38 namespace ARDOUR {
39
40 class Route;
41 class Playlist;
42 class Session;
43 class MidiFilter;
44 class MidiSource;
45 class MidiRingBuffer;
46
47 class MidiRegion : public Region
48 {
49   public:
50         ~MidiRegion();
51
52         boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
53
54         nframes_t read_at (MidiRingBuffer& dst,
55                            nframes_t position,
56                            nframes_t dur, 
57                            uint32_t  chan_n = 0,
58                            NoteMode  mode = Sustained) const;
59
60         nframes_t master_read_at (MidiRingBuffer& dst,
61                         nframes_t position,
62                         nframes_t dur,
63                         uint32_t  chan_n = 0,
64                         NoteMode  mode = Sustained) const;
65
66         XMLNode& state (bool);
67         int      set_state (const XMLNode&);
68
69         int separate_by_channel (ARDOUR::Session&, vector<MidiRegion*>&) const;
70
71         UndoAction get_memento() const;
72
73         // Act as a proxy for MidiModel automation stuff (for CC)
74         // Yep, this is pretty ugly...
75         Controls&       controls()       { return midi_source()->model()->controls(); }
76         const Controls& controls() const { return midi_source()->model()->controls(); }
77         
78         boost::shared_ptr<AutomationControl> control(Parameter id, bool create_if_missing=false)
79                         { return midi_source()->model()->control(id, create_if_missing); }
80
81         boost::shared_ptr<const AutomationControl> control(Parameter id) const
82                         { return midi_source()->model()->control(id); }
83
84   private:
85         friend class RegionFactory;
86
87         MidiRegion (boost::shared_ptr<MidiSource>, nframes_t start, nframes_t length);
88         MidiRegion (boost::shared_ptr<MidiSource>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
89         MidiRegion (SourceList &, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
90         MidiRegion (boost::shared_ptr<const MidiRegion>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
91         MidiRegion (boost::shared_ptr<const MidiRegion>);
92         MidiRegion (boost::shared_ptr<MidiSource>, const XMLNode&);
93         MidiRegion (SourceList &, const XMLNode&);
94
95   private:
96         nframes_t _read_at (const SourceList&, MidiRingBuffer& dst,
97                             nframes_t position,
98                             nframes_t dur, 
99                             uint32_t chan_n = 0,
100                                 NoteMode mode = Sustained) const;
101
102         void recompute_at_start ();
103         void recompute_at_end ();
104
105         void switch_source(boost::shared_ptr<Source> source);
106
107   protected:
108
109         int set_live_state (const XMLNode&, Change&, bool send);
110 };
111
112 } /* namespace ARDOUR */
113
114
115 #endif /* __ardour_midi_region_h__ */