SVG of thorsten's editor track/bus list icons
[ardour2.git] / libs / surfaces / generic_midi / midicontrollable.h
blob2e70e98a751e461c68a7b886accf86e21df2fd3d
1 /*
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__
23 #include <string>
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"
33 namespace PBD {
34 class ControllableDescriptor;
37 namespace MIDI {
38 class Channel;
39 class Port;
40 class Parser;
43 class MIDIControllable : public PBD::Stateful
45 public:
46 MIDIControllable (MIDI::Port&, PBD::Controllable&, bool momentary);
47 MIDIControllable (MIDI::Port&, bool momentary = false);
48 virtual ~MIDIControllable ();
50 int init (const std::string&);
52 void rediscover_controllable ();
53 bool bank_relative() const { return _bank_relative; }
54 uint32_t rid() const { return _rid; }
55 std::string what() const { return _what; }
57 void send_feedback ();
58 MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
60 void midi_rebind (MIDI::channel_t channel=-1);
61 void midi_forget ();
62 void learn_about_external_control ();
63 void stop_learning ();
64 void drop_external_control ();
66 bool get_midi_feedback () { return feedback; }
67 void set_midi_feedback (bool val) { feedback = val; }
69 float control_to_midi(float val);
70 float midi_to_control(float val);
72 bool learned() const { return _learned; }
74 MIDI::Port& get_port() const { return _port; }
75 PBD::Controllable* get_controllable() const { return controllable; }
76 void set_controllable (PBD::Controllable*);
77 const std::string& current_uri() const { return _current_uri; }
79 PBD::ControllableDescriptor& descriptor() const { return *_descriptor; }
81 std::string control_description() const { return _control_description; }
83 XMLNode& get_state (void);
84 int set_state (const XMLNode&, int version);
86 void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
87 MIDI::channel_t get_control_channel () { return control_channel; }
88 MIDI::eventType get_control_type () { return control_type; }
89 MIDI::byte get_control_additional () { return control_additional; }
91 private:
92 PBD::Controllable* controllable;
93 PBD::ControllableDescriptor* _descriptor;
94 std::string _current_uri;
95 MIDI::Port& _port;
96 bool setting;
97 MIDI::byte last_value;
98 bool _momentary;
99 bool _is_gain_controller;
100 bool _learned;
101 int midi_msg_id; /* controller ID or note number */
102 PBD::ScopedConnection midi_sense_connection[2];
103 PBD::ScopedConnection midi_learn_connection;
104 MIDI::eventType control_type;
105 MIDI::byte control_additional;
106 MIDI::channel_t control_channel;
107 std::string _control_description;
108 bool feedback;
109 uint32_t _rid;
110 std::string _what;
111 bool _bank_relative;
113 void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t);
114 void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on);
115 void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
116 void midi_sense_note_off (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
117 void midi_sense_controller (MIDI::Parser &, MIDI::EventTwoBytes *);
118 void midi_sense_program_change (MIDI::Parser &, MIDI::byte);
119 void midi_sense_pitchbend (MIDI::Parser &, MIDI::pitchbend_t);
122 #endif // __gm_midicontrollable_h__