2008-12-08 04:50:19 -05:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2008-2012 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
* Copyright (C) 2008-2016 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-12-08 04:50:19 -05:00
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <algorithm>
|
2008-12-09 02:42:19 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
#include "midi++/midnam_patch.h"
|
2012-03-20 14:01:59 -04:00
|
|
|
#include "pbd/compose.h"
|
2008-12-10 05:54:45 -05:00
|
|
|
#include "pbd/convert.h"
|
2012-03-20 14:01:59 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2008-12-10 05:54:45 -05:00
|
|
|
|
2008-12-09 02:42:19 -05:00
|
|
|
using namespace std;
|
2012-03-20 14:01:59 -04:00
|
|
|
using PBD::error;
|
2008-12-09 02:42:19 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace MIDI
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Name
|
|
|
|
{
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-12 00:05:10 -04:00
|
|
|
Patch::Patch (std::string name, uint8_t p_number, uint16_t b_number)
|
|
|
|
: _name (name)
|
|
|
|
, _id (p_number, b_number)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
static int
|
|
|
|
string_to_int(const XMLTree& tree, const std::string& str)
|
|
|
|
{
|
|
|
|
char* endptr = NULL;
|
|
|
|
const int i = strtol(str.c_str(), &endptr, 10);
|
|
|
|
if (str.empty() || *endptr != '\0') {
|
|
|
|
PBD::error << string_compose("%1: Bad number `%2'", tree.filename(), str)
|
|
|
|
<< endmsg;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
initialize_primary_key_from_commands (
|
|
|
|
const XMLTree& tree, PatchPrimaryKey& id, const XMLNode* node)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-12-17 19:43:09 -05:00
|
|
|
uint16_t bank = 0;
|
|
|
|
uint8_t program = 0;
|
2012-10-08 23:17:15 -04:00
|
|
|
|
2009-01-14 22:13:24 -05:00
|
|
|
const XMLNodeList events = node->children();
|
2008-06-02 17:41:35 -04:00
|
|
|
for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
|
2012-10-08 23:17:15 -04:00
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
XMLNode* node = *i;
|
|
|
|
if (node->name() == "ControlChange") {
|
2013-01-20 02:33:27 -05:00
|
|
|
const string& control = node->property("Control")->value();
|
|
|
|
const string& value = node->property("Value")->value();
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
if (control == "0") {
|
2014-12-17 19:43:09 -05:00
|
|
|
bank |= string_to_int(tree, value) << 7;
|
2008-12-10 05:54:45 -05:00
|
|
|
} else if (control == "32") {
|
2014-12-17 19:43:09 -05:00
|
|
|
bank |= string_to_int(tree, value);
|
2008-12-10 05:54:45 -05:00
|
|
|
}
|
2012-10-08 23:17:15 -04:00
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
} else if (node->name() == "ProgramChange") {
|
2013-01-20 02:33:27 -05:00
|
|
|
const string& number = node->property("Number")->value();
|
2008-12-10 05:54:45 -05:00
|
|
|
assert(number != "");
|
2014-12-17 19:43:09 -05:00
|
|
|
program = string_to_int(tree, number);
|
2009-01-14 22:13:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 19:43:09 -05:00
|
|
|
id = PatchPrimaryKey(program, bank);
|
2012-03-20 14:01:59 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-14 22:13:24 -05:00
|
|
|
|
2012-06-12 00:05:10 -04:00
|
|
|
XMLNode&
|
|
|
|
Patch::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("Patch");
|
|
|
|
|
|
|
|
/* XXX this is totally wrong */
|
|
|
|
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Number", _id.program());
|
|
|
|
node->set_property("Name", _name);
|
2012-06-12 00:05:10 -04:00
|
|
|
|
|
|
|
/*
|
2017-09-24 12:03:54 -04:00
|
|
|
typedef std::list< boost::shared_ptr< Evoral::Event<Temporal::Beats> > > PatchMidiCommands;
|
2012-06-12 00:05:10 -04:00
|
|
|
XMLNode* commands = node->add_child("PatchMIDICommands");
|
|
|
|
for (PatchMidiCommands::const_iterator event = _patch_midi_commands.begin();
|
|
|
|
event != _patch_midi_commands.end();
|
|
|
|
++event) {
|
2016-11-06 22:04:35 -05:00
|
|
|
commands->add_child_copy(Evoral::MIDIXML::midi_to_xml(*event));
|
2012-06-12 00:05:10 -04:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
2009-01-14 22:13:24 -05:00
|
|
|
int
|
2013-01-20 02:33:27 -05:00
|
|
|
Patch::set_state (const XMLTree& tree, const XMLNode& node)
|
2009-01-14 22:13:24 -05:00
|
|
|
{
|
2012-03-20 14:01:59 -04:00
|
|
|
if (node.name() != "Patch") {
|
2018-11-23 16:43:26 -05:00
|
|
|
cerr << "Incorrect node type '" << node.name() << "' handed to Patch" << endl;
|
2012-03-20 14:01:59 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
/* Note there is a "Number" attribute, but it's really more like a label
|
|
|
|
and is often not numeric. We currently do not use it. */
|
2012-03-20 14:01:59 -04:00
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
const XMLProperty* program_change = node.property("ProgramChange");
|
|
|
|
if (program_change) {
|
2014-12-17 19:43:09 -05:00
|
|
|
_id = PatchPrimaryKey(string_to_int(tree, program_change->value()), _id.bank());
|
2012-03-20 14:01:59 -04:00
|
|
|
}
|
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
const XMLProperty* name = node.property("Name");
|
|
|
|
if (!name) {
|
2012-03-20 14:01:59 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2013-01-20 02:33:27 -05:00
|
|
|
_name = name->value();
|
2012-03-20 14:01:59 -04:00
|
|
|
|
2009-01-14 22:13:24 -05:00
|
|
|
XMLNode* commands = node.child("PatchMIDICommands");
|
|
|
|
if (commands) {
|
2013-01-20 02:33:27 -05:00
|
|
|
if (initialize_primary_key_from_commands(tree, _id, commands) &&
|
|
|
|
!program_change) {
|
|
|
|
return -1; // Failed to find a program number anywhere
|
2012-03-20 14:01:59 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-01-19 19:46:55 -05:00
|
|
|
XMLNode* use_note_name_list = node.child("UsesNoteNameList");
|
|
|
|
if (use_note_name_list) {
|
|
|
|
_note_list_name = use_note_name_list->property ("Name")->value();
|
|
|
|
}
|
2012-03-20 14:01:59 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-05 19:07:07 -05:00
|
|
|
XMLNode&
|
|
|
|
Note::get_state (void)
|
|
|
|
{
|
2008-12-05 23:38:44 -05:00
|
|
|
XMLNode* node = new XMLNode("Note");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Number", _number);
|
|
|
|
node->set_property("Name", _name);
|
2008-12-05 19:07:07 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-01-19 23:27:12 -05:00
|
|
|
Note::set_state (const XMLTree& tree, const XMLNode& node)
|
2008-12-05 19:07:07 -05:00
|
|
|
{
|
2008-12-05 23:38:44 -05:00
|
|
|
assert(node.name() == "Note");
|
2013-01-19 19:46:55 -05:00
|
|
|
|
2013-01-20 02:33:27 -05:00
|
|
|
const int num = string_to_int(tree, node.property("Number")->value());
|
2014-12-29 20:18:57 -05:00
|
|
|
if (num > 127) {
|
2013-01-19 23:27:12 -05:00
|
|
|
PBD::warning << string_compose("%1: Note number %2 (%3) out of range",
|
2013-01-20 02:33:27 -05:00
|
|
|
tree.filename(), num, _name)
|
2013-01-19 23:27:12 -05:00
|
|
|
<< endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-12-29 20:18:57 -05:00
|
|
|
_number = num;
|
2013-01-20 02:33:27 -05:00
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
2008-12-05 19:07:07 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-05 23:38:44 -05:00
|
|
|
XMLNode&
|
|
|
|
NoteNameList::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("NoteNameList");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Name", _name);
|
2008-12-05 23:38:44 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
2013-01-19 23:27:12 -05:00
|
|
|
static void
|
|
|
|
add_note_from_xml (NoteNameList::Notes& notes, const XMLTree& tree, const XMLNode& node)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Note> note(new Note());
|
|
|
|
if (!note->set_state (tree, node)) {
|
|
|
|
if (!notes[note->number()]) {
|
|
|
|
notes[note->number()] = note;
|
|
|
|
} else {
|
|
|
|
PBD::warning
|
|
|
|
<< string_compose("%1: Duplicate note number %2 (%3) ignored",
|
|
|
|
tree.filename(), (int)note->number(), note->name())
|
|
|
|
<< endmsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-05 23:38:44 -05:00
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
NoteNameList::set_state (const XMLTree& tree, const XMLNode& node)
|
2008-12-05 23:38:44 -05:00
|
|
|
{
|
|
|
|
assert(node.name() == "NoteNameList");
|
2013-01-19 19:46:55 -05:00
|
|
|
_name = node.property("Name")->value();
|
|
|
|
_notes.clear();
|
|
|
|
_notes.resize(128);
|
2008-12-05 23:38:44 -05:00
|
|
|
|
2013-01-19 19:46:55 -05:00
|
|
|
for (XMLNodeList::const_iterator i = node.children().begin();
|
|
|
|
i != node.children().end(); ++i) {
|
2013-01-19 23:27:12 -05:00
|
|
|
if ((*i)->name() == "Note") {
|
|
|
|
add_note_from_xml(_notes, tree, **i);
|
|
|
|
} else if ((*i)->name() == "NoteGroup") {
|
|
|
|
for (XMLNodeList::const_iterator j = (*i)->children().begin();
|
|
|
|
j != (*i)->children().end(); ++j) {
|
|
|
|
if ((*j)->name() == "Note") {
|
|
|
|
add_note_from_xml(_notes, tree, **j);
|
|
|
|
} else {
|
|
|
|
PBD::warning << string_compose("%1: Invalid NoteGroup child %2 ignored",
|
|
|
|
tree.filename(), (*j)->name())
|
|
|
|
<< endmsg;
|
|
|
|
}
|
|
|
|
}
|
2013-01-19 19:46:55 -05:00
|
|
|
}
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-05 23:38:44 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-16 03:24:31 -05:00
|
|
|
XMLNode&
|
|
|
|
Control::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("Control");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Type", _type);
|
|
|
|
node->set_property("Number", _number);
|
|
|
|
node->set_property("Name", _name);
|
2013-01-16 03:24:31 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-01-20 03:56:00 -05:00
|
|
|
Control::set_state (const XMLTree& tree, const XMLNode& node)
|
2013-01-16 03:24:31 -05:00
|
|
|
{
|
|
|
|
assert(node.name() == "Control");
|
2013-01-27 12:15:46 -05:00
|
|
|
if (node.property("Type")) {
|
|
|
|
_type = node.property("Type")->value();
|
|
|
|
} else {
|
|
|
|
_type = "7bit";
|
|
|
|
}
|
2019-05-03 18:07:26 -04:00
|
|
|
if (_type == "NRPN") {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-20 03:56:00 -05:00
|
|
|
_number = string_to_int(tree, node.property("Number")->value());
|
2013-01-16 03:24:31 -05:00
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
for (XMLNodeList::const_iterator i = node.children().begin();
|
|
|
|
i != node.children().end(); ++i) {
|
|
|
|
if ((*i)->name() == "Values") {
|
|
|
|
// <Values> has Min and Max properties, but we don't care
|
|
|
|
for (XMLNodeList::const_iterator j = (*i)->children().begin();
|
|
|
|
j != (*i)->children().end(); ++j) {
|
|
|
|
if ((*j)->name() == "ValueNameList") {
|
|
|
|
_value_name_list = boost::shared_ptr<ValueNameList>(new ValueNameList());
|
|
|
|
_value_name_list->set_state(tree, **j);
|
|
|
|
} else if ((*j)->name() == "UsesValueNameList") {
|
|
|
|
_value_name_list_name = (*j)->property("Name")->value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-16 03:24:31 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
ControlNameList::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("ControlNameList");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Name", _name);
|
2013-01-16 03:24:31 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ControlNameList::set_state (const XMLTree& tree, const XMLNode& node)
|
|
|
|
{
|
|
|
|
assert(node.name() == "ControlNameList");
|
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
_controls.clear();
|
2013-01-16 03:24:31 -05:00
|
|
|
for (XMLNodeList::const_iterator i = node.children().begin();
|
|
|
|
i != node.children().end(); ++i) {
|
2013-01-20 03:56:00 -05:00
|
|
|
if ((*i)->name() == "Control") {
|
2013-01-19 05:02:00 -05:00
|
|
|
boost::shared_ptr<Control> control(new Control());
|
2019-05-03 18:07:26 -04:00
|
|
|
if (control->set_state (tree, *(*i))) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-20 03:56:00 -05:00
|
|
|
if (_controls.find(control->number()) == _controls.end()) {
|
|
|
|
_controls.insert(make_pair(control->number(), control));
|
|
|
|
} else {
|
|
|
|
PBD::warning << string_compose("%1: Duplicate control %2 ignored",
|
|
|
|
tree.filename(), control->number())
|
|
|
|
<< endmsg;
|
|
|
|
}
|
2013-01-19 05:02:00 -05:00
|
|
|
}
|
2013-01-16 03:24:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-05 23:38:44 -05:00
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
boost::shared_ptr<const Control>
|
|
|
|
ControlNameList::control(uint16_t num) const
|
|
|
|
{
|
|
|
|
Controls::const_iterator i = _controls.find(num);
|
|
|
|
if (i != _controls.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<const Control>();
|
|
|
|
}
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
XMLNode&
|
|
|
|
Value::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("Value");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Number", _number);
|
|
|
|
node->set_property("Name", _name);
|
2014-01-06 17:02:55 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Value::set_state (const XMLTree& tree, const XMLNode& node)
|
|
|
|
{
|
|
|
|
assert(node.name() == "Value");
|
|
|
|
_number = string_to_int(tree, node.property("Number")->value());
|
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
ValueNameList::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("ValueNameList");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Name", _name);
|
2014-01-06 17:02:55 -05:00
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ValueNameList::set_state (const XMLTree& tree, const XMLNode& node)
|
|
|
|
{
|
|
|
|
assert(node.name() == "ValueNameList");
|
|
|
|
const XMLProperty* name_prop = node.property("Name");
|
|
|
|
if (name_prop) {
|
|
|
|
// May be anonymous if written inline within a single <Control> tag
|
|
|
|
_name = name_prop->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
_values.clear();
|
|
|
|
for (XMLNodeList::const_iterator i = node.children().begin();
|
|
|
|
i != node.children().end(); ++i) {
|
|
|
|
if ((*i)->name() == "Value") {
|
|
|
|
boost::shared_ptr<Value> value(new Value());
|
|
|
|
value->set_state (tree, *(*i));
|
|
|
|
if (_values.find(value->number()) == _values.end()) {
|
|
|
|
_values.insert(make_pair(value->number(), value));
|
|
|
|
} else {
|
|
|
|
PBD::warning << string_compose("%1: Duplicate value %2 ignored",
|
|
|
|
tree.filename(), value->number())
|
|
|
|
<< endmsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<const Value>
|
|
|
|
ValueNameList::value(uint16_t num) const
|
|
|
|
{
|
|
|
|
Values::const_iterator i = _values.find(num);
|
|
|
|
if (i != _values.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<const Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<const Value>
|
|
|
|
ValueNameList::max_value_below(uint16_t num) const
|
|
|
|
{
|
|
|
|
Values::const_iterator i = _values.lower_bound(num);
|
|
|
|
if (i->first == num) {
|
|
|
|
// Exact match
|
|
|
|
return i->second;
|
|
|
|
} else if (i == _values.begin()) {
|
|
|
|
// No value is < num
|
|
|
|
return boost::shared_ptr<const Value>();
|
|
|
|
} else {
|
|
|
|
// Found the smallest element >= num, so the previous one is our result
|
|
|
|
--i;
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-04 18:37:24 -04:00
|
|
|
XMLNode&
|
2008-06-02 17:41:35 -04:00
|
|
|
PatchBank::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("PatchBank");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Name", _name);
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode* patch_name_list = node->add_child("PatchNameList");
|
2008-08-04 18:37:24 -04:00
|
|
|
for (PatchNameList::iterator patch = _patch_name_list.begin();
|
2008-06-02 17:41:35 -04:00
|
|
|
patch != _patch_name_list.end();
|
|
|
|
++patch) {
|
2008-12-12 00:17:53 -05:00
|
|
|
patch_name_list->add_child_nocopy((*patch)->get_state());
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
PatchBank::set_state (const XMLTree& tree, const XMLNode& node)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
assert(node.name() == "PatchBank");
|
|
|
|
_name = node.property("Name")->value();
|
2009-01-14 22:13:24 -05:00
|
|
|
|
|
|
|
XMLNode* commands = node.child("MIDICommands");
|
|
|
|
if (commands) {
|
2012-06-12 00:05:10 -04:00
|
|
|
PatchPrimaryKey id (0, 0);
|
2013-01-20 02:33:27 -05:00
|
|
|
if (initialize_primary_key_from_commands (tree, id, commands)) {
|
2012-03-20 14:01:59 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-12-17 19:43:09 -05:00
|
|
|
_number = id.bank();
|
2009-01-14 22:13:24 -05:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode* patch_name_list = node.child("PatchNameList");
|
2012-03-20 14:01:59 -04:00
|
|
|
|
|
|
|
if (patch_name_list) {
|
|
|
|
const XMLNodeList patches = patch_name_list->children();
|
|
|
|
for (XMLNodeList::const_iterator i = patches.begin(); i != patches.end(); ++i) {
|
2012-06-12 00:05:10 -04:00
|
|
|
boost::shared_ptr<Patch> patch (new Patch (string(), 0, _number));
|
2018-11-23 16:43:26 -05:00
|
|
|
if (0 == patch->set_state(tree, *(*i))) {
|
|
|
|
_patch_name_list.push_back(patch);
|
|
|
|
}
|
2012-03-20 14:01:59 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XMLNode* use_patch_name_list = node.child ("UsesPatchNameList");
|
|
|
|
if (use_patch_name_list) {
|
2012-06-03 11:47:23 -04:00
|
|
|
_patch_list_name = use_patch_name_list->property ("Name")->value();
|
2012-03-20 14:01:59 -04:00
|
|
|
} else {
|
|
|
|
error << "Patch without patch name list - patchfile will be ignored" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
PatchBank::set_patch_name_list (const PatchNameList& pnl)
|
|
|
|
{
|
|
|
|
_patch_name_list = pnl;
|
|
|
|
_patch_list_name = "";
|
2012-06-12 12:32:06 -04:00
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
for (PatchNameList::iterator p = _patch_name_list.begin(); p != _patch_name_list.end(); p++) {
|
2012-06-12 00:05:10 -04:00
|
|
|
(*p)->set_bank_number (_number);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-12 12:32:06 -04:00
|
|
|
std::ostream&
|
|
|
|
operator<< (std::ostream& os, const ChannelNameSet& cns)
|
|
|
|
{
|
|
|
|
os << "Channel Name Set: name = " << cns._name << endl
|
|
|
|
<< "Map size " << cns._patch_map.size () << endl
|
|
|
|
<< "List size " << cns._patch_list.size() << endl
|
|
|
|
<< "Patch list name = [" << cns._patch_list_name << ']' << endl
|
|
|
|
<< "Available channels : ";
|
2013-07-25 02:19:51 -04:00
|
|
|
for (set<uint8_t>::const_iterator x = cns._available_for_channels.begin(); x != cns._available_for_channels.end(); ++x) {
|
2012-06-12 12:32:06 -04:00
|
|
|
os << (int) (*x) << ' ';
|
|
|
|
}
|
|
|
|
os << endl;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-12 12:32:06 -04:00
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator pbi = cns._patch_banks.begin(); pbi != cns._patch_banks.end(); ++pbi) {
|
|
|
|
os << "\tPatch Bank " << (*pbi)->name() << " with " << (*pbi)->patch_name_list().size() << " patches\n";
|
2013-01-20 03:56:00 -05:00
|
|
|
for (PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
|
2012-06-12 12:32:06 -04:00
|
|
|
os << "\t\tPatch name " << (*pni)->name() << " prog " << (int) (*pni)->program_number() << " bank " << (*pni)->bank_number() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2012-06-11 18:59:35 -04:00
|
|
|
void
|
|
|
|
ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb)
|
|
|
|
{
|
|
|
|
_patch_banks = pb;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-11 18:59:35 -04:00
|
|
|
_patch_map.clear ();
|
|
|
|
_patch_list.clear ();
|
|
|
|
_patch_list_name = "";
|
|
|
|
_available_for_channels.clear ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-11 18:59:35 -04:00
|
|
|
for (PatchBanks::const_iterator pbi = _patch_banks.begin(); pbi != _patch_banks.end(); ++pbi) {
|
2013-01-20 03:56:00 -05:00
|
|
|
for (PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
|
2012-06-11 18:59:35 -04:00
|
|
|
_patch_map[(*pni)->patch_primary_key()] = (*pni);
|
|
|
|
_patch_list.push_back ((*pni)->patch_primary_key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint8_t n = 0; n < 16; ++n) {
|
|
|
|
_available_for_channels.insert (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 12:32:06 -04:00
|
|
|
void
|
2013-01-20 03:56:00 -05:00
|
|
|
ChannelNameSet::use_patch_name_list (const PatchNameList& pnl)
|
2012-06-12 12:32:06 -04:00
|
|
|
{
|
2013-01-20 03:56:00 -05:00
|
|
|
for (PatchNameList::const_iterator p = pnl.begin(); p != pnl.end(); ++p) {
|
2012-06-12 12:32:06 -04:00
|
|
|
_patch_map[(*p)->patch_primary_key()] = (*p);
|
|
|
|
_patch_list.push_back ((*p)->patch_primary_key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-04 18:37:24 -04:00
|
|
|
XMLNode&
|
2008-06-02 17:41:35 -04:00
|
|
|
ChannelNameSet::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("ChannelNameSet");
|
2016-08-28 09:18:36 -04:00
|
|
|
node->set_property("Name", _name);
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode* available_for_channels = node->add_child("AvailableForChannels");
|
|
|
|
assert(available_for_channels);
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
for (uint8_t channel = 0; channel < 16; ++channel) {
|
|
|
|
XMLNode* available_channel = available_for_channels->add_child("AvailableChannel");
|
|
|
|
assert(available_channel);
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2016-08-28 09:18:36 -04:00
|
|
|
available_channel->set_property("Channel", channel);
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (_available_for_channels.find(channel) != _available_for_channels.end()) {
|
2016-08-28 09:18:36 -04:00
|
|
|
available_channel->set_property("Available", "true");
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2016-08-28 09:18:36 -04:00
|
|
|
available_channel->set_property("Available", "false");
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
2008-08-04 18:37:24 -04:00
|
|
|
|
|
|
|
for (PatchBanks::iterator patch_bank = _patch_banks.begin();
|
2008-06-02 17:41:35 -04:00
|
|
|
patch_bank != _patch_banks.end();
|
|
|
|
++patch_bank) {
|
2008-12-12 00:17:53 -05:00
|
|
|
node->add_child_nocopy((*patch_bank)->get_state());
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
ChannelNameSet::set_state (const XMLTree& tree, const XMLNode& node)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
assert(node.name() == "ChannelNameSet");
|
2013-01-20 03:56:00 -05:00
|
|
|
_name = node.property("Name")->value();
|
2012-10-08 23:17:15 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
const XMLNodeList children = node.children();
|
|
|
|
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
|
|
|
|
XMLNode* node = *i;
|
|
|
|
assert(node);
|
|
|
|
if (node->name() == "AvailableForChannels") {
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> channels =
|
2012-10-08 23:17:15 -04:00
|
|
|
tree.find("//AvailableChannel[@Available = 'true']/@Channel", node);
|
2013-01-20 03:56:00 -05:00
|
|
|
for (XMLSharedNodeList::const_iterator i = channels->begin();
|
2008-06-02 17:41:35 -04:00
|
|
|
i != channels->end();
|
|
|
|
++i) {
|
2017-08-30 11:53:31 -04:00
|
|
|
try {
|
|
|
|
_available_for_channels.insert(
|
|
|
|
string_to_int(tree, (*i)->attribute_value()));
|
|
|
|
} catch (XMLException &e) {
|
|
|
|
cerr << "ChannelNameSet::set_state: " << e.what () << endl;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2013-01-20 03:56:00 -05:00
|
|
|
} else if (node->name() == "PatchBank") {
|
2012-06-12 00:05:10 -04:00
|
|
|
boost::shared_ptr<PatchBank> bank (new PatchBank ());
|
2012-03-20 14:01:59 -04:00
|
|
|
bank->set_state(tree, *node);
|
2008-12-12 00:17:53 -05:00
|
|
|
_patch_banks.push_back(bank);
|
2013-01-20 03:56:00 -05:00
|
|
|
const PatchNameList& patches = bank->patch_name_list();
|
|
|
|
for (PatchNameList::const_iterator patch = patches.begin();
|
2008-12-10 05:54:45 -05:00
|
|
|
patch != patches.end();
|
|
|
|
++patch) {
|
2008-12-12 00:17:53 -05:00
|
|
|
_patch_map[(*patch)->patch_primary_key()] = *patch;
|
2008-12-15 06:05:41 -05:00
|
|
|
_patch_list.push_back((*patch)->patch_primary_key());
|
2008-12-10 05:54:45 -05:00
|
|
|
}
|
2013-01-20 03:56:00 -05:00
|
|
|
} else if (node->name() == "UsesNoteNameList") {
|
2013-01-19 21:41:27 -05:00
|
|
|
_note_list_name = node->property ("Name")->value();
|
2013-01-20 03:56:00 -05:00
|
|
|
} else if (node->name() == "UsesControlNameList") {
|
|
|
|
_control_list_name = node->property ("Name")->value();
|
2013-01-19 21:41:27 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
CustomDeviceMode::set_state(const XMLTree& tree, const XMLNode& a_node)
|
2008-11-23 14:42:09 -05:00
|
|
|
{
|
2008-12-09 02:42:19 -05:00
|
|
|
assert(a_node.name() == "CustomDeviceMode");
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
_name = a_node.property("Name")->value();
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> channel_name_set_assignments =
|
2012-10-29 12:16:07 -04:00
|
|
|
tree.find("//ChannelNameSetAssign", const_cast<XMLNode *>(&a_node));
|
2013-01-20 03:56:00 -05:00
|
|
|
for (XMLSharedNodeList::const_iterator i = channel_name_set_assignments->begin();
|
2008-11-23 14:42:09 -05:00
|
|
|
i != channel_name_set_assignments->end();
|
|
|
|
++i) {
|
2013-01-20 02:33:27 -05:00
|
|
|
const int channel = string_to_int(tree, (*i)->property("Channel")->value());
|
|
|
|
const string& name_set = (*i)->property("NameSet")->value();
|
2008-11-23 14:42:09 -05:00
|
|
|
assert( 1 <= channel && channel <= 16 );
|
2008-12-12 00:17:53 -05:00
|
|
|
_channel_name_set_assignments[channel - 1] = name_set;
|
2008-11-23 14:42:09 -05:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
CustomDeviceMode::get_state(void)
|
|
|
|
{
|
|
|
|
XMLNode* custom_device_mode = new XMLNode("CustomDeviceMode");
|
2016-08-28 09:18:36 -04:00
|
|
|
custom_device_mode->set_property("Name", _name);
|
2009-10-20 20:15:42 -04:00
|
|
|
XMLNode* channel_name_set_assignments =
|
2008-11-23 14:42:09 -05:00
|
|
|
custom_device_mode->add_child("ChannelNameSetAssignments");
|
|
|
|
for (int i = 0; i < 15 && !_channel_name_set_assignments[i].empty(); i++) {
|
2009-10-20 20:15:42 -04:00
|
|
|
XMLNode* channel_name_set_assign =
|
2008-11-23 14:42:09 -05:00
|
|
|
channel_name_set_assignments->add_child("ChannelNameSetAssign");
|
2016-08-28 09:18:36 -04:00
|
|
|
channel_name_set_assign->set_property("Channel", i + 1);
|
|
|
|
channel_name_set_assign->set_property("NameSet", _channel_name_set_assignments[i]);
|
2008-11-23 14:42:09 -05:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
return *custom_device_mode;
|
|
|
|
}
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
boost::shared_ptr<const ValueNameList>
|
|
|
|
MasterDeviceNames::value_name_list_by_control(const std::string& mode, uint8_t channel, uint8_t number)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<ChannelNameSet> chan_names = channel_name_set_by_channel(mode, channel);
|
|
|
|
if (!chan_names) {
|
|
|
|
return boost::shared_ptr<const ValueNameList>();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<ControlNameList> control_names = control_name_list(chan_names->control_list_name());
|
|
|
|
if (!control_names) {
|
|
|
|
return boost::shared_ptr<const ValueNameList>();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<const Control> control = control_names->control(number);
|
|
|
|
if (!control) {
|
|
|
|
return boost::shared_ptr<const ValueNameList>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!control->value_name_list_name().empty()) {
|
|
|
|
return value_name_list(control->value_name_list_name());
|
|
|
|
} else {
|
|
|
|
return control->value_name_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
boost::shared_ptr<CustomDeviceMode>
|
2013-01-20 02:33:27 -05:00
|
|
|
MasterDeviceNames::custom_device_mode_by_name(const std::string& mode_name)
|
2012-06-12 12:32:06 -04:00
|
|
|
{
|
|
|
|
return _custom_device_modes[mode_name];
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
boost::shared_ptr<ChannelNameSet>
|
2014-01-06 17:02:55 -05:00
|
|
|
MasterDeviceNames::channel_name_set_by_channel(const std::string& mode, uint8_t channel)
|
2012-06-12 12:32:06 -04:00
|
|
|
{
|
|
|
|
boost::shared_ptr<CustomDeviceMode> cdm = custom_device_mode_by_name(mode);
|
|
|
|
boost::shared_ptr<ChannelNameSet> cns = _channel_name_sets[cdm->channel_name_set_name_by_channel(channel)];
|
|
|
|
return cns;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
boost::shared_ptr<Patch>
|
|
|
|
MasterDeviceNames::find_patch(const std::string& mode, uint8_t channel, const PatchPrimaryKey& key)
|
2012-06-12 12:32:06 -04:00
|
|
|
{
|
2014-01-06 17:02:55 -05:00
|
|
|
boost::shared_ptr<ChannelNameSet> cns = channel_name_set_by_channel(mode, channel);
|
2013-12-30 10:24:27 -05:00
|
|
|
if (!cns) return boost::shared_ptr<Patch>();
|
|
|
|
return cns->find_patch(key);
|
2012-06-12 12:32:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:46:55 -05:00
|
|
|
boost::shared_ptr<ChannelNameSet>
|
|
|
|
MasterDeviceNames::channel_name_set(const std::string& name)
|
|
|
|
{
|
|
|
|
ChannelNameSets::const_iterator i = _channel_name_sets.find(name);
|
|
|
|
if (i != _channel_name_sets.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<ChannelNameSet>();
|
|
|
|
}
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
boost::shared_ptr<ControlNameList>
|
|
|
|
MasterDeviceNames::control_name_list(const std::string& name)
|
|
|
|
{
|
|
|
|
ControlNameLists::const_iterator i = _control_name_lists.find(name);
|
|
|
|
if (i != _control_name_lists.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<ControlNameList>();
|
|
|
|
}
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
boost::shared_ptr<ValueNameList>
|
|
|
|
MasterDeviceNames::value_name_list(const std::string& name)
|
|
|
|
{
|
|
|
|
ValueNameLists::const_iterator i = _value_name_lists.find(name);
|
|
|
|
if (i != _value_name_lists.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<ValueNameList>();
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:46:55 -05:00
|
|
|
boost::shared_ptr<NoteNameList>
|
|
|
|
MasterDeviceNames::note_name_list(const std::string& name)
|
|
|
|
{
|
|
|
|
NoteNameLists::const_iterator i = _note_name_lists.find(name);
|
|
|
|
if (i != _note_name_lists.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<NoteNameList>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
MasterDeviceNames::note_name(const std::string& mode_name,
|
|
|
|
uint8_t channel,
|
|
|
|
uint16_t bank,
|
|
|
|
uint8_t program,
|
|
|
|
uint8_t number)
|
|
|
|
{
|
|
|
|
if (number > 127) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-07-13 23:36:45 -04:00
|
|
|
boost::shared_ptr<const NoteNameList> note_names;
|
2013-01-19 19:46:55 -05:00
|
|
|
boost::shared_ptr<const Patch> patch(
|
|
|
|
find_patch(mode_name, channel, PatchPrimaryKey(program, bank)));
|
2014-07-13 23:36:45 -04:00
|
|
|
if (patch) {
|
|
|
|
note_names = note_name_list(patch->note_list_name());
|
2013-01-19 19:46:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-19 21:41:27 -05:00
|
|
|
if (!note_names) {
|
|
|
|
/* No note names specific to this patch, check the ChannelNameSet */
|
2014-01-06 17:02:55 -05:00
|
|
|
boost::shared_ptr<ChannelNameSet> chan_names = channel_name_set_by_channel(
|
2013-01-19 21:41:27 -05:00
|
|
|
mode_name, channel);
|
|
|
|
if (chan_names) {
|
|
|
|
note_names = note_name_list(chan_names->note_list_name());
|
|
|
|
}
|
|
|
|
}
|
2013-01-19 19:46:55 -05:00
|
|
|
if (!note_names) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<const Note> note(note_names->notes()[number]);
|
|
|
|
return note ? note->name() : "";
|
|
|
|
}
|
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
int
|
2013-01-16 03:24:31 -05:00
|
|
|
MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode&)
|
2008-11-23 14:42:09 -05:00
|
|
|
{
|
2008-12-05 23:38:44 -05:00
|
|
|
// Manufacturer
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> manufacturer = tree.find("//Manufacturer");
|
2008-12-05 23:38:44 -05:00
|
|
|
assert(manufacturer->size() == 1);
|
2012-10-08 00:32:12 -04:00
|
|
|
_manufacturer = manufacturer->front()->children().front()->content();
|
2008-12-05 23:38:44 -05:00
|
|
|
|
|
|
|
// Models
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> models = tree.find("//Model");
|
2008-12-05 23:38:44 -05:00
|
|
|
assert(models->size() >= 1);
|
|
|
|
for (XMLSharedNodeList::iterator i = models->begin();
|
|
|
|
i != models->end();
|
|
|
|
++i) {
|
2008-12-09 02:42:19 -05:00
|
|
|
const XMLNodeList& contents = (*i)->children();
|
|
|
|
assert(contents.size() == 1);
|
|
|
|
XMLNode * content = *(contents.begin());
|
|
|
|
assert(content->is_content());
|
2013-01-19 14:25:06 -05:00
|
|
|
_models.insert(content->content());
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CustomDeviceModes
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> custom_device_modes = tree.find("//CustomDeviceMode");
|
2008-12-05 23:38:44 -05:00
|
|
|
for (XMLSharedNodeList::iterator i = custom_device_modes->begin();
|
|
|
|
i != custom_device_modes->end();
|
|
|
|
++i) {
|
2008-12-12 00:17:53 -05:00
|
|
|
boost::shared_ptr<CustomDeviceMode> custom_device_mode(new CustomDeviceMode());
|
2012-03-20 14:01:59 -04:00
|
|
|
custom_device_mode->set_state(tree, *(*i));
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-12 00:17:53 -05:00
|
|
|
_custom_device_modes[custom_device_mode->name()] = custom_device_mode;
|
2008-12-10 05:54:45 -05:00
|
|
|
_custom_device_mode_names.push_back(custom_device_mode->name());
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChannelNameSets
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> channel_name_sets = tree.find("//ChannelNameSet");
|
2008-12-05 23:38:44 -05:00
|
|
|
for (XMLSharedNodeList::iterator i = channel_name_sets->begin();
|
|
|
|
i != channel_name_sets->end();
|
|
|
|
++i) {
|
2008-12-12 00:17:53 -05:00
|
|
|
boost::shared_ptr<ChannelNameSet> channel_name_set(new ChannelNameSet());
|
2012-03-20 14:01:59 -04:00
|
|
|
channel_name_set->set_state(tree, *(*i));
|
2008-12-12 00:17:53 -05:00
|
|
|
_channel_name_sets[channel_name_set->name()] = channel_name_set;
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NoteNameLists
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> note_name_lists = tree.find("//NoteNameList");
|
2008-12-05 23:38:44 -05:00
|
|
|
for (XMLSharedNodeList::iterator i = note_name_lists->begin();
|
|
|
|
i != note_name_lists->end();
|
|
|
|
++i) {
|
2008-12-12 00:17:53 -05:00
|
|
|
boost::shared_ptr<NoteNameList> note_name_list(new NoteNameList());
|
2012-03-20 14:01:59 -04:00
|
|
|
note_name_list->set_state (tree, *(*i));
|
2013-01-20 03:56:00 -05:00
|
|
|
_note_name_lists[note_name_list->name()] = note_name_list;
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
|
|
|
|
2013-01-16 03:24:31 -05:00
|
|
|
// ControlNameLists
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> control_name_lists = tree.find("//ControlNameList");
|
|
|
|
for (XMLSharedNodeList::iterator i = control_name_lists->begin();
|
|
|
|
i != control_name_lists->end();
|
|
|
|
++i) {
|
|
|
|
boost::shared_ptr<ControlNameList> control_name_list(new ControlNameList());
|
|
|
|
control_name_list->set_state (tree, *(*i));
|
2013-01-20 03:56:00 -05:00
|
|
|
_control_name_lists[control_name_list->name()] = control_name_list;
|
2013-01-16 03:24:31 -05:00
|
|
|
}
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
// ValueNameLists
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> value_name_lists = tree.find("/child::MIDINameDocument/child::MasterDeviceNames/child::ValueNameList");
|
|
|
|
for (XMLSharedNodeList::iterator i = value_name_lists->begin();
|
|
|
|
i != value_name_lists->end();
|
|
|
|
++i) {
|
|
|
|
boost::shared_ptr<ValueNameList> value_name_list(new ValueNameList());
|
|
|
|
value_name_list->set_state (tree, *(*i));
|
|
|
|
_value_name_lists[value_name_list->name()] = value_name_list;
|
|
|
|
}
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
// global/post-facto PatchNameLists
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> patch_name_lists = tree.find("/child::MIDINameDocument/child::MasterDeviceNames/child::PatchNameList");
|
|
|
|
for (XMLSharedNodeList::iterator i = patch_name_lists->begin();
|
|
|
|
i != patch_name_lists->end();
|
|
|
|
++i) {
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
PatchNameList patch_name_list;
|
2012-03-20 14:01:59 -04:00
|
|
|
const XMLNodeList patches = (*i)->children();
|
|
|
|
|
|
|
|
for (XMLNodeList::const_iterator p = patches.begin(); p != patches.end(); ++p) {
|
2012-06-12 00:05:10 -04:00
|
|
|
boost::shared_ptr<Patch> patch (new Patch ());
|
2012-03-20 14:01:59 -04:00
|
|
|
patch->set_state(tree, *(*p));
|
|
|
|
patch_name_list.push_back(patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!patch_name_list.empty()) {
|
|
|
|
_patch_name_lists[(*i)->property ("Name")->value()] = patch_name_list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now traverse patches and hook up anything that used UsePatchNameList
|
|
|
|
* to the right patch list
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (ChannelNameSets::iterator cns = _channel_name_sets.begin(); cns != _channel_name_sets.end(); ++cns) {
|
|
|
|
ChannelNameSet::PatchBanks pbs = cns->second->patch_banks();
|
2012-06-12 12:32:06 -04:00
|
|
|
PatchNameLists::iterator p;
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
for (ChannelNameSet::PatchBanks::iterator pb = pbs.begin(); pb != pbs.end(); ++pb) {
|
2013-01-20 02:33:27 -05:00
|
|
|
const std::string& pln = (*pb)->patch_list_name();
|
2012-03-20 14:01:59 -04:00
|
|
|
if (!pln.empty()) {
|
2012-06-12 12:32:06 -04:00
|
|
|
if ((p = _patch_name_lists.find (pln)) != _patch_name_lists.end()) {
|
2012-03-20 14:01:59 -04:00
|
|
|
if ((*pb)->set_patch_name_list (p->second)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-06-12 12:32:06 -04:00
|
|
|
cns->second->use_patch_name_list (p->second);
|
2012-03-20 14:01:59 -04:00
|
|
|
} else {
|
|
|
|
error << string_compose ("Patch list name %1 was not found - patch file ignored", pln) << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 12:32:06 -04:00
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
}
|
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
MasterDeviceNames::get_state(void)
|
|
|
|
{
|
|
|
|
static XMLNode nothing("<nothing>");
|
|
|
|
return nothing;
|
|
|
|
}
|
|
|
|
|
2015-10-19 06:18:16 -04:00
|
|
|
MIDINameDocument::MIDINameDocument (const string& file_path)
|
|
|
|
: _file_path(file_path)
|
2009-10-20 20:15:42 -04:00
|
|
|
{
|
2014-09-09 17:53:27 -04:00
|
|
|
XMLTree document;
|
2015-10-19 06:18:16 -04:00
|
|
|
if (!document.read (file_path)) {
|
2012-03-20 14:01:59 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
2012-06-03 11:47:23 -04:00
|
|
|
|
2015-10-19 06:18:16 -04:00
|
|
|
document.set_filename (file_path);
|
2014-09-09 17:53:27 -04:00
|
|
|
set_state (document, *document.root());
|
2009-10-15 14:56:11 -04:00
|
|
|
}
|
|
|
|
|
2008-08-04 18:37:24 -04:00
|
|
|
int
|
2013-01-16 03:24:31 -05:00
|
|
|
MIDINameDocument::set_state (const XMLTree& tree, const XMLNode&)
|
2008-08-04 18:37:24 -04:00
|
|
|
{
|
2008-12-06 00:00:20 -05:00
|
|
|
// Author
|
2012-03-20 14:01:59 -04:00
|
|
|
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> author = tree.find("//Author");
|
|
|
|
if (author->size() < 1) {
|
|
|
|
error << "No author information in MIDNAM file" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-10-08 00:32:12 -04:00
|
|
|
if (author->front()->children().size() > 0) {
|
|
|
|
_author = author->front()->children().front()->content();
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-06 00:00:20 -05:00
|
|
|
// MasterDeviceNames
|
2012-03-20 14:01:59 -04:00
|
|
|
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> master_device_names_list = tree.find ("//MasterDeviceNames");
|
|
|
|
|
2008-12-06 00:00:20 -05:00
|
|
|
for (XMLSharedNodeList::iterator i = master_device_names_list->begin();
|
|
|
|
i != master_device_names_list->end();
|
|
|
|
++i) {
|
2008-12-09 02:42:19 -05:00
|
|
|
boost::shared_ptr<MasterDeviceNames> master_device_names(new MasterDeviceNames());
|
2012-03-20 14:01:59 -04:00
|
|
|
|
|
|
|
if (master_device_names->set_state(tree, *(*i))) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-09 02:42:19 -05:00
|
|
|
for (MasterDeviceNames::Models::const_iterator model = master_device_names->models().begin();
|
|
|
|
model != master_device_names->models().end();
|
|
|
|
++model) {
|
2012-03-20 14:01:59 -04:00
|
|
|
_master_device_names_list.insert(
|
|
|
|
std::pair<std::string, boost::shared_ptr<MasterDeviceNames> >
|
|
|
|
(*model, master_device_names));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-01-19 14:25:06 -05:00
|
|
|
_all_models.insert(*model);
|
2008-12-09 02:42:19 -05:00
|
|
|
}
|
2008-12-06 00:00:20 -05:00
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
return 0;
|
2008-08-04 18:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
MIDINameDocument::get_state(void)
|
|
|
|
{
|
2008-09-18 20:47:49 -04:00
|
|
|
static XMLNode nothing("<nothing>");
|
|
|
|
return nothing;
|
2008-08-04 18:37:24 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 05:02:00 -05:00
|
|
|
boost::shared_ptr<MasterDeviceNames>
|
|
|
|
MIDINameDocument::master_device_names(const std::string& model)
|
|
|
|
{
|
|
|
|
MasterDeviceNamesList::const_iterator m = _master_device_names_list.find(model);
|
|
|
|
if (m != _master_device_names_list.end()) {
|
|
|
|
return boost::shared_ptr<MasterDeviceNames>(m->second);
|
|
|
|
}
|
|
|
|
return boost::shared_ptr<MasterDeviceNames>();
|
|
|
|
}
|
|
|
|
|
2012-06-11 18:59:35 -04:00
|
|
|
const char* general_midi_program_names[128] = {
|
|
|
|
"Acoustic Grand Piano",
|
|
|
|
"Bright Acoustic Piano",
|
|
|
|
"Electric Grand Piano",
|
|
|
|
"Honky-tonk Piano",
|
|
|
|
"Rhodes Piano",
|
|
|
|
"Chorused Piano",
|
|
|
|
"Harpsichord",
|
|
|
|
"Clavinet",
|
|
|
|
"Celesta",
|
|
|
|
"Glockenspiel",
|
|
|
|
"Music Box",
|
|
|
|
"Vibraphone",
|
|
|
|
"Marimba",
|
|
|
|
"Xylophone",
|
|
|
|
"Tubular Bells",
|
|
|
|
"Dulcimer",
|
|
|
|
"Hammond Organ",
|
|
|
|
"Percussive Organ",
|
|
|
|
"Rock Organ",
|
|
|
|
"Church Organ",
|
|
|
|
"Reed Organ",
|
|
|
|
"Accordion",
|
|
|
|
"Harmonica",
|
|
|
|
"Tango Accordion",
|
|
|
|
"Acoustic Guitar (nylon)",
|
|
|
|
"Acoustic Guitar (steel)",
|
|
|
|
"Electric Guitar (jazz)",
|
|
|
|
"Electric Guitar (clean)",
|
|
|
|
"Electric Guitar (muted)",
|
|
|
|
"Overdriven Guitar",
|
|
|
|
"Distortion Guitar",
|
|
|
|
"Guitar Harmonics",
|
|
|
|
"Acoustic Bass",
|
|
|
|
"Electric Bass (finger)",
|
|
|
|
"Electric Bass (pick)",
|
|
|
|
"Fretless Bass",
|
|
|
|
"Slap Bass 1",
|
|
|
|
"Slap Bass 2",
|
|
|
|
"Synth Bass 1",
|
|
|
|
"Synth Bass 2",
|
|
|
|
"Violin",
|
|
|
|
"Viola",
|
|
|
|
"Cello",
|
|
|
|
"Contrabass",
|
|
|
|
"Tremolo Strings",
|
|
|
|
"Pizzicato Strings",
|
|
|
|
"Orchestral Harp",
|
|
|
|
"Timpani",
|
|
|
|
"String Ensemble 1",
|
|
|
|
"String Ensemble 2",
|
|
|
|
"SynthStrings 1",
|
|
|
|
"SynthStrings 2",
|
|
|
|
"Choir Aahs",
|
|
|
|
"Voice Oohs",
|
|
|
|
"Synth Voice",
|
|
|
|
"Orchestra Hit",
|
|
|
|
"Trumpet",
|
|
|
|
"Trombone",
|
|
|
|
"Tuba",
|
|
|
|
"Muted Trumpet",
|
|
|
|
"French Horn",
|
|
|
|
"Brass Section",
|
|
|
|
"Synth Brass 1",
|
|
|
|
"Synth Brass 2",
|
|
|
|
"Soprano Sax",
|
|
|
|
"Alto Sax",
|
|
|
|
"Tenor Sax",
|
|
|
|
"Baritone Sax",
|
|
|
|
"Oboe",
|
|
|
|
"English Horn",
|
|
|
|
"Bassoon",
|
|
|
|
"Clarinet",
|
|
|
|
"Piccolo",
|
|
|
|
"Flute",
|
|
|
|
"Recorder",
|
|
|
|
"Pan Flute",
|
|
|
|
"Bottle Blow",
|
|
|
|
"Shakuhachi",
|
|
|
|
"Whistle",
|
|
|
|
"Ocarina",
|
|
|
|
"Lead 1 (square)",
|
|
|
|
"Lead 2 (sawtooth)",
|
|
|
|
"Lead 3 (calliope lead)",
|
|
|
|
"Lead 4 (chiff lead)",
|
|
|
|
"Lead 5 (charang)",
|
|
|
|
"Lead 6 (voice)",
|
|
|
|
"Lead 7 (fifths)",
|
|
|
|
"Lead 8 (bass + lead)",
|
|
|
|
"Pad 1 (new age)",
|
|
|
|
"Pad 2 (warm)",
|
|
|
|
"Pad 3 (polysynth)",
|
|
|
|
"Pad 4 (choir)",
|
|
|
|
"Pad 5 (bowed)",
|
|
|
|
"Pad 6 (metallic)",
|
|
|
|
"Pad 7 (halo)",
|
|
|
|
"Pad 8 (sweep)",
|
|
|
|
"FX 1 (rain)",
|
|
|
|
"FX 2 (soundtrack)",
|
|
|
|
"FX 3 (crystal)",
|
|
|
|
"FX 4 (atmosphere)",
|
|
|
|
"FX 5 (brightness)",
|
|
|
|
"FX 6 (goblins)",
|
|
|
|
"FX 7 (echoes)",
|
|
|
|
"FX 8 (sci-fi)",
|
|
|
|
"Sitar",
|
|
|
|
"Banjo",
|
|
|
|
"Shamisen",
|
|
|
|
"Koto",
|
|
|
|
"Kalimba",
|
|
|
|
"Bagpipe",
|
|
|
|
"Fiddle",
|
|
|
|
"Shanai",
|
|
|
|
"Tinkle Bell",
|
|
|
|
"Agogo",
|
|
|
|
"Steel Drums",
|
|
|
|
"Woodblock",
|
|
|
|
"Taiko Drum",
|
|
|
|
"Melodic Tom",
|
|
|
|
"Synth Drum",
|
|
|
|
"Reverse Cymbal",
|
|
|
|
"Guitar Fret Noise",
|
|
|
|
"Breath Noise",
|
|
|
|
"Seashore",
|
|
|
|
"Bird Tweet",
|
|
|
|
"Telephone Ring",
|
|
|
|
"Helicopter",
|
|
|
|
"Applause",
|
|
|
|
"Gunshot",
|
|
|
|
};
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} //namespace Name
|
|
|
|
|
|
|
|
} //namespace MIDI
|
|
|
|
|