globally remove all trailing whitespace from .cpp and .hpp files missed by previous...
[ardour.git] / libs / midi++2 / midnam_patch.cc
index 1ec60622059cb300b918de88e440274de5df9dc8..9f62c12dfe734b76c7e3a8f3cb47c5f18212c324 100644 (file)
@@ -58,7 +58,8 @@ static int
 initialize_primary_key_from_commands (
        const XMLTree& tree, PatchPrimaryKey& id, const XMLNode* node)
 {
-       id.bank_number = 0;
+       uint16_t bank    = 0;
+       uint8_t  program = 0;
 
        const XMLNodeList events = node->children();
        for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
@@ -69,18 +70,19 @@ initialize_primary_key_from_commands (
                        const string& value   = node->property("Value")->value();
 
                        if (control == "0") {
-                               id.bank_number |= string_to_int(tree, value) << 7;
+                               bank |= string_to_int(tree, value) << 7;
                        } else if (control == "32") {
-                               id.bank_number |= string_to_int(tree, value);
+                               bank |= string_to_int(tree, value);
                        }
 
                } else if (node->name() == "ProgramChange") {
                        const string& number = node->property("Number")->value();
                        assert(number != "");
-                       id.program_number = string_to_int(tree, number);
+                       program = string_to_int(tree, number);
                }
        }
 
+       id = PatchPrimaryKey(program, bank);
        return 0;
 }
 
@@ -91,11 +93,11 @@ Patch::get_state (void)
 
        /* XXX this is totally wrong */
 
-       node->add_property("Number", string_compose ("%1", _id.program_number));
+       node->add_property("Number", string_compose ("%1", _id.program()));
        node->add_property("Name",   _name);
 
        /*
-       typedef std::list< boost::shared_ptr< Evoral::MIDIEvent<double> > > PatchMidiCommands;
+       typedef std::list< boost::shared_ptr< Evoral::MIDIEvent<Evoral::Beats> > > PatchMidiCommands;
        XMLNode* commands = node->add_child("PatchMIDICommands");
        for (PatchMidiCommands::const_iterator event = _patch_midi_commands.begin();
            event != _patch_midi_commands.end();
@@ -120,7 +122,7 @@ Patch::set_state (const XMLTree& tree, const XMLNode& node)
 
        const XMLProperty* program_change = node.property("ProgramChange");
        if (program_change) {
-               _id.program_number = string_to_int(tree, program_change->value());
+               _id = PatchPrimaryKey(string_to_int(tree, program_change->value()), _id.bank());
        }
 
        const XMLProperty* name = node.property("Name");
@@ -149,7 +151,7 @@ XMLNode&
 Note::get_state (void)
 {
        XMLNode* node = new XMLNode("Note");
-       node->add_property("Number", _number + 1);
+       node->add_property("Number", _number);
        node->add_property("Name",   _name);
 
        return *node;
@@ -161,14 +163,14 @@ Note::set_state (const XMLTree& tree, const XMLNode& node)
        assert(node.name() == "Note");
 
        const int num = string_to_int(tree, node.property("Number")->value());
-       if (num < 1 || num > 128) {
+       if (num > 127) {
                PBD::warning << string_compose("%1: Note number %2 (%3) out of range",
                                               tree.filename(), num, _name)
                             << endmsg;
                return -1;
        }
 
-       _number = num - 1;
+       _number = num;
        _name   = node.property("Name")->value();
 
        return 0;
@@ -426,7 +428,7 @@ PatchBank::set_state (const XMLTree& tree, const XMLNode& node)
                if (initialize_primary_key_from_commands (tree, id, commands)) {
                        return -1;
                }
-               _number = id.bank_number;
+               _number = id.bank();
        }
 
        XMLNode* patch_name_list = node.child("PatchNameList");
@@ -651,13 +653,13 @@ MasterDeviceNames::value_name_list_by_control(const std::string& mode, uint8_t c
        }
 }
 
-boost::shared_ptr<CustomDeviceMode> 
+boost::shared_ptr<CustomDeviceMode>
 MasterDeviceNames::custom_device_mode_by_name(const std::string& mode_name)
 {
        return _custom_device_modes[mode_name];
 }
 
-boost::shared_ptr<ChannelNameSet> 
+boost::shared_ptr<ChannelNameSet>
 MasterDeviceNames::channel_name_set_by_channel(const std::string& mode, uint8_t channel)
 {
        boost::shared_ptr<CustomDeviceMode> cdm = custom_device_mode_by_name(mode);
@@ -665,8 +667,8 @@ MasterDeviceNames::channel_name_set_by_channel(const std::string& mode, uint8_t
        return cns;
 }
 
-boost::shared_ptr<Patch> 
-MasterDeviceNames::find_patch(const std::string& mode, uint8_t channel, const PatchPrimaryKey& key) 
+boost::shared_ptr<Patch>
+MasterDeviceNames::find_patch(const std::string& mode, uint8_t channel, const PatchPrimaryKey& key)
 {
        boost::shared_ptr<ChannelNameSet> cns = channel_name_set_by_channel(mode, channel);
        if (!cns) return boost::shared_ptr<Patch>();
@@ -877,12 +879,13 @@ MasterDeviceNames::get_state(void)
 
 MIDINameDocument::MIDINameDocument (const string& filename)
 {
-       if (!_document.read (filename)) {
+       XMLTree document;
+       if (!document.read (filename)) {
                throw failed_constructor ();
        }
 
-       _document.set_filename (filename);
-       set_state (_document, *_document.root());
+       document.set_filename (filename);
+       set_state (document, *document.root());
 }
 
 int