rework Stateful::set_state() patch to avoid default version argument
[ardour.git] / libs / ardour / ardour / midi_track.h
1 /*
2     Copyright (C) 2006 Paul Davis
3     Written by Dave 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
26 namespace ARDOUR
27 {
28
29 class Session;
30 class MidiDiskstream;
31 class MidiPlaylist;
32 class RouteGroup;
33
34 class MidiTrack : public Track
35 {
36 public:
37         MidiTrack (Session&, string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal);
38         MidiTrack (Session&, const XMLNode&, int);
39         ~MidiTrack ();
40
41         int roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
42                         int declick, bool can_record, bool rec_monitors_input);
43
44         void handle_transport_stopped (bool abort, bool did_locate, bool flush_processors);
45
46         boost::shared_ptr<MidiDiskstream> midi_diskstream() const;
47
48         int use_diskstream (string name);
49         int use_diskstream (const PBD::ID& id);
50
51         void set_latency_delay (nframes_t);
52
53         int export_stuff (BufferSet& bufs, nframes_t nframes, sframes_t end_frame);
54
55         void freeze (InterThreadInfo&);
56         void unfreeze ();
57
58         boost::shared_ptr<Region> bounce (InterThreadInfo&);
59         boost::shared_ptr<Region>  bounce_range (
60                         nframes_t start, nframes_t end, InterThreadInfo&, bool enable_processing);
61
62         int set_state(const XMLNode&, int version);
63
64         void midi_panic(void);
65         bool write_immediate_event(size_t size, const uint8_t* buf);
66
67         /** A control that will send "immediate" events to a MIDI track when twiddled */
68         struct MidiControl : public AutomationControl {
69                 MidiControl(MidiTrack* route, const Evoral::Parameter& param,
70                                 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
71                         : AutomationControl (route->session(), param, al)
72                         , _route (route)
73                 {}
74
75                 void set_value (float val);
76
77                 MidiTrack* _route;
78         };
79
80         NoteMode note_mode() const { return _note_mode; }
81         void set_note_mode (NoteMode m);
82
83         bool step_editing() const { return _step_editing; }
84         void set_step_editing (bool yn);
85         MidiRingBuffer<nframes_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
86
87         uint8_t default_channel() const { return _default_channel; }
88         void set_default_channel (uint8_t chn);
89
90         bool midi_thru() const { return _midi_thru; }
91         void set_midi_thru (bool yn);
92
93 protected:
94         XMLNode& state (bool full);
95         
96         int _set_state (const XMLNode&, int, bool call_base);
97
98 private:
99         void write_out_of_band_data (
100                         BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes);
101
102         int set_diskstream (boost::shared_ptr<MidiDiskstream> ds);
103         void use_new_diskstream ();
104         void set_state_part_two ();
105         void set_state_part_three ();
106
107         MidiRingBuffer<nframes_t> _immediate_events;
108         MidiRingBuffer<nframes_t> _step_edit_ring_buffer;
109         NoteMode                  _note_mode;
110         bool                      _step_editing;
111         uint8_t                   _default_channel;
112         bool                      _midi_thru;
113
114
115         int no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
116                         bool state_changing, bool can_record, bool rec_monitors_input);
117         void push_midi_input_to_step_edit_ringbuffer (nframes_t nframes);
118 };
119
120 } /* namespace ARDOUR*/
121
122 #endif /* __ardour_midi_track_h__ */