2 Copyright (C) 1998-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 __gm_midicontrollable_h__
21 #define __gm_midicontrollable_h__
25 #include "midi++/types.h"
27 #include "pbd/controllable.h"
28 #include "pbd/signals.h"
29 #include "pbd/stateful.h"
31 #include "ardour/types.h"
34 class ControllableDescriptor;
42 class GenericMidiControlProtocol;
48 class MIDIControllable : public PBD::Stateful
51 MIDIControllable (GenericMidiControlProtocol *, MIDI::Parser&, PBD::Controllable&, bool momentary);
52 MIDIControllable (GenericMidiControlProtocol *, MIDI::Parser&, bool momentary = false);
53 virtual ~MIDIControllable ();
55 int init (const std::string&);
57 void rediscover_controllable ();
58 bool bank_relative() const { return _bank_relative; }
59 uint32_t rid() const { return _rid; }
60 std::string what() const { return _what; }
70 MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
72 void midi_rebind (MIDI::channel_t channel=-1);
74 void learn_about_external_control ();
75 void stop_learning ();
76 void drop_external_control ();
78 int control_to_midi(float val);
79 float midi_to_control(int val);
81 bool learned() const { return _learned; }
83 Encoder get_encoder() const { return _encoder; }
84 void set_encoder (Encoder val) { _encoder = val; }
86 MIDI::Parser& get_parser() { return _parser; }
87 PBD::Controllable* get_controllable() const { return controllable; }
88 void set_controllable (PBD::Controllable*);
89 const std::string& current_uri() const { return _current_uri; }
91 ARDOUR::ControllableDescriptor& descriptor() const { return *_descriptor; }
93 std::string control_description() const { return _control_description; }
95 XMLNode& get_state (void);
96 int set_state (const XMLNode&, int version);
98 void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
99 void bind_rpn_value (MIDI::channel_t, uint16_t rpn);
100 void bind_nrpn_value (MIDI::channel_t, uint16_t rpn);
101 void bind_rpn_change (MIDI::channel_t, uint16_t rpn);
102 void bind_nrpn_change (MIDI::channel_t, uint16_t rpn);
104 MIDI::channel_t get_control_channel () { return control_channel; }
105 MIDI::eventType get_control_type () { return control_type; }
106 MIDI::byte get_control_additional () { return control_additional; }
108 int lookup_controllable();
112 int max_value_for_type () const;
114 GenericMidiControlProtocol* _surface;
115 PBD::Controllable* controllable;
116 ARDOUR::ControllableDescriptor* _descriptor;
117 std::string _current_uri;
118 MIDI::Parser& _parser;
121 float last_controllable_value;
123 bool _is_gain_controller;
126 int midi_msg_id; /* controller ID or note number */
127 PBD::ScopedConnection midi_sense_connection[2];
128 PBD::ScopedConnection midi_learn_connection;
129 PBD::ScopedConnection controllable_death_connection;
130 /** the type of MIDI message that is used for this control */
131 MIDI::eventType control_type;
132 MIDI::byte control_additional;
133 MIDI::channel_t control_channel;
134 std::string _control_description;
136 int16_t control_nrpn;
141 void drop_controllable (PBD::Controllable*);
143 void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t);
144 void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on);
145 void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
146 void midi_sense_note_off (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
147 void midi_sense_controller (MIDI::Parser &, MIDI::EventTwoBytes *);
148 void midi_sense_program_change (MIDI::Parser &, MIDI::byte);
149 void midi_sense_pitchbend (MIDI::Parser &, MIDI::pitchbend_t);
151 void nrpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
152 void rpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
153 void rpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
154 void nrpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
158 #endif // __gm_midicontrollable_h__