use per-channel signals to pick up scene changes, rather than global ones
[ardour.git] / libs / ardour / ardour / midi_scene_changer.h
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libardour_midi_scene_changer_h__
21 #define __libardour_midi_scene_changer_h__
22
23 #include "ardour/scene_changer.h"
24
25 namespace ARDOUR
26 {
27
28 class MIDISceneChanger : public SceneChanger
29 {
30     public:
31         MIDISceneChanger (Session&);
32         ~MIDISceneChanger ();
33
34         void run (framepos_t start, framepos_t end);
35         void set_input_port (MIDI::Port*);
36         void set_output_port (boost::shared_ptr<MidiPort>);
37
38         uint8_t bank_at (framepos_t, uint8_t channel);
39         uint8_t program_at (framepos_t, uint8_t channel);
40
41         void set_recording (bool);
42         void locate (framepos_t);
43
44     private:
45         typedef std::multimap<framepos_t,boost::shared_ptr<MIDISceneChange> > Scenes;
46
47         MIDI::Port* input_port;
48         boost::shared_ptr<MidiPort> output_port;
49         Scenes scenes;
50         bool _recording;
51         framepos_t last_bank_message_time;
52         framepos_t last_program_message_time;
53         unsigned short current_bank;
54         int last_delivered_program;
55         int last_delivered_bank;
56
57         void gather ();
58         bool recording () const;
59         void jump_to (int bank, int program);
60         void deliver (MidiBuffer&, framepos_t, boost::shared_ptr<MIDISceneChange>);
61
62         void bank_change_input (MIDI::Parser&, unsigned short, int channel);
63         void program_change_input (MIDI::Parser&, MIDI::byte, int channel);
64         void locations_changed (Locations::Change);
65
66         PBD::ScopedConnectionList incoming_connections;
67 };
68
69 } // namespace
70
71 #endif /* __libardour_midi_scene_changer_h__ */