Ardour  9.0-pre0-582-g084a23a80d
midicontrollable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2007-2016 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009 David Robillard <d@drobilla.net>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7  * Copyright (C) 2015 Len Ovens <len@ovenwerks.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __gm_midicontrollable_h__
25 #define __gm_midicontrollable_h__
26 
27 #include <string>
28 
29 #include "midi++/types.h"
30 
31 #include "pbd/controllable.h"
32 #include "pbd/signals.h"
33 #include "pbd/stateful.h"
34 
35 #include "ardour/types.h"
36 
37 namespace MIDI {
38  class Channel;
39  class Parser;
40 }
41 
43 
44 namespace ARDOUR {
45  class AsyncMIDIPort;
46  class Stripable;
47 }
48 
50 {
51 public:
52  MIDIControllable (GenericMidiControlProtocol*, MIDI::Parser&, std::shared_ptr<PBD::Controllable>, bool momentary);
54  virtual ~MIDIControllable ();
55 
56  int init (const std::string&);
57 
59  bool bank_relative() const { return _bank_relative; }
60  uint32_t rid() const { return _rid; }
61  std::string what() const { return _what; }
62 
63  enum CtlType {
67  };
68 
69  enum Encoder {
75  };
76 
77  MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
78 
79  void midi_rebind (MIDI::channel_t channel=-1);
80  void midi_forget ();
82  void stop_learning ();
84 
85  int control_to_midi(float val);
86  float midi_to_control(int val);
87 
88  bool learned() const { return _learned; }
89 
90  CtlType get_ctltype() const { return _ctltype; }
91  void set_ctltype (CtlType val) { _ctltype = val; }
92 
93  Encoder get_encoder() const { return _encoder; }
94  void set_encoder (Encoder val) { _encoder = val; }
95 
97  void set_controllable (std::shared_ptr<PBD::Controllable>);
98  std::shared_ptr<PBD::Controllable> get_controllable () const;
99  const std::string& current_uri() const { return _current_uri; }
100 
101  std::string control_description() const { return _control_description; }
102 
103  XMLNode& get_state () const;
104  int set_state (const XMLNode&, int version);
105 
107  void bind_rpn_value (MIDI::channel_t, uint16_t rpn);
108  void bind_nrpn_value (MIDI::channel_t, uint16_t rpn);
109  void bind_rpn_change (MIDI::channel_t, uint16_t rpn);
110  void bind_nrpn_change (MIDI::channel_t, uint16_t rpn);
111 
115 
117 
118  void bind_remap (std::shared_ptr<ARDOUR::Stripable>);
119 
120 private:
121 
122  int max_value_for_type () const;
123 
125  std::shared_ptr<PBD::Controllable> _controllable;
126  std::string _current_uri;
128  bool setting;
134  bool _learned;
137  int midi_msg_id; /* controller ID or note number */
146  std::string _control_description;
147  int16_t control_rpn;
148  int16_t control_nrpn;
149  uint32_t _rid;
150  std::string _what;
152 
154  Glib::Threads::Mutex controllable_lock;
155 
156  void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t);
163 
164  void nrpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
165  void rpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
166  void rpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
167  void nrpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
168 };
169 
170 #endif // __gm_midicontrollable_h__
void midi_sense_note_on(MIDI::Parser &p, MIDI::EventTwoBytes *tb)
void bind_rpn_value(MIDI::channel_t, uint16_t rpn)
void drop_external_control()
MIDIControllable(GenericMidiControlProtocol *, MIDI::Parser &, std::shared_ptr< PBD::Controllable >, bool momentary)
void nrpn_value_change(MIDI::Parser &, uint16_t nrpn, float val)
float midi_to_control(int val)
bool learned() const
void bind_remap(std::shared_ptr< ARDOUR::Stripable >)
PBD::ScopedConnection midi_sense_connection[2]
std::shared_ptr< PBD::Controllable > _controllable
const std::string & current_uri() const
MIDI::Parser & get_parser()
int max_value_for_type() const
GenericMidiControlProtocol * _surface
void bind_nrpn_change(MIDI::channel_t, uint16_t rpn)
std::string what() const
void set_encoder(Encoder val)
void midi_sense_program_change(MIDI::Parser &, MIDI::byte)
void rediscover_controllable()
virtual ~MIDIControllable()
PBD::ScopedConnection controllable_remapped_connection
MIDI::channel_t control_channel
Encoder get_encoder() const
void midi_sense_controller(MIDI::Parser &, MIDI::EventTwoBytes *)
void learn_about_external_control()
std::string control_description() const
void midi_sense_pitchbend(MIDI::Parser &, MIDI::pitchbend_t)
void nrpn_change(MIDI::Parser &, uint16_t nrpn, int direction)
int lookup_controllable()
void rpn_change(MIDI::Parser &, uint16_t nrpn, int direction)
int set_state(const XMLNode &, int version)
void midi_sense_note(MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on)
void bind_midi(MIDI::channel_t, MIDI::eventType, MIDI::byte)
CtlType get_ctltype() const
void midi_sense_note_off(MIDI::Parser &p, MIDI::EventTwoBytes *tb)
MIDI::channel_t get_control_channel()
void drop_controllable()
void rpn_value_change(MIDI::Parser &, uint16_t nrpn, float val)
std::shared_ptr< PBD::Controllable > get_controllable() const
MIDI::byte control_additional
void set_controllable(std::shared_ptr< PBD::Controllable >)
void midi_receiver(MIDI::Parser &p, MIDI::byte *, size_t)
void set_ctltype(CtlType val)
XMLNode & get_state() const
Glib::Threads::Mutex controllable_lock
void bind_rpn_change(MIDI::channel_t, uint16_t rpn)
MIDI::eventType get_control_type()
int control_to_midi(float val)
std::string _current_uri
uint32_t rid() const
MIDI::byte * write_feedback(MIDI::byte *buf, int32_t &bufsize, bool force=false)
MIDI::eventType control_type
std::string _control_description
PBD::ScopedConnection controllable_death_connection
void bind_nrpn_value(MIDI::channel_t, uint16_t rpn)
MIDI::byte get_control_additional()
int init(const std::string &)
MIDIControllable(GenericMidiControlProtocol *, MIDI::Parser &, bool momentary=false)
bool bank_relative() const
PBD::ScopedConnection midi_learn_connection
MIDI::Parser & _parser
void midi_rebind(MIDI::channel_t channel=-1)
Definition: xml++.h:114
unsigned short pitchbend_t