From 448d6e329a55848e357d57f8ca225d987627ee08 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 13 Jan 2013 09:23:42 +0000 Subject: Move merge operation to Machine::merge(). Delete unused Engine::import_machine(). git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4956 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Engine.cpp | 9 --------- src/engine/JackDriver.cpp | 11 +---------- src/engine/Machine.cpp | 15 +++++++++++++++ src/engine/MachineBuilder.cpp | 1 - src/engine/machina/Engine.hpp | 2 -- src/engine/machina/Machine.hpp | 6 +++++- src/gui/MachinaGUI.cpp | 1 + 7 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 90aea9b..7807f87 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -96,15 +96,6 @@ Engine::load_machine_midi(const Glib::ustring& uri, return machine; } -void -Engine::import_machine(SPtr machine) -{ - _driver->machine()->nodes().insert(machine->nodes().begin(), - machine->nodes().end()); - // FIXME: thread safe? - // FIXME: announce -} - void Engine::export_midi(const Glib::ustring& filename, Raul::TimeDuration dur) { diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index 0276cc5..c56e83d 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -437,16 +437,7 @@ JackDriver::finish_record() _play_state = PlayState::PLAYING; SPtr machine = _recorder->finish(); _recorder.reset(); - for (const auto& m : machine->nodes()) { - if (m->is_initial()) { - for (const auto& e : m->edges()) { - e->set_tail(_machine->initial_node()); - _machine->initial_node()->edges().insert(e); - } - } else { - _machine->nodes().insert(m); - } - } + _machine->merge(*machine.get()); } int diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index a6abcff..b5cfb28 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -100,6 +100,21 @@ Machine::operator=(const Machine& copy) return *this; } +void +Machine::merge(const Machine& machine) +{ + for (const auto& m : machine.nodes()) { + if (m->is_initial()) { + for (const auto& e : m->edges()) { + e->set_tail(_initial_node); + _initial_node->edges().insert(e); + } + } else { + _nodes.insert(m); + } + } +} + /** Always returns a node, unless there are none */ SPtr Machine::random_node() diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp index 0a515a4..ff2ee77 100644 --- a/src/engine/MachineBuilder.cpp +++ b/src/engine/MachineBuilder.cpp @@ -45,7 +45,6 @@ void MachineBuilder::reset() { _time = TimeStamp(_machine->time().unit()); // = 0 - _initial_node = SPtr(new Node(_time, true)); // duration 0 _connect_node = _initial_node; _connect_node_end_time = _time; // = 0 } diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp index 7e0c9bc..39974f1 100644 --- a/src/engine/machina/Engine.hpp +++ b/src/engine/machina/Engine.hpp @@ -54,8 +54,6 @@ public: double q, Raul::TimeDuration dur); - void import_machine(SPtr machine); - void export_midi(const Glib::ustring& filename, Raul::TimeDuration dur); diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index 8a98e4c..d4eccea 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -51,7 +51,11 @@ public: */ Machine(const Machine& copy); - Machine& operator=(const Machine& other); + /** Completely replace this machine's contents with a deep copy. */ + Machine& operator=(const Machine& copy); + + /** Merge another machine into this machine. */ + void merge(const Machine& machine); bool is_empty() { return _nodes.empty(); } bool is_finished() { return _is_finished; } diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index f95eec2..beb7b3a 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -543,6 +543,7 @@ MachinaGUI::menu_import_midi() dialog.hide(); machine->reset(NULL, machine->time()); _engine->driver()->set_machine(machine); + _canvas->clear(); rebuild_canvas(); } else { Gtk::MessageDialog msg_dialog(dialog, "Error loading MIDI file", -- cgit v1.2.1