0030fdc52049bd138f7856861ed1f17f31460e49
[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&);
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         boost::shared_ptr<MidiDiskstream> midi_diskstream() const;
45
46         int use_diskstream (string name);
47         int use_diskstream (const PBD::ID& id);
48
49         void set_latency_delay (nframes_t);
50
51         int export_stuff (BufferSet& bufs, nframes_t nframes, sframes_t end_frame);
52
53         void freeze (InterThreadInfo&);
54         void unfreeze ();
55
56         boost::shared_ptr<Region> bounce (InterThreadInfo&);
57         boost::shared_ptr<Region>  bounce_range (nframes_t start, nframes_t end, InterThreadInfo&,
58                                                  bool enable_processing);
59
60         int set_state(const XMLNode& node);
61
62         void midi_panic(void);
63         bool write_immediate_event(size_t size, const uint8_t* buf);
64         
65         /** A control that will send "immediate" events to a MIDI track when twiddled */
66         struct MidiControl : public AutomationControl {
67             MidiControl(MidiTrack* route, const Evoral::Parameter& param,
68                                 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>())
69                         : AutomationControl (route->session(), param, al)
70                         , _route (route)
71                 {}
72          
73             void set_value (float val);
74    
75                 MidiTrack* _route;
76         };
77         
78         NoteMode note_mode() const { return _note_mode; }
79         void set_note_mode (NoteMode m);
80
81         bool step_editing() const { return _step_editing; }
82         void set_step_editing (bool yn);
83         MidiRingBuffer<nframes_t>& step_edit_ring_buffer() { return _step_edit_ring_buffer; }
84         
85 protected:
86         XMLNode& state (bool full);
87         
88         int _set_state (const XMLNode&, bool call_base);
89
90 private:
91         void write_out_of_band_data (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame,
92                                      nframes_t nframes);
93
94         int set_diskstream (boost::shared_ptr<MidiDiskstream> ds);
95         void use_new_diskstream ();
96         void set_state_part_two ();
97         void set_state_part_three ();
98
99         MidiRingBuffer<nframes_t> _immediate_events;
100         MidiRingBuffer<nframes_t> _step_edit_ring_buffer;
101         NoteMode                  _note_mode;
102         bool                      _step_editing;
103         
104         int no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, 
105                      bool state_changing, bool can_record, bool rec_monitors_input);
106         void push_midi_input_to_step_edit_ringbuffer (nframes_t nframes);
107 };
108
109 } /* namespace ARDOUR*/
110
111 #endif /* __ardour_midi_track_h__ */