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 MIDIFunction::MIDIFunction (MIDI::Port& p)
35 MIDIFunction::~MIDIFunction ()
41 MIDIFunction::init (GenericMidiControlProtocol& ui, const std::string& function_name, MIDI::byte* sysex_data, size_t sysex_sz)
43 if (strcasecmp (function_name.c_str(), "transport-stop") == 0) {
44 _function = TransportStop;
45 } else if (strcasecmp (function_name.c_str(), "transport-roll") == 0) {
46 _function = TransportRoll;
47 } else if (strcasecmp (function_name.c_str(), "transport-zero") == 0) {
48 _function = TransportZero;
49 } else if (strcasecmp (function_name.c_str(), "transport-start") == 0) {
50 _function = TransportStart;
51 } else if (strcasecmp (function_name.c_str(), "transport-end") == 0) {
52 _function = TransportEnd;
53 } else if (strcasecmp (function_name.c_str(), "loop-toggle") == 0) {
54 _function = TransportLoopToggle;
55 } else if (strcasecmp (function_name.c_str(), "rec-enable") == 0) {
56 _function = TransportRecordEnable;
57 } else if (strcasecmp (function_name.c_str(), "rec-disable") == 0) {
58 _function = TransportRecordDisable;
59 } else if (strcasecmp (function_name.c_str(), "next-bank") == 0) {
61 } else if (strcasecmp (function_name.c_str(), "prev-bank") == 0) {
70 /* we take ownership of the sysex data */
72 sysex_size = sysex_sz;
79 MIDIFunction::execute ()
91 _ui->transport_stop ();
95 _ui->transport_play ();
103 // need this in BasicUI
110 case TransportLoopToggle:
114 case TransportRecordEnable:
115 _ui->set_record_enable (true);
118 case TransportRecordDisable:
119 _ui->set_record_enable (false);
125 MIDIFunction::midi_sense_note_on (Parser &p, EventTwoBytes *tb)
127 midi_sense_note (p, tb, true);
131 MIDIFunction::midi_sense_note_off (Parser &p, EventTwoBytes *tb)
133 midi_sense_note (p, tb, false);
137 MIDIFunction::midi_sense_note (Parser &, EventTwoBytes *msg, bool /* is_on */)
139 if (msg->note_number == control_additional) {
145 MIDIFunction::midi_sense_controller (Parser &, EventTwoBytes *msg)
147 if (control_additional == msg->controller_number) {
153 MIDIFunction::midi_sense_program_change (Parser &, byte msg)
155 if (msg == control_additional) {
161 MIDIFunction::midi_sense_sysex (Parser &, byte* msg, size_t sz)
163 if (sz != sysex_size) {
167 if (memcmp (msg, sysex, sysex_size) != 0) {
175 MIDIFunction::bind_midi (channel_t chn, eventType ev, MIDI::byte additional)
177 midi_sense_connection[0].disconnect ();
178 midi_sense_connection[1].disconnect ();
181 control_channel = chn;
182 control_additional = additional;
184 if (_port.input() == 0) {
188 Parser& p = *_port.input();
192 /* incoming MIDI is parsed by Ardour' MidiUI event loop/thread, and we want our handlers to execute in that context, so we use
193 Signal::connect_same_thread() here.
198 p.channel_note_off[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIFunction::midi_sense_note_off, this, _1, _2));
202 p.channel_note_on[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIFunction::midi_sense_note_on, this, _1, _2));
205 case MIDI::controller:
206 p.channel_controller[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIFunction::midi_sense_controller, this, _1, _2));
210 p.channel_program_change[chn_i].connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIFunction::midi_sense_program_change, this, _1, _2));
214 p.sysex.connect_same_thread (midi_sense_connection[0], boost::bind (&MIDIFunction::midi_sense_sysex, this, _1, _2, _3));
223 MIDIFunction::get_state ()
225 XMLNode* node = new XMLNode ("MIDIFunction");
230 MIDIFunction::set_state (const XMLNode& node, int version)