Add a missing #define to our MSVC project (portaudio_backend)
[ardour.git] / libs / ardour / ardour / midi_track.h
1 /*
2     Copyright (C) 2006 Paul Davis
3     Author: David Robillard
4
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.
9
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.
14
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.
18 */
19
20 #ifndef __ardour_midi_track_h__
21 #define __ardour_midi_track_h__
22
23 #include "ardour/midi_channel_filter.h"
24 #include "ardour/midi_ring_buffer.h"
25 #include "ardour/track.h"
26
27 namespace ARDOUR
28 {
29
30 class InterThreadInfo;
31 class MidiDiskstream;
32 class MidiPlaylist;
33 class RouteGroup;
34 class SMFSource;
35 class Session;
36
37 class LIBARDOUR_API MidiTrack : public Track
38 {
39 public:
40         MidiTrack (Session&, std::string name, TrackMode m = Normal);
41         ~MidiTrack ();
42
43         int init ();
44
45         int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& need_butler);
46
47         void realtime_handle_transport_stopped ();
48         void realtime_locate ();
49         void non_realtime_locate (framepos_t);
50
51         boost::shared_ptr<Diskstream> create_diskstream ();
52         void set_diskstream (boost::shared_ptr<Diskstream>);
53
54         bool can_be_record_enabled ();
55         bool can_be_record_safe ();
56
57         DataType data_type () const {
58                 return DataType::MIDI;
59         }
60
61         void freeze_me (InterThreadInfo&);
62         void unfreeze ();
63
64         bool bounceable (boost::shared_ptr<Processor>, bool) const { return false; }
65         boost::shared_ptr<Region> bounce (InterThreadInfo&);
66         boost::shared_ptr<Region> bounce_range (framepos_t                   start,
67                                                 framepos_t                   end,
68                                                 InterThreadInfo&             iti,
69                                                 boost::shared_ptr<Processor> endpoint,
70                                                 bool                         include_endpoint);
71
72         int export_stuff (BufferSet&                   bufs,
73                           framepos_t                   start_frame,
74                           framecnt_t                   end_frame,
75                           boost::shared_ptr<Processor> endpoint,
76                           bool                         include_endpoint,
77                           bool                         for_export,
78                           bool                         for_freeze);
79
80         int set_state (const XMLNode&, int version);
81
82         void midi_panic(void);
83         bool write_immediate_event(size_t size, const uint8_t* buf);
84
85         /** A control that will send "immediate" events to a MIDI track when twiddled */
86         struct MidiControl : public AutomationControl {
87                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
88                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
89                         : AutomationControl (route->session(), param, ParameterDescriptor(param), al)
90                         , _route (route)
91                 {}
92
93                 bool writable() const { return true; }
94                 void restore_value ();
95
96                 MidiTrack* _route;
97
98         private:
99                 void actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
100         };
101
102         virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
103
104         NoteMode note_mode() const { return _note_mode; }
105         void set_note_mode (NoteMode m);
106
107         std::string describe_parameter (Evoral::Parameter param);
108
109         bool step_editing() const { return _step_editing; }
110         void set_step_editing (bool yn);
111         MidiRingBuffer<framepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
112
113         PBD::Signal1<void,bool> StepEditStatusChange;
114
115         boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
116
117         /* Configure capture/playback channels (see MidiChannelFilter). */
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);
122
123         ChannelMode get_playback_channel_mode() const { return _playback_filter.get_channel_mode(); }
124         ChannelMode get_capture_channel_mode()  const { return _capture_filter.get_channel_mode(); }
125         uint16_t    get_playback_channel_mask() const { return _playback_filter.get_channel_mask(); }
126         uint16_t    get_capture_channel_mask()  const { return _capture_filter.get_channel_mask(); }
127
128         MidiChannelFilter& playback_filter() { return _playback_filter; }
129         MidiChannelFilter& capture_filter()  { return _capture_filter; }
130
131         boost::shared_ptr<MidiPlaylist> midi_playlist ();
132
133         PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
134         boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
135
136         MonitorState monitoring_state () const;
137
138         void set_input_active (bool);
139         bool input_active () const;
140         PBD::Signal0<void> InputActiveChanged;
141
142 protected:
143         XMLNode& state (bool full);
144
145         void act_on_mute ();
146         void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
147
148 private:
149         MidiRingBuffer<framepos_t> _immediate_events;
150         MidiRingBuffer<framepos_t> _step_edit_ring_buffer;
151         NoteMode                   _note_mode;
152         bool                       _step_editing;
153         bool                       _input_active;
154         MidiChannelFilter          _playback_filter;
155         MidiChannelFilter          _capture_filter;
156
157         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &);
158
159         boost::shared_ptr<MidiDiskstream> midi_diskstream () const;
160
161         void write_out_of_band_data (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
162
163         void set_state_part_two ();
164         void set_state_part_three ();
165
166
167         int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing);
168         void push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes);
169
170         void diskstream_data_recorded (boost::weak_ptr<MidiSource>);
171         PBD::ScopedConnection _diskstream_data_recorded_connection;
172
173         void track_input_active (IOChange, void*);
174         void map_input_active (bool);
175
176         /** Update automation controls to reflect any changes in buffers. */
177         void update_controls (const BufferSet& bufs);
178         void restore_controls ();
179 };
180
181 } /* namespace ARDOUR*/
182
183 #endif /* __ardour_midi_track_h__ */