AlignmentChoise is a Track Property
[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         void realtime_locate ();
46         void non_realtime_locate (samplepos_t);
47
48         bool can_be_record_enabled ();
49         bool can_be_record_safe ();
50
51         void freeze_me (InterThreadInfo&);
52         void unfreeze ();
53
54         bool bounceable (boost::shared_ptr<Processor>, bool) const { return false; }
55         boost::shared_ptr<Region> bounce (InterThreadInfo&);
56         boost::shared_ptr<Region> bounce_range (samplepos_t                   start,
57                                                 samplepos_t                   end,
58                                                 InterThreadInfo&             iti,
59                                                 boost::shared_ptr<Processor> endpoint,
60                                                 bool                         include_endpoint);
61
62         int export_stuff (BufferSet&                   bufs,
63                           samplepos_t                   start_sample,
64                           samplecnt_t                   end_sample,
65                           boost::shared_ptr<Processor> endpoint,
66                           bool                         include_endpoint,
67                           bool                         for_export,
68                           bool                         for_freeze);
69
70         int set_state (const XMLNode&, int version);
71
72         void midi_panic(void);
73         bool write_immediate_event(size_t size, const uint8_t* buf);
74
75         /** A control that will send "immediate" events to a MIDI track when twiddled */
76         struct MidiControl : public AutomationControl {
77                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
78                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
79                         : AutomationControl (route->session(), param, ParameterDescriptor(param), al)
80                         , _route (route)
81                 {}
82
83                 bool writable() const { return true; }
84                 void restore_value ();
85
86                 MidiTrack* _route;
87
88         private:
89                 void actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
90         };
91
92         virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
93
94         NoteMode note_mode() const { return _note_mode; }
95         void set_note_mode (NoteMode m);
96
97         std::string describe_parameter (Evoral::Parameter param);
98
99         bool step_editing() const { return _step_editing; }
100         void set_step_editing (bool yn);
101         MidiRingBuffer<samplepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
102
103         PBD::Signal1<void,bool> StepEditStatusChange;
104
105         boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
106
107         /* Configure capture/playback channels (see MidiChannelFilter). */
108         void set_capture_channel_mode (ChannelMode mode, uint16_t mask);
109         void set_playback_channel_mode (ChannelMode mode, uint16_t mask);
110         void set_playback_channel_mask (uint16_t mask);
111         void set_capture_channel_mask (uint16_t mask);
112
113         ChannelMode get_playback_channel_mode() const { return _playback_filter.get_channel_mode(); }
114         ChannelMode get_capture_channel_mode()  const { return _capture_filter.get_channel_mode(); }
115         uint16_t    get_playback_channel_mask() const { return _playback_filter.get_channel_mask(); }
116         uint16_t    get_capture_channel_mask()  const { return _capture_filter.get_channel_mask(); }
117
118         MidiChannelFilter& playback_filter() { return _playback_filter; }
119         MidiChannelFilter& capture_filter()  { return _capture_filter; }
120
121         virtual void filter_input (BufferSet& bufs);
122
123         boost::shared_ptr<MidiPlaylist> midi_playlist ();
124
125         PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
126         boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
127
128         MonitorState monitoring_state () const;
129
130         void set_input_active (bool);
131         bool input_active () const;
132         PBD::Signal0<void> InputActiveChanged;
133
134 protected:
135         XMLNode& state (bool full);
136
137         void act_on_mute ();
138         void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
139
140 private:
141         MidiRingBuffer<samplepos_t> _immediate_events;
142         MidiRingBuffer<samplepos_t> _step_edit_ring_buffer;
143         NoteMode                   _note_mode;
144         bool                       _step_editing;
145         bool                       _input_active;
146         MidiChannelFilter          _playback_filter;
147         MidiChannelFilter          _capture_filter;
148
149         void write_out_of_band_data (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, samplecnt_t nframes);
150
151         void set_state_part_two ();
152         void set_state_part_three ();
153
154         int no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool state_changing);
155         void push_midi_input_to_step_edit_ringbuffer (samplecnt_t nframes);
156
157         void track_input_active (IOChange, void*);
158         void map_input_active (bool);
159
160         /** Update automation controls to reflect any changes in buffers. */
161         void update_controls (const BufferSet& bufs);
162         void restore_controls ();
163 };
164
165 } /* namespace ARDOUR*/
166
167 #endif /* __ardour_midi_track_h__ */