diff options
author | David Robillard <d@drobilla.net> | 2007-03-12 18:13:03 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-03-12 18:13:03 +0000 |
commit | cc78e514acdf2e3587d38bcdb42f091c0c7c4ebe (patch) | |
tree | 342928c7d554ef48984b165c2cd4a9dfbf8d6032 /src | |
parent | 218b41a2fbaab0540780e0bd45bea135c7c98bd3 (diff) | |
download | machina-cc78e514acdf2e3587d38bcdb42f091c0c7c4ebe.tar.gz machina-cc78e514acdf2e3587d38bcdb42f091c0c7c4ebe.tar.bz2 machina-cc78e514acdf2e3587d38bcdb42f091c0c7c4ebe.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SMFDriver.cpp | 8 | ||||
-rw-r--r-- | src/gui/EdgeView.cpp | 10 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 91 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.hpp | 2 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 9 |
5 files changed, 70 insertions, 50 deletions
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<Machine> 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> node(new Node()); node->add_enter_action(SharedPtr<Action>(new MidiAction(ev_size, buf))); connect_node->add_outgoing_edge(SharedPtr<Edge>(new Edge(connect_node, node))); node->enter(SharedPtr<Raul::MIDISink>(), 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<SharedPtr<Node> >::iterator i = active_nodes.begin(); i != active_nodes.end(); ++i) { SharedPtr<MidiAction> action = PtrCast<MidiAction>((*i)->enter_action()); @@ -126,7 +126,7 @@ SMFDriver::learn_track(SharedPtr<Machine> 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<Action>(new MidiAction(ev_size, buf))); (*i)->set_duration(t - (*i)->enter_time()); (*i)->exit(SharedPtr<Raul::MIDISink>(), 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<FlowCanvas> 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 <map> #include <raul/SharedPtr.h> #include "machina/Node.hpp" #include "machina/Machine.hpp" @@ -169,57 +170,73 @@ MachinaCanvas::disconnect_node(boost::shared_ptr<NodeView> src, } +SharedPtr<NodeView> +MachinaCanvas::create_node_view(SharedPtr<Machina::Node> node) +{ + SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), + "", 10, 10)); + + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, + &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); + + add_item(view); + //view->resize(); + + return view; +} + + void MachinaCanvas::build(SharedPtr<Machina::Machine> machine) { destroy(); + std::map<SharedPtr<Machina::Node>, SharedPtr<NodeView> > 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<NodeView> view(new NodeView((*i), shared_from_this(), - "", 10, 10)); - - view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, - &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); - - add_item(view); - //view->resize(); + const SharedPtr<NodeView> view = create_node_view(*i); + views.insert(std::make_pair((*i), view)); } - - for (ItemMap::iterator n = _items.begin(); n != _items.end(); ++n) { - - SharedPtr<NodeView> src = PtrCast<NodeView>(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<NodeView> dst; - for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { - SharedPtr<NodeView> nv = PtrCast<NodeView>((*m).second); - if (nv && nv->node() == (*e)->dst()) { - dst = nv; - break; - } - } - - if (dst) { - boost::shared_ptr<Connection> 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<NodeView> view = PtrCast<NodeView>(*i); + if (!view) + continue; + for (Machina::Node::Edges::const_iterator e = view->node()->outgoing_edges().begin(); + e != view->node()->outgoing_edges().end(); ++e) { + + SharedPtr<NodeView> dst_view = views[(*e)->dst()]; + assert(dst_view); + + boost::shared_ptr<Connection> 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<boost::shared_ptr<Connection> >::iterator c = _connections.begin(); c != _connections.end(); ++c) { + const SharedPtr<EdgeView> view = PtrCast<EdgeView>(*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<NodeView> item, GdkEventButton* ev); private: + SharedPtr<NodeView> create_node_view(SharedPtr<Machina::Node> node); + MachinaGUI* _app; WeakPtr<NodeView> _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<NodeView> nv = PtrCast<NodeView>(i->second); + for (ItemList::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { + const SharedPtr<NodeView> nv = PtrCast<NodeView>(*i); if (nv) nv->update_state(); } @@ -465,12 +465,13 @@ MachinaGUI::menu_import_midi() SharedPtr<Machina::Machine> 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(); } |