remove some debug output
[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 roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
43                   int declick, bool can_record, bool rec_monitors_input, bool& need_butler);
44
45         void realtime_handle_transport_stopped ();
46         void realtime_locate ();
47
48         void use_new_diskstream ();
49         void set_diskstream (boost::shared_ptr<Diskstream>);
50         void set_record_enabled (bool yn, void *src);
51
52         DataType data_type () const {
53                 return DataType::MIDI;
54         }
55
56         int export_stuff (BufferSet& bufs, framecnt_t nframes, framepos_t end_frame);
57
58         void freeze_me (InterThreadInfo&);
59         void unfreeze ();
60
61         boost::shared_ptr<Region> bounce (InterThreadInfo&);
62         boost::shared_ptr<Region> bounce_range (
63                         framepos_t start, framepos_t end, InterThreadInfo&, bool enable_processing
64                 );
65
66         int set_state(const XMLNode&, int version);
67
68         void midi_panic(void);
69         bool write_immediate_event(size_t size, const uint8_t* buf);
70
71         /** A control that will send "immediate" events to a MIDI track when twiddled */
72         struct MidiControl : public AutomationControl {
73                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
74                             boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
75                         : AutomationControl (route->session(), param, al)
76                         , _route (route)
77                 {}
78
79                 void set_value (double val);
80
81                 MidiTrack* _route;
82         };
83
84         NoteMode note_mode() const { return _note_mode; }
85         void set_note_mode (NoteMode m);
86
87         bool step_editing() const { return _step_editing; }
88         void set_step_editing (bool yn);
89         MidiRingBuffer<framepos_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
90
91         PBD::Signal1<void,bool> StepEditStatusChange;
92
93         bool midi_thru() const { return _midi_thru; }
94         void set_midi_thru (bool yn);
95
96         boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
97         void set_channel_mode (ChannelMode, uint16_t);
98         ChannelMode get_channel_mode ();
99         uint16_t get_channel_mask ();
100         boost::shared_ptr<MidiPlaylist> midi_playlist ();
101
102         bool bounceable () const {
103                 return false;
104         }
105
106         PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded;
107
108 protected:
109         XMLNode& state (bool full);
110
111         int _set_state (const XMLNode&, int, bool call_base);
112         bool should_monitor () const;
113         bool send_silence () const;
114
115   private:
116         boost::shared_ptr<MidiDiskstream> midi_diskstream () const;
117
118         void write_out_of_band_data (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
119
120         void set_state_part_two ();
121         void set_state_part_three ();
122
123         MidiRingBuffer<framepos_t> _immediate_events;
124         MidiRingBuffer<framepos_t> _step_edit_ring_buffer;
125         NoteMode                  _note_mode;
126         bool                      _step_editing;
127         bool                      _midi_thru;
128
129         int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
130                         bool state_changing, bool can_record, bool rec_monitors_input);
131         void push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes);
132
133         void diskstream_data_recorded (boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource>);
134         PBD::ScopedConnection _diskstream_data_recorded_connection;
135 };
136
137 } /* namespace ARDOUR*/
138
139 #endif /* __ardour_midi_track_h__ */