switch from std::auto_ptr<> (deprecated) to boost::scoped_ptr<>
[ardour.git] / libs / ardour / midi_scene_change.cc
index edcc8a658d2faf4e6dfdbeac2b5ddf6f15f6f57f..75fcf32d9199f4cf28a22f0603f753cffc6e973c 100644 (file)
 
 #include "pbd/error.h"
 #include "pbd/compose.h"
+#include "pbd/types_convert.h"
 
 #include "ardour/midi_port.h"
 #include "ardour/midi_scene_change.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace ARDOUR;
@@ -77,7 +78,7 @@ MIDISceneChange::get_bank_lsb_message (uint8_t* buf, size_t size) const
 
        buf[0] = 0xB0 | (_channel & 0xf);
        buf[1] = 0x20;
-       buf[2] = _bank & 0x7f;  
+       buf[2] = _bank & 0x7f;
 
        return 3;
 }
@@ -98,18 +99,14 @@ MIDISceneChange::get_program_message (uint8_t* buf, size_t size) const
 XMLNode&
 MIDISceneChange::get_state ()
 {
-       char buf[32];
        XMLNode* node = new XMLNode (SceneChange::xml_node_name);
 
-       node->add_property (X_("type"), X_("MIDI"));
-       snprintf (buf, sizeof (buf), "%d", (int) _program);
-       node->add_property (X_("id"), id().to_s());
-       snprintf (buf, sizeof (buf), "%d", (int) _program);
-       node->add_property (X_("program"), buf);
-       snprintf (buf, sizeof (buf), "%d", (int) _bank);
-       node->add_property (X_("bank"), buf);
-       snprintf (buf, sizeof (buf), "%d", (int) _channel);
-       node->add_property (X_("channel"), buf);
+       node->set_property (X_("type"), X_("MIDI"));
+       node->set_property (X_("id"), id());
+       node->set_property (X_("program"), _program);
+       node->set_property (X_("bank"), _bank);
+       node->set_property (X_("channel"), _channel);
+       node->set_property (X_("color"), _color);
 
        return *node;
 }
@@ -121,22 +118,14 @@ MIDISceneChange::set_state (const XMLNode& node, int /* version-ignored */)
                return -1;
        }
 
-       const XMLProperty* prop;
-
-       if ((prop = node.property (X_("program"))) == 0) {
-               return -1;
-       }
-       _program = atoi (prop->value());
-
-       if ((prop = node.property (X_("bank"))) == 0) {
+       if (!node.get_property (X_("program"), _program) || !node.get_property (X_("bank"), _bank) ||
+           !node.get_property (X_("channel"), _channel)) {
                return -1;
        }
-       _bank = atoi (prop->value());
 
-       if ((prop = node.property (X_("channel"))) == 0) {
-               return -1;
+       if (!node.get_property (X_("color"), _color)) {
+               _color = out_of_bound_color;
        }
-       _channel = atoi (prop->value());
 
        return 0;
 }
@@ -144,7 +133,27 @@ MIDISceneChange::set_state (const XMLNode& node, int /* version-ignored */)
 bool
 MIDISceneChange::operator==(const MIDISceneChange& other) const
 {
-        return _program == other._program &&
-                _bank == other._bank &&
-                _channel == other._channel;
+       return _program == other._program &&
+               _bank == other._bank &&
+               _channel == other._channel;
+}
+
+void
+MIDISceneChange::set_channel (int channel)
+{
+        _channel = channel;
 }
+
+void
+MIDISceneChange::set_program (int program)
+{
+        _program = program;
+}
+
+void
+MIDISceneChange::set_bank (int bank)
+{
+        _bank = bank;
+}
+
+