From cc78e514acdf2e3587d38bcdb42f091c0c7c4ebe Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Mar 2007 18:13:03 +0000 Subject: Removed name-based interface for FlowCanvas (using the view as a model = evil), related performance improvements (especially for Machina). Updates for FlowCanvas API changes. Machina SMF import performance improvements (temporarily disabled node labels). git-svn-id: http://svn.drobilla.net/lad/machina@356 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/SMFDriver.cpp | 8 ++--- src/gui/EdgeView.cpp | 10 +++--- src/gui/MachinaCanvas.cpp | 91 ++++++++++++++++++++++++++++------------------- src/gui/MachinaCanvas.hpp | 2 ++ src/gui/MachinaGUI.cpp | 9 ++--- 5 files changed, 70 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index 72bd8c6..abd0fb2 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -105,17 +105,17 @@ SMFDriver::learn_track(SharedPtr m, uint32_t ev_time; while (reader.read_event(4, buf, &ev_size, &ev_time) >= 0) { t += ev_time / (double)reader.ppqn(); - cerr << "t = " << t << endl; + //cerr << "t = " << t << endl; if (ev_size > 0) { if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) { - cerr << "NOTE ON: " << (int)buf[1] << endl; + //cerr << "NOTE ON: " << (int)buf[1] << endl; SharedPtr node(new Node()); node->add_enter_action(SharedPtr(new MidiAction(ev_size, buf))); connect_node->add_outgoing_edge(SharedPtr(new Edge(connect_node, node))); node->enter(SharedPtr(), t); active_nodes.push_back(node); } else if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_OFF) { - cerr << "NOTE OFF: " << (int)buf[1] << endl; + //cerr << "NOTE OFF: " << (int)buf[1] << endl; for (list >::iterator i = active_nodes.begin(); i != active_nodes.end(); ++i) { SharedPtr action = PtrCast((*i)->enter_action()); @@ -126,7 +126,7 @@ SMFDriver::learn_track(SharedPtr m, const unsigned char* ev = action->event(); if (ev_size == 3 && (ev[0] & 0xF0) == MIDI_CMD_NOTE_ON && ev[1] == buf[1]) { - cerr << "FOUND MATCHING NOTE ON!\n"; + //cerr << "FOUND MATCHING NOTE ON!\n"; (*i)->add_exit_action(SharedPtr(new MidiAction(ev_size, buf))); (*i)->set_duration(t - (*i)->enter_time()); (*i)->exit(SharedPtr(), t); diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp index 3b5b8ec..4817eca 100644 --- a/src/gui/EdgeView.cpp +++ b/src/gui/EdgeView.cpp @@ -31,17 +31,15 @@ EdgeView::EdgeView(SharedPtr canvas, : LibFlowCanvas::Connection(canvas, src, dst, 0x9999AAff, true) , _edge(edge) { - update_label(); } void EdgeView::update_label() { - std::ostringstream label; - label << std::setw(4); - label << _edge->probability(); - set_label(label.str()); + char label[4]; + snprintf(label, 4, "%3f", _edge->probability()); + set_label(label); } @@ -64,3 +62,5 @@ EdgeView::on_event(GdkEvent* ev) return false; } + + diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 327b2b0..3c2c1e8 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -16,6 +16,7 @@ */ //#include "config.h" +#include #include #include "machina/Node.hpp" #include "machina/Machine.hpp" @@ -169,57 +170,73 @@ MachinaCanvas::disconnect_node(boost::shared_ptr src, } +SharedPtr +MachinaCanvas::create_node_view(SharedPtr node) +{ + SharedPtr view(new NodeView(node, shared_from_this(), + "", 10, 10)); + + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, + &MachinaCanvas::node_clicked), WeakPtr(view))); + + add_item(view); + //view->resize(); + + return view; +} + + void MachinaCanvas::build(SharedPtr machine) { destroy(); + std::map, SharedPtr > views; + for (Machina::Machine::Nodes::const_iterator i = machine->nodes().begin(); i != machine->nodes().end(); ++i) { - //const double x = 1600 + rand() % 300; - //const double y = 1200 + rand() % 300; - - SharedPtr view(new NodeView((*i), shared_from_this(), - "", 10, 10)); - - view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, - &MachinaCanvas::node_clicked), WeakPtr(view))); - - add_item(view); - //view->resize(); + const SharedPtr view = create_node_view(*i); + views.insert(std::make_pair((*i), view)); } - - for (ItemMap::iterator n = _items.begin(); n != _items.end(); ++n) { - - SharedPtr src = PtrCast(n->second); - if (!src) - continue; - for (Machina::Node::Edges::const_iterator e = src->node()->outgoing_edges().begin(); - e != src->node()->outgoing_edges().end(); ++e) { - - SharedPtr dst; - for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { - SharedPtr nv = PtrCast((*m).second); - if (nv && nv->node() == (*e)->dst()) { - dst = nv; - break; - } - } - - if (dst) { - boost::shared_ptr c(new EdgeView(shared_from_this(), - src, dst, (*e))); - src->add_connection(c); - dst->add_connection(c); - add_connection(c); - } + for (ItemList::iterator i = _items.begin(); i != _items.end(); ++i) { + const SharedPtr view = PtrCast(*i); + if (!view) + continue; + for (Machina::Node::Edges::const_iterator e = view->node()->outgoing_edges().begin(); + e != view->node()->outgoing_edges().end(); ++e) { + + SharedPtr dst_view = views[(*e)->dst()]; + assert(dst_view); + + boost::shared_ptr c(new EdgeView(shared_from_this(), + view, dst_view, (*e))); + view->add_connection(c); + dst_view->add_connection(c); + add_connection(c); } + + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); } - + arrange(); + /* + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + + for (list >::iterator c = _connections.begin(); c != _connections.end(); ++c) { + const SharedPtr view = PtrCast(*c); + if (view) + view->update_label(); // very, very slow + + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + + } + */ } diff --git a/src/gui/MachinaCanvas.hpp b/src/gui/MachinaCanvas.hpp index feead3e..302ffa4 100644 --- a/src/gui/MachinaCanvas.hpp +++ b/src/gui/MachinaCanvas.hpp @@ -50,6 +50,8 @@ protected: void node_clicked(WeakPtr item, GdkEventButton* ev); private: + SharedPtr create_node_view(SharedPtr node); + MachinaGUI* _app; WeakPtr _last_clicked; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index db5e70c..592001f 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -242,8 +242,8 @@ MachinaGUI::attach() bool MachinaGUI::idle_callback() { - for (ItemMap::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { - SharedPtr nv = PtrCast(i->second); + for (ItemList::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { + const SharedPtr nv = PtrCast(*i); if (nv) nv->update_state(); } @@ -465,12 +465,13 @@ MachinaGUI::menu_import_midi() SharedPtr machine = file_driver->learn(dialog.get_uri()); if (machine) { + dialog.hide(); machine->activate(); machine->reset(); - _engine->driver()->set_machine(machine); _canvas->build(machine); + _engine->driver()->set_machine(machine); } else { - Gtk::MessageDialog msg_dialog(*_main_window, "Error loading MIDI file", + Gtk::MessageDialog msg_dialog(dialog, "Error loading MIDI file", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); msg_dialog.run(); } -- cgit v1.2.1