f7e6c97ea03e7050c310e1f80f956d8ac2ca76d6
[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 "evoral/types.hpp"
27
28 #include "ardour/ardour.h"
29 #include "ardour/region.h"
30
31 class XMLNode;
32
33 namespace ARDOUR {
34         namespace Properties {
35                 LIBARDOUR_API extern PBD::PropertyDescriptor<Evoral::Beats> start_beats;
36                 LIBARDOUR_API extern PBD::PropertyDescriptor<Evoral::Beats> length_beats;
37         }
38 }
39
40 namespace Evoral {
41 template<typename Time> class EventSink;
42 }
43
44 namespace ARDOUR {
45
46 class Route;
47 class Playlist;
48 class Session;
49 class MidiFilter;
50 class MidiModel;
51 class MidiSource;
52 class MidiStateTracker;
53
54 template<typename T> class MidiRingBuffer;
55
56 class LIBARDOUR_API MidiRegion : public Region
57 {
58   public:
59         static void make_property_quarks ();
60
61         ~MidiRegion();
62
63         boost::shared_ptr<MidiRegion> clone (std::string path = std::string()) const;
64         boost::shared_ptr<MidiRegion> clone (boost::shared_ptr<MidiSource>) const;
65
66         boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
67
68         /* Stub Readable interface */
69         virtual framecnt_t read (Sample*, framepos_t /*pos*/, framecnt_t /*cnt*/, int /*channel*/) const { return 0; }
70         virtual framecnt_t readable_length() const { return length(); }
71
72         framecnt_t read_at (Evoral::EventSink<framepos_t>& dst,
73                             framepos_t position,
74                             framecnt_t dur,
75                             uint32_t  chan_n = 0,
76                             NoteMode  mode = Sustained,
77                             MidiStateTracker* tracker = 0) const;
78
79         framecnt_t master_read_at (MidiRingBuffer<framepos_t>& dst,
80                                    framepos_t position,
81                                    framecnt_t dur,
82                                    uint32_t  chan_n = 0,
83                                    NoteMode  mode = Sustained) const;
84
85         XMLNode& state ();
86         int      set_state (const XMLNode&, int version);
87
88         int separate_by_channel (ARDOUR::Session&, std::vector< boost::shared_ptr<Region> >&) const;
89
90         /* automation */
91
92         boost::shared_ptr<Evoral::Control> control(const Evoral::Parameter& id, bool create=false);
93
94         virtual boost::shared_ptr<const Evoral::Control> control(const Evoral::Parameter& id) const;
95
96         /* export */
97
98         boost::shared_ptr<MidiModel> model();
99         boost::shared_ptr<const MidiModel> model() const;
100
101         void fix_negative_start ();
102         void transpose (int);
103
104   protected:
105
106         virtual bool can_trim_start_before_source_start () const {
107                 return true;
108         }
109
110   private:
111         friend class RegionFactory;
112         PBD::Property<Evoral::Beats> _start_beats;
113         PBD::Property<Evoral::Beats> _length_beats;
114
115         MidiRegion (const SourceList&);
116         MidiRegion (boost::shared_ptr<const MidiRegion>);
117         MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset);
118
119         framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
120                              framepos_t position,
121                              framecnt_t dur,
122                              uint32_t chan_n = 0,
123                              NoteMode mode = Sustained,
124                              MidiStateTracker* tracker = 0) const;
125
126         void register_properties ();
127         void post_set (const PBD::PropertyChange&);
128
129         void recompute_at_start ();
130         void recompute_at_end ();
131
132         void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
133         void set_length_internal (framecnt_t len);
134         void set_start_internal (framecnt_t);
135         void update_length_beats ();
136
137         void model_changed ();
138         void model_automation_state_changed (Evoral::Parameter const &);
139
140         void set_start_beats_from_start_frames ();
141         void update_after_tempo_map_change ();
142
143         std::set<Evoral::Parameter> _filtered_parameters; ///< parameters that we ask our source not to return when reading
144         PBD::ScopedConnection _model_connection;
145         PBD::ScopedConnection _source_connection;
146         PBD::ScopedConnection _model_contents_connection;
147
148         double _last_length_beats;
149 };
150
151 } /* namespace ARDOUR */
152
153
154 #endif /* __ardour_midi_region_h__ */