2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998-2006 Paul Davis
|
2009-10-20 20:15:42 -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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-12-30 07:41:10 -05:00
|
|
|
#define __STDC_FORMAT_MACROS 1
|
|
|
|
#include <stdint.h>
|
2010-01-01 13:14:32 -05:00
|
|
|
#include <cmath>
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <climits>
|
2009-12-21 13:23:07 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/error.h"
|
2009-12-31 18:43:47 -05:00
|
|
|
#include "pbd/controllable_descriptor.h"
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/xml++.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "midi++/port.h"
|
|
|
|
#include "midi++/channel.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "ardour/automation_control.h"
|
2009-12-30 11:48:58 -05:00
|
|
|
#include "ardour/utils.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "midicontrollable.h"
|
|
|
|
|
2009-12-10 22:18:17 -05:00
|
|
|
using namespace std;
|
2008-06-02 17:41:35 -04:00
|
|
|
using namespace MIDI;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
MIDIControllable::MIDIControllable (Port& p, bool m)
|
2009-12-30 07:41:10 -05:00
|
|
|
: controllable (0)
|
2009-12-31 18:43:47 -05:00
|
|
|
, _descriptor (0)
|
2009-12-30 07:41:10 -05:00
|
|
|
, _port (p)
|
2010-01-01 13:14:32 -05:00
|
|
|
, _momentary (m)
|
2009-12-10 21:00:22 -05:00
|
|
|
{
|
2009-12-30 07:41:10 -05:00
|
|
|
_learned = false; /* from URI */
|
|
|
|
setting = false;
|
|
|
|
last_value = 0; // got a better idea ?
|
|
|
|
control_type = none;
|
|
|
|
_control_description = "MIDI Control: none";
|
|
|
|
control_additional = (byte) -1;
|
|
|
|
feedback = true; // for now
|
2009-12-10 21:00:22 -05:00
|
|
|
}
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
MIDIControllable::MIDIControllable (Port& p, Controllable& c, bool m)
|
2009-12-30 07:41:10 -05:00
|
|
|
: controllable (&c)
|
2009-12-31 18:43:47 -05:00
|
|
|
, _descriptor (0)
|
2009-12-30 07:41:10 -05:00
|
|
|
, _port (p)
|
2010-01-01 13:14:32 -05:00
|
|
|
, _momentary (m)
|
2009-12-10 21:00:22 -05:00
|
|
|
{
|
2009-12-30 07:41:10 -05:00
|
|
|
_learned = true; /* from controllable */
|
|
|
|
setting = false;
|
|
|
|
last_value = 0; // got a better idea ?
|
|
|
|
control_type = none;
|
|
|
|
_control_description = "MIDI Control: none";
|
|
|
|
control_additional = (byte) -1;
|
|
|
|
feedback = true; // for now
|
2009-12-10 21:00:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MIDIControllable::~MIDIControllable ()
|
|
|
|
{
|
|
|
|
drop_external_control ();
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:41:10 -05:00
|
|
|
int
|
|
|
|
MIDIControllable::init (const std::string& s)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-12-30 07:41:10 -05:00
|
|
|
_current_uri = s;
|
2009-12-31 18:43:47 -05:00
|
|
|
delete _descriptor;
|
|
|
|
_descriptor = new ControllableDescriptor;
|
|
|
|
return _descriptor->set (s);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::midi_forget ()
|
|
|
|
{
|
|
|
|
/* stop listening for incoming messages, but retain
|
|
|
|
our existing event + type information.
|
|
|
|
*/
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
midi_sense_connection[0].disconnect ();
|
|
|
|
midi_sense_connection[1].disconnect ();
|
|
|
|
midi_learn_connection.disconnect ();
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
void
|
|
|
|
MIDIControllable::drop_external_control ()
|
|
|
|
{
|
2009-12-30 07:41:10 -05:00
|
|
|
midi_forget ();
|
2009-12-19 15:26:31 -05:00
|
|
|
control_type = none;
|
|
|
|
control_additional = (byte) -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-12-10 21:00:22 -05:00
|
|
|
void
|
2009-12-28 11:49:44 -05:00
|
|
|
MIDIControllable::set_controllable (Controllable* c)
|
2009-12-10 21:00:22 -05:00
|
|
|
{
|
2009-12-28 11:49:44 -05:00
|
|
|
controllable = c;
|
2009-12-10 21:00:22 -05:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
|
|
|
MIDIControllable::midi_rebind (channel_t c)
|
|
|
|
{
|
|
|
|
if (c >= 0) {
|
|
|
|
bind_midi (c, control_type, control_additional);
|
|
|
|
} else {
|
|
|
|
midi_forget ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::learn_about_external_control ()
|
|
|
|
{
|
|
|
|
drop_external_control ();
|
2009-12-21 13:23:07 -05:00
|
|
|
_port.input()->any.connect_same_thread (midi_learn_connection, boost::bind (&MIDIControllable::midi_receiver, this, _1, _2, _3));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::stop_learning ()
|
|
|
|
{
|
|
|
|
midi_learn_connection.disconnect ();
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:30:06 -05:00
|
|
|
float
|
|
|
|
MIDIControllable::control_to_midi(float val)
|
|
|
|
{
|
|
|
|
float control_min = 0.0f;
|
|
|
|
float control_max = 1.0f;
|
2009-12-10 22:18:17 -05:00
|
|
|
ARDOUR::AutomationControl* ac = dynamic_cast<ARDOUR::AutomationControl*>(controllable);
|
2009-02-18 17:30:06 -05:00
|
|
|
if (ac) {
|
|
|
|
control_min = ac->parameter().min();
|
|
|
|
control_max = ac->parameter().max();
|
|
|
|
}
|
|
|
|
|
|
|
|
const float control_range = control_max - control_min;
|
|
|
|
const float midi_range = 127.0f; // TODO: NRPN etc.
|
|
|
|
|
|
|
|
return (val - control_min) / control_range * midi_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
MIDIControllable::midi_to_control(float val)
|
|
|
|
{
|
|
|
|
float control_min = 0.0f;
|
|
|
|
float control_max = 1.0f;
|
2009-12-10 22:18:17 -05:00
|
|
|
ARDOUR::AutomationControl* ac = dynamic_cast<ARDOUR::AutomationControl*>(controllable);
|
2009-12-30 14:33:52 -05:00
|
|
|
|
|
|
|
const float midi_range = 127.0f; // TODO: NRPN etc.
|
|
|
|
|
2009-02-18 17:30:06 -05:00
|
|
|
if (ac) {
|
2009-12-30 14:33:52 -05:00
|
|
|
|
|
|
|
if (ac->is_gain_like()) {
|
|
|
|
return slider_position_to_gain (val/midi_range);
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:30:06 -05:00
|
|
|
control_min = ac->parameter().min();
|
|
|
|
control_max = ac->parameter().max();
|
|
|
|
}
|
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
const float control_range = control_max - control_min;
|
|
|
|
return val / midi_range * control_range + control_min;
|
2009-02-18 17:30:06 -05:00
|
|
|
}
|
|
|
|
|
2009-10-20 20:15:42 -04:00
|
|
|
void
|
|
|
|
MIDIControllable::midi_sense_note_on (Parser &p, EventTwoBytes *tb)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
midi_sense_note (p, tb, true);
|
|
|
|
}
|
|
|
|
|
2009-10-20 20:15:42 -04:00
|
|
|
void
|
|
|
|
MIDIControllable::midi_sense_note_off (Parser &p, EventTwoBytes *tb)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
midi_sense_note (p, tb, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-04 13:15:29 -05:00
|
|
|
MIDIControllable::midi_sense_note (Parser &, EventTwoBytes *msg, bool is_on)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-12-10 21:00:22 -05:00
|
|
|
if (!controllable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
|
|
|
|
if (!controllable->is_toggle()) {
|
2009-12-10 21:00:22 -05:00
|
|
|
controllable->set_value (msg->note_number/127.0);
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
if (control_additional == msg->note_number) {
|
|
|
|
controllable->set_value (controllable->get_value() > 0.5f ? 0.0f : 1.0f);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 21:00:22 -05:00
|
|
|
last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
|
|
|
|
{
|
2009-12-10 21:00:22 -05:00
|
|
|
if (!controllable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controllable->touching()) {
|
2009-02-18 18:54:41 -05:00
|
|
|
return; // to prevent feedback fights when e.g. dragging a UI slider
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (control_additional == msg->controller_number) {
|
2010-01-01 13:14:32 -05:00
|
|
|
|
|
|
|
if (!controllable->is_toggle()) {
|
|
|
|
controllable->set_value (midi_to_control (msg->value));
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2010-01-01 13:14:32 -05:00
|
|
|
if (msg->value > 64.0f) {
|
2009-12-10 21:00:22 -05:00
|
|
|
controllable->set_value (1);
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2009-12-10 21:00:22 -05:00
|
|
|
controllable->set_value (0);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 21:00:22 -05:00
|
|
|
last_value = (MIDI::byte) (control_to_midi(controllable->get_value())); // to prevent feedback fights
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
MIDIControllable::midi_sense_program_change (Parser &, byte msg)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-12-10 21:00:22 -05:00
|
|
|
if (!controllable) {
|
|
|
|
return;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
if (!controllable->is_toggle()) {
|
2009-12-10 21:00:22 -05:00
|
|
|
controllable->set_value (msg/127.0);
|
2010-01-01 13:14:32 -05:00
|
|
|
} else {
|
|
|
|
controllable->set_value (controllable->get_value() > 0.5f ? 0.0f : 1.0f);
|
2009-10-20 20:15:42 -04:00
|
|
|
}
|
2010-01-01 13:14:32 -05:00
|
|
|
|
|
|
|
last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
MIDIControllable::midi_sense_pitchbend (Parser &, pitchbend_t pb)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-12-10 21:00:22 -05:00
|
|
|
if (!controllable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
if (!controllable->is_toggle()) {
|
|
|
|
/* XXX gack - get rid of assumption about typeof pitchbend_t */
|
|
|
|
controllable->set_value ((pb/(float) SHRT_MAX));
|
|
|
|
} else {
|
|
|
|
controllable->set_value (controllable->get_value() > 0.5f ? 0.0f : 1.0f);
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-10 21:00:22 -05:00
|
|
|
last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights
|
2009-10-20 20:15:42 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
MIDIControllable::midi_receiver (Parser &, byte *msg, size_t /*len*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
/* we only respond to channel messages */
|
|
|
|
|
|
|
|
if ((msg[0] & 0xF0) < 0x80 || (msg[0] & 0xF0) > 0xE0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the our port doesn't do input anymore, forget it ... */
|
|
|
|
|
|
|
|
if (!_port.input()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_midi ((channel_t) (msg[0] & 0xf), eventType (msg[0] & 0xF0), msg[1]);
|
|
|
|
|
2009-12-10 21:00:22 -05:00
|
|
|
controllable->LearningFinished ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::bind_midi (channel_t chn, eventType ev, MIDI::byte additional)
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
drop_external_control ();
|
|
|
|
|
|
|
|
control_type = ev;
|
|
|
|
control_channel = chn;
|
|
|
|
control_additional = additional;
|
|
|
|
|
|
|
|
if (_port.input() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
Parser& p = *_port.input();
|
|
|
|
|
|
|
|
int chn_i = chn;
|
|
|
|
switch (ev) {
|
|
|
|
case MIDI::off:
|
2009-12-21 13:23:07 -05:00
|
|
|
p.channel_note_off[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIControllable::midi_sense_note_off, this, _1, _2));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
/* if this is a togglee, connect to noteOn as well,
|
2008-06-02 17:41:35 -04:00
|
|
|
and we'll toggle back and forth between the two.
|
|
|
|
*/
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
if (_momentary) {
|
2009-12-21 13:23:07 -05:00
|
|
|
p.channel_note_on[chn_i].connect_same_thread (midi_sense_connection[1], boost::bind (&MIDIControllable::midi_sense_note_on, this, _1, _2));
|
2009-12-19 15:26:31 -05:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_control_description = "MIDI control: NoteOff";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDI::on:
|
2009-12-21 13:23:07 -05:00
|
|
|
p.channel_note_on[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIControllable::midi_sense_note_on, this, _1, _2));
|
2010-01-01 13:14:32 -05:00
|
|
|
if (_momentary) {
|
2009-12-21 13:23:07 -05:00
|
|
|
p.channel_note_off[chn_i].connect_same_thread (midi_sense_connection[1], boost::bind (&MIDIControllable::midi_sense_note_off, this, _1, _2));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
_control_description = "MIDI control: NoteOn";
|
|
|
|
break;
|
2009-12-17 13:24:23 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
case MIDI::controller:
|
2009-12-21 13:23:07 -05:00
|
|
|
p.channel_controller[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIControllable::midi_sense_controller, this, _1, _2));
|
2008-06-02 17:41:35 -04:00
|
|
|
snprintf (buf, sizeof (buf), "MIDI control: Controller %d", control_additional);
|
|
|
|
_control_description = buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDI::program:
|
2010-01-01 13:14:32 -05:00
|
|
|
p.channel_program_change[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIControllable::midi_sense_program_change, this, _1, _2));
|
|
|
|
_control_description = "MIDI control: ProgramChange";
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDI::pitchbend:
|
2010-01-01 13:14:32 -05:00
|
|
|
p.channel_pitchbend[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIControllable::midi_sense_pitchbend, this, _1, _2));
|
|
|
|
_control_description = "MIDI control: Pitchbend";
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MIDIControllable::send_feedback ()
|
|
|
|
{
|
|
|
|
byte msg[3];
|
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
if (!_learned || setting || !feedback || control_type == none) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-20 20:15:42 -04:00
|
|
|
msg[0] = (control_type & 0xF0) | (control_channel & 0xF);
|
2008-06-02 17:41:35 -04:00
|
|
|
msg[1] = control_additional;
|
2010-01-01 13:14:32 -05:00
|
|
|
|
|
|
|
if (controllable->is_gain_like()) {
|
|
|
|
msg[2] = (byte) lrintf (gain_to_slider_position (controllable->get_value()) * 127.0f);
|
|
|
|
} else {
|
|
|
|
msg[2] = (byte) (control_to_midi(controllable->get_value()));
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-18 15:53:54 -05:00
|
|
|
_port.write (msg, 3, 0);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MIDI::byte*
|
2009-07-21 11:55:17 -04:00
|
|
|
MIDIControllable::write_feedback (MIDI::byte* buf, int32_t& bufsize, bool /*force*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
if (control_type != none && feedback && bufsize > 2) {
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2010-01-01 13:14:32 -05:00
|
|
|
MIDI::byte gm;
|
|
|
|
|
|
|
|
if (controllable->is_gain_like()) {
|
|
|
|
gm = (byte) lrintf (gain_to_slider_position (controllable->get_value()) * 127.0f);
|
|
|
|
} else {
|
|
|
|
gm = (byte) (control_to_midi(controllable->get_value()));
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (gm != last_value) {
|
|
|
|
*buf++ = (0xF0 & control_type) | (0xF & control_channel);
|
|
|
|
*buf++ = control_additional; /* controller number */
|
|
|
|
*buf++ = gm;
|
|
|
|
last_value = gm;
|
|
|
|
bufsize -= 3;
|
|
|
|
}
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2009-10-20 20:15:42 -04:00
|
|
|
int
|
|
|
|
MIDIControllable::set_state (const XMLNode& node, int /*version*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
const XMLProperty* prop;
|
|
|
|
int xx;
|
|
|
|
|
|
|
|
if ((prop = node.property ("event")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "0x%x", &xx);
|
|
|
|
control_type = (MIDI::eventType) xx;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = node.property ("channel")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "%d", &xx);
|
|
|
|
control_channel = (MIDI::channel_t) xx;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = node.property ("additional")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "0x%x", &xx);
|
|
|
|
control_additional = (MIDI::byte) xx;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = node.property ("feedback")) != 0) {
|
|
|
|
feedback = (prop->value() == "yes");
|
|
|
|
} else {
|
|
|
|
feedback = true; // default
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_midi (control_channel, control_type, control_additional);
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
MIDIControllable::get_state ()
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
2009-12-10 22:18:17 -05:00
|
|
|
XMLNode* node = new XMLNode ("MIDIControllable");
|
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
if (!_current_uri.empty()) {
|
|
|
|
node->add_property ("uri", _current_uri);
|
|
|
|
}
|
|
|
|
|
2009-12-10 22:18:17 -05:00
|
|
|
if (controllable) {
|
|
|
|
snprintf (buf, sizeof(buf), "0x%x", (int) control_type);
|
|
|
|
node->add_property ("event", buf);
|
|
|
|
snprintf (buf, sizeof(buf), "%d", (int) control_channel);
|
|
|
|
node->add_property ("channel", buf);
|
|
|
|
snprintf (buf, sizeof(buf), "0x%x", (int) control_additional);
|
|
|
|
node->add_property ("additional", buf);
|
|
|
|
node->add_property ("feedback", (feedback ? "yes" : "no"));
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-10 22:18:17 -05:00
|
|
|
return *node;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|