Ardour  9.7-53-gdd292e0e94
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 
27 #define ABSTRACT_UI_EXPORTS
28 #include "pbd/abstract_ui.h"
29 #include "pbd/mutex.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:
63  GenericMidiControlProtocol (ARDOUR::Session&, std::string const & config);
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  static std::map<std::string, std::vector<std::string>> enumerate ();
97  int load_bindings (const std::string&);
98  void drop_bindings ();
99  void drop_all ();
100 
101  void check_used_event (int, int);
102 
103  std::string current_binding() const { return _current_binding; }
104 
105  struct MapInfo {
106  std::string name;
107  std::string path;
108  };
109 
110  std::list<MapInfo> map_info;
111  void reload_maps ();
112 
113  void set_current_bank (uint32_t);
114  void next_bank ();
115  void prev_bank ();
116 
117  void set_motorised (bool);
118 
119  bool motorised () const {
120  return _motorised;
121  }
122 
123  void set_threshold (int);
124 
125  int threshold () const {
126  return _threshold;
127  }
128 
129  void add_rid_to_selection (int rid);
130  void set_rid_selection (int rid);
131  void toggle_rid_selection (int rid);
133 
135 
137 
138 private:
139  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
140  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
141  std::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
142  std::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
143 
146 
148  void _send_feedback ();
149  void send_feedback ();
150 
151  typedef std::list<MIDIControllable*> MIDIControllables;
153 
154  typedef std::list<MIDIFunction*> MIDIFunctions;
156 
157  typedef std::list<MIDIAction*> MIDIActions;
159 
162  bool own_mc;
164 
166  : mc (c)
167  , own_mc (omc)
168  {}
169  };
170  typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
174 
175  bool start_learning (std::weak_ptr<PBD::Controllable>);
176  void stop_learning (std::weak_ptr<PBD::Controllable>);
177 
179 
183 
185 
188  OutputConnected = 0x2
189  };
190 
192  bool connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
194 
195  std::string _current_binding;
196  std::string _config;
197  uint32_t _bank_size;
198  uint32_t _current_bank;
206 
207  mutable void *gui;
208  void build_gui ();
209 
211 
212  bool midi_input_handler (Glib::IOCondition ioc, std::weak_ptr<ARDOUR::AsyncMIDIPort> port);
215 };
216 
217 #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 &, std::string const &config)
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 &)
static std::map< std::string, std::vector< std::string > > enumerate()
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