2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998-2006 Paul Davis
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __gm_midicontrollable_h__
|
|
|
|
#define __gm_midicontrollable_h__
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "midi++/types.h"
|
2009-12-19 15:26:31 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/controllable.h"
|
2009-12-19 15:26:31 -05:00
|
|
|
#include "pbd/signals.h"
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/stateful.h"
|
2009-12-19 15:26:31 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "ardour/types.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-31 18:43:47 -05:00
|
|
|
namespace PBD {
|
|
|
|
class ControllableDescriptor;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-31 18:43:47 -05:00
|
|
|
namespace MIDI {
|
|
|
|
class Channel;
|
|
|
|
class Parser;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-03-06 20:11:22 -05:00
|
|
|
class GenericMidiControlProtocol;
|
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
class AsyncMIDIPort;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
class MIDIControllable : public PBD::Stateful
|
|
|
|
{
|
|
|
|
public:
|
2013-08-07 22:22:11 -04:00
|
|
|
MIDIControllable (GenericMidiControlProtocol *, MIDI::Parser&, PBD::Controllable&, bool momentary);
|
|
|
|
MIDIControllable (GenericMidiControlProtocol *, MIDI::Parser&, bool momentary = false);
|
2008-06-02 17:41:35 -04:00
|
|
|
virtual ~MIDIControllable ();
|
|
|
|
|
2009-12-30 07:41:10 -05:00
|
|
|
int init (const std::string&);
|
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
void rediscover_controllable ();
|
2009-12-30 07:41:10 -05:00
|
|
|
bool bank_relative() const { return _bank_relative; }
|
|
|
|
uint32_t rid() const { return _rid; }
|
|
|
|
std::string what() const { return _what; }
|
2009-12-10 21:00:22 -05:00
|
|
|
|
2015-07-24 20:34:22 -04:00
|
|
|
enum Encoder {
|
|
|
|
No_enc,
|
|
|
|
Enc_R,
|
|
|
|
Enc_L,
|
|
|
|
Enc_2,
|
|
|
|
Enc_B,
|
|
|
|
};
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
|
|
|
|
|
|
|
|
void midi_rebind (MIDI::channel_t channel=-1);
|
|
|
|
void midi_forget ();
|
|
|
|
void learn_about_external_control ();
|
|
|
|
void stop_learning ();
|
|
|
|
void drop_external_control ();
|
|
|
|
|
|
|
|
bool get_midi_feedback () { return feedback; }
|
|
|
|
void set_midi_feedback (bool val) { feedback = val; }
|
|
|
|
|
2012-03-06 20:11:22 -05:00
|
|
|
int control_to_midi(float val);
|
|
|
|
float midi_to_control(int val);
|
2009-02-18 17:30:06 -05:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
bool learned() const { return _learned; }
|
|
|
|
|
2015-07-24 20:34:22 -04:00
|
|
|
Encoder get_encoder() const { return _encoder; }
|
|
|
|
void set_encoder (Encoder val) { _encoder = val; }
|
2015-07-21 02:15:53 -04:00
|
|
|
|
2015-07-24 20:34:22 -04:00
|
|
|
MIDI::Parser& get_parser() { return _parser; }
|
2009-12-10 21:00:22 -05:00
|
|
|
PBD::Controllable* get_controllable() const { return controllable; }
|
2009-12-28 11:49:44 -05:00
|
|
|
void set_controllable (PBD::Controllable*);
|
|
|
|
const std::string& current_uri() const { return _current_uri; }
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-31 18:43:47 -05:00
|
|
|
PBD::ControllableDescriptor& descriptor() const { return *_descriptor; }
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
std::string control_description() const { return _control_description; }
|
|
|
|
|
|
|
|
XMLNode& get_state (void);
|
2009-10-15 14:56:11 -04:00
|
|
|
int set_state (const XMLNode&, int version);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
|
|
|
|
MIDI::channel_t get_control_channel () { return control_channel; }
|
|
|
|
MIDI::eventType get_control_type () { return control_type; }
|
|
|
|
MIDI::byte get_control_additional () { return control_additional; }
|
2012-06-28 10:44:29 -04:00
|
|
|
|
|
|
|
int lookup_controllable();
|
2009-12-10 21:00:22 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
private:
|
2012-03-06 10:08:17 -05:00
|
|
|
|
|
|
|
int max_value_for_type () const;
|
2012-03-06 20:11:22 -05:00
|
|
|
|
|
|
|
GenericMidiControlProtocol* _surface;
|
2009-12-10 21:00:22 -05:00
|
|
|
PBD::Controllable* controllable;
|
2009-12-31 18:43:47 -05:00
|
|
|
PBD::ControllableDescriptor* _descriptor;
|
2013-08-07 22:22:11 -04:00
|
|
|
std::string _current_uri;
|
|
|
|
MIDI::Parser& _parser;
|
2008-06-02 17:41:35 -04:00
|
|
|
bool setting;
|
2012-03-06 10:08:17 -05:00
|
|
|
int last_value;
|
2011-12-14 10:57:48 -05:00
|
|
|
float last_controllable_value;
|
2010-01-01 13:14:32 -05:00
|
|
|
bool _momentary;
|
2009-12-30 11:48:58 -05:00
|
|
|
bool _is_gain_controller;
|
2009-12-29 16:31:14 -05:00
|
|
|
bool _learned;
|
2015-07-24 20:34:22 -04:00
|
|
|
Encoder _encoder;
|
2008-06-02 17:41:35 -04:00
|
|
|
int midi_msg_id; /* controller ID or note number */
|
2009-12-19 15:26:31 -05:00
|
|
|
PBD::ScopedConnection midi_sense_connection[2];
|
|
|
|
PBD::ScopedConnection midi_learn_connection;
|
2012-06-25 21:55:53 -04:00
|
|
|
PBD::ScopedConnection controllable_death_connection;
|
2012-03-06 10:08:17 -05:00
|
|
|
/** the type of MIDI message that is used for this control */
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDI::eventType control_type;
|
|
|
|
MIDI::byte control_additional;
|
|
|
|
MIDI::channel_t control_channel;
|
|
|
|
std::string _control_description;
|
|
|
|
bool feedback;
|
2009-12-30 07:41:10 -05:00
|
|
|
uint32_t _rid;
|
|
|
|
std::string _what;
|
|
|
|
bool _bank_relative;
|
2012-06-25 08:33:13 -04:00
|
|
|
|
2012-06-25 21:55:53 -04:00
|
|
|
void drop_controllable();
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t);
|
|
|
|
void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on);
|
|
|
|
void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
|
|
|
|
void midi_sense_note_off (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
|
|
|
|
void midi_sense_controller (MIDI::Parser &, MIDI::EventTwoBytes *);
|
|
|
|
void midi_sense_program_change (MIDI::Parser &, MIDI::byte);
|
|
|
|
void midi_sense_pitchbend (MIDI::Parser &, MIDI::pitchbend_t);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __gm_midicontrollable_h__
|
|
|
|
|