diff options
author | David Robillard <d@drobilla.net> | 2007-02-10 03:39:10 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-02-10 03:39:10 +0000 |
commit | b924ead0db7c09ee50d2d4eee487b844c5fb867b (patch) | |
tree | 36fa1a6c879989a111f4fbbaf9a03b7f442b618c /src/gui | |
parent | 9f2a520a8f20661385bf6c9f7447aef1227d8696 (diff) | |
download | machina-b924ead0db7c09ee50d2d4eee487b844c5fb867b.tar.gz machina-b924ead0db7c09ee50d2d4eee487b844c5fb867b.tar.bz2 machina-b924ead0db7c09ee50d2d4eee487b844c5fb867b.zip |
Machine GUI talking to Jack engine, running machines made in GUI, etc.
git-svn-id: http://svn.drobilla.net/lad/machina@297 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 176 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.hpp | 17 | ||||
-rw-r--r-- | src/gui/MachinaGUI.hpp | 7 | ||||
-rw-r--r-- | src/gui/Makefile.am | 4 |
4 files changed, 97 insertions, 107 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 303774f..775ae28 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -17,10 +17,17 @@ //#include "config.h" #include <raul/SharedPtr.h> -#include <flowcanvas/Ellipse.h> +#include "machina/Node.hpp" +#include "machina/Machine.hpp" +#include "machina/Action.hpp" +#include "machina/Edge.hpp" +#include "NodeView.hpp" #include "MachinaCanvas.hpp" #include "MachinaGUI.hpp" +using namespace LibFlowCanvas; + + MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height) : FlowCanvas(width, height), _app(app) @@ -30,31 +37,86 @@ MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height) void -MachinaCanvas::connect(boost::shared_ptr<Connectable>, //item1, - boost::shared_ptr<Connectable>) //item2) +MachinaCanvas::status_message(const string& msg) { -#if 0 - boost::shared_ptr<MachinaPort> p1 = boost::dynamic_pointer_cast<MachinaPort>(port1); - boost::shared_ptr<MachinaPort> p2 = boost::dynamic_pointer_cast<MachinaPort>(port2); - if (!p1 || !p2) + _app->status_message(string("[Canvas] ").append(msg)); +} + + +void +MachinaCanvas::node_clicked(SharedPtr<NodeView> item, GdkEventButton* event) +{ + cerr << "CLICKED: " << item->name() << endl; + + SharedPtr<NodeView> node = PtrCast<NodeView>(item); + if (!node) return; + + SharedPtr<NodeView> last = _last_clicked.lock(); - if (p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO - || (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI)) - _app->jack_driver()->connect(p1, p2); -#ifdef HAVE_ALSA - else if (p1->type() == ALSA_MIDI && p2->type() == ALSA_MIDI) - _app->alsa_driver()->connect(p1, p2); -#endif - else - status_message("WARNING: Cannot make connection, incompatible port types."); -#endif + if (last) { + connect(last, node); + _last_clicked.reset(); + } else { + _last_clicked = node; + } +} + + +bool +MachinaCanvas::canvas_event(GdkEvent* event) +{ + static int last = 0; + + assert(event); + + if (event->type == GDK_BUTTON_PRESS) { + + const double x = event->button.x; + const double y = event->button.y; + + if (event->button.button == 1) { + string name = string("Note")+(char)(last++ +'0'); + + SharedPtr<Machina::Node> node(new Machina::Node(1024*10, false)); + node->add_enter_action(new Machina::PrintAction(name)); + SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), + name, x, y)); + + //view->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, + // &MachinaCanvas::node_clicked), view)); + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, + &MachinaCanvas::node_clicked), view)); + add_item(view); + view->resize(); + view->raise_to_top(); + + _app->machine()->add_node(node); + } + } + + return FlowCanvas::canvas_event(event); } void -MachinaCanvas::disconnect(boost::shared_ptr<Connectable>,// item1, - boost::shared_ptr<Connectable>)// item2) +MachinaCanvas::connect(boost::shared_ptr<NodeView> src, + boost::shared_ptr<NodeView> dst) +{ + boost::shared_ptr<Connection> c(new Connection(shared_from_this(), + src, dst, 0x9999AAFF, true)); + src->add_connection(c); + dst->add_connection(c); + add_connection(c); + + src->node()->add_outgoing_edge(SharedPtr<Machina::Edge>( + new Machina::Edge(src->node(), dst->node()))); +} + + +void +MachinaCanvas::disconnect(boost::shared_ptr<NodeView>,// item1, + boost::shared_ptr<NodeView>)// item2) { #if 0 boost::shared_ptr<MachinaPort> input @@ -90,79 +152,3 @@ MachinaCanvas::disconnect(boost::shared_ptr<Connectable>,// item1, } -void -MachinaCanvas::status_message(const string& msg) -{ - _app->status_message(string("[Canvas] ").append(msg)); -} - - -void -MachinaCanvas::item_selected(SharedPtr<Item> i) -{ - cerr << "SELECTED: " << i->name() << endl; - - SharedPtr<Connectable> item = PtrCast<Connectable>(i); - if (!item) - return; - - SharedPtr<Connectable> last = _last_selected.lock(); - - if (last) { - boost::shared_ptr<Connection> c(new Connection(shared_from_this(), - last, item, 0x9999AAFF, true)); - last->add_connection(c); - item->add_connection(c); - add_connection(c); - i->raise_to_top(); - _last_selected.reset(); - } else { - _last_selected = item; - } -} - - -void -MachinaCanvas::item_clicked(SharedPtr<Item> i, GdkEventButton* event) -{ - cerr << "CLICKED " << event->button << ": " << i->name() << endl; - - //return false; -} - - -bool -MachinaCanvas::canvas_event(GdkEvent* event) -{ - static int last = 0; - - assert(event); - - if (event->type == GDK_BUTTON_PRESS) { - - const double x = event->button.x; - const double y = event->button.y; - - SharedPtr<Item> item; - - if (event->button.button == 1) { - item = SharedPtr<Item>(new Ellipse(shared_from_this(), - string("Note")+(char)(last++ +'0'), x, y, 30, 30, true)); - } else if (event->button.button == 2) { - item = SharedPtr<Item>(new Module(shared_from_this(), - string("Note")+(char)(last++ +'0'), x, y, true)); - } - - if (item) { - item->signal_selected.connect(sigc::bind(sigc::mem_fun(this, - &MachinaCanvas::item_selected), item)); - item->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, - &MachinaCanvas::item_clicked), item)); - add_item(item); - item->resize(); - item->raise_to_top(); - } - } - - return FlowCanvas::canvas_event(event); -} diff --git a/src/gui/MachinaCanvas.hpp b/src/gui/MachinaCanvas.hpp index b06a5d8..6cd5ea0 100644 --- a/src/gui/MachinaCanvas.hpp +++ b/src/gui/MachinaCanvas.hpp @@ -26,30 +26,31 @@ using namespace LibFlowCanvas; class MachinaGUI; +class NodeView; + class MachinaCanvas : public FlowCanvas { public: - MachinaCanvas(MachinaGUI* _app, int width, int height); + MachinaCanvas(MachinaGUI* app, int width, int height); - void connect(boost::shared_ptr<Connectable> port1, - boost::shared_ptr<Connectable> port2); + void connect(SharedPtr<NodeView> port1, + SharedPtr<NodeView> port2); - void disconnect(boost::shared_ptr<Connectable> port1, - boost::shared_ptr<Connectable> port2); + void disconnect(SharedPtr<NodeView> port1, + SharedPtr<NodeView> port2); void status_message(const string& msg); protected: bool canvas_event(GdkEvent* event); - void item_selected(SharedPtr<Item> item); - void item_clicked(SharedPtr<Item> item, GdkEventButton* ev); + void node_clicked(SharedPtr<NodeView> item, GdkEventButton* ev); private: MachinaGUI* _app; - WeakPtr<Connectable> _last_selected; + WeakPtr<NodeView> _last_clicked; }; diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 804bf41..4bcca5a 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -35,7 +35,8 @@ public: MachinaGUI(SharedPtr<Machina::Machine> machine/*int argc, char** argv*/); ~MachinaGUI(); - boost::shared_ptr<MachinaCanvas> canvas() { return _canvas; } + boost::shared_ptr<MachinaCanvas> canvas() { return _canvas; } + boost::shared_ptr<Machina::Machine> machine() { return _machine; } Gtk::Window* window() { return _main_window; } @@ -68,8 +69,8 @@ protected: bool _refresh; - boost::shared_ptr<MachinaCanvas> _canvas; - boost::shared_ptr<Machina::Machine> _machine; + boost::shared_ptr<MachinaCanvas> _canvas; + boost::shared_ptr<Machina::Machine> _machine; Gtk::Main* _gtk_main; diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 1bdb381..6a9ff3b 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -17,6 +17,8 @@ machina_gui_SOURCES = \ MachinaGUI.hpp \ MachinaGUI.cpp \ MachinaCanvas.hpp \ - MachinaCanvas.cpp + MachinaCanvas.cpp \ + NodeView.hpp \ + NodeView.cpp endif |