2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
18 $Id: midiregion.h 733 2006-08-01 17:19:38Z drobilla $
21 #ifndef __ardour_midi_region_h__
22 #define __ardour_midi_region_h__
26 #include "evoral/Beats.hpp"
28 #include "ardour/ardour.h"
29 #include "ardour/region.h"
34 namespace Properties {
35 LIBARDOUR_API extern PBD::PropertyDescriptor<Evoral::Beats> start_beats;
36 LIBARDOUR_API extern PBD::PropertyDescriptor<Evoral::Beats> length_beats;
37 LIBARDOUR_API extern PBD::PropertyDescriptor<double> start_pulse;
38 LIBARDOUR_API extern PBD::PropertyDescriptor<double> length_pulse;
43 template<typename Time> class EventSink;
48 class MidiChannelFilter;
52 class MidiStateTracker;
57 template<typename T> class MidiRingBuffer;
59 class LIBARDOUR_API MidiRegion : public Region
62 static void make_property_quarks ();
66 bool do_export (std::string path) const;
68 boost::shared_ptr<MidiRegion> clone (std::string path = std::string()) const;
69 boost::shared_ptr<MidiRegion> clone (boost::shared_ptr<MidiSource>) const;
71 boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;
73 /* Stub Readable interface */
74 virtual framecnt_t read (Sample*, framepos_t /*pos*/, framecnt_t /*cnt*/, int /*channel*/) const { return 0; }
75 virtual framecnt_t readable_length() const { return length(); }
77 framecnt_t read_at (Evoral::EventSink<framepos_t>& dst,
81 NoteMode mode = Sustained,
82 MidiStateTracker* tracker = 0,
83 MidiChannelFilter* filter = 0) const;
85 framecnt_t master_read_at (MidiRingBuffer<framepos_t>& dst,
89 NoteMode mode = Sustained) const;
92 int set_state (const XMLNode&, int version);
94 int separate_by_channel (ARDOUR::Session&, std::vector< boost::shared_ptr<Region> >&) const;
98 boost::shared_ptr<Evoral::Control> control(const Evoral::Parameter& id, bool create=false);
100 virtual boost::shared_ptr<const Evoral::Control> control(const Evoral::Parameter& id) const;
104 boost::shared_ptr<MidiModel> model();
105 boost::shared_ptr<const MidiModel> model() const;
107 void fix_negative_start ();
108 Evoral::Beats start_beats () {return _start_beats.val(); }
109 Evoral::Beats length_beats () {return _length_beats.val(); }
110 double start_pulse () const {return _start_pulse; }
111 double length_pulse () const {return _length_pulse; }
114 virtual bool can_trim_start_before_source_start () const {
119 friend class RegionFactory;
120 PBD::Property<Evoral::Beats> _start_beats;
121 PBD::Property<Evoral::Beats> _length_beats;
122 PBD::Property<double> _start_pulse;
123 PBD::Property<double> _length_pulse;
125 MidiRegion (const SourceList&);
126 MidiRegion (boost::shared_ptr<const MidiRegion>);
127 MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset, const int32_t sub_num = 0);
129 framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
133 NoteMode mode = Sustained,
134 MidiStateTracker* tracker = 0,
135 MidiChannelFilter* filter = 0) const;
137 void register_properties ();
138 void post_set (const PBD::PropertyChange&);
140 void recompute_at_start ();
141 void recompute_at_end ();
143 void set_position_internal (framepos_t pos, bool allow_bbt_recompute, const int32_t sub_num);
144 void set_length_internal (framecnt_t len, const int32_t sub_num);
145 void set_start_internal (framecnt_t, const int32_t sub_num);
146 void trim_to_internal (framepos_t position, framecnt_t length, const int32_t sub_num);
147 void update_length_beats (const int32_t sub_num);
149 void model_changed ();
150 void model_automation_state_changed (Evoral::Parameter const &);
152 void set_start_beats_from_start_frames ();
153 void update_after_tempo_map_change (bool send_change = true);
155 std::set<Evoral::Parameter> _filtered_parameters; ///< parameters that we ask our source not to return when reading
156 PBD::ScopedConnection _model_connection;
157 PBD::ScopedConnection _source_connection;
158 PBD::ScopedConnection _model_contents_connection;
160 double _last_length_beats;
163 } /* namespace ARDOUR */
166 #endif /* __ardour_midi_region_h__ */