2 Copyright (C) 2006 Paul Davis
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.
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.
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.
20 #ifndef ardour_generic_midi_control_protocol_h
21 #define ardour_generic_midi_control_protocol_h
24 #include <glibmm/threads.h>
26 #include "ardour/types.h"
27 #include "ardour/port.h"
29 #include "control_protocol/control_protocol.h"
33 class ControllableDescriptor;
45 class MIDIControllable;
49 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
51 GenericMidiControlProtocol (ARDOUR::Session&);
52 virtual ~GenericMidiControlProtocol();
54 int set_active (bool yn);
55 static bool probe() { return true; }
57 ARDOUR::Port* input_port () const { return ((ARDOUR::Port*) _input_port); }
58 ARDOUR::Port* output_port () const { return ((ARDOUR::Port*) _output_port); }
60 void set_feedback_interval (ARDOUR::microseconds_t);
62 int set_feedback (bool yn);
63 bool get_feedback () const;
65 boost::shared_ptr<PBD::Controllable> lookup_controllable (const PBD::ControllableDescriptor&) const;
67 XMLNode& get_state ();
68 int set_state (const XMLNode&, int version);
70 bool has_editor () const { return true; }
71 void* get_gui () const;
72 void tear_down_gui ();
74 int load_bindings (const std::string&);
75 void drop_bindings ();
77 void check_used_event (int, int);
79 std::string current_binding() const { return _current_binding; }
86 std::list<MapInfo> map_info;
89 void set_current_bank (uint32_t);
93 void set_motorised (bool);
95 bool motorised () const {
99 void set_threshold (int);
101 int threshold () const {
105 PBD::Signal0<void> ConnectionChange;
107 MIDI::Port* _input_port;
108 MIDI::Port* _output_port;
109 ARDOUR::microseconds_t _feedback_interval;
110 ARDOUR::microseconds_t last_feedback_time;
113 void _send_feedback ();
114 void send_feedback ();
116 typedef std::list<MIDIControllable*> MIDIControllables;
117 MIDIControllables controllables;
119 typedef std::list<MIDIFunction*> MIDIFunctions;
120 MIDIFunctions functions;
122 typedef std::list<MIDIAction*> MIDIActions;
125 typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
126 typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
127 MIDIPendingControllables pending_controllables;
128 Glib::Threads::Mutex controllables_lock;
129 Glib::Threads::Mutex pending_lock;
131 bool start_learning (PBD::Controllable*);
132 void stop_learning (PBD::Controllable*);
134 void learning_stopped (MIDIControllable*);
136 void create_binding (PBD::Controllable*, int, int);
137 void delete_binding (PBD::Controllable*);
139 MIDIControllable* create_binding (const XMLNode&);
140 MIDIFunction* create_function (const XMLNode&);
141 MIDIAction* create_action (const XMLNode&);
143 void reset_controllables ();
146 std::string _current_binding;
148 uint32_t _current_bank;
149 /** true if this surface is motorised. If it is, we assume
150 that the surface's controls are never out of sync with
151 Ardour's state, so we don't have to take steps to avoid
152 values jumping around when things are not in sync.
161 #endif /* ardour_generic_midi_control_protocol_h */