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"
37 class ControllableDescriptor;
46 class MIDIControllable;
50 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
52 GenericMidiControlProtocol (ARDOUR::Session&);
53 virtual ~GenericMidiControlProtocol();
55 int set_active (bool yn);
56 static bool probe() { return true; }
58 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
60 boost::shared_ptr<ARDOUR::Port> input_port () const;
61 boost::shared_ptr<ARDOUR::Port> output_port () const;
63 void set_feedback_interval (ARDOUR::microseconds_t);
65 int set_feedback (bool yn);
66 bool get_feedback () const;
68 boost::shared_ptr<PBD::Controllable> lookup_controllable (const ARDOUR::ControllableDescriptor&) const;
70 void maybe_start_touch (PBD::Controllable*);
72 XMLNode& get_state ();
73 int set_state (const XMLNode&, int version);
75 bool has_editor () const { return true; }
76 void* get_gui () const;
77 void tear_down_gui ();
79 int load_bindings (const std::string&);
80 void drop_bindings ();
82 void check_used_event (int, int);
84 std::string current_binding() const { return _current_binding; }
91 std::list<MapInfo> map_info;
94 void set_current_bank (uint32_t);
98 void set_motorised (bool);
100 bool motorised () const {
104 void set_threshold (int);
106 int threshold () const {
110 PBD::Signal0<void> ConnectionChange;
113 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
114 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
115 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
116 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
118 ARDOUR::microseconds_t _feedback_interval;
119 ARDOUR::microseconds_t last_feedback_time;
122 void _send_feedback ();
123 void send_feedback ();
125 typedef std::list<MIDIControllable*> MIDIControllables;
126 MIDIControllables controllables;
128 typedef std::list<MIDIFunction*> MIDIFunctions;
129 MIDIFunctions functions;
131 typedef std::list<MIDIAction*> MIDIActions;
134 struct MIDIPendingControllable {
135 MIDIControllable* mc;
137 PBD::ScopedConnection connection;
139 MIDIPendingControllable (MIDIControllable* c, bool omc)
144 typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
145 MIDIPendingControllables pending_controllables;
146 Glib::Threads::Mutex controllables_lock;
147 Glib::Threads::Mutex pending_lock;
149 bool start_learning (PBD::Controllable*);
150 void stop_learning (PBD::Controllable*);
152 void learning_stopped (MIDIControllable*);
154 void create_binding (PBD::Controllable*, int, int);
155 void delete_binding (PBD::Controllable*);
157 MIDIControllable* create_binding (const XMLNode&);
158 MIDIFunction* create_function (const XMLNode&);
159 MIDIAction* create_action (const XMLNode&);
161 void reset_controllables ();
164 enum ConnectionState {
165 InputConnected = 0x1,
166 OutputConnected = 0x2
169 int connection_state;
170 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
171 PBD::ScopedConnection port_connection;
174 std::string _current_binding;
176 uint32_t _current_bank;
177 /** true if this surface is motorised. If it is, we assume
178 that the surface's controls are never out of sync with
179 Ardour's state, so we don't have to take steps to avoid
180 values jumping around when things are not in sync.
191 #endif /* ardour_generic_midi_control_protocol_h */