Show matching controller name in automation lane header.
[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/interthread_info.h"
24 #include "ardour/track.h"
25 #include "ardour/midi_ring_buffer.h"
26 #include "ardour/midi_state_tracker.h"
27
28 namespace ARDOUR
29 {
30
31 class Session;
32 class MidiDiskstream;
33 class MidiPlaylist;
34 class RouteGroup;
35 class SMFSource;
36
37 class MidiTrack : public Track
38 {
39 public:
40         MidiTrack (Session&, string name, Route::Flag f = Route::Flag (0), 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
50         boost::shared_ptr<Diskstream> create_diskstream ();
51         void set_diskstream (boost::shared_ptr<Diskstream>);
52         void set_record_enabled (bool yn, void *src);
53
54         DataType data_type () const {
55                 return DataType::MIDI;
56         }
57
58         void freeze_me (InterThreadInfo&);
59         void unfreeze ();
60
61         bool bounceable (boost::shared_ptr<Processor>, bool) const { return false; }
62         boost::shared_ptr<Region> bounce (InterThreadInfo&);
63         boost::shared_ptr<Region> bounce_range (framepos_t                   start,
64                                                 framepos_t                   end,
65                                                 InterThreadInfo&             iti,
66                                                 boost::shared_ptr<Processor> endpoint,
67                                                 bool                         include_endpoint);
68
69         int export_stuff (BufferSet&                   bufs,
70                           framepos_t                   start_frame,
71                           framecnt_t                   end_frame,
72                           boost::shared_ptr<Processor> endpoint,
73                           bool                         include_endpoint,
74                           bool                         for_export);
75
76         int set_state (const XMLNode&, int version);
77
78         void midi_panic(void);
79         bool write_immediate_event(size_t size, const uint8_t* buf);
80
81         /** A control that will send "immediate" events to a MIDI track when twiddled */
82         struct MidiControl : public AutomationControl {
83                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
84                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
85                         : AutomationControl (route->session(), param, al)
86                         , _route (route)
87                 {}
88
89                 void set_value (double val);
90
91                 MidiTrack* _route;
92         };
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<framepos_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         void set_channel_mode (ChannelMode, uint16_t);
107         ChannelMode get_channel_mode ();
108         uint16_t get_channel_mask ();
109         boost::shared_ptr<MidiPlaylist> midi_playlist ();
110
111         PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
112         boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
113
114         void set_monitoring (MonitorChoice);
115         MonitorState monitoring_state () const;
116
117         void set_input_active (bool);
118         bool input_active () const;
119         PBD::Signal0<void> InputActiveChanged;
120
121 protected:
122         XMLNode& state (bool full);
123
124         void act_on_mute ();
125
126 private:
127
128         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &);
129         
130         boost::shared_ptr<MidiDiskstream> midi_diskstream () const;
131
132         void write_out_of_band_data (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
133
134         void set_state_part_two ();
135         void set_state_part_three ();
136
137         MidiRingBuffer<framepos_t> _immediate_events;
138         MidiRingBuffer<framepos_t> _step_edit_ring_buffer;
139         NoteMode                  _note_mode;
140         bool                      _step_editing;
141         bool                      _input_active;
142
143         int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing);
144         void push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes);
145
146         void diskstream_data_recorded (boost::weak_ptr<MidiSource>);
147         PBD::ScopedConnection _diskstream_data_recorded_connection;
148
149         void track_input_active (IOChange, void*);
150         void map_input_active (bool);
151 };
152
153 } /* namespace ARDOUR*/
154
155 #endif /* __ardour_midi_track_h__ */