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