2 * Copyright (C) 2008-2012 Hans Baier <hansfbaier@googlemail.com>
3 * Copyright (C) 2008-2016 David Robillard <d@drobilla.net>
4 * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
7 * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "midi++/midnam_patch.h"
30 #include "pbd/compose.h"
31 #include "pbd/convert.h"
32 #include "pbd/error.h"
33 #include "pbd/failed_constructor.h"
44 Patch::Patch (std::string name, uint8_t p_number, uint16_t b_number)
46 , _id (p_number, b_number)
51 string_to_int(const XMLTree& tree, const std::string& str)
54 const int i = strtol(str.c_str(), &endptr, 10);
55 if (str.empty() || *endptr != '\0') {
56 PBD::error << string_compose("%1: Bad number `%2'", tree.filename(), str)
63 initialize_primary_key_from_commands (
64 const XMLTree& tree, PatchPrimaryKey& id, const XMLNode* node)
69 const XMLNodeList events = node->children();
70 for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
73 if (node->name() == "ControlChange") {
74 const string& control = node->property("Control")->value();
75 const string& value = node->property("Value")->value();
78 bank |= string_to_int(tree, value) << 7;
79 } else if (control == "32") {
80 bank |= string_to_int(tree, value);
83 } else if (node->name() == "ProgramChange") {
84 const string& number = node->property("Number")->value();
86 program = string_to_int(tree, number);
90 id = PatchPrimaryKey(program, bank);
95 Patch::get_state (void)
97 XMLNode* node = new XMLNode("Patch");
99 /* XXX this is totally wrong */
101 node->set_property("Number", _id.program());
102 node->set_property("Name", _name);
105 typedef std::list< boost::shared_ptr< Evoral::Event<Temporal::Beats> > > PatchMidiCommands;
106 XMLNode* commands = node->add_child("PatchMIDICommands");
107 for (PatchMidiCommands::const_iterator event = _patch_midi_commands.begin();
108 event != _patch_midi_commands.end();
110 commands->add_child_copy(Evoral::MIDIXML::midi_to_xml(*event));
118 Patch::set_state (const XMLTree& tree, const XMLNode& node)
120 if (node.name() != "Patch") {
121 cerr << "Incorrect node type '" << node.name() << "' handed to Patch" << endl;
125 /* Note there is a "Number" attribute, but it's really more like a label
126 and is often not numeric. We currently do not use it. */
128 const XMLProperty* program_change = node.property("ProgramChange");
129 if (program_change) {
130 _id = PatchPrimaryKey(string_to_int(tree, program_change->value()), _id.bank());
133 const XMLProperty* name = node.property("Name");
137 _name = name->value();
139 XMLNode* commands = node.child("PatchMIDICommands");
141 if (initialize_primary_key_from_commands(tree, _id, commands) &&
143 return -1; // Failed to find a program number anywhere
147 XMLNode* use_note_name_list = node.child("UsesNoteNameList");
148 if (use_note_name_list) {
149 _note_list_name = use_note_name_list->property ("Name")->value();
156 Note::get_state (void)
158 XMLNode* node = new XMLNode("Note");
159 node->set_property("Number", _number);
160 node->set_property("Name", _name);
166 Note::set_state (const XMLTree& tree, const XMLNode& node)
168 assert(node.name() == "Note");
170 const int num = string_to_int(tree, node.property("Number")->value());
172 PBD::warning << string_compose("%1: Note number %2 (%3) out of range",
173 tree.filename(), num, _name)
179 _name = node.property("Name")->value();
185 NoteNameList::get_state (void)
187 XMLNode* node = new XMLNode("NoteNameList");
188 node->set_property("Name", _name);
194 add_note_from_xml (NoteNameList::Notes& notes, const XMLTree& tree, const XMLNode& node)
196 boost::shared_ptr<Note> note(new Note());
197 if (!note->set_state (tree, node)) {
198 if (!notes[note->number()]) {
199 notes[note->number()] = note;
202 << string_compose("%1: Duplicate note number %2 (%3) ignored",
203 tree.filename(), (int)note->number(), note->name())
210 NoteNameList::set_state (const XMLTree& tree, const XMLNode& node)
212 assert(node.name() == "NoteNameList");
213 _name = node.property("Name")->value();
217 for (XMLNodeList::const_iterator i = node.children().begin();
218 i != node.children().end(); ++i) {
219 if ((*i)->name() == "Note") {
220 add_note_from_xml(_notes, tree, **i);
221 } else if ((*i)->name() == "NoteGroup") {
222 for (XMLNodeList::const_iterator j = (*i)->children().begin();
223 j != (*i)->children().end(); ++j) {
224 if ((*j)->name() == "Note") {
225 add_note_from_xml(_notes, tree, **j);
227 PBD::warning << string_compose("%1: Invalid NoteGroup child %2 ignored",
228 tree.filename(), (*j)->name())
239 Control::get_state (void)
241 XMLNode* node = new XMLNode("Control");
242 node->set_property("Type", _type);
243 node->set_property("Number", _number);
244 node->set_property("Name", _name);
250 Control::set_state (const XMLTree& tree, const XMLNode& node)
252 assert(node.name() == "Control");
253 if (node.property("Type")) {
254 _type = node.property("Type")->value();
258 if (_type == "NRPN") {
261 _number = string_to_int(tree, node.property("Number")->value());
262 _name = node.property("Name")->value();
264 for (XMLNodeList::const_iterator i = node.children().begin();
265 i != node.children().end(); ++i) {
266 if ((*i)->name() == "Values") {
267 // <Values> has Min and Max properties, but we don't care
268 for (XMLNodeList::const_iterator j = (*i)->children().begin();
269 j != (*i)->children().end(); ++j) {
270 if ((*j)->name() == "ValueNameList") {
271 _value_name_list = boost::shared_ptr<ValueNameList>(new ValueNameList());
272 _value_name_list->set_state(tree, **j);
273 } else if ((*j)->name() == "UsesValueNameList") {
274 _value_name_list_name = (*j)->property("Name")->value();
284 ControlNameList::get_state (void)
286 XMLNode* node = new XMLNode("ControlNameList");
287 node->set_property("Name", _name);
293 ControlNameList::set_state (const XMLTree& tree, const XMLNode& node)
295 assert(node.name() == "ControlNameList");
296 _name = node.property("Name")->value();
299 for (XMLNodeList::const_iterator i = node.children().begin();
300 i != node.children().end(); ++i) {
301 if ((*i)->name() == "Control") {
302 boost::shared_ptr<Control> control(new Control());
303 if (control->set_state (tree, *(*i))) {
306 if (_controls.find(control->number()) == _controls.end()) {
307 _controls.insert(make_pair(control->number(), control));
309 PBD::warning << string_compose("%1: Duplicate control %2 ignored",
310 tree.filename(), control->number())
319 boost::shared_ptr<const Control>
320 ControlNameList::control(uint16_t num) const
322 Controls::const_iterator i = _controls.find(num);
323 if (i != _controls.end()) {
326 return boost::shared_ptr<const Control>();
330 Value::get_state (void)
332 XMLNode* node = new XMLNode("Value");
333 node->set_property("Number", _number);
334 node->set_property("Name", _name);
340 Value::set_state (const XMLTree& tree, const XMLNode& node)
342 assert(node.name() == "Value");
343 _number = string_to_int(tree, node.property("Number")->value());
344 _name = node.property("Name")->value();
350 ValueNameList::get_state (void)
352 XMLNode* node = new XMLNode("ValueNameList");
353 node->set_property("Name", _name);
359 ValueNameList::set_state (const XMLTree& tree, const XMLNode& node)
361 assert(node.name() == "ValueNameList");
362 const XMLProperty* name_prop = node.property("Name");
364 // May be anonymous if written inline within a single <Control> tag
365 _name = name_prop->value();
369 for (XMLNodeList::const_iterator i = node.children().begin();
370 i != node.children().end(); ++i) {
371 if ((*i)->name() == "Value") {
372 boost::shared_ptr<Value> value(new Value());
373 value->set_state (tree, *(*i));
374 if (_values.find(value->number()) == _values.end()) {
375 _values.insert(make_pair(value->number(), value));
377 PBD::warning << string_compose("%1: Duplicate value %2 ignored",
378 tree.filename(), value->number())
387 boost::shared_ptr<const Value>
388 ValueNameList::value(uint16_t num) const
390 Values::const_iterator i = _values.find(num);
391 if (i != _values.end()) {
394 return boost::shared_ptr<const Value>();
397 boost::shared_ptr<const Value>
398 ValueNameList::max_value_below(uint16_t num) const
400 Values::const_iterator i = _values.lower_bound(num);
401 if (i->first == num) {
404 } else if (i == _values.begin()) {
406 return boost::shared_ptr<const Value>();
408 // Found the smallest element >= num, so the previous one is our result
415 PatchBank::get_state (void)
417 XMLNode* node = new XMLNode("PatchBank");
418 node->set_property("Name", _name);
419 XMLNode* patch_name_list = node->add_child("PatchNameList");
420 for (PatchNameList::iterator patch = _patch_name_list.begin();
421 patch != _patch_name_list.end();
423 patch_name_list->add_child_nocopy((*patch)->get_state());
430 PatchBank::set_state (const XMLTree& tree, const XMLNode& node)
432 assert(node.name() == "PatchBank");
433 _name = node.property("Name")->value();
435 XMLNode* commands = node.child("MIDICommands");
437 PatchPrimaryKey id (0, 0);
438 if (initialize_primary_key_from_commands (tree, id, commands)) {
444 XMLNode* patch_name_list = node.child("PatchNameList");
446 if (patch_name_list) {
447 const XMLNodeList patches = patch_name_list->children();
448 for (XMLNodeList::const_iterator i = patches.begin(); i != patches.end(); ++i) {
449 boost::shared_ptr<Patch> patch (new Patch (string(), 0, _number));
450 if (0 == patch->set_state(tree, *(*i))) {
451 _patch_name_list.push_back(patch);
455 XMLNode* use_patch_name_list = node.child ("UsesPatchNameList");
456 if (use_patch_name_list) {
457 _patch_list_name = use_patch_name_list->property ("Name")->value();
459 error << "Patch without patch name list - patchfile will be ignored" << endmsg;
468 PatchBank::set_patch_name_list (const PatchNameList& pnl)
470 _patch_name_list = pnl;
471 _patch_list_name = "";
473 for (PatchNameList::iterator p = _patch_name_list.begin(); p != _patch_name_list.end(); p++) {
474 (*p)->set_bank_number (_number);
481 operator<< (std::ostream& os, const ChannelNameSet& cns)
483 os << "Channel Name Set: name = " << cns._name << endl
484 << "Map size " << cns._patch_map.size () << endl
485 << "List size " << cns._patch_list.size() << endl
486 << "Patch list name = [" << cns._patch_list_name << ']' << endl
487 << "Available channels : ";
488 for (set<uint8_t>::const_iterator x = cns._available_for_channels.begin(); x != cns._available_for_channels.end(); ++x) {
489 os << (int) (*x) << ' ';
493 for (ChannelNameSet::PatchBanks::const_iterator pbi = cns._patch_banks.begin(); pbi != cns._patch_banks.end(); ++pbi) {
494 os << "\tPatch Bank " << (*pbi)->name() << " with " << (*pbi)->patch_name_list().size() << " patches\n";
495 for (PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
496 os << "\t\tPatch name " << (*pni)->name() << " prog " << (int) (*pni)->program_number() << " bank " << (*pni)->bank_number() << endl;
504 ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb)
509 _patch_list.clear ();
510 _patch_list_name = "";
511 _available_for_channels.clear ();
513 for (PatchBanks::const_iterator pbi = _patch_banks.begin(); pbi != _patch_banks.end(); ++pbi) {
514 for (PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
515 _patch_map[(*pni)->patch_primary_key()] = (*pni);
516 _patch_list.push_back ((*pni)->patch_primary_key());
520 for (uint8_t n = 0; n < 16; ++n) {
521 _available_for_channels.insert (n);
526 ChannelNameSet::use_patch_name_list (const PatchNameList& pnl)
528 for (PatchNameList::const_iterator p = pnl.begin(); p != pnl.end(); ++p) {
529 _patch_map[(*p)->patch_primary_key()] = (*p);
530 _patch_list.push_back ((*p)->patch_primary_key());
535 ChannelNameSet::get_state (void)
537 XMLNode* node = new XMLNode("ChannelNameSet");
538 node->set_property("Name", _name);
540 XMLNode* available_for_channels = node->add_child("AvailableForChannels");
541 assert(available_for_channels);
543 for (uint8_t channel = 0; channel < 16; ++channel) {
544 XMLNode* available_channel = available_for_channels->add_child("AvailableChannel");
545 assert(available_channel);
547 available_channel->set_property("Channel", channel);
549 if (_available_for_channels.find(channel) != _available_for_channels.end()) {
550 available_channel->set_property("Available", "true");
552 available_channel->set_property("Available", "false");
556 for (PatchBanks::iterator patch_bank = _patch_banks.begin();
557 patch_bank != _patch_banks.end();
559 node->add_child_nocopy((*patch_bank)->get_state());
566 ChannelNameSet::set_state (const XMLTree& tree, const XMLNode& node)
568 assert(node.name() == "ChannelNameSet");
569 _name = node.property("Name")->value();
571 const XMLNodeList children = node.children();
572 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
575 if (node->name() == "AvailableForChannels") {
576 boost::shared_ptr<XMLSharedNodeList> channels =
577 tree.find("//AvailableChannel[@Available = 'true']/@Channel", node);
578 for (XMLSharedNodeList::const_iterator i = channels->begin();
579 i != channels->end();
582 _available_for_channels.insert(
583 string_to_int(tree, (*i)->attribute_value()));
584 } catch (XMLException &e) {
585 cerr << "ChannelNameSet::set_state: " << e.what () << endl;
588 } else if (node->name() == "PatchBank") {
589 boost::shared_ptr<PatchBank> bank (new PatchBank ());
590 bank->set_state(tree, *node);
591 _patch_banks.push_back(bank);
592 const PatchNameList& patches = bank->patch_name_list();
593 for (PatchNameList::const_iterator patch = patches.begin();
594 patch != patches.end();
596 _patch_map[(*patch)->patch_primary_key()] = *patch;
597 _patch_list.push_back((*patch)->patch_primary_key());
599 } else if (node->name() == "UsesNoteNameList") {
600 _note_list_name = node->property ("Name")->value();
601 } else if (node->name() == "UsesControlNameList") {
602 _control_list_name = node->property ("Name")->value();
610 CustomDeviceMode::set_state(const XMLTree& tree, const XMLNode& a_node)
612 assert(a_node.name() == "CustomDeviceMode");
614 _name = a_node.property("Name")->value();
616 boost::shared_ptr<XMLSharedNodeList> channel_name_set_assignments =
617 tree.find("//ChannelNameSetAssign", const_cast<XMLNode *>(&a_node));
618 for (XMLSharedNodeList::const_iterator i = channel_name_set_assignments->begin();
619 i != channel_name_set_assignments->end();
621 const int channel = string_to_int(tree, (*i)->property("Channel")->value());
622 const string& name_set = (*i)->property("NameSet")->value();
623 assert( 1 <= channel && channel <= 16 );
624 _channel_name_set_assignments[channel - 1] = name_set;
630 CustomDeviceMode::get_state(void)
632 XMLNode* custom_device_mode = new XMLNode("CustomDeviceMode");
633 custom_device_mode->set_property("Name", _name);
634 XMLNode* channel_name_set_assignments =
635 custom_device_mode->add_child("ChannelNameSetAssignments");
636 for (int i = 0; i < 15 && !_channel_name_set_assignments[i].empty(); i++) {
637 XMLNode* channel_name_set_assign =
638 channel_name_set_assignments->add_child("ChannelNameSetAssign");
639 channel_name_set_assign->set_property("Channel", i + 1);
640 channel_name_set_assign->set_property("NameSet", _channel_name_set_assignments[i]);
643 return *custom_device_mode;
646 boost::shared_ptr<const ValueNameList>
647 MasterDeviceNames::value_name_list_by_control(const std::string& mode, uint8_t channel, uint8_t number)
649 boost::shared_ptr<ChannelNameSet> chan_names = channel_name_set_by_channel(mode, channel);
651 return boost::shared_ptr<const ValueNameList>();
654 boost::shared_ptr<ControlNameList> control_names = control_name_list(chan_names->control_list_name());
655 if (!control_names) {
656 return boost::shared_ptr<const ValueNameList>();
659 boost::shared_ptr<const Control> control = control_names->control(number);
661 return boost::shared_ptr<const ValueNameList>();
664 if (!control->value_name_list_name().empty()) {
665 return value_name_list(control->value_name_list_name());
667 return control->value_name_list();
671 boost::shared_ptr<CustomDeviceMode>
672 MasterDeviceNames::custom_device_mode_by_name(const std::string& mode_name)
674 return _custom_device_modes[mode_name];
677 boost::shared_ptr<ChannelNameSet>
678 MasterDeviceNames::channel_name_set_by_channel(const std::string& mode, uint8_t channel)
680 boost::shared_ptr<CustomDeviceMode> cdm = custom_device_mode_by_name(mode);
681 boost::shared_ptr<ChannelNameSet> cns = _channel_name_sets[cdm->channel_name_set_name_by_channel(channel)];
685 boost::shared_ptr<Patch>
686 MasterDeviceNames::find_patch(const std::string& mode, uint8_t channel, const PatchPrimaryKey& key)
688 boost::shared_ptr<ChannelNameSet> cns = channel_name_set_by_channel(mode, channel);
689 if (!cns) return boost::shared_ptr<Patch>();
690 return cns->find_patch(key);
693 boost::shared_ptr<ChannelNameSet>
694 MasterDeviceNames::channel_name_set(const std::string& name)
696 ChannelNameSets::const_iterator i = _channel_name_sets.find(name);
697 if (i != _channel_name_sets.end()) {
700 return boost::shared_ptr<ChannelNameSet>();
703 boost::shared_ptr<ControlNameList>
704 MasterDeviceNames::control_name_list(const std::string& name)
706 ControlNameLists::const_iterator i = _control_name_lists.find(name);
707 if (i != _control_name_lists.end()) {
710 return boost::shared_ptr<ControlNameList>();
713 boost::shared_ptr<ValueNameList>
714 MasterDeviceNames::value_name_list(const std::string& name)
716 ValueNameLists::const_iterator i = _value_name_lists.find(name);
717 if (i != _value_name_lists.end()) {
720 return boost::shared_ptr<ValueNameList>();
723 boost::shared_ptr<NoteNameList>
724 MasterDeviceNames::note_name_list(const std::string& name)
726 NoteNameLists::const_iterator i = _note_name_lists.find(name);
727 if (i != _note_name_lists.end()) {
730 return boost::shared_ptr<NoteNameList>();
734 MasterDeviceNames::note_name(const std::string& mode_name,
744 boost::shared_ptr<const NoteNameList> note_names;
745 boost::shared_ptr<const Patch> patch(
746 find_patch(mode_name, channel, PatchPrimaryKey(program, bank)));
748 note_names = note_name_list(patch->note_list_name());
752 /* No note names specific to this patch, check the ChannelNameSet */
753 boost::shared_ptr<ChannelNameSet> chan_names = channel_name_set_by_channel(
756 note_names = note_name_list(chan_names->note_list_name());
763 boost::shared_ptr<const Note> note(note_names->notes()[number]);
764 return note ? note->name() : "";
768 MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode&)
771 boost::shared_ptr<XMLSharedNodeList> manufacturer = tree.find("//Manufacturer");
772 assert(manufacturer->size() == 1);
773 _manufacturer = manufacturer->front()->children().front()->content();
776 boost::shared_ptr<XMLSharedNodeList> models = tree.find("//Model");
777 assert(models->size() >= 1);
778 for (XMLSharedNodeList::iterator i = models->begin();
781 const XMLNodeList& contents = (*i)->children();
782 assert(contents.size() == 1);
783 XMLNode * content = *(contents.begin());
784 assert(content->is_content());
785 _models.insert(content->content());
789 boost::shared_ptr<XMLSharedNodeList> custom_device_modes = tree.find("//CustomDeviceMode");
790 for (XMLSharedNodeList::iterator i = custom_device_modes->begin();
791 i != custom_device_modes->end();
793 boost::shared_ptr<CustomDeviceMode> custom_device_mode(new CustomDeviceMode());
794 custom_device_mode->set_state(tree, *(*i));
796 _custom_device_modes[custom_device_mode->name()] = custom_device_mode;
797 _custom_device_mode_names.push_back(custom_device_mode->name());
801 boost::shared_ptr<XMLSharedNodeList> channel_name_sets = tree.find("//ChannelNameSet");
802 for (XMLSharedNodeList::iterator i = channel_name_sets->begin();
803 i != channel_name_sets->end();
805 boost::shared_ptr<ChannelNameSet> channel_name_set(new ChannelNameSet());
806 channel_name_set->set_state(tree, *(*i));
807 _channel_name_sets[channel_name_set->name()] = channel_name_set;
811 boost::shared_ptr<XMLSharedNodeList> note_name_lists = tree.find("//NoteNameList");
812 for (XMLSharedNodeList::iterator i = note_name_lists->begin();
813 i != note_name_lists->end();
815 boost::shared_ptr<NoteNameList> note_name_list(new NoteNameList());
816 note_name_list->set_state (tree, *(*i));
817 _note_name_lists[note_name_list->name()] = note_name_list;
821 boost::shared_ptr<XMLSharedNodeList> control_name_lists = tree.find("//ControlNameList");
822 for (XMLSharedNodeList::iterator i = control_name_lists->begin();
823 i != control_name_lists->end();
825 boost::shared_ptr<ControlNameList> control_name_list(new ControlNameList());
826 control_name_list->set_state (tree, *(*i));
827 _control_name_lists[control_name_list->name()] = control_name_list;
831 boost::shared_ptr<XMLSharedNodeList> value_name_lists = tree.find("/child::MIDINameDocument/child::MasterDeviceNames/child::ValueNameList");
832 for (XMLSharedNodeList::iterator i = value_name_lists->begin();
833 i != value_name_lists->end();
835 boost::shared_ptr<ValueNameList> value_name_list(new ValueNameList());
836 value_name_list->set_state (tree, *(*i));
837 _value_name_lists[value_name_list->name()] = value_name_list;
840 // global/post-facto PatchNameLists
841 boost::shared_ptr<XMLSharedNodeList> patch_name_lists = tree.find("/child::MIDINameDocument/child::MasterDeviceNames/child::PatchNameList");
842 for (XMLSharedNodeList::iterator i = patch_name_lists->begin();
843 i != patch_name_lists->end();
846 PatchNameList patch_name_list;
847 const XMLNodeList patches = (*i)->children();
849 for (XMLNodeList::const_iterator p = patches.begin(); p != patches.end(); ++p) {
850 boost::shared_ptr<Patch> patch (new Patch ());
851 patch->set_state(tree, *(*p));
852 patch_name_list.push_back(patch);
855 if (!patch_name_list.empty()) {
856 _patch_name_lists[(*i)->property ("Name")->value()] = patch_name_list;
860 /* now traverse patches and hook up anything that used UsePatchNameList
861 * to the right patch list
864 for (ChannelNameSets::iterator cns = _channel_name_sets.begin(); cns != _channel_name_sets.end(); ++cns) {
865 ChannelNameSet::PatchBanks pbs = cns->second->patch_banks();
866 PatchNameLists::iterator p;
868 for (ChannelNameSet::PatchBanks::iterator pb = pbs.begin(); pb != pbs.end(); ++pb) {
869 const std::string& pln = (*pb)->patch_list_name();
871 if ((p = _patch_name_lists.find (pln)) != _patch_name_lists.end()) {
872 if ((*pb)->set_patch_name_list (p->second)) {
875 cns->second->use_patch_name_list (p->second);
877 error << string_compose ("Patch list name %1 was not found - patch file ignored", pln) << endmsg;
889 MasterDeviceNames::get_state(void)
891 static XMLNode nothing("<nothing>");
895 MIDINameDocument::MIDINameDocument (const string& file_path)
896 : _file_path(file_path)
899 if (!document.read (file_path)) {
900 throw failed_constructor ();
903 document.set_filename (file_path);
904 set_state (document, *document.root());
908 MIDINameDocument::set_state (const XMLTree& tree, const XMLNode&)
912 boost::shared_ptr<XMLSharedNodeList> author = tree.find("//Author");
913 if (author->size() < 1) {
914 error << "No author information in MIDNAM file" << endmsg;
918 if (author->front()->children().size() > 0) {
919 _author = author->front()->children().front()->content();
924 boost::shared_ptr<XMLSharedNodeList> master_device_names_list = tree.find ("//MasterDeviceNames");
926 for (XMLSharedNodeList::iterator i = master_device_names_list->begin();
927 i != master_device_names_list->end();
929 boost::shared_ptr<MasterDeviceNames> master_device_names(new MasterDeviceNames());
931 if (master_device_names->set_state(tree, *(*i))) {
935 for (MasterDeviceNames::Models::const_iterator model = master_device_names->models().begin();
936 model != master_device_names->models().end();
938 _master_device_names_list.insert(
939 std::pair<std::string, boost::shared_ptr<MasterDeviceNames> >
940 (*model, master_device_names));
942 _all_models.insert(*model);
950 MIDINameDocument::get_state(void)
952 static XMLNode nothing("<nothing>");
956 boost::shared_ptr<MasterDeviceNames>
957 MIDINameDocument::master_device_names(const std::string& model)
959 MasterDeviceNamesList::const_iterator m = _master_device_names_list.find(model);
960 if (m != _master_device_names_list.end()) {
961 return boost::shared_ptr<MasterDeviceNames>(m->second);
963 return boost::shared_ptr<MasterDeviceNames>();
966 const char* general_midi_program_names[128] = {
967 "Acoustic Grand Piano",
968 "Bright Acoustic Piano",
969 "Electric Grand Piano",
991 "Acoustic Guitar (nylon)",
992 "Acoustic Guitar (steel)",
993 "Electric Guitar (jazz)",
994 "Electric Guitar (clean)",
995 "Electric Guitar (muted)",
1000 "Electric Bass (finger)",
1001 "Electric Bass (pick)",
1012 "Pizzicato Strings",
1015 "String Ensemble 1",
1016 "String Ensemble 2",
1048 "Lead 2 (sawtooth)",
1049 "Lead 3 (calliope lead)",
1050 "Lead 4 (chiff lead)",
1054 "Lead 8 (bass + lead)",
1057 "Pad 3 (polysynth)",
1064 "FX 2 (soundtrack)",
1066 "FX 4 (atmosphere)",
1067 "FX 5 (brightness)",
1087 "Guitar Fret Noise",