2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-03 08:34:29 -04:00
|
|
|
* Copyright (C) 2006-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2007-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2009 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Len Ovens <len@ovenwerks.net>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#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 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
|
|
|
|
{
|
2019-03-22 21:09:39 -04:00
|
|
|
public:
|
|
|
|
MIDIControllable (GenericMidiControlProtocol*, MIDI::Parser&, boost::shared_ptr<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
|
|
|
|
2018-03-03 08:04:12 -05:00
|
|
|
enum CtlType {
|
|
|
|
Ctl_Momentary,
|
|
|
|
Ctl_Toggle,
|
2018-06-21 22:28:11 -04:00
|
|
|
Ctl_Dial,
|
2018-03-03 08:04:12 -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);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void midi_rebind (MIDI::channel_t channel=-1);
|
|
|
|
void midi_forget ();
|
|
|
|
void learn_about_external_control ();
|
|
|
|
void stop_learning ();
|
|
|
|
void drop_external_control ();
|
|
|
|
|
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; }
|
|
|
|
|
2018-03-03 08:04:12 -05:00
|
|
|
CtlType get_ctltype() const { return _ctltype; }
|
|
|
|
void set_ctltype (CtlType val) { _ctltype = val; }
|
|
|
|
|
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; }
|
2019-03-22 21:09:39 -04:00
|
|
|
void set_controllable (boost::shared_ptr<PBD::Controllable>);
|
|
|
|
boost::shared_ptr<PBD::Controllable> get_controllable () const;
|
2009-12-28 11:49:44 -05:00
|
|
|
const std::string& current_uri() const { return _current_uri; }
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
std::string control_description() const { return _control_description; }
|
|
|
|
|
2022-04-06 23:56:32 -04:00
|
|
|
XMLNode& get_state () const;
|
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);
|
2015-11-23 12:26:23 -05:00
|
|
|
void bind_rpn_value (MIDI::channel_t, uint16_t rpn);
|
|
|
|
void bind_nrpn_value (MIDI::channel_t, uint16_t rpn);
|
|
|
|
void bind_rpn_change (MIDI::channel_t, uint16_t rpn);
|
|
|
|
void bind_nrpn_change (MIDI::channel_t, uint16_t rpn);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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
|
|
|
|
2019-03-22 21:09:39 -04:00
|
|
|
int lookup_controllable();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-03-22 21:09:39 -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;
|
2019-03-23 11:32:48 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> _controllable;
|
2013-08-07 22:22:11 -04:00
|
|
|
std::string _current_uri;
|
2019-03-22 21:09:39 -04:00
|
|
|
MIDI::Parser& _parser;
|
2008-06-02 17:41:35 -04:00
|
|
|
bool setting;
|
2012-03-06 10:08:17 -05:00
|
|
|
int last_value;
|
2018-06-21 22:28:11 -04:00
|
|
|
int last_incoming;
|
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;
|
2018-03-03 08:04:12 -05:00
|
|
|
CtlType _ctltype;
|
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;
|
2021-06-20 23:27:11 -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;
|
2015-11-23 12:26:23 -05:00
|
|
|
int16_t control_rpn;
|
|
|
|
int16_t control_nrpn;
|
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
|
|
|
|
2019-03-23 11:32:48 -04:00
|
|
|
void drop_controllable ();
|
|
|
|
Glib::Threads::Mutex controllable_lock;
|
2012-06-25 21:55:53 -04:00
|
|
|
|
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);
|
2015-11-23 12:26:23 -05:00
|
|
|
|
|
|
|
void nrpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
|
|
|
|
void rpn_value_change (MIDI::Parser&, uint16_t nrpn, float val);
|
|
|
|
void rpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
|
|
|
|
void nrpn_change (MIDI::Parser&, uint16_t nrpn, int direction);
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __gm_midicontrollable_h__
|