diff --git a/src/gui.cpp b/src/gui.cpp index 6d185c0..8c69fcf 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -24,6 +24,9 @@ Gui::Gui(BaseObjectType *cobject, const Glib::RefPtr &builder) Refresh(); Glib::signal_timeout().connect(sigc::mem_fun(*this, &Gui::on_timeout), 50); +#ifndef HAVE_RENAME + Glib::signal_timeout().connect(sigc::mem_fun(*this, &Gui::on_timeout_2), 1000); +#endif Glib::RefPtr uim = Glib::RefPtr::cast_static(builder->get_object("uimanager1")); uim->get_action("/menubar1/menuitem1/menu_quit")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_quit)); @@ -173,6 +176,20 @@ bool Gui::on_timeout() return true; } +#ifndef HAVE_RENAME +bool Gui::on_timeout_2() +{ + if (m_closing) return false; + + if (pm.PollPortRenames()) { + Refresh(); + queue_draw(); + } + + return true; +} +#endif + void Gui::on_notebook_switch_page(GtkNotebookPage * /* page */, guint /* page_num */) { if (m_closing) return; diff --git a/src/gui.h b/src/gui.h index dde34b6..f020db9 100644 --- a/src/gui.h +++ b/src/gui.h @@ -30,6 +30,9 @@ public: protected: bool on_timeout(); +#ifndef HAVE_RENAME + bool on_timeout_2(); +#endif void on_notebook_switch_page(GtkNotebookPage * /* page */, guint /* page_num */); void on_quit(); diff --git a/src/jack.cpp b/src/jack.cpp index 87a9099..a34bd34 100644 --- a/src/jack.cpp +++ b/src/jack.cpp @@ -37,9 +37,11 @@ void JackDriver::Connect() jack_on_shutdown(m_client, &ShutdownCallbackHandler, this); jack_set_port_registration_callback(m_client, &PortRegistrationCallbackHandler, this); jack_set_port_connect_callback(m_client, &PortConnectCallbackHandler, this); +#ifdef HAVE_RENAME if (jack_set_port_rename_callback) { jack_set_port_rename_callback(m_client, &PortRenameCallbackHandler, this); } +#endif jack_activate(m_client); diff --git a/src/port.h b/src/port.h index c383399..414c90f 100644 --- a/src/port.h +++ b/src/port.h @@ -89,6 +89,9 @@ struct Port : Base Client *m_client; PortGroup *m_group; PortList m_connections; +#ifndef HAVE_RENAME + std::string m_real_name; +#endif virtual ConnectionMode ConnectedTo(Port *port); virtual ConnectionMode ConnectedTo(PortGroup *group); diff --git a/src/portmanager.cpp b/src/portmanager.cpp index 69f6a8a..9608acb 100644 --- a/src/portmanager.cpp +++ b/src/portmanager.cpp @@ -118,6 +118,10 @@ void PortManager::Add(jack_port_t *port) p->m_port = port; p->m_is_input = (JackPortFlags)jack_port_flags(port) & JackPortIsInput; +#ifndef HAVE_RENAME + p->m_real_name = jack_port_name(port); +#endif + std::string type = jack_port_type(port); p->m_is_midi = type == JACK_DEFAULT_MIDI_TYPE; @@ -223,6 +227,32 @@ void PortManager::Rename(jack_port_t *port) RefreshConnections(); } +#ifndef HAVE_RENAME +bool PortManager::PollPortRenames() +{ + // Queue for storing ports to be renamed, to avoid messing up the + // port iterator. + PortList queue; + + PortList::iterator it; + for (it = m_ports.begin(); it != m_ports.end(); ++it) { + Port *p = *it; + if (strcmp(p->m_real_name.c_str(), jack_port_name(p->m_port))) { + // Queue for rename. + queue.push_back(p); + } + } + + // Now push the renames through. + for (it = queue.begin(); it != queue.end(); ++it) { + Port *p = *it; + Rename(p->m_port); + } + + return queue.size() > 0; +} +#endif + Client *PortManager::FindOrMakeClient(std::string name, bool is_input, bool is_midi) { ClientList::iterator it; diff --git a/src/portmanager.h b/src/portmanager.h index d0445d1..286bb04 100644 --- a/src/portmanager.h +++ b/src/portmanager.h @@ -46,6 +46,9 @@ public: void Disconnect(jack_port_t *port_a, jack_port_t *port_b); void Rename(jack_port_t *port); +#ifndef HAVE_RENAME + bool PollPortRenames(); +#endif Client *FindOrMakeClient(std::string name, bool is_input, bool is_midi); PortGroup *FindOrMakeGroup(Client *client, std::string name);