diff options
author | David Robillard <d@drobilla.net> | 2008-02-23 18:48:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-02-23 18:48:59 +0000 |
commit | 52c970b2d32cce2090efbbaaed6ff50de80958df (patch) | |
tree | 8e69392e8054c8349ce6dad9a4b4028d08e1ae7c /src/PatchageCanvas.cpp | |
parent | 8efff32d97b1b578f8c42fe2db7b30cfc44ecf2f (diff) | |
download | patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.tar.gz patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.tar.bz2 patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.zip |
Rearrange event port referencing stuff to make a bit more sense.
git-svn-id: http://svn.drobilla.net/lad/patchage@1159 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/PatchageCanvas.cpp')
-rw-r--r-- | src/PatchageCanvas.cpp | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index b32ca6e..ffc5627 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -60,41 +60,71 @@ PatchageCanvas::find_module(const string& name, ModuleType type) } -#ifdef HAVE_ALSA boost::shared_ptr<PatchagePort> -PatchageCanvas::find_port(snd_seq_addr_t alsa_addr, bool input) +PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) { + jack_port_t* jack_port = NULL; + string module_name; + string port_name; + + SharedPtr<PatchageModule> module; boost::shared_ptr<PatchagePort> pp; - for (ItemList::iterator m = _items.begin(); m != _items.end(); ++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) + // TODO: filthy. keep a port map and make this O(log(n)) + switch (ref.type) { + case PatchageEvent::PortRef::JACK_ID: + jack_port = jack_port_by_id(_app->jack_driver()->client(), ref.id.jack_id); + if (!jack_port) + return boost::shared_ptr<PatchagePort>(); + + _app->jack_driver()->port_names(ref, module_name, port_name); + + module = find_module(module_name, + (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); + + if (module) + return PtrCast<PatchagePort>(module->get_port(port_name)); + else + return boost::shared_ptr<PatchagePort>(); + + break; + +#ifdef HAVE_ALSA + case PatchageEvent::PortRef::ALSA_ADDR: + for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { + SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(*m); + if (!module) 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; + + for (PortVector::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) { + pp = boost::dynamic_pointer_cast<PatchagePort>(*p); + 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 == ref.id.alsa_addr.client + && pp->alsa_addr()->port == ref.id.alsa_addr.port) { + if (!ref.is_input && module->type() == Input) { + //cerr << "WRONG DIRECTION, SKIPPED PORT" << endl; + } else { + return pp; + } } } } } + default: + break; } +#endif // HAVE_ALSA return boost::shared_ptr<PatchagePort>(); } -#endif + void PatchageCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) |