From 586484abf0d7816be06879a28c29175d90f03f26 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 20 Jan 2013 04:27:12 +0000 Subject: Support loading MIDI note names in NoteGroup tags as well. git-svn-id: svn://localhost/ardour2/branches/3.0@13919 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/midi++2/midnam_patch.cc | 54 +++++++++++++++++++++++++++++-------------- patchfiles/Yamaha_EX-5.midnam | 16 ------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/libs/midi++2/midnam_patch.cc b/libs/midi++2/midnam_patch.cc index 624e1605b5..916dfe7be7 100644 --- a/libs/midi++2/midnam_patch.cc +++ b/libs/midi++2/midnam_patch.cc @@ -148,7 +148,7 @@ Note::get_state (void) } int -Note::set_state (const XMLTree&, const XMLNode& node) +Note::set_state (const XMLTree& tree, const XMLNode& node) { assert(node.name() == "Note"); @@ -160,6 +160,13 @@ Note::set_state (const XMLTree&, const XMLNode& node) _number = atoi(node.property("Number")->value().c_str()) - 1; _name = node.property("Name")->value(); + if (_number > 127) { + PBD::warning << string_compose("%1: Note number %2 (%3) out of range", + tree.filename(), (int)_number, _name) + << endmsg; + return -1; + } + return 0; } @@ -172,6 +179,22 @@ NoteNameList::get_state (void) return *node; } +static void +add_note_from_xml (NoteNameList::Notes& notes, const XMLTree& tree, const XMLNode& node) +{ + boost::shared_ptr 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; + } + } +} + int NoteNameList::set_state (const XMLTree& tree, const XMLNode& node) { @@ -182,22 +205,19 @@ NoteNameList::set_state (const XMLTree& tree, const XMLNode& node) for (XMLNodeList::const_iterator i = node.children().begin(); i != node.children().end(); ++i) { - if ((*i)->name() != "Note") { - continue; - } - boost::shared_ptr note(new Note()); - note->set_state (tree, *(*i)); - if (note->number() > 127) { - PBD::warning << string_compose("%1: Note number %2 (%3) out of range", - tree.filename(), (int)note->number(), note->name()) - << endmsg; - } else if (_notes[note->number()]) { - PBD::warning << - string_compose("%1: Duplicate note number %2 (%3) ignored", - tree.filename(), (int)note->number(), note->name()) - << endmsg; - } else { - _notes[note->number()] = note; + 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; + } + } } } diff --git a/patchfiles/Yamaha_EX-5.midnam b/patchfiles/Yamaha_EX-5.midnam index 2d177bdc99..2cac3901eb 100644 --- a/patchfiles/Yamaha_EX-5.midnam +++ b/patchfiles/Yamaha_EX-5.midnam @@ -882,8 +882,6 @@ - - @@ -961,8 +959,6 @@ - - @@ -1040,8 +1036,6 @@ - - @@ -1119,8 +1113,6 @@ - - @@ -1198,8 +1190,6 @@ - - @@ -1266,8 +1256,6 @@ - - @@ -1334,8 +1322,6 @@ - - @@ -1472,8 +1458,6 @@ - - -- cgit v1.2.3