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