summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorHans Baier <hansfbaier@googlemail.com>2008-04-10 07:30:10 +0000
committerHans Baier <hansfbaier@googlemail.com>2008-04-10 07:30:10 +0000
commit9aa8af5a28abbb86c9ae86c6991838eb6828d0a9 (patch)
treebfb401905c2d24b9d511a6762373c618f092203f /libs
parent1a0044b35d2cca7e7316d6afbb8e4955b6d7a627 (diff)
* refactored (un)marshalling of DeltaCommand into cleaner code using sigc
git-svn-id: svn://localhost/ardour2/branches/3.0@3245 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/midi_model.h18
-rw-r--r--libs/ardour/midi_model.cc34
2 files changed, 22 insertions, 30 deletions
diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h
index 5d16c30836..3ba0fc1279 100644
--- a/libs/ardour/ardour/midi_model.h
+++ b/libs/ardour/ardour/midi_model.h
@@ -124,20 +124,16 @@ public:
void remove(const boost::shared_ptr<Note> note);
private:
- class NoteMarshaller {
- public:
- XMLNode *operator()(const boost::shared_ptr<Note> note);
- };
+ XMLNode &marshal_note(const boost::shared_ptr<Note> note);
+ boost::shared_ptr<Note> unmarshal_note(XMLNode *xml_note);
- class NoteUnmarshaller {
- public:
- boost::shared_ptr<Note> operator()(XMLNode *xml_note);
- };
-
MidiModel& _model;
const std::string _name;
- std::list< boost::shared_ptr<Note> > _added_notes;
- std::list< boost::shared_ptr<Note> > _removed_notes;
+
+ typedef std::list< boost::shared_ptr<Note> > NoteList;
+
+ NoteList _added_notes;
+ NoteList _removed_notes;
};
MidiModel::DeltaCommand* new_delta_command(const std::string name="midi edit");
diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc
index 94a725d272..14441d2ee4 100644
--- a/libs/ardour/midi_model.cc
+++ b/libs/ardour/midi_model.cc
@@ -658,8 +658,8 @@ MidiModel::DeltaCommand::undo()
_model.ContentsChanged(); /* EMIT SIGNAL */
}
-XMLNode *
-MidiModel::DeltaCommand::NoteMarshaller::operator()(const boost::shared_ptr<Note> note)
+XMLNode &
+MidiModel::DeltaCommand::marshal_note(const boost::shared_ptr<Note> note)
{
XMLNode *xml_note = new XMLNode("note");
ostringstream note_str(ios::ate);
@@ -682,11 +682,11 @@ MidiModel::DeltaCommand::NoteMarshaller::operator()(const boost::shared_ptr<Note
velocity_str << (unsigned int) note->velocity();
xml_note->add_property("velocity", velocity_str.str());
- return xml_note;
+ return *xml_note;
}
boost::shared_ptr<Note>
-MidiModel::DeltaCommand::NoteUnmarshaller::operator()(XMLNode *xml_note)
+MidiModel::DeltaCommand::unmarshal_note(XMLNode *xml_note)
{
unsigned int note;
istringstream note_str(xml_note->property("note")->value());
@@ -722,9 +722,6 @@ MidiModel::DeltaCommand::NoteUnmarshaller::operator()(XMLNode *xml_note)
int
MidiModel::DeltaCommand::set_state (const XMLNode& delta_command)
{
-
- cerr << "Unmarshalling Deltacommand" << endl;
-
if(delta_command.name() != string(DELTA_COMMAND_ELEMENT)) {
return 1;
}
@@ -733,13 +730,13 @@ MidiModel::DeltaCommand::set_state (const XMLNode& delta_command)
XMLNode *added_notes = delta_command.child(ADDED_NOTES_ELEMENT);
XMLNodeList notes = added_notes->children();
transform(notes.begin(), notes.end(), back_inserter(_added_notes),
- MidiModel::DeltaCommand::NoteUnmarshaller());
+ sigc::mem_fun(*this, &DeltaCommand::unmarshal_note));
_removed_notes.clear();
XMLNode *removed_notes = delta_command.child(REMOVED_NOTES_ELEMENT);
notes = removed_notes->children();
transform(notes.begin(), notes.end(), back_inserter(_removed_notes),
- MidiModel::DeltaCommand::NoteUnmarshaller());
+ sigc::mem_fun(*this, &DeltaCommand::unmarshal_note));
return 0;
}
@@ -749,19 +746,18 @@ MidiModel::DeltaCommand::get_state ()
{
XMLNode *delta_command = new XMLNode(DELTA_COMMAND_ELEMENT);
delta_command->add_property("midi_source", _model.midi_source().id().to_s());
+ delta_command->add_property("midi_source_name", _model.midi_source().name());
XMLNode *added_notes = delta_command->add_child(ADDED_NOTES_ELEMENT);
- for (std::list< boost::shared_ptr<Note> >::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i) {
- NoteMarshaller marshaller;
- added_notes->add_child_nocopy(*marshaller(*i));
- }
-
- XMLNode *removed_notes = delta_command->add_child(REMOVED_NOTES_ELEMENT);
- for (std::list< boost::shared_ptr<Note> >::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i) {
- NoteMarshaller marshaller;
- removed_notes->add_child_nocopy(*marshaller(*i));
- }
+ for_each(_added_notes.begin(), _added_notes.end(),
+ sigc::compose(sigc::mem_fun(*added_notes, &XMLNode::add_child_nocopy),
+ sigc::mem_fun(*this, &DeltaCommand::marshal_note)));
+ XMLNode *removed_notes = delta_command->add_child(REMOVED_NOTES_ELEMENT);
+ for_each(_removed_notes.begin(), _removed_notes.end(),
+ sigc::compose(sigc::mem_fun(*removed_notes, &XMLNode::add_child_nocopy),
+ sigc::mem_fun(*this, &DeltaCommand::marshal_note)));
+
return *delta_command;
}