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