summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/midi_region.h
blob: 8f1edded210fc2af81200e12f8f372a11dfba5a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
    Copyright (C) 2000-2006 Paul Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id: midiregion.h 733 2006-08-01 17:19:38Z drobilla $
*/

#ifndef __ardour_midi_region_h__
#define __ardour_midi_region_h__

#include <vector>

#include "evoral/Beats.hpp"
#include "evoral/Range.hpp"

#include "ardour/ardour.h"
#include "ardour/midi_cursor.h"
#include "ardour/region.h"

class XMLNode;

namespace ARDOUR {
	namespace Properties {
		LIBARDOUR_API extern PBD::PropertyDescriptor<double> start_beats;
		LIBARDOUR_API extern PBD::PropertyDescriptor<double> length_beats;
	}
}

namespace Evoral {
template<typename Time> class EventSink;
}

namespace ARDOUR {

class MidiChannelFilter;
class MidiFilter;
class MidiModel;
class MidiSource;
class MidiStateTracker;
class Playlist;
class Route;
class Session;

template<typename T> class MidiRingBuffer;

class LIBARDOUR_API MidiRegion : public Region
{
  public:
	static void make_property_quarks ();

	~MidiRegion();

	bool do_export (std::string path) const;

	boost::shared_ptr<MidiRegion> clone (std::string path = std::string()) const;
	boost::shared_ptr<MidiRegion> clone (boost::shared_ptr<MidiSource>) const;

	boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const;

	/* Stub Readable interface */
	virtual framecnt_t read (Sample*, framepos_t /*pos*/, framecnt_t /*cnt*/, int /*channel*/) const { return 0; }
	virtual framecnt_t readable_length() const { return length(); }

	framecnt_t read_at (Evoral::EventSink<framepos_t>& dst,
	                    framepos_t position,
	                    framecnt_t dur,
	                    Evoral::Range<framepos_t>* loop_range,
	                    MidiCursor& cursor,
	                    uint32_t  chan_n = 0,
	                    NoteMode  mode = Sustained,
	                    MidiStateTracker* tracker = 0,
	                    MidiChannelFilter* filter = 0) const;

	framecnt_t master_read_at (MidiRingBuffer<framepos_t>& dst,
	                           framepos_t position,
	                           framecnt_t dur,
	                           Evoral::Range<framepos_t>* loop_range,
	                           MidiCursor& cursor,
	                           uint32_t  chan_n = 0,
	                           NoteMode  mode = Sustained) const;

	XMLNode& state ();
	int      set_state (const XMLNode&, int version);

	int separate_by_channel (ARDOUR::Session&, std::vector< boost::shared_ptr<Region> >&) const;

	/* automation */

	boost::shared_ptr<Evoral::Control> control(const Evoral::Parameter& id, bool create=false);

	virtual boost::shared_ptr<const Evoral::Control> control(const Evoral::Parameter& id) const;

	/* export */

	boost::shared_ptr<MidiModel> model();
	boost::shared_ptr<const MidiModel> model() const;

	void fix_negative_start ();
	double start_beats () const {return _start_beats; }
	double length_beats () const {return _length_beats; }

	void clobber_sources (boost::shared_ptr<MidiSource> source);

  protected:

	virtual bool can_trim_start_before_source_start () const {
		return true;
	}

  private:
	friend class RegionFactory;
	PBD::Property<double> _start_beats;
	PBD::Property<double> _length_beats;

	MidiRegion (const SourceList&);
	MidiRegion (boost::shared_ptr<const MidiRegion>);
	MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset, const int32_t sub_num = 0);

	framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
	                     framepos_t position,
	                     framecnt_t dur,
	                     Evoral::Range<framepos_t>* loop_range,
	                     MidiCursor& cursor,
	                     uint32_t chan_n = 0,
	                     NoteMode mode = Sustained,
	                     MidiStateTracker* tracker = 0,
	                     MidiChannelFilter* filter = 0) const;

	void register_properties ();
	void post_set (const PBD::PropertyChange&);

	void recompute_at_start ();
	void recompute_at_end ();

	void set_position_internal (framepos_t pos, bool allow_bbt_recompute, const int32_t sub_num);
	void set_length_internal (framecnt_t len, const int32_t sub_num);
	void set_start_internal (framecnt_t, const int32_t sub_num);
	void trim_to_internal (framepos_t position, framecnt_t length, const int32_t sub_num);
	void update_length_beats (const int32_t sub_num);

	void model_changed ();
	void model_automation_state_changed (Evoral::Parameter const &);

	void set_start_beats_from_start_frames ();
	void update_after_tempo_map_change (bool send_change = true);

	std::set<Evoral::Parameter> _filtered_parameters; ///< parameters that we ask our source not to return when reading
	PBD::ScopedConnection _model_connection;
	PBD::ScopedConnection _source_connection;
	PBD::ScopedConnection _model_contents_connection;
};

} /* namespace ARDOUR */


#endif /* __ardour_midi_region_h__ */