summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-25 01:06:22 +0000
committerDavid Robillard <d@drobilla.net>2007-07-25 01:06:22 +0000
commit5837be3b45c83bd5743735de8cf451c5bdf3541d (patch)
tree3a0331f2a5391726efbb7b6362004a06050f50f1 /src
parent35b1c7c0683a72978f646c883f411e1eabd595ae (diff)
downloadpatchage-5837be3b45c83bd5743735de8cf451c5bdf3541d.tar.gz
patchage-5837be3b45c83bd5743735de8cf451c5bdf3541d.tar.bz2
patchage-5837be3b45c83bd5743735de8cf451c5bdf3541d.zip
Avoid some canvas text measuring overhead in Patchage (module resizing).
Fix duplex Alsa Sequencer ports (fix ticket 12). git-svn-id: http://svn.drobilla.net/lad/patchage@617 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/AlsaDriver.cpp60
-rw-r--r--src/AlsaDriver.hpp2
-rw-r--r--src/JackDriver.cpp9
-rw-r--r--src/PatchageCanvas.cpp26
-rw-r--r--src/PatchageCanvas.hpp2
-rw-r--r--src/PatchageEvent.cpp2
-rw-r--r--src/PatchageEvent.hpp17
7 files changed, 91 insertions, 27 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index 5aad6aa..115524d 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -16,8 +16,10 @@
*/
#include <string>
+#include <set>
#include <iostream>
#include <cassert>
+#include <raul/SharedPtr.hpp>
#include "PatchageCanvas.hpp"
#include "AlsaDriver.hpp"
#include "Patchage.hpp"
@@ -128,6 +130,8 @@ AlsaDriver::refresh_ports()
bool is_input = false;
bool is_duplex = false;
bool is_application = true;
+
+ set<SharedPtr<PatchageModule> > resized_modules;
while (snd_seq_query_next_client (_seq, cinfo) >= 0) {
snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
@@ -166,11 +170,12 @@ AlsaDriver::refresh_ports()
is_application = (type & SND_SEQ_PORT_TYPE_APPLICATION);
port_name = snd_seq_port_info_get_name(pinfo);
boost::shared_ptr<PatchageModule> m;
+
+ bool split = _app->state_manager()->get_module_split(client_name, !is_application)
+ || is_duplex;
//cout << client_name << " : " << port_name << " is_application = " << is_application
- // << " is_duplex = " << is_duplex << endl;
-
- bool split = _app->state_manager()->get_module_split(client_name, !is_application);
+ // << " is_duplex = " << is_duplex << ", split = " << split << endl;
// Application input/output ports go on the same module
if (!split) {
@@ -188,7 +193,9 @@ AlsaDriver::refresh_ports()
m->add_port(create_port(m, port_name, true, addr));
m->add_port(create_port(m, port_name, false, addr));
}
+ resized_modules.insert(m);
}
+
} else { // non-application input/output ports (hw interface, etc) go on separate modules
ModuleType type = InputOutput;
@@ -196,8 +203,8 @@ AlsaDriver::refresh_ports()
// is pretty nasty...
if (!is_duplex) { // just one port to add
- if (is_input) type = Input;
- else type = Output;
+
+ type = ((is_input) ? Input : Output);
// See if an InputOutput module exists (maybe with Jack ports on it)
m = _app->canvas()->find_module(client_name, InputOutput);
@@ -211,8 +218,12 @@ AlsaDriver::refresh_ports()
m->load_location();
m->store_location();
}
- if (!m->get_port(port_name))
+
+ if (!m->get_port(port_name)) {
m->add_port(create_port(m, port_name, is_input, addr));
+ resized_modules.insert(m);
+ }
+
} else { // two ports to add
type = Input;
@@ -227,12 +238,15 @@ AlsaDriver::refresh_ports()
new PatchageModule(_app, client_name, type));
m->load_location();
m->store_location();
+ _app->canvas()->add_item(m);
}
assert(m);
- if (!m->get_port(port_name))
+ if (!m->get_port(port_name)) {
m->add_port(create_port(m, port_name, true, addr));
+ resized_modules.insert(m);
+ }
type = Output;
@@ -247,17 +261,21 @@ AlsaDriver::refresh_ports()
new PatchageModule(_app, client_name, type));
m->load_location();
m->store_location();
+ _app->canvas()->add_item(m);
}
- if (!m->get_port(port_name))
+
+ if (!m->get_port(port_name)) {
m->add_port(create_port(m, port_name, false, addr));
+ resized_modules.insert(m);
+ }
}
}
-
- _app->canvas()->add_item(m);
-
- m->resize();
}
}
+
+ for (set<SharedPtr<PatchageModule> >::const_iterator i = resized_modules.begin();
+ i != resized_modules.end(); ++i)
+ (*i)->resize();
}
@@ -307,10 +325,12 @@ AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port)
snd_seq_query_subscribe_set_root(subsinfo, addr);
snd_seq_query_subscribe_set_index(subsinfo, 0);
- while(!snd_seq_query_port_subscribers(_seq, subsinfo)) {
+ while (!snd_seq_query_port_subscribers(_seq, subsinfo)) {
const snd_seq_addr_t* connected_addr = snd_seq_query_subscribe_get_addr(subsinfo);
+ if (!connected_addr)
+ continue;
- connected_port = _app->canvas()->find_port(connected_addr);
+ connected_port = _app->canvas()->find_port(*connected_addr, true);
if (connected_port) {
boost::shared_ptr<Connection> existing = _app->canvas()->get_connection(port, connected_port);
@@ -505,6 +525,12 @@ AlsaDriver::_refresh_main()
switch (ev->type) {
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
+ /*cout << "Subscription: ";
+ print_addr(ev->data.connect.sender);
+ cout << " -> ";
+ print_addr(ev->data.connect.dest);
+ cout << endl;*/
+
_events.push(PatchageEvent(PatchageEvent::CONNECTION,
ev->data.connect.sender, ev->data.connect.dest));
break;
@@ -530,3 +556,9 @@ AlsaDriver::_refresh_main()
}
}
+
+void
+AlsaDriver::print_addr(snd_seq_addr_t addr)
+{
+ cout << (int)addr.client << ":" << (int)addr.port << endl;
+}
diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp
index d251d78..11adac7 100644
--- a/src/AlsaDriver.hpp
+++ b/src/AlsaDriver.hpp
@@ -51,6 +51,8 @@ public:
bool disconnect(boost::shared_ptr<PatchagePort> src_port,
boost::shared_ptr<PatchagePort> dst_port);
+
+ void print_addr(snd_seq_addr_t addr);
private:
void refresh_ports();
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index 5572769..761c1c2 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -18,6 +18,7 @@
#include <cassert>
#include <cstring>
#include <string>
+#include <set>
#include <iostream>
#include "config.h"
#include <jack/jack.h>
@@ -202,6 +203,8 @@ JackDriver::refresh()
string port1_name;
string client2_name;
string port2_name;
+
+ set<SharedPtr<PatchageModule> > resized_modules;
// Add all ports
if (ports)
@@ -258,7 +261,7 @@ JackDriver::refresh()
m->add_port(create_port(m, port));
}
- m->resize();
+ resized_modules.insert(m);
}
// Add all connections
@@ -320,6 +323,10 @@ JackDriver::refresh()
free(connected_ports);
}
}
+
+ for (set<SharedPtr<PatchageModule> >::const_iterator i = resized_modules.begin();
+ i != resized_modules.end(); ++i)
+ (*i)->resize();
free(ports);
}
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index 22b4d1f..ea4e371 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -62,19 +62,33 @@ PatchageCanvas::find_module(const string& name, ModuleType type)
#ifdef HAVE_ALSA
boost::shared_ptr<PatchagePort>
-PatchageCanvas::find_port(const snd_seq_addr_t* alsa_addr)
+PatchageCanvas::find_port(snd_seq_addr_t alsa_addr, bool input)
{
boost::shared_ptr<PatchagePort> pp;
for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) {
- SharedPtr<Module> module = PtrCast<Module>(*m);
+ SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(*m);
if (!module)
continue;
+
for (PortVector::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) {
pp = boost::dynamic_pointer_cast<PatchagePort>(*p);
- if (pp && pp->type() == ALSA_MIDI && pp->alsa_addr()
- && pp->alsa_addr()->client == alsa_addr->client
- && pp->alsa_addr()->port == alsa_addr->port)
- return pp;
+ if (!pp)
+ continue;
+
+ if (pp->type() == ALSA_MIDI) {
+ /*cerr << "ALSA PORT: " << (int)pp->alsa_addr()->client << ":"
+ << (int)pp->alsa_addr()->port << endl;*/
+
+ if (pp->alsa_addr()
+ && pp->alsa_addr()->client == alsa_addr.client
+ && pp->alsa_addr()->port == alsa_addr.port) {
+ if (!input && module->type() == Input) {
+ //cerr << "WRONG DIRECTION, SKIPPED PORT" << endl;
+ } else {
+ return pp;
+ }
+ }
+ }
}
}
diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp
index fd662f1..0ef54fb 100644
--- a/src/PatchageCanvas.hpp
+++ b/src/PatchageCanvas.hpp
@@ -40,7 +40,7 @@ public:
boost::shared_ptr<PatchageModule> find_module(const string& name, ModuleType type);
#ifdef HAVE_ALSA
- boost::shared_ptr<PatchagePort> find_port(const snd_seq_addr_t* alsa_addr);
+ boost::shared_ptr<PatchagePort> find_port(snd_seq_addr_t alsa_addr, bool input);
#endif
void connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2);
void disconnect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2);
diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp
index a6b237f..e2849b7 100644
--- a/src/PatchageEvent.cpp
+++ b/src/PatchageEvent.cpp
@@ -32,7 +32,7 @@ PatchageEvent::find_port(const Patchage* patchage, const PortRef& ref)
#ifdef HAVE_ALSA
if (ref.type == PortRef::ALSA_ADDR) {
- return patchage->canvas()->find_port(&ref.id.alsa_addr);
+ return patchage->canvas()->find_port(ref.id.alsa_addr, ref.is_input);
} else
#endif
{
diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp
index ada4718..19cf16d 100644
--- a/src/PatchageEvent.hpp
+++ b/src/PatchageEvent.hpp
@@ -25,6 +25,9 @@
#endif
#include "PatchagePort.hpp"
+#include <iostream>
+using namespace std;
+
class Patchage;
@@ -58,8 +61,8 @@ public:
#ifdef HAVE_ALSA
PatchageEvent(Type type, snd_seq_addr_t port_1, snd_seq_addr_t port_2)
: _type(type)
- , _port_1(port_1)
- , _port_2(port_2)
+ , _port_1(port_1, false)
+ , _port_2(port_2, true)
{}
#endif
@@ -71,13 +74,14 @@ private:
uint8_t _type;
struct PortRef {
- PortRef() : type(NULL_PORT_REF) { id.jack_id = 0; }
+ PortRef() : type(NULL_PORT_REF) { memset(&id, 0, sizeof(id)); }
PortRef(jack_port_id_t jack_id) : type(JACK_ID) { id.jack_id = jack_id; }
PortRef(jack_port_t* jack_port) : type(JACK_PORT) { id.jack_port = jack_port; }
#ifdef HAVE_ALSA
- PortRef(snd_seq_addr_t addr) : type(ALSA_ADDR) { id.alsa_addr = addr; }
+ PortRef(snd_seq_addr_t addr, bool input) : type(ALSA_ADDR)
+ { id.alsa_addr = addr; is_input = input; }
#endif
enum { NULL_PORT_REF, JACK_ID, JACK_PORT, ALSA_ADDR } type;
@@ -89,6 +93,11 @@ private:
snd_seq_addr_t alsa_addr;
#endif
} id;
+
+#ifdef HAVE_ALSA
+ bool is_input;
+#endif
+
};
PortRef _port_1;