* set right interpolation on MidiModel controls after recording too
[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/midi_source.h>
34
35 class XMLNode;
36
37 using std::vector;
38
39 namespace ARDOUR {
40
41 class Route;
42 class Playlist;
43 class Session;
44 class MidiFilter;
45 class MidiSource;
46 class MidiRingBuffer;
47
48 class MidiRegion : public Region
49 {
50   public:
51         ~MidiRegion();
52
53         boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
54         
55         /* Stub Readable interface */
56         virtual nframes64_t read (Sample*, nframes64_t pos, nframes64_t cnt, int channel) const { return 0; }
57         virtual nframes64_t readable_length() const { return length(); }
58
59         nframes_t read_at (MidiRingBuffer& dst,
60                            nframes_t position,
61                            nframes_t dur, 
62                            uint32_t  chan_n = 0,
63                            NoteMode  mode = Sustained) const;
64
65         nframes_t master_read_at (MidiRingBuffer& dst,
66                         nframes_t position,
67                         nframes_t dur,
68                         uint32_t  chan_n = 0,
69                         NoteMode  mode = Sustained) const;
70
71         XMLNode& state (bool);
72         int      set_state (const XMLNode&);
73
74         int separate_by_channel (ARDOUR::Session&, vector<MidiRegion*>&) const;
75         
76         /* automation */
77         
78         boost::shared_ptr<Evoral::Control>
79         control(const Evoral::Parameter& id, bool create=false) {
80                 return model()->data().control(id, create);
81         }
82
83         virtual boost::shared_ptr<const Evoral::Control>
84         control(const Evoral::Parameter& id) const {
85                 return model()->data().control(id);
86         }
87
88         /* export */
89         
90         int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&);
91
92         UndoAction get_memento() const;
93
94         boost::shared_ptr<MidiModel> model()             { return midi_source()->model(); }
95         boost::shared_ptr<const MidiModel> model() const { return midi_source()->model(); }
96
97   private:
98         friend class RegionFactory;
99
100         MidiRegion (boost::shared_ptr<MidiSource>, nframes_t start, nframes_t length);
101         MidiRegion (boost::shared_ptr<MidiSource>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
102         MidiRegion (const SourceList &, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
103         MidiRegion (boost::shared_ptr<const MidiRegion>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
104         MidiRegion (boost::shared_ptr<const MidiRegion>);
105         MidiRegion (boost::shared_ptr<MidiSource>, const XMLNode&);
106         MidiRegion (const SourceList &, const XMLNode&);
107
108   private:
109         nframes_t _read_at (const SourceList&, MidiRingBuffer& dst,
110                             nframes_t position,
111                             nframes_t dur, 
112                             uint32_t chan_n = 0,
113                                 NoteMode mode = Sustained) const;
114
115         void recompute_at_start ();
116         void recompute_at_end ();
117
118         void switch_source(boost::shared_ptr<Source> source);
119
120   protected:
121
122         int set_live_state (const XMLNode&, Change&, bool send);
123 };
124
125 } /* namespace ARDOUR */
126
127
128 #endif /* __ardour_midi_region_h__ */