2 Copyright (C) 2014 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.
20 #include "pbd/error.h"
21 #include "pbd/compose.h"
23 #include "ardour/midi_port.h"
24 #include "ardour/midi_scene_change.h"
29 using namespace ARDOUR;
31 MIDISceneChange::MIDISceneChange (int c, int b, int p)
35 , _color (0x00000000) /* note: zero alpha means invisible, which acts as out-of-bound signal */
46 MIDISceneChange::MIDISceneChange (const XMLNode& node, int version)
51 set_state (node, version);
54 MIDISceneChange::~MIDISceneChange ()
59 MIDISceneChange::get_bank_msb_message (uint8_t* buf, size_t size) const
61 if (size < 3 || _bank < 0) {
65 buf[0] = 0xB0 | (_channel & 0xf);
67 buf[2] = (_bank >> 7) & 0x7f;
73 MIDISceneChange::get_bank_lsb_message (uint8_t* buf, size_t size) const
75 if (size < 3 || _bank < 0) {
79 buf[0] = 0xB0 | (_channel & 0xf);
81 buf[2] = _bank & 0x7f;
87 MIDISceneChange::get_program_message (uint8_t* buf, size_t size) const
89 if (size < 2 || _program < 0) {
93 buf[0] = 0xC0 | (_channel & 0xf);
94 buf[1] = _program & 0x7f;
100 MIDISceneChange::get_state ()
103 XMLNode* node = new XMLNode (SceneChange::xml_node_name);
105 node->add_property (X_("type"), X_("MIDI"));
106 snprintf (buf, sizeof (buf), "%d", (int) _program);
107 node->add_property (X_("id"), id().to_s());
108 snprintf (buf, sizeof (buf), "%d", (int) _program);
109 node->add_property (X_("program"), buf);
110 snprintf (buf, sizeof (buf), "%d", (int) _bank);
111 node->add_property (X_("bank"), buf);
112 snprintf (buf, sizeof (buf), "%d", (int) _channel);
113 node->add_property (X_("channel"), buf);
119 MIDISceneChange::set_state (const XMLNode& node, int /* version-ignored */)
121 if (!set_id (node)) {
125 const XMLProperty* prop;
127 if ((prop = node.property (X_("program"))) == 0) {
130 _program = atoi (prop->value());
132 if ((prop = node.property (X_("bank"))) == 0) {
135 _bank = atoi (prop->value());
137 if ((prop = node.property (X_("channel"))) == 0) {
140 _channel = atoi (prop->value());
146 MIDISceneChange::operator==(const MIDISceneChange& other) const
148 return _program == other._program &&
149 _bank == other._bank &&
150 _channel == other._channel;
154 MIDISceneChange::set_color (uint32_t c)
157 ColorChanged (); /* EMIT SIGNAL */
161 MIDISceneChange::color() const