mostly cosmetic changes to LTC generator
[ardour.git] / libs / midi++2 / midnam_patch.cc
index 2b32fee42e78eebd7e5fc1b4eb7a105006c88686..2d5ee9973d3ec29f849fa34c7915acf3cc3dfd90 100644 (file)
@@ -44,8 +44,11 @@ Patch::Patch (std::string name, uint8_t p_number, uint16_t b_number)
 
 int initialize_primary_key_from_commands (PatchPrimaryKey& id, const XMLNode* node)
 {
+       id.bank_number = 0;
+
        const XMLNodeList events = node->children();
        for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
+
                XMLNode* node = *i;
                if (node->name() == "ControlChange") {
                        string control = node->property("Control")->value();
@@ -53,13 +56,12 @@ int initialize_primary_key_from_commands (PatchPrimaryKey& id, const XMLNode* no
                        string value = node->property("Value")->value();
                        assert(value != "");
 
-                       id.bank_number = 0;
-
                        if (control == "0") {
-                               id.bank_number |= (PBD::atoi (value)<<7);
+                               id.bank_number |= (PBD::atoi (value)) << 7;
                        } else if (control == "32") {
                                id.bank_number |= PBD::atoi (value);
                        }
+
                } else if (node->name() == "ProgramChange") {
                        string number = node->property("Number")->value();
                        assert(number != "");
@@ -333,13 +335,14 @@ ChannelNameSet::set_state (const XMLTree& tree, const XMLNode& node)
 {
        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 =
-                               tree.find("//AvailableChannel[@Available = 'true']/@Channel");
+                               tree.find("//AvailableChannel[@Available = 'true']/@Channel", node);
                        for(XMLSharedNodeList::const_iterator i = channels->begin();
                            i != channels->end();
                            ++i) {
@@ -372,7 +375,7 @@ CustomDeviceMode::set_state(const XMLTree& tree, const XMLNode& a_node)
        _name = a_node.property("Name")->value();
 
        boost::shared_ptr<XMLSharedNodeList> channel_name_set_assignments =
-               tree.find("//ChannelNameSetAssign");
+               tree.find("//ChannelNameSetAssign", (XMLNode *)&a_node);
        for(XMLSharedNodeList::const_iterator i = channel_name_set_assignments->begin();
            i != channel_name_set_assignments->end();
            ++i) {
@@ -404,7 +407,8 @@ CustomDeviceMode::get_state(void)
 boost::shared_ptr<CustomDeviceMode> 
 MasterDeviceNames::custom_device_mode_by_name(std::string mode_name)
 {
-       assert(mode_name != "");
+       // can't assert this, since in many of the patch files the mode name is empty
+       //assert(mode_name != "");
        return _custom_device_modes[mode_name];
 }
 
@@ -428,7 +432,7 @@ MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode& a_node)
        // Manufacturer
        boost::shared_ptr<XMLSharedNodeList> manufacturer = tree.find("//Manufacturer");
        assert(manufacturer->size() == 1);
-       _manufacturer = manufacturer->front()->content();
+       _manufacturer = manufacturer->front()->children().front()->content();
 
        // Models
        boost::shared_ptr<XMLSharedNodeList> models = tree.find("//Model");
@@ -549,7 +553,10 @@ MIDINameDocument::set_state (const XMLTree& tree, const XMLNode& a_node)
                error << "No author information in MIDNAM file" << endmsg;
                return -1;
        }
-       _author = author->front()->content();
+       
+       if (author->front()->children().size() > 0) {
+               _author = author->front()->children().front()->content();
+       }
 
        // MasterDeviceNames