diff options
author | David Robillard <d@drobilla.net> | 2008-08-14 06:27:29 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-08-14 06:27:29 +0000 |
commit | 46d363c84afd6306a0fa7fe60b77808087047b44 (patch) | |
tree | 0972a00760874f37e05b33cdae776a08f42bdb86 /src | |
parent | 576774c657d99c7c9954eefff27b886694913022 (diff) | |
download | ingen-46d363c84afd6306a0fa7fe60b77808087047b44.tar.gz ingen-46d363c84afd6306a0fa7fe60b77808087047b44.tar.bz2 ingen-46d363c84afd6306a0fa7fe60b77808087047b44.zip |
Don't present (or even load widgets from XML) connection window until some time has passed (i.e. don't show it at all if the connection happens fast enough).
git-svn-id: http://svn.drobilla.net/lad/ingen@1375 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/engine/OSCEngineReceiver.cpp | 4 | ||||
-rw-r--r-- | src/libs/gui/ConnectWindow.cpp | 168 | ||||
-rw-r--r-- | src/libs/gui/ConnectWindow.hpp | 9 |
3 files changed, 123 insertions, 58 deletions
diff --git a/src/libs/engine/OSCEngineReceiver.cpp b/src/libs/engine/OSCEngineReceiver.cpp index 120b86b4..8fd65e85 100644 --- a/src/libs/engine/OSCEngineReceiver.cpp +++ b/src/libs/engine/OSCEngineReceiver.cpp @@ -257,7 +257,9 @@ OSCEngineReceiver::error_cb(int num, const char* msg, const char* path) int OSCEngineReceiver::_ping_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) { - _responder->respond_ok(); + const lo_address addr = lo_message_get_source(msg); + if (lo_send(addr, "/ingen/ok", "i", argv[0]->i) < 0) + cerr << "WARNING: Unable to send response: " << lo_address_errstr(addr) << endl; return 0; } diff --git a/src/libs/gui/ConnectWindow.cpp b/src/libs/gui/ConnectWindow.cpp index 811dd919..4846644a 100644 --- a/src/libs/gui/ConnectWindow.cpp +++ b/src/libs/gui/ConnectWindow.cpp @@ -62,31 +62,14 @@ struct OSCSigEmitter : public OSCClientReceiver, public ThreadedSigClientInterfa ConnectWindow::ConnectWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& xml) : Gtk::Dialog(cobject) + , _xml(xml) , _mode(CONNECT_REMOTE) , _ping_id(-1) , _attached(false) + , _widgets_loaded(false) , _connect_stage(0) , _new_engine(NULL) { - xml->get_widget("connect_icon", _icon); - xml->get_widget("connect_progress_bar", _progress_bar); - xml->get_widget("connect_progress_label", _progress_label); - xml->get_widget("connect_server_radiobutton", _server_radio); - xml->get_widget("connect_url_entry", _url_entry); - xml->get_widget("connect_launch_radiobutton", _launch_radio); - xml->get_widget("connect_port_spinbutton", _port_spinbutton); - xml->get_widget("connect_internal_radiobutton", _internal_radio); - xml->get_widget("connect_disconnect_button", _disconnect_button); - xml->get_widget("connect_connect_button", _connect_button); - xml->get_widget("connect_quit_button", _quit_button); - - _server_radio->signal_toggled().connect(sigc::mem_fun(this, &ConnectWindow::server_toggled)); - _launch_radio->signal_toggled().connect(sigc::mem_fun(this, &ConnectWindow::launch_toggled)); - _internal_radio->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::internal_toggled)); - _disconnect_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::disconnect)); - _connect_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::connect)); - _quit_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::quit)); - _engine_module = Ingen::Shared::load_module("ingen_engine"); if (!_engine_module) { @@ -100,8 +83,6 @@ ConnectWindow::ConnectWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome:: cerr << "Unable to find module entry point, internal engine unavailable." << endl; _engine_module.reset(); } - - server_toggled(); } @@ -110,7 +91,8 @@ ConnectWindow::start(Ingen::Shared::World* world) { if (world->local_engine) { _mode = INTERNAL; - _internal_radio->set_active(true); + if (_widgets_loaded) + _internal_radio->set_active(true); } set_connected_to(world->engine); @@ -122,9 +104,15 @@ ConnectWindow::start(Ingen::Shared::World* world) void ConnectWindow::set_connected_to(SharedPtr<Shared::EngineInterface> engine) { + App::instance().world()->engine = engine; + + if (!_widgets_loaded) + return; + if (engine) { _icon->set(Gtk::Stock::CONNECT, Gtk::ICON_SIZE_LARGE_TOOLBAR); _progress_bar->set_fraction(1.0); + _progress_label->set_text("Connected to engine"); _url_entry->set_sensitive(false); _connect_button->set_sensitive(false); _disconnect_button->set_label("gtk-disconnect"); @@ -146,15 +134,30 @@ ConnectWindow::set_connected_to(SharedPtr<Shared::EngineInterface> engine) _server_radio->set_sensitive(true); _launch_radio->set_sensitive(true); - if ( _mode == CONNECT_REMOTE ) + if (_mode == CONNECT_REMOTE ) _url_entry->set_sensitive(true); - else if ( _mode == LAUNCH_REMOTE ) + else if (_mode == LAUNCH_REMOTE ) _port_spinbutton->set_sensitive(true); _progress_label->set_text(string("Disconnected")); } +} - App::instance().world()->engine = engine; + +void +ConnectWindow::set_connecting_widget_states() +{ + if (!_widgets_loaded) + return; + + _connect_button->set_sensitive(false); + _disconnect_button->set_label("gtk-cancel"); + _disconnect_button->set_sensitive(true); + _server_radio->set_sensitive(false); + _launch_radio->set_sensitive(false); + _internal_radio->set_sensitive(false); + _url_entry->set_sensitive(false); + _port_spinbutton->set_sensitive(false); } @@ -169,24 +172,14 @@ ConnectWindow::connect() assert(!_attached); assert(!App::instance().client()); - _connect_button->set_sensitive(false); - _disconnect_button->set_label("gtk-cancel"); - _disconnect_button->set_sensitive(true); - - // Avoid user messing with our parameters whilst we're trying to connect. - _server_radio->set_sensitive(false); - _launch_radio->set_sensitive(false); - _internal_radio->set_sensitive(false); - _url_entry->set_sensitive(false); - _port_spinbutton->set_sensitive(false); - _connect_stage = 0; + set_connecting_widget_states(); Ingen::Shared::World* world = App::instance().world(); if (_mode == CONNECT_REMOTE) { - world->engine = SharedPtr<EngineInterface>( - new OSCEngineSender(_url_entry->get_text())); + const string url = (_widgets_loaded ? _url_entry->get_text() : "osc.udp://localhost:16180"); + world->engine = SharedPtr<EngineInterface>(new OSCEngineSender(url)); OSCSigEmitter* ose = new OSCSigEmitter(1024, 16181); // FIXME: args SharedPtr<ThreadedSigClientInterface> client(ose); @@ -254,12 +247,15 @@ ConnectWindow::disconnect() _connect_stage = -1; _attached = false; + App::instance().detach(); + set_connected_to(SharedPtr<Ingen::Shared::EngineInterface>()); + + if (!_widgets_loaded) + return; + _progress_bar->set_fraction(0.0); _connect_button->set_sensitive(false); _disconnect_button->set_sensitive(false); - - App::instance().detach(); - set_connected_to(SharedPtr<Ingen::Shared::EngineInterface>()); _connect_button->set_sensitive(true); _disconnect_button->set_sensitive(false); @@ -267,6 +263,48 @@ ConnectWindow::disconnect() void +ConnectWindow::on_show() +{ + if (!_widgets_loaded) { + load_widgets(); + if (_attached) + set_connected_to(App::instance().engine()); + } + + Gtk::Dialog::on_show(); +} + + +void +ConnectWindow::load_widgets() +{ + _xml->get_widget("connect_icon", _icon); + _xml->get_widget("connect_progress_bar", _progress_bar); + _xml->get_widget("connect_progress_label", _progress_label); + _xml->get_widget("connect_server_radiobutton", _server_radio); + _xml->get_widget("connect_url_entry", _url_entry); + _xml->get_widget("connect_launch_radiobutton", _launch_radio); + _xml->get_widget("connect_port_spinbutton", _port_spinbutton); + _xml->get_widget("connect_internal_radiobutton", _internal_radio); + _xml->get_widget("connect_disconnect_button", _disconnect_button); + _xml->get_widget("connect_connect_button", _connect_button); + _xml->get_widget("connect_quit_button", _quit_button); + + _server_radio->signal_toggled().connect(sigc::mem_fun(this, &ConnectWindow::server_toggled)); + _launch_radio->signal_toggled().connect(sigc::mem_fun(this, &ConnectWindow::launch_toggled)); + _internal_radio->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::internal_toggled)); + _disconnect_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::disconnect)); + _connect_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::connect)); + _quit_button->signal_clicked().connect(sigc::mem_fun(this, &ConnectWindow::quit)); + + _widgets_loaded = true; + + _progress_bar->set_pulse_step(0.01); + server_toggled(); +} + + +void ConnectWindow::on_hide() { Gtk::Dialog::on_hide(); @@ -328,7 +366,18 @@ ConnectWindow::gtk_callback() // Timing stuff for repeated attach attempts timeval now; gettimeofday(&now, NULL); + static const timeval start = now; static timeval last = now; + + // Show if attempted connection goes on for a noticeable amount of time + if (!is_visible()) { + const float ms_since_start = (now.tv_sec - start.tv_sec) * 1000.0f + + (now.tv_usec - start.tv_usec) * 0.001f; + if (ms_since_start > 500) { + present(); + set_connecting_widget_states(); + } + } /* Connecting to engine */ if (_connect_stage == 0) { @@ -341,13 +390,14 @@ ConnectWindow::gtk_callback() App::instance().client()->signal_response_ok.connect( sigc::mem_fun(this, &ConnectWindow::response_ok_received)); - _ping_id = rand() * 2; + _ping_id = abs(rand()) / 2 * 2; // avoid -1 App::instance().engine()->set_next_response_id(_ping_id); App::instance().engine()->ping(); - _progress_label->set_text("Connecting to engine..."); - _progress_bar->set_pulse_step(0.01); - present(); + if (_widgets_loaded) { + _progress_label->set_text("Connecting to engine..."); + _progress_bar->set_pulse_step(0.01); + } ++_connect_stage; @@ -357,7 +407,7 @@ ConnectWindow::gtk_callback() ++_connect_stage; } else { const float ms_since_last = (now.tv_sec - last.tv_sec) * 1000.0f + - (now.tv_usec - last.tv_usec) * 0.001f; + (now.tv_usec - last.tv_usec) * 0.001f; if (ms_since_last > 1000) { App::instance().engine()->set_next_response_id(_ping_id); App::instance().engine()->ping(); @@ -366,7 +416,8 @@ ConnectWindow::gtk_callback() } } else if (_connect_stage == 2) { App::instance().engine()->request_all_objects(); - _progress_label->set_text(string("Requesting root patch...")); + if (_widgets_loaded) + _progress_label->set_text(string("Requesting root patch...")); ++_connect_stage; } else if (_connect_stage == 3) { if (App::instance().store()->objects().size() > 0) { @@ -375,27 +426,32 @@ ConnectWindow::gtk_callback() set_connected_to(App::instance().engine()); App::instance().window_factory()->present_patch(root); App::instance().engine()->load_plugins(); - _progress_label->set_text(string("Loading plugins...")); + if (_widgets_loaded) + _progress_label->set_text(string("Loading plugins...")); ++_connect_stage; } } } else if (_connect_stage == 4) { App::instance().engine()->request_plugins(); hide(); - _progress_label->set_text("Connected to engine"); + if (_widgets_loaded) + _progress_label->set_text("Connected to engine"); _connect_stage = 0; // set ourselves up for next time (if there is one) return false; // deregister this callback } - _progress_bar->pulse(); + if (_widgets_loaded) + _progress_bar->pulse(); if (_connect_stage == -1) { // we were cancelled - _icon->set(Gtk::Stock::DISCONNECT, Gtk::ICON_SIZE_LARGE_TOOLBAR); - _progress_bar->set_fraction(0.0); - _connect_button->set_sensitive(true); - _disconnect_button->set_sensitive(false); - _disconnect_button->set_label("gtk-disconnect"); - _progress_label->set_text(string("Disconnected")); + if (_widgets_loaded) { + _icon->set(Gtk::Stock::DISCONNECT, Gtk::ICON_SIZE_LARGE_TOOLBAR); + _progress_bar->set_fraction(0.0); + _connect_button->set_sensitive(true); + _disconnect_button->set_sensitive(false); + _disconnect_button->set_label("gtk-disconnect"); + _progress_label->set_text(string("Disconnected")); + } return false; } else { return true; diff --git a/src/libs/gui/ConnectWindow.hpp b/src/libs/gui/ConnectWindow.hpp index d8635804..e7620026 100644 --- a/src/libs/gui/ConnectWindow.hpp +++ b/src/libs/gui/ConnectWindow.hpp @@ -65,15 +65,22 @@ private: void disconnect(); void connect(); void quit(); + void on_show(); void on_hide(); + void load_widgets(); + void set_connecting_widget_states(); + bool gtk_callback(); + const Glib::RefPtr<Gnome::Glade::Xml> _xml; + Mode _mode; int32_t _ping_id; bool _attached; - int _connect_stage; + bool _widgets_loaded; + int _connect_stage; SharedPtr<Glib::Module> _engine_module; Ingen::Engine* (*_new_engine)(Ingen::Shared::World* world); |