Add polled-based port renaming detection for jack1.

git-svn-id: file:///home/vcs/svn/jsweeper/trunk@40 6611ac79-6612-48ef-a1e9-b906f853523e
master
petern 2010-03-26 14:21:42 +00:00
parent 04d0397d75
commit c444ab7334
6 changed files with 58 additions and 0 deletions

View File

@ -24,6 +24,9 @@ Gui::Gui(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &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<Gtk::UIManager> uim = Glib::RefPtr<Gtk::UIManager>::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;

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);