Ardour  9.0-pre0-582-g084a23a80d
generic_midi_control_protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef ardour_generic_midi_control_protocol_h
23 #define ardour_generic_midi_control_protocol_h
24 
25 #include <list>
26 #include <glibmm/threads.h>
27 
28 #define ABSTRACT_UI_EXPORTS
29 #include "pbd/abstract_ui.h"
30 
31 #include "ardour/types.h"
32 #include "ardour/port.h"
33 
35 
36 namespace PBD {
37  class Controllable;
38 }
39 
40 namespace ARDOUR {
41  class AsyncMIDIPort;
42  class MidiPort;
43  class Session;
44 }
45 
46 namespace MIDI {
47  class Port;
48 }
49 
50 class MIDIControllable;
51 class MIDIFunction;
52 class MIDIAction;
53 
54 struct GenericMIDIRequest : public BaseUI::BaseRequestObject {
55 public:
58 };
59 
60 
61 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol, public AbstractUI<GenericMIDIRequest> {
62 public:
65 
67  int stop ();
68 
69  void thread_init ();
70 
71  int set_active (bool yn);
72 
74 
75  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
76 
77  std::shared_ptr<ARDOUR::Port> input_port () const;
78  std::shared_ptr<ARDOUR::Port> output_port () const;
79 
81 
82  int set_feedback (bool yn);
83  bool get_feedback () const;
84 
85  std::shared_ptr<PBD::Controllable> lookup_controllable (std::string const &, MIDIControllable&) const;
86 
87  void maybe_start_touch (std::shared_ptr<PBD::Controllable>);
88 
89  XMLNode& get_state () const;
90  int set_state (const XMLNode&, int version);
91 
92  bool has_editor () const { return true; }
93  void* get_gui () const;
94  void tear_down_gui ();
95 
96  int load_bindings (const std::string&);
97  void drop_bindings ();
98  void drop_all ();
99 
100  void check_used_event (int, int);
101 
102  std::string current_binding() const { return _current_binding; }
103 
104  struct MapInfo {
105  std::string name;
106  std::string path;
107  };
108 
109  std::list<MapInfo> map_info;
110  void reload_maps ();
111 
112  void set_current_bank (uint32_t);
113  void next_bank ();
114  void prev_bank ();
115 
116  void set_motorised (bool);
117 
118  bool motorised () const {
119  return _motorised;
120  }
121 
122  void set_threshold (int);
123 
124  int threshold () const {
125  return _threshold;
126  }
127 
128  void add_rid_to_selection (int rid);
129  void set_rid_selection (int rid);
130  void toggle_rid_selection (int rid);
132 
134 
136 
137 private:
138  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
139  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
140  std::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
141  std::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
142 
145 
147  void _send_feedback ();
148  void send_feedback ();
149 
150  typedef std::list<MIDIControllable*> MIDIControllables;
152 
153  typedef std::list<MIDIFunction*> MIDIFunctions;
155 
156  typedef std::list<MIDIAction*> MIDIActions;
158 
161  bool own_mc;
163 
165  : mc (c)
166  , own_mc (omc)
167  {}
168  };
169  typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
171  mutable Glib::Threads::Mutex controllables_lock;
172  Glib::Threads::Mutex pending_lock;
173 
174  bool start_learning (std::weak_ptr<PBD::Controllable>);
175  void stop_learning (std::weak_ptr<PBD::Controllable>);
176 
178 
182 
184 
187  OutputConnected = 0x2
188  };
189 
191  bool connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
193 
194  std::string _current_binding;
195  uint32_t _bank_size;
196  uint32_t _current_bank;
204 
205  mutable void *gui;
206  void build_gui ();
207 
209 
210  bool midi_input_handler (Glib::IOCondition ioc, std::weak_ptr<ARDOUR::AsyncMIDIPort> port);
213 };
214 
215 #endif /* ardour_generic_midi_control_protocol_h */
void set_feedback_interval(PBD::microseconds_t)
void stop_learning(std::weak_ptr< PBD::Controllable >)
void maybe_start_touch(std::shared_ptr< PBD::Controllable >)
std::shared_ptr< ARDOUR::AsyncMIDIPort > _input_port
XMLNode & get_state() const
std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
virtual ~GenericMidiControlProtocol()
std::shared_ptr< ARDOUR::Port > input_port() const
MIDIAction * create_action(const XMLNode &)
void learning_stopped(MIDIControllable *)
std::shared_ptr< PBD::Controllable > lookup_controllable(std::string const &, MIDIControllable &) const
bool start_learning(std::weak_ptr< PBD::Controllable >)
MIDIPendingControllables pending_controllables
MIDIFunction * create_function(const XMLNode &)
std::shared_ptr< ARDOUR::AsyncMIDIPort > _output_port
void set_rid_selection(int rid)
void add_rid_to_selection(int rid)
GenericMidiControlProtocol(ARDOUR::Session &)
int set_state(const XMLNode &, int version)
void do_request(GenericMIDIRequest *)
std::shared_ptr< ARDOUR::Bundle > _output_bundle
std::shared_ptr< ARDOUR::Port > output_port() const
std::list< MIDIPendingControllable * > MIDIPendingControllables
std::shared_ptr< ARDOUR::Bundle > _input_bundle
void remove_rid_from_selection(int rid)
int load_bindings(const std::string &)
void check_used_event(int, int)
bool midi_input_handler(Glib::IOCondition ioc, std::weak_ptr< ARDOUR::AsyncMIDIPort > port)
bool connection_handler(std::weak_ptr< ARDOUR::Port >, std::string name1, std::weak_ptr< ARDOUR::Port >, std::string name2, bool yn)
void set_current_bank(uint32_t)
PBD::ScopedConnectionList midi_connections
std::list< MIDIFunction * > MIDIFunctions
MIDIControllable * create_binding(const XMLNode &)
void toggle_rid_selection(int rid)
std::list< MIDIControllable * > MIDIControllables
Definition: xml++.h:114
std::shared_ptr< PBD::Controllable > Controllable
Definition: console1.h:80
Definition: axis_view.h:42
int64_t microseconds_t
Definition: microseconds.h:28