2 * Copyright (C) 2014-2016 Paul Davis <paul@linuxaudiosystems.com>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "pbd/error.h"
20 #include "pbd/compose.h"
21 #include "pbd/types_convert.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)
45 MIDISceneChange::MIDISceneChange (const XMLNode& node, int version)
50 set_state (node, version);
53 MIDISceneChange::~MIDISceneChange ()
58 MIDISceneChange::get_bank_msb_message (uint8_t* buf, size_t size) const
60 if (size < 3 || _bank < 0) {
64 buf[0] = 0xB0 | (_channel & 0xf);
66 buf[2] = (_bank >> 7) & 0x7f;
72 MIDISceneChange::get_bank_lsb_message (uint8_t* buf, size_t size) const
74 if (size < 3 || _bank < 0) {
78 buf[0] = 0xB0 | (_channel & 0xf);
80 buf[2] = _bank & 0x7f;
86 MIDISceneChange::get_program_message (uint8_t* buf, size_t size) const
88 if (size < 2 || _program < 0) {
92 buf[0] = 0xC0 | (_channel & 0xf);
93 buf[1] = _program & 0x7f;
99 MIDISceneChange::get_state ()
101 XMLNode* node = new XMLNode (SceneChange::xml_node_name);
103 node->set_property (X_("type"), X_("MIDI"));
104 node->set_property (X_("id"), id());
105 node->set_property (X_("program"), _program);
106 node->set_property (X_("bank"), _bank);
107 node->set_property (X_("channel"), _channel);
108 node->set_property (X_("color"), _color);
114 MIDISceneChange::set_state (const XMLNode& node, int /* version-ignored */)
116 if (!set_id (node)) {
120 if (!node.get_property (X_("program"), _program) || !node.get_property (X_("bank"), _bank) ||
121 !node.get_property (X_("channel"), _channel)) {
125 if (!node.get_property (X_("color"), _color)) {
126 _color = out_of_bound_color;
133 MIDISceneChange::operator==(const MIDISceneChange& other) const
135 return _program == other._program &&
136 _bank == other._bank &&
137 _channel == other._channel;
141 MIDISceneChange::set_channel (int channel)
147 MIDISceneChange::set_program (int program)
153 MIDISceneChange::set_bank (int bank)