2
Copyright (C) 2009 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.
21
#include "midi++/port.h"
23
#include "midifunction.h"
24
#include "generic_midi_control_protocol.h"
28
MIDIInvokable::MIDIInvokable (MIDI::Port& p)
35
MIDIInvokable::~MIDIInvokable ()
41
MIDIInvokable::init (GenericMidiControlProtocol& ui, const std::string& name, MIDI::byte* msg_data, size_t data_sz)
44
_invokable_name = name;
47
/* we take ownership of the sysex data */
56
MIDIInvokable::midi_sense_note_on (Parser &p, EventTwoBytes *tb)
58
midi_sense_note (p, tb, true);
62
MIDIInvokable::midi_sense_note_off (Parser &p, EventTwoBytes *tb)
64
midi_sense_note (p, tb, false);
68
MIDIInvokable::midi_sense_note (Parser &, EventTwoBytes *msg, bool /* is_on */)
70
if (msg->note_number == control_additional) {
76
MIDIInvokable::midi_sense_controller (Parser &, EventTwoBytes *msg)
78
if (control_additional == msg->controller_number) {
84
MIDIInvokable::midi_sense_program_change (Parser &, byte msg)
86
if (msg == control_additional) {
92
MIDIInvokable::midi_sense_sysex (Parser &, byte* msg, size_t sz)
94
if (sz != data_size) {
98
if (memcmp (msg, data, data_size) != 0) {
106
MIDIInvokable::midi_sense_any (Parser &, byte* msg, size_t sz)
108
if (sz != data_size) {
112
if (memcmp (msg, data, data_size) != 0) {
121
MIDIInvokable::bind_midi (channel_t chn, eventType ev, MIDI::byte additional)
123
midi_sense_connection[0].disconnect ();
124
midi_sense_connection[1].disconnect ();
127
control_channel = chn;
128
control_additional = additional;
130
if (_port.parser() == 0) {
134
Parser& p = *_port.parser();
138
/* incoming MIDI is parsed by Ardour' MidiUI event loop/thread, and we want our handlers to execute in that context, so we use
139
Signal::connect_same_thread() here.
144
p.channel_note_off[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_note_off, this, _1, _2));
148
p.channel_note_on[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_note_on, this, _1, _2));
151
case MIDI::controller:
152
p.channel_controller[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_controller, this, _1, _2));
156
p.channel_program_change[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_program_change, this, _1, _2));
160
p.sysex.connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_sysex, this, _1, _2, _3));
164
p.any.connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIInvokable::midi_sense_any, this, _1, _2, _3));