2008-12-08 04:50:19 -05:00
|
|
|
/*
|
2009-10-20 20:15:42 -04:00
|
|
|
Copyright (C) 2008 Hans Baier
|
2008-12-08 04:50:19 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
Patch::Patch (PatchBank* b)
|
|
|
|
{
|
|
|
|
use_bank_info (b);
|
|
|
|
}
|
|
|
|
|
|
|
|
Patch::Patch (std::string a_number, std::string a_name, PatchBank* a_bank)
|
|
|
|
: _number (a_number)
|
|
|
|
, _name (a_name)
|
|
|
|
{
|
|
|
|
use_bank_info (a_bank);
|
|
|
|
}
|
|
|
|
|
2008-08-04 18:37:24 -04:00
|
|
|
XMLNode&
|
2008-06-02 17:41:35 -04:00
|
|
|
Patch::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("Patch");
|
|
|
|
node->add_property("Number", _number);
|
|
|
|
node->add_property("Name", _name);
|
2009-01-14 22:13:24 -05:00
|
|
|
/*
|
2009-02-18 13:04:54 -05:00
|
|
|
typedef std::list< boost::shared_ptr< Evoral::MIDIEvent<double> > > PatchMidiCommands;
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode* commands = node->add_child("PatchMIDICommands");
|
2008-08-04 18:37:24 -04:00
|
|
|
for (PatchMidiCommands::const_iterator event = _patch_midi_commands.begin();
|
2008-06-02 17:41:35 -04:00
|
|
|
event != _patch_midi_commands.end();
|
|
|
|
++event) {
|
2008-09-22 12:28:02 -04:00
|
|
|
commands->add_child_copy(*((((Evoral::MIDIEvent&)*event)).to_xml()));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-01-14 22:13:24 -05:00
|
|
|
*/
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
int initialize_primary_key_from_commands (PatchPrimaryKey& id, const XMLNode* node)
|
2008-06-02 17:41:35 -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) {
|
2008-12-10 05:54:45 -05:00
|
|
|
XMLNode* node = *i;
|
|
|
|
if (node->name() == "ControlChange") {
|
|
|
|
string control = node->property("Control")->value();
|
|
|
|
assert(control != "");
|
|
|
|
string value = node->property("Value")->value();
|
|
|
|
assert(value != "");
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-12-10 05:54:45 -05:00
|
|
|
if (control == "0") {
|
2009-01-14 22:13:24 -05:00
|
|
|
id.msb = PBD::atoi(value);
|
2008-12-10 05:54:45 -05:00
|
|
|
} else if (control == "32") {
|
2009-01-14 22:13:24 -05:00
|
|
|
id.lsb = PBD::atoi(value);
|
2008-12-10 05:54:45 -05:00
|
|
|
}
|
|
|
|
} else if (node->name() == "ProgramChange") {
|
|
|
|
string number = node->property("Number")->value();
|
|
|
|
assert(number != "");
|
2009-01-14 22:13:24 -05:00
|
|
|
id.program_number = PBD::atoi(number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-14 22:13:24 -05:00
|
|
|
|
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
Patch::set_state (const XMLTree&, const XMLNode& node)
|
2009-01-14 22:13:24 -05:00
|
|
|
{
|
2012-03-20 14:01:59 -04:00
|
|
|
if (node.name() != "Patch") {
|
|
|
|
cerr << "Incorrect node " << node.name() << " handed to Patch" << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XMLProperty* prop = node.property ("Number");
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_number = prop->value();
|
|
|
|
|
|
|
|
prop = node.property ("Name");
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_name = prop->value();
|
|
|
|
|
2009-01-14 22:13:24 -05:00
|
|
|
XMLNode* commands = node.child("PatchMIDICommands");
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2009-01-14 22:13:24 -05:00
|
|
|
if (commands) {
|
2012-03-20 14:01:59 -04:00
|
|
|
if (initialize_primary_key_from_commands(_id, commands)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-01-14 22:13:24 -05:00
|
|
|
} else {
|
|
|
|
string program_change = node.property("ProgramChange")->value();
|
|
|
|
assert(program_change.length());
|
2012-03-20 14:01:59 -04:00
|
|
|
_id.program_number = PBD::atoi(program_change);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Patch::use_bank_info (PatchBank* bank)
|
|
|
|
{
|
|
|
|
if (bank) {
|
|
|
|
if (bank->patch_primary_key() ) {
|
|
|
|
_id.msb = bank->patch_primary_key()->msb;
|
|
|
|
_id.lsb = bank->patch_primary_key()->lsb;
|
|
|
|
} else {
|
|
|
|
return -1;
|
2008-12-10 05:54:45 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2008-08-04 18:37:24 -04:00
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
if (!_id.is_sane()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-20 20:15:42 -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");
|
2008-12-05 19:07:07 -05:00
|
|
|
node->add_property("Number", _number);
|
|
|
|
node->add_property("Name", _name);
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
Note::set_state (const XMLTree&, const XMLNode& node)
|
2008-12-05 19:07:07 -05:00
|
|
|
{
|
2008-12-05 23:38:44 -05:00
|
|
|
assert(node.name() == "Note");
|
2008-12-05 19:07:07 -05:00
|
|
|
_number = node.property("Number")->value();
|
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-05 23:38:44 -05:00
|
|
|
XMLNode&
|
|
|
|
NoteNameList::get_state (void)
|
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode("NoteNameList");
|
|
|
|
node->add_property("Name", _name);
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
_name = node.property("Name")->value();
|
|
|
|
|
2012-03-20 14:01:59 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> notes = tree.find("//Note");
|
2008-12-05 23:38:44 -05:00
|
|
|
for (XMLSharedNodeList::const_iterator i = notes->begin(); i != notes->end(); ++i) {
|
2008-12-12 00:17:53 -05:00
|
|
|
boost::shared_ptr<Note> note(new Note());
|
2012-03-20 14:01:59 -04:00
|
|
|
note->set_state (tree, *(*i));
|
2008-12-12 00:17:53 -05:00
|
|
|
_notes.push_back(note);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
node->add_property("Name", _name);
|
|
|
|
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) {
|
|
|
|
_id = new PatchPrimaryKey();
|
2012-03-20 14:01:59 -04:00
|
|
|
if (initialize_primary_key_from_commands(*_id, commands)) {
|
|
|
|
return -1;
|
|
|
|
}
|
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) {
|
|
|
|
boost::shared_ptr<Patch> patch(new Patch(this));
|
|
|
|
patch->set_state(tree, *(*i));
|
|
|
|
_patch_name_list.push_back(patch);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XMLNode* use_patch_name_list = node.child ("UsesPatchNameList");
|
|
|
|
if (use_patch_name_list) {
|
|
|
|
_patch_list_name = node.property ("Name")->value();
|
|
|
|
} 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 = "";
|
|
|
|
|
|
|
|
for (PatchNameList::iterator p = _patch_name_list.begin(); p != _patch_name_list.end(); p++) {
|
|
|
|
if ((*p)->use_bank_info (this)) {
|
|
|
|
return -1;
|
|
|
|
}
|
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-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");
|
|
|
|
node->add_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
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
available_channel->add_property("Channel", (long) 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()) {
|
2008-08-04 18:37:24 -04:00
|
|
|
available_channel->add_property("Available", "true");
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2008-08-04 18:37:24 -04:00
|
|
|
available_channel->add_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");
|
|
|
|
_name = node.property("Name")->value();
|
|
|
|
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-03-20 14:01:59 -04:00
|
|
|
tree.find("//AvailableChannel[@Available = 'true']/@Channel");
|
2008-06-02 17:41:35 -04:00
|
|
|
for(XMLSharedNodeList::const_iterator i = channels->begin();
|
|
|
|
i != channels->end();
|
|
|
|
++i) {
|
|
|
|
_available_for_channels.insert(atoi((*i)->attribute_value().c_str()));
|
|
|
|
}
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (node->name() == "PatchBank") {
|
2008-12-12 00:17:53 -05: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);
|
2008-12-10 05:54:45 -05:00
|
|
|
const PatchBank::PatchNameList& patches = bank->patch_name_list();
|
|
|
|
for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
|
|
|
|
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
|
|
|
}
|
2008-08-04 18:37:24 -04: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-03-20 14:01:59 -04:00
|
|
|
tree.find("//ChannelNameSetAssign");
|
2008-11-23 14:42:09 -05:00
|
|
|
for(XMLSharedNodeList::const_iterator i = channel_name_set_assignments->begin();
|
|
|
|
i != channel_name_set_assignments->end();
|
|
|
|
++i) {
|
|
|
|
int channel = atoi((*i)->property("Channel")->value().c_str());
|
|
|
|
string name_set = (*i)->property("NameSet")->value();
|
|
|
|
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");
|
|
|
|
custom_device_mode->add_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");
|
|
|
|
channel_name_set_assign->add_property("Channel", i + 1);
|
|
|
|
channel_name_set_assign->add_property("NameSet", _channel_name_set_assignments[i]);
|
|
|
|
}
|
2009-10-20 20:15:42 -04:00
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
return *custom_device_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode& a_node)
|
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);
|
|
|
|
_manufacturer = manufacturer->front()->content();
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
_models.push_back(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));
|
2008-12-12 00:17:53 -05:00
|
|
|
_note_name_lists.push_back(note_name_list);
|
2008-12-05 23:38:44 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
PatchBank::PatchNameList patch_name_list;
|
|
|
|
const XMLNodeList patches = (*i)->children();
|
|
|
|
|
|
|
|
for (XMLNodeList::const_iterator p = patches.begin(); p != patches.end(); ++p) {
|
|
|
|
boost::shared_ptr<Patch> patch(new Patch());
|
|
|
|
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();
|
|
|
|
for (ChannelNameSet::PatchBanks::iterator pb = pbs.begin(); pb != pbs.end(); ++pb) {
|
|
|
|
std::string pln = (*pb)->patch_list_name();
|
|
|
|
if (!pln.empty()) {
|
|
|
|
PatchNameLists::iterator p = _patch_name_lists.find (pln);
|
|
|
|
if (p != _patch_name_lists.end()) {
|
|
|
|
if ((*pb)->set_patch_name_list (p->second)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error << string_compose ("Patch list name %1 was not found - patch file ignored", pln) << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-23 14:42:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
MasterDeviceNames::get_state(void)
|
|
|
|
{
|
|
|
|
static XMLNode nothing("<nothing>");
|
|
|
|
return nothing;
|
|
|
|
}
|
|
|
|
|
2009-10-15 14:56:11 -04:00
|
|
|
MIDINameDocument::MIDINameDocument (const string& filename)
|
2009-10-20 20:15:42 -04:00
|
|
|
{
|
2012-03-20 14:01:59 -04:00
|
|
|
if (!_document.read (filename)) {
|
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
|
|
|
set_state (_document, *_document.root());
|
2009-10-15 14:56:11 -04:00
|
|
|
}
|
|
|
|
|
2008-08-04 18:37:24 -04:00
|
|
|
int
|
2012-03-20 14:01:59 -04:00
|
|
|
MIDINameDocument::set_state (const XMLTree& tree, const XMLNode& a_node)
|
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;
|
|
|
|
}
|
2008-12-06 00:00:20 -05:00
|
|
|
_author = author->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));
|
|
|
|
|
|
|
|
_all_models.push_back(*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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} //namespace Name
|
|
|
|
|
|
|
|
} //namespace MIDI
|
|
|
|
|