Move some code up from {Midi,Audio}Track to Track.
[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/track.h"
24 #include "ardour/midi_ring_buffer.h"
25 #include "ardour/midi_state_tracker.h"
26
27 namespace ARDOUR
28 {
29
30 class Session;
31 class MidiDiskstream;
32 class MidiPlaylist;
33 class RouteGroup;
34 class SMFSource;
35
36 class MidiTrack : public Track
37 {
38 public:
39         MidiTrack (Session&, string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal);
40         ~MidiTrack ();
41
42         int init ();
43
44         int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& need_butler);
45
46         void realtime_handle_transport_stopped ();
47         void realtime_locate ();
48
49         void use_new_diskstream ();
50         void set_diskstream (boost::shared_ptr<Diskstream>);
51         void set_record_enabled (bool yn, void *src);
52
53         DataType data_type () const {
54                 return DataType::MIDI;
55         }
56
57         int export_stuff (BufferSet& bufs, framecnt_t nframes, framepos_t end_frame);
58
59         void freeze_me (InterThreadInfo&);
60         void unfreeze ();
61
62         boost::shared_ptr<Region> bounce (InterThreadInfo&);
63         boost::shared_ptr<Region> bounce_range (
64                         framepos_t start, framepos_t end, InterThreadInfo&, bool enable_processing
65                 );
66
67         int set_state(const XMLNode&, int version);
68
69         void midi_panic(void);
70         bool write_immediate_event(size_t size, const uint8_t* buf);
71
72         /** A control that will send "immediate" events to a MIDI track when twiddled */
73         struct MidiControl : public AutomationControl {
74                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
75                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
76                         : AutomationControl (route->session(), param, al)
77                         , _route (route)
78                 {}
79
80                 void set_value (double val);
81
82                 MidiTrack* _route;
83         };
84
85         NoteMode note_mode() const { return _note_mode; }
86         void set_note_mode (NoteMode m);
87
88         bool step_editing() const { return _step_editing; }
89         void set_step_editing (bool yn);
90         MidiRingBuffer<framepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
91
92         PBD::Signal1<void,bool> StepEditStatusChange;
93
94         bool midi_thru() const { return _midi_thru; }
95         void set_midi_thru (bool yn);
96
97         boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
98         void set_channel_mode (ChannelMode, uint16_t);
99         ChannelMode get_channel_mode ();
100         uint16_t get_channel_mask ();
101         boost::shared_ptr<MidiPlaylist> midi_playlist ();
102
103         bool bounceable () const {
104                 return false;
105         }
106
107         PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded;
108
109         void set_input_active (bool);
110         bool input_active () const;
111         PBD::Signal0<void> InputActiveChanged;
112
113 protected:
114         XMLNode& state (bool full);
115
116         int _set_state (const XMLNode&, int);
117         bool should_monitor () const;
118         bool send_silence () const;
119
120   private:
121
122         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &);
123         
124         boost::shared_ptr<MidiDiskstream> midi_diskstream () const;
125
126         void write_out_of_band_data (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
127
128         void set_state_part_two ();
129         void set_state_part_three ();
130
131         MidiRingBuffer<framepos_t> _immediate_events;
132         MidiRingBuffer<framepos_t> _step_edit_ring_buffer;
133         NoteMode                  _note_mode;
134         bool                      _step_editing;
135         bool                      _midi_thru;
136         bool                      _input_active;
137
138         int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing);
139         void push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes);
140
141         void diskstream_data_recorded (boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource>);
142         PBD::ScopedConnection _diskstream_data_recorded_connection;
143
144         void track_input_active (IOChange, void*);
145         void map_input_active (bool);
146 };
147
148 } /* namespace ARDOUR*/
149
150 #endif /* __ardour_midi_track_h__ */