2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998-2006 Paul Davis
|
|
|
|
|
|
|
|
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 Port;
|
|
|
|
class Parser;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class MIDIControllable : public PBD::Stateful
|
|
|
|
{
|
|
|
|
public:
|
2010-01-01 13:14:32 -05:00
|
|
|
MIDIControllable (MIDI::Port&, PBD::Controllable&, bool momentary);
|
|
|
|
MIDIControllable (MIDI::Port&, 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
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void send_feedback ();
|
|
|
|
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; }
|
|
|
|
|
2009-02-18 17:30:06 -05:00
|
|
|
float control_to_midi(float val);
|
|
|
|
float midi_to_control(float val);
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
bool learned() const { return _learned; }
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDI::Port& get_port() const { return _port; }
|
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; }
|
2009-12-10 21:00:22 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
private:
|
2009-12-10 21:00:22 -05:00
|
|
|
PBD::Controllable* controllable;
|
2009-12-31 18:43:47 -05:00
|
|
|
PBD::ControllableDescriptor* _descriptor;
|
2009-12-10 21:00:22 -05:00
|
|
|
std::string _current_uri;
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDI::Port& _port;
|
|
|
|
bool setting;
|
|
|
|
MIDI::byte 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;
|
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;
|
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;
|
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__
|
|
|
|
|