globally change all use of "frame" to refer to audio into "sample".
[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, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler);
46
47         void realtime_locate ();
48         void non_realtime_locate (samplepos_t);
49
50         bool can_be_record_enabled ();
51         bool can_be_record_safe ();
52
53         void freeze_me (InterThreadInfo&);
54         void unfreeze ();
55
56         bool bounceable (boost::shared_ptr<Processor>, bool) const { return false; }
57         boost::shared_ptr<Region> bounce (InterThreadInfo&);
58         boost::shared_ptr<Region> bounce_range (samplepos_t                   start,
59                                                 samplepos_t                   end,
60                                                 InterThreadInfo&             iti,
61                                                 boost::shared_ptr<Processor> endpoint,
62                                                 bool                         include_endpoint);
63
64         int export_stuff (BufferSet&                   bufs,
65                           samplepos_t                   start_sample,
66                           samplecnt_t                   end_sample,
67                           boost::shared_ptr<Processor> endpoint,
68                           bool                         include_endpoint,
69                           bool                         for_export,
70                           bool                         for_freeze);
71
72         int set_state (const XMLNode&, int version);
73
74         void midi_panic(void);
75         bool write_immediate_event(size_t size, const uint8_t* buf);
76
77         /** A control that will send "immediate" events to a MIDI track when twiddled */
78         struct MidiControl : public AutomationControl {
79                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
80                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
81                         : AutomationControl (route->session(), param, ParameterDescriptor(param), al)
82                         , _route (route)
83                 {}
84
85                 bool writable() const { return true; }
86                 void restore_value ();
87
88                 MidiTrack* _route;
89
90         private:
91                 void actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
92         };
93
94         virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
95
96         NoteMode note_mode() const { return _note_mode; }
97         void set_note_mode (NoteMode m);
98
99         std::string describe_parameter (Evoral::Parameter param);
100
101         bool step_editing() const { return _step_editing; }
102         void set_step_editing (bool yn);
103         MidiRingBuffer<samplepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
104
105         PBD::Signal1<void,bool> StepEditStatusChange;
106
107         boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
108
109         /* Configure capture/playback channels (see MidiChannelFilter). */
110         void set_capture_channel_mode (ChannelMode mode, uint16_t mask);
111         void set_playback_channel_mode (ChannelMode mode, uint16_t mask);
112         void set_playback_channel_mask (uint16_t mask);
113         void set_capture_channel_mask (uint16_t mask);
114
115         ChannelMode get_playback_channel_mode() const { return _playback_filter.get_channel_mode(); }
116         ChannelMode get_capture_channel_mode()  const { return _capture_filter.get_channel_mode(); }
117         uint16_t    get_playback_channel_mask() const { return _playback_filter.get_channel_mask(); }
118         uint16_t    get_capture_channel_mask()  const { return _capture_filter.get_channel_mask(); }
119
120         MidiChannelFilter& playback_filter() { return _playback_filter; }
121         MidiChannelFilter& capture_filter()  { return _capture_filter; }
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__ */