Remove all use of nframes_t.
[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         namespace Properties {
40                 /* this is pseudo-property: nothing has this as an actual
41                    property, but it allows us to signal changes to the
42                    MidiModel used by the MidiRegion 
43                 */
44                 extern PBD::PropertyDescriptor<void*> midi_data; 
45         }
46 }
47
48 namespace ARDOUR {
49
50 class Route;
51 class Playlist;
52 class Session;
53 class MidiFilter;
54 class MidiSource;
55 class MidiStateTracker;
56 template<typename T> class MidiRingBuffer;
57
58 class MidiRegion : public Region
59 {
60   public:
61         static void make_property_quarks ();
62
63         ~MidiRegion();
64
65         boost::shared_ptr<MidiRegion> clone ();
66         
67         boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
68
69         /* Stub Readable interface */
70         virtual framecnt_t read (Sample*, framepos_t /*pos*/, framecnt_t /*cnt*/, int /*channel*/) const { return 0; }
71         virtual framecnt_t readable_length() const { return length(); }
72
73         framecnt_t read_at (Evoral::EventSink<framepos_t>& dst,
74                             framepos_t position,
75                             framecnt_t dur,
76                             uint32_t  chan_n = 0,
77                             NoteMode  mode = Sustained,
78                             MidiStateTracker* tracker = 0) const;
79         
80         framepos_t master_read_at (MidiRingBuffer<framepos_t>& dst,
81                                    framepos_t position,
82                                    framecnt_t dur,
83                                    uint32_t  chan_n = 0,
84                                    NoteMode  mode = Sustained) const;
85
86         XMLNode& state ();
87         int      set_state (const XMLNode&, int version);
88         
89         int separate_by_channel (ARDOUR::Session&, std::vector< boost::shared_ptr<Region> >&) const;
90
91         /* automation */
92         
93         boost::shared_ptr<Evoral::Control>
94         control(const Evoral::Parameter& id, bool create=false) {
95                 return model()->control(id, create);
96         }
97
98         virtual boost::shared_ptr<const Evoral::Control>
99         control(const Evoral::Parameter& id) const {
100                 return model()->control(id);
101         }
102
103         /* export */
104
105         int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&);
106
107         boost::shared_ptr<MidiModel> model()             { return midi_source()->model(); }
108         boost::shared_ptr<const MidiModel> model() const { return midi_source()->model(); }
109
110   private:
111         friend class RegionFactory;
112
113         MidiRegion (const SourceList&);
114         MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset = 0, bool offset_relative = true);
115
116   private:
117         framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
118                              framepos_t position,
119                              framecnt_t dur,
120                              uint32_t chan_n = 0,
121                              NoteMode mode = Sustained, 
122                              MidiStateTracker* tracker = 0) const;
123
124         void register_properties ();
125
126         void recompute_at_start ();
127         void recompute_at_end ();
128
129         void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
130
131         void model_changed ();
132         void model_automation_state_changed (Evoral::Parameter const &);
133         void model_contents_changed ();
134
135         std::set<Evoral::Parameter> _filtered_parameters; ///< parameters that we ask our source not to return when reading
136         PBD::ScopedConnection _model_connection;
137         PBD::ScopedConnection _source_connection;
138         PBD::ScopedConnection _model_contents_connection;
139 };
140
141 } /* namespace ARDOUR */
142
143
144 #endif /* __ardour_midi_region_h__ */