diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-04-28 19:58:24 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-04-28 19:58:24 -0400 |
commit | 2cf411e4be0b10e6ecf47d2070963299b6a810e7 (patch) | |
tree | c6dfb7e7fcd71d5ee2d4a7c2ba490fb882dde3ca /libs/ardour/midi_scene_change.cc | |
parent | b945cda5582d6565ef2ce4fa8cbafee8fd8e5db0 (diff) |
merge (squash) with scenechange topic branch to provide MIDI-driven scene change markers
Diffstat (limited to 'libs/ardour/midi_scene_change.cc')
-rw-r--r-- | libs/ardour/midi_scene_change.cc | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/libs/ardour/midi_scene_change.cc b/libs/ardour/midi_scene_change.cc new file mode 100644 index 0000000000..81a74911a9 --- /dev/null +++ b/libs/ardour/midi_scene_change.cc @@ -0,0 +1,144 @@ +/* + Copyright (C) 2014 Paul Davis + + 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. + +*/ + +#include "pbd/error.h" +#include "pbd/compose.h" + +#include "ardour/midi_port.h" +#include "ardour/midi_scene_change.h" + +#include "i18n.h" + +using namespace PBD; +using namespace ARDOUR; + +MIDISceneChange::MIDISceneChange (framepos_t time, int c, int b, int p) + : SceneChange (time) + , _bank (b) + , _program (p) + , _channel (c & 0xf) +{ + if (_bank > 16384) { + _bank = -1; + } + + if (_program > 128) { + _program = -1; + } +} + +MIDISceneChange::MIDISceneChange (const XMLNode& node, int version) + : SceneChange (0) + , _bank (-1) + , _program (-1) + , _channel (-1) +{ + set_state (node, version); +} + +MIDISceneChange::~MIDISceneChange () +{ +} + +size_t +MIDISceneChange::get_bank_msb_message (uint8_t* buf, size_t size) const +{ + if (size < 3 || _bank < 0) { + return 0; + } + + buf[0] = 0xB0 | (_channel & 0xf); + buf[1] = 0x0; + buf[2] = (_bank & 0xf700) >> 8; + + return 3; +} + +size_t +MIDISceneChange::get_bank_lsb_message (uint8_t* buf, size_t size) const +{ + if (size < 3 || _bank < 0) { + return 0; + } + + buf[0] = 0xB0 | (_channel & 0xf); + buf[1] = 0x20; + buf[2] = (_bank & 0xf7); + + return 3; +} + +size_t +MIDISceneChange::get_program_message (uint8_t* buf, size_t size) const +{ + if (size < 2 || _program < 0) { + return 0; + } + + buf[0] = 0xC0 | (_channel & 0xf); + buf[1] = _program & 0xf7; + + return 2; +} + +XMLNode& +MIDISceneChange::get_state () +{ + char buf[32]; + XMLNode* node = new XMLNode (SceneChange::xml_node_name); + + node->add_property (X_("type"), X_("MIDI")); + snprintf (buf, sizeof (buf), "%d", (int) _program); + node->add_property (X_("id"), id().to_s()); + snprintf (buf, sizeof (buf), "%d", (int) _program); + node->add_property (X_("program"), buf); + snprintf (buf, sizeof (buf), "%d", (int) _bank); + node->add_property (X_("bank"), buf); + snprintf (buf, sizeof (buf), "%d", (int) _channel); + node->add_property (X_("channel"), buf); + + return *node; +} + +int +MIDISceneChange::set_state (const XMLNode& node, int /* version-ignored */) +{ + if (!set_id (node)) { + return -1; + } + + const XMLProperty* prop; + + if ((prop = node.property (X_("program"))) == 0) { + return -1; + } + _program = atoi (prop->value()); + + if ((prop = node.property (X_("bank"))) == 0) { + return -1; + } + _bank = atoi (prop->value()); + + if ((prop = node.property (X_("channel"))) == 0) { + return -1; + } + _channel = atoi (prop->value()); + + return 0; +} |