MIDI region forking, plus Playlist::regions_to_read() fix forward ported from 2.X...
[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 namespace ARDOUR {
39
40 class Route;
41 class Playlist;
42 class Session;
43 class MidiFilter;
44 class MidiSource;
45 class MidiStateTracker;
46 template<typename T> class MidiRingBuffer;
47
48 class MidiRegion : public Region
49 {
50   public:
51         ~MidiRegion();
52
53         boost::shared_ptr<MidiRegion> clone ();
54         
55         boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
56
57         /* Stub Readable interface */
58         virtual framecnt_t read (Sample*, framepos_t /*pos*/, framecnt_t /*cnt*/, int /*channel*/) const { return 0; }
59         virtual framecnt_t readable_length() const { return length(); }
60
61         framecnt_t read_at (Evoral::EventSink<nframes_t>& dst,
62                             framepos_t position,
63                             framecnt_t dur,
64                             uint32_t  chan_n = 0,
65                             NoteMode  mode = Sustained,
66                             MidiStateTracker* tracker = 0) const;
67         
68         framepos_t master_read_at (MidiRingBuffer<nframes_t>& dst,
69                                    framepos_t position,
70                                    framecnt_t dur,
71                                    uint32_t  chan_n = 0,
72                                    NoteMode  mode = Sustained) const;
73
74         XMLNode& state (bool);
75         int      set_state (const XMLNode&, int version);
76         
77         int separate_by_channel (ARDOUR::Session&, std::vector< boost::shared_ptr<Region> >&) const;
78
79         /* automation */
80         
81         boost::shared_ptr<Evoral::Control>
82         control(const Evoral::Parameter& id, bool create=false) {
83                 return model()->control(id, create);
84         }
85
86         virtual boost::shared_ptr<const Evoral::Control>
87         control(const Evoral::Parameter& id) const {
88                 return model()->control(id);
89         }
90
91         /* export */
92
93         int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&);
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 (const SourceList&);
102         MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset = 0, bool offset_relative = true);
103
104   private:
105         framecnt_t _read_at (const SourceList&, Evoral::EventSink<nframes_t>& dst,
106                              framepos_t position,
107                              framecnt_t dur,
108                              uint32_t chan_n = 0,
109                              NoteMode mode = Sustained, 
110                              MidiStateTracker* tracker = 0) const;
111
112         void recompute_at_start ();
113         void recompute_at_end ();
114
115         void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
116
117         void switch_source(boost::shared_ptr<Source> source);
118 };
119
120 } /* namespace ARDOUR */
121
122
123 #endif /* __ardour_midi_region_h__ */