2 Copyright (C) 2006 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_midi_track_h__
21 #define __ardour_midi_track_h__
25 #include "ardour/track.h"
26 #include "ardour/midi_ring_buffer.h"
31 class InterThreadInfo;
38 class LIBARDOUR_API MidiTrack : public Track
41 MidiTrack (Session&, std::string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal);
46 int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& need_butler);
48 void realtime_handle_transport_stopped ();
49 void realtime_locate ();
51 boost::shared_ptr<Diskstream> create_diskstream ();
52 void set_diskstream (boost::shared_ptr<Diskstream>);
53 void set_record_enabled (bool yn, void *src);
55 DataType data_type () const {
56 return DataType::MIDI;
59 void freeze_me (InterThreadInfo&);
62 bool bounceable (boost::shared_ptr<Processor>, bool) const { return false; }
63 boost::shared_ptr<Region> bounce (InterThreadInfo&);
64 boost::shared_ptr<Region> bounce_range (framepos_t start,
67 boost::shared_ptr<Processor> endpoint,
68 bool include_endpoint);
70 int export_stuff (BufferSet& bufs,
71 framepos_t start_frame,
73 boost::shared_ptr<Processor> endpoint,
74 bool include_endpoint,
78 int set_state (const XMLNode&, int version);
80 void midi_panic(void);
81 bool write_immediate_event(size_t size, const uint8_t* buf);
83 /** A control that will send "immediate" events to a MIDI track when twiddled */
84 struct MidiControl : public AutomationControl {
85 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
86 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
87 : AutomationControl (route->session(), param, ParameterDescriptor(param), al)
91 void set_value (double val);
96 virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
98 NoteMode note_mode() const { return _note_mode; }
99 void set_note_mode (NoteMode m);
101 std::string describe_parameter (Evoral::Parameter param);
103 bool step_editing() const { return _step_editing; }
104 void set_step_editing (bool yn);
105 MidiRingBuffer<framepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
107 PBD::Signal1<void,bool> StepEditStatusChange;
109 boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
111 /** Channel filtering mode.
112 * @param mask If mode is FilterChannels, each bit represents a midi channel:
113 * bit 0 = channel 0, bit 1 = channel 1 etc. the read and write methods will only
114 * process events whose channel bit is 1.
115 * If mode is ForceChannel, mask is simply a channel number which all events will
116 * be forced to while reading.
118 void set_capture_channel_mode (ChannelMode mode, uint16_t mask);
119 void set_playback_channel_mode (ChannelMode mode, uint16_t mask);
120 void set_playback_channel_mask (uint16_t mask);
121 void set_capture_channel_mask (uint16_t mask);
123 ChannelMode get_playback_channel_mode() const {
124 return static_cast<ChannelMode>((g_atomic_int_get(&_playback_channel_mask) & 0xffff0000) >> 16);
126 uint16_t get_playback_channel_mask() const {
127 return g_atomic_int_get(&_playback_channel_mask) & 0x0000ffff;
129 ChannelMode get_capture_channel_mode() const {
130 return static_cast<ChannelMode>((g_atomic_int_get(&_capture_channel_mask) & 0xffff0000) >> 16);
132 uint16_t get_capture_channel_mask() const {
133 return g_atomic_int_get(&_capture_channel_mask) & 0x0000ffff;
136 boost::shared_ptr<MidiPlaylist> midi_playlist ();
138 PBD::Signal0<void> PlaybackChannelMaskChanged;
139 PBD::Signal0<void> PlaybackChannelModeChanged;
140 PBD::Signal0<void> CaptureChannelMaskChanged;
141 PBD::Signal0<void> CaptureChannelModeChanged;
143 PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
144 boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
146 void set_monitoring (MonitorChoice);
147 MonitorState monitoring_state () const;
149 void set_input_active (bool);
150 bool input_active () const;
151 PBD::Signal0<void> InputActiveChanged;
154 XMLNode& state (bool full);
159 MidiRingBuffer<framepos_t> _immediate_events;
160 MidiRingBuffer<framepos_t> _step_edit_ring_buffer;
164 uint32_t _playback_channel_mask; // 16 bits mode, 16 bits mask
165 uint32_t _capture_channel_mask; // 16 bits mode, 16 bits mask
167 virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &);
169 boost::shared_ptr<MidiDiskstream> midi_diskstream () const;
171 void write_out_of_band_data (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
173 void set_state_part_two ();
174 void set_state_part_three ();
177 int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing);
178 void push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes);
180 void diskstream_data_recorded (boost::weak_ptr<MidiSource>);
181 PBD::ScopedConnection _diskstream_data_recorded_connection;
183 void track_input_active (IOChange, void*);
184 void map_input_active (bool);
186 void filter_channels (BufferSet& bufs, ChannelMode mode, uint32_t mask);
188 /* if mode is ForceChannel, force mask to the lowest set channel or 1 if no
191 #define force_mask(mode,mask) (((mode) == ForceChannel) ? (((mask) ? (1<<(PBD::ffs((mask))-1)) : 1)) : mask)
193 void _set_playback_channel_mode(ChannelMode mode, uint16_t mask) {
194 mask = force_mask (mode, mask);
195 g_atomic_int_set(&_playback_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
197 void _set_playback_channel_mask (uint16_t mask) {
198 mask = force_mask (get_playback_channel_mode(), mask);
199 g_atomic_int_set(&_playback_channel_mask, (uint32_t(get_playback_channel_mode()) << 16) | uint32_t(mask));
201 void _set_capture_channel_mode(ChannelMode mode, uint16_t mask) {
202 mask = force_mask (mode, mask);
203 g_atomic_int_set(&_capture_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
205 void _set_capture_channel_mask (uint16_t mask) {
206 mask = force_mask (get_capture_channel_mode(), mask);
207 g_atomic_int_set(&_capture_channel_mask, (uint32_t(get_capture_channel_mode()) << 16) | uint32_t(mask));
213 } /* namespace ARDOUR*/
215 #endif /* __ardour_midi_track_h__ */