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