summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/AlsaDriver.cpp80
-rw-r--r--src/AlsaDriver.hpp35
-rw-r--r--src/Driver.hpp10
-rw-r--r--src/JackDbusDriver.cpp13
-rw-r--r--src/JackDbusDriver.hpp12
-rw-r--r--src/JackDriver.cpp79
-rw-r--r--src/JackDriver.hpp18
-rw-r--r--src/Patchage.cpp10
-rw-r--r--src/PatchageCanvas.cpp95
-rw-r--r--src/PatchageCanvas.hpp30
-rw-r--r--src/PatchageEvent.cpp17
-rw-r--r--src/PatchageModule.cpp4
-rw-r--r--src/PatchageModule.hpp4
-rw-r--r--src/PatchagePort.hpp10
14 files changed, 228 insertions, 189 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index abd6b82..a22ecc8 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -82,6 +82,20 @@ AlsaDriver::detach()
}
}
+static bool
+is_alsa_port(const PatchagePort* port)
+{
+ return port->type() == ALSA_MIDI;
+}
+
+/** Destroy all JACK (canvas) ports.
+ */
+void
+AlsaDriver::destroy_all()
+{
+ _app->canvas()->remove_ports(is_alsa_port);
+}
+
/** Refresh all Alsa Midi ports and connections.
*/
void
@@ -96,38 +110,38 @@ AlsaDriver::refresh()
refresh_connections();
}
-boost::shared_ptr<PatchagePort>
+PatchagePort*
AlsaDriver::create_port_view(Patchage* patchage,
const PortID& id)
{
- boost::shared_ptr<PatchageModule> parent;
- boost::shared_ptr<PatchagePort> port;
+ PatchageModule* parent;
+ PatchagePort* port;
create_port_view_internal(patchage, id.id.alsa_addr, parent, port);
return port;
}
-boost::shared_ptr<PatchageModule>
+PatchageModule*
AlsaDriver::find_or_create_module(
Patchage* patchage,
const std::string& client_name,
ModuleType type)
{
- boost::shared_ptr<PatchageModule> m = _app->canvas()->find_module(client_name, type);
+ PatchageModule* m = _app->canvas()->find_module(client_name, type);
if (!m) {
- m = boost::shared_ptr<PatchageModule>(new PatchageModule(patchage, client_name, type));
+ m = new PatchageModule(patchage, client_name, type);
m->load_location();
_app->canvas()->add_module(client_name, m);
- _app->enqueue_resize(m.get());
+ _app->enqueue_resize(m);
}
return m;
}
void
AlsaDriver::create_port_view_internal(
- Patchage* patchage,
- snd_seq_addr_t addr,
- boost::shared_ptr<PatchageModule>& m,
- boost::shared_ptr<PatchagePort>& port)
+ Patchage* patchage,
+ snd_seq_addr_t addr,
+ PatchageModule*& m,
+ PatchagePort*& port)
{
if (ignore(addr))
return;
@@ -184,7 +198,7 @@ AlsaDriver::create_port_view_internal(
if (!split) {
m = find_or_create_module(_app, client_name, InputOutput);
if (!m->get_port(port_name)) {
- port = create_port(m, port_name, is_input, addr);
+ port = create_port(*m, port_name, is_input, addr);
port->show();
m->add_port(port);
}
@@ -193,7 +207,7 @@ AlsaDriver::create_port_view_internal(
ModuleType type = ((is_input) ? Input : Output);
m = find_or_create_module(_app, client_name, type);
if (!m->get_port(port_name)) {
- port = create_port(m, port_name, is_input, addr);
+ port = create_port(*m, port_name, is_input, addr);
port->show();
m->add_port(port);
}
@@ -202,7 +216,7 @@ AlsaDriver::create_port_view_internal(
type = ((!is_input) ? Input : Output);
m = find_or_create_module(_app, client_name, type);
if (!m->get_port(port_name)) {
- port = create_port(m, port_name, !is_input, addr);
+ port = create_port(*m, port_name, !is_input, addr);
port->show();
m->add_port(port);
}
@@ -210,15 +224,15 @@ AlsaDriver::create_port_view_internal(
}
}
-boost::shared_ptr<PatchagePort>
-AlsaDriver::create_port(boost::shared_ptr<PatchageModule> parent,
+PatchagePort*
+AlsaDriver::create_port(PatchageModule& parent,
const string& name, bool is_input, snd_seq_addr_t addr)
{
- boost::shared_ptr<PatchagePort> ret(
- new PatchagePort(parent, ALSA_MIDI, name, is_input,
- _app->state_manager()->get_port_color(ALSA_MIDI)));
+ PatchagePort* ret = new PatchagePort(
+ parent, ALSA_MIDI, name, is_input,
+ _app->state_manager()->get_port_color(ALSA_MIDI));
- dynamic_cast<PatchageCanvas*>(parent->canvas())->index_port(
+ dynamic_cast<PatchageCanvas*>(parent.canvas())->index_port(
PortID(addr, is_input), ret);
ret->alsa_addr(addr);
@@ -281,10 +295,10 @@ AlsaDriver::refresh_ports()
snd_seq_port_info_t* pinfo;
snd_seq_port_info_alloca(&pinfo);
- boost::shared_ptr<PatchageModule> parent;
- boost::shared_ptr<PatchagePort> port;
+ PatchageModule* parent;
+ PatchagePort* port;
- std::set< boost::shared_ptr<PatchageModule> > to_resize;
+ std::set<PatchageModule*> to_resize;
while (snd_seq_query_next_client (_seq, cinfo) >= 0) {
snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
@@ -294,7 +308,7 @@ AlsaDriver::refresh_ports()
if (!ignore(addr)) {
create_port_view_internal(_app, addr, parent, port);
if (parent)
- _app->enqueue_resize(parent.get());
+ _app->enqueue_resize(parent);
}
}
}
@@ -308,15 +322,15 @@ AlsaDriver::refresh_connections()
assert(is_attached());
assert(_seq);
- boost::shared_ptr<PatchageModule> m;
- boost::shared_ptr<PatchagePort> p;
+ PatchageModule* m = NULL;
+ PatchagePort* p = NULL;
for (FlowCanvas::Canvas::Items::iterator i = _app->canvas()->items().begin();
i != _app->canvas()->items().end(); ++i) {
- m = boost::dynamic_pointer_cast<PatchageModule>(*i);
+ m = dynamic_cast<PatchageModule*>(*i);
if (m) {
for (FlowCanvas::Module::Ports::const_iterator j = m->ports().begin(); j != m->ports().end(); ++j) {
- p = boost::dynamic_pointer_cast<PatchagePort>(*j);
+ p = dynamic_cast<PatchagePort*>(*j);
if (p->type() == ALSA_MIDI)
add_connections(p);
}
@@ -327,13 +341,13 @@ AlsaDriver::refresh_connections()
/** Add all connections for the given port.
*/
void
-AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port)
+AlsaDriver::add_connections(PatchagePort* port)
{
assert(is_attached());
assert(_seq);
const snd_seq_addr_t* addr = port->alsa_addr();
- boost::shared_ptr<PatchagePort> connected_port;
+ PatchagePort* connected_port;
// Fix a problem with duplex->duplex connections (would show up twice)
// No sense doing them all twice anyway..
@@ -366,7 +380,8 @@ AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port)
* \return Whether connection succeeded.
*/
bool
-AlsaDriver::connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port)
+AlsaDriver::connect(PatchagePort* src_port,
+ PatchagePort* dst_port)
{
const snd_seq_addr_t* src = src_port->alsa_addr();
const snd_seq_addr_t* dst = dst_port->alsa_addr();
@@ -410,7 +425,8 @@ AlsaDriver::connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<
* \return Whether disconnection succeeded.
*/
bool
-AlsaDriver::disconnect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port)
+AlsaDriver::disconnect(PatchagePort* src_port,
+ PatchagePort* dst_port)
{
const snd_seq_addr_t* src = src_port->alsa_addr();
const snd_seq_addr_t* dst = dst_port->alsa_addr();
diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp
index ab849b9..54c35b1 100644
--- a/src/AlsaDriver.hpp
+++ b/src/AlsaDriver.hpp
@@ -44,16 +44,17 @@ public:
bool is_attached() const { return (_seq != NULL); }
void refresh();
+ void destroy_all();
- boost::shared_ptr<PatchagePort> create_port_view(
+ PatchagePort* create_port_view(
Patchage* patchage,
const PortID& id);
- bool connect(boost::shared_ptr<PatchagePort> src_port,
- boost::shared_ptr<PatchagePort> dst_port);
+ bool connect(PatchagePort* src_port,
+ PatchagePort* dst_port);
- bool disconnect(boost::shared_ptr<PatchagePort> src_port,
- boost::shared_ptr<PatchagePort> dst_port);
+ bool disconnect(PatchagePort* src_port,
+ PatchagePort* dst_port);
void print_addr(snd_seq_addr_t addr);
@@ -63,13 +64,13 @@ private:
void refresh_ports();
void refresh_connections();
- void add_connections(boost::shared_ptr<PatchagePort> port);
+ void add_connections(PatchagePort* port);
bool create_refresh_port();
static void* refresh_main(void* me);
void _refresh_main();
- boost::shared_ptr<PatchageModule>
+ PatchageModule*
find_or_create_module(
Patchage* patchage,
const std::string& client_name,
@@ -77,16 +78,16 @@ private:
void
create_port_view_internal(
- Patchage* patchage,
- snd_seq_addr_t addr,
- boost::shared_ptr<PatchageModule>& parent,
- boost::shared_ptr<PatchagePort>& port);
-
- boost::shared_ptr<PatchagePort> create_port(
- boost::shared_ptr<PatchageModule> parent,
- const std::string& name,
- bool is_input,
- snd_seq_addr_t addr);
+ Patchage* patchage,
+ snd_seq_addr_t addr,
+ PatchageModule*& parent,
+ PatchagePort*& port);
+
+ PatchagePort* create_port(
+ PatchageModule& parent,
+ const std::string& name,
+ bool is_input,
+ snd_seq_addr_t addr);
Patchage* _app;
snd_seq_t* _seq;
diff --git a/src/Driver.hpp b/src/Driver.hpp
index feae11b..05b9e0b 100644
--- a/src/Driver.hpp
+++ b/src/Driver.hpp
@@ -42,15 +42,15 @@ public:
virtual void refresh() = 0;
virtual void destroy_all() {}
- virtual boost::shared_ptr<PatchagePort> create_port_view(
+ virtual PatchagePort* create_port_view(
Patchage* patchage,
const PortID& id) = 0;
- virtual bool connect(boost::shared_ptr<PatchagePort> src_port,
- boost::shared_ptr<PatchagePort> dst_port) = 0;
+ virtual bool connect(PatchagePort* src_port,
+ PatchagePort* dst_port) = 0;
- virtual bool disconnect(boost::shared_ptr<PatchagePort> src_port,
- boost::shared_ptr<PatchagePort> dst_port) = 0;
+ virtual bool disconnect(PatchagePort* src_port,
+ PatchagePort* dst_port) = 0;
sigc::signal<void> signal_attached;
sigc::signal<void> signal_detached;
diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp
index 51f71c6..7b43e58 100644
--- a/src/JackDbusDriver.cpp
+++ b/src/JackDbusDriver.cpp
@@ -97,8 +97,7 @@ JackDriver::destroy_all()
for (FlowCanvas::Module::Ports::iterator p = ports.begin(); p != ports.end(); ++p) {
SharedPtr<PatchagePort> port = boost::dynamic_pointer_cast<PatchagePort>(*p);
if (port && (port->type() == JACK_AUDIO || port->type() == JACK_MIDI)) {
- module->remove_port(port);
- port->hide();
+ _app->canvas()->remove_port(port->id());
}
}
@@ -845,8 +844,8 @@ JackDriver::refresh()
bool
JackDriver::connect(
- SharedPtr<PatchagePort> src,
- SharedPtr<PatchagePort> dst)
+ PatchagePort* src,
+ PatchagePort* dst)
{
const char* client1_name;
const char* port1_name;
@@ -874,8 +873,8 @@ JackDriver::connect(
bool
JackDriver::disconnect(
- SharedPtr<PatchagePort> src,
- SharedPtr<PatchagePort> dst)
+ PatchagePort* src,
+ PatchagePort* dst)
{
const char* client1_name;
const char* port1_name;
@@ -1070,7 +1069,7 @@ JackDriver::reset_max_dsp_load()
_max_dsp_load = 0.0;
}
-SharedPtr<PatchagePort>
+PatchagePort*
JackDriver::create_port_view(
Patchage* patchage,
const PortID& id)
diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp
index 9e790ee..ca4fb91 100644
--- a/src/JackDbusDriver.hpp
+++ b/src/JackDbusDriver.hpp
@@ -48,13 +48,13 @@ public:
void destroy_all();
bool connect(
- boost::shared_ptr<PatchagePort> src,
- boost::shared_ptr<PatchagePort> dst);
+ PatchagePort* src,
+ PatchagePort* dst);
bool disconnect(
- boost::shared_ptr<PatchagePort> src,
- boost::shared_ptr<PatchagePort> dst);
-
+ PatchagePort* src,
+ PatchagePort* dst);
+
size_t get_xruns();
void reset_xruns();
@@ -67,7 +67,7 @@ public:
void process_events(Patchage* app) {}
- boost::shared_ptr<PatchagePort> create_port_view(
+ PatchagePort* create_port_view(
Patchage* patchage,
const PortID& ref);
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index 773fba9..1973303 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -109,33 +109,21 @@ JackDriver::detach()
_app->status_msg("[JACK] Detached");
}
+static bool
+is_jack_port(const PatchagePort* port)
+{
+ return port->type() == JACK_AUDIO || port->type() == JACK_MIDI;
+}
+
/** Destroy all JACK (canvas) ports.
*/
void
JackDriver::destroy_all()
{
- FlowCanvas::Canvas::Items modules = _app->canvas()->items(); // copy
- for (FlowCanvas::Canvas::Items::iterator m = modules.begin(); m != modules.end(); ++m) {
- SharedPtr<FlowCanvas::Module> module = PtrCast<FlowCanvas::Module>(*m);
- if (!module)
- continue;
- FlowCanvas::Module::Ports ports = module->ports(); // copy
- for (FlowCanvas::Module::Ports::iterator p = ports.begin(); p != ports.end(); ++p) {
- boost::shared_ptr<PatchagePort> port = boost::dynamic_pointer_cast<PatchagePort>(*p);
- if ((port && port->type() == JACK_AUDIO) || (port->type() == JACK_MIDI)) {
- module->remove_port(port);
- port->hide();
- }
- }
-
- if (module->ports().empty())
- _app->canvas()->remove_item(module);
- else
- _app->enqueue_resize(module.get());
- }
+ _app->canvas()->remove_ports(is_jack_port);
}
-boost::shared_ptr<PatchagePort>
+PatchagePort*
JackDriver::create_port_view(Patchage* patchage,
const PortID& id)
{
@@ -145,7 +133,7 @@ JackDriver::create_port_view(Patchage* patchage,
jack_port = jack_port_by_id(_client, id.id.jack_id);
if (jack_port == NULL)
- return boost::shared_ptr<PatchagePort>();
+ return NULL;
const int jack_flags = jack_port_flags(jack_port);
@@ -162,38 +150,35 @@ JackDriver::create_port_view(Patchage* patchage,
}
}
- boost::shared_ptr<PatchageModule> parent
- = _app->canvas()->find_module(module_name, type);
+ PatchageModule* parent = _app->canvas()->find_module(module_name, type);
bool resize = false;
if (!parent) {
- parent = boost::shared_ptr<PatchageModule>(
- new PatchageModule(patchage, module_name, type));
+ parent = new PatchageModule(patchage, module_name, type);
parent->load_location();
patchage->canvas()->add_module(module_name, parent);
parent->show();
resize = true;
}
- boost::shared_ptr<PatchagePort> port
- = boost::dynamic_pointer_cast<PatchagePort>(parent->get_port(port_name));
+ PatchagePort* port = dynamic_cast<PatchagePort*>(parent->get_port(port_name));
if (!port) {
- port = create_port(parent, jack_port, id);
+ port = create_port(*parent, jack_port, id);
port->show();
parent->add_port(port);
resize = true;
}
if (resize)
- _app->enqueue_resize(parent.get());
+ _app->enqueue_resize(parent);
return port;
}
-boost::shared_ptr<PatchagePort>
-JackDriver::create_port(boost::shared_ptr<PatchageModule> parent, jack_port_t* port, PortID id)
+PatchagePort*
+JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id)
{
assert(port);
const char* const type_str = jack_port_type(port);
@@ -205,16 +190,16 @@ JackDriver::create_port(boost::shared_ptr<PatchageModule> parent, jack_port_t* p
port_type = JACK_MIDI;
} else {
Raul::warn << jack_port_name(port) << " has unknown type \'" << type_str << "\'" << endl;
- return boost::shared_ptr<PatchagePort>();
+ return NULL;
}
- boost::shared_ptr<PatchagePort> ret(
+ PatchagePort* ret(
new PatchagePort(parent, port_type, jack_port_short_name(port),
(jack_port_flags(port) & JackPortIsInput),
_app->state_manager()->get_port_color(port_type)));
if (id.type != PortID::NULL_PORT_ID) {
- dynamic_cast<PatchageCanvas*>(parent->canvas())->index_port(id, ret);
+ dynamic_cast<PatchageCanvas*>(parent.canvas())->index_port(id, ret);
}
return ret;
@@ -274,10 +259,10 @@ JackDriver::refresh()
}
}
- boost::shared_ptr<PatchageModule> m = _app->canvas()->find_module(client1_name, type);
+ PatchageModule* m = _app->canvas()->find_module(client1_name, type);
if (!m) {
- m = boost::shared_ptr<PatchageModule>(new PatchageModule(_app, client1_name, type));
+ m = new PatchageModule(_app, client1_name, type);
m->load_location();
_app->canvas()->add_module(client1_name, m);
}
@@ -296,9 +281,9 @@ JackDriver::refresh()
}
if (!m->get_port(jack_port_short_name(port)))
- m->add_port(create_port(m, port, PortID()));
+ m->add_port(create_port(*m, port, PortID()));
- _app->enqueue_resize(m.get());
+ _app->enqueue_resize(m);
}
// Add all connections
@@ -314,7 +299,7 @@ JackDriver::refresh()
const ModuleType port1_type = (jack_port_flags(port) & JackPortIsInput) ? Input : Output;
- boost::shared_ptr<PatchageModule> client1_module
+ PatchageModule* client1_module
= _app->canvas()->find_module(client1_name, port1_type);
if (connected_ports) {
@@ -327,17 +312,17 @@ JackDriver::refresh()
const ModuleType port2_type = (port1_type == Input) ? Output : Input;
- boost::shared_ptr<PatchageModule> client2_module
+ PatchageModule* client2_module
= _app->canvas()->find_module(client2_name, port2_type);
- boost::shared_ptr<FlowCanvas::Port> port1 = client1_module->get_port(port1_name);
- boost::shared_ptr<FlowCanvas::Port> port2 = client2_module->get_port(port2_name);
+ FlowCanvas::Port* port1 = client1_module->get_port(port1_name);
+ FlowCanvas::Port* port2 = client2_module->get_port(port2_name);
if (!port1 || !port2)
continue;
- boost::shared_ptr<FlowCanvas::Port> src;
- boost::shared_ptr<FlowCanvas::Port> dst;
+ FlowCanvas::Port* src = NULL;
+ FlowCanvas::Port* dst = NULL;
if (port1->is_output() && port2->is_input()) {
src = port1;
@@ -387,7 +372,8 @@ JackDriver::port_names(const PortID& id,
* \return Whether connection succeeded.
*/
bool
-JackDriver::connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port)
+JackDriver::connect(PatchagePort* src_port,
+ PatchagePort* dst_port)
{
if (_client == NULL)
return false;
@@ -409,7 +395,8 @@ JackDriver::connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<
* \return Whether disconnection succeeded.
*/
bool
-JackDriver::disconnect(boost::shared_ptr<PatchagePort> const src_port, boost::shared_ptr<PatchagePort> const dst_port)
+JackDriver::disconnect(PatchagePort* const src_port,
+ PatchagePort* const dst_port)
{
if (_client == NULL)
return false;
diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp
index 311b72a..f503bf9 100644
--- a/src/JackDriver.hpp
+++ b/src/JackDriver.hpp
@@ -55,15 +55,15 @@ public:
std::string& module_name,
std::string& port_name);
- boost::shared_ptr<PatchagePort> create_port_view(
+ PatchagePort* create_port_view(
Patchage* patchage,
const PortID& id);
- bool connect(boost::shared_ptr<PatchagePort> src,
- boost::shared_ptr<PatchagePort> dst);
+ bool connect(PatchagePort* src,
+ PatchagePort* dst);
- bool disconnect(boost::shared_ptr<PatchagePort> src,
- boost::shared_ptr<PatchagePort> dst);
+ bool disconnect(PatchagePort* src,
+ PatchagePort* dst);
uint32_t get_xruns() { return _xruns; }
void reset_xruns();
@@ -80,10 +80,10 @@ public:
void process_events(Patchage* app);
private:
- boost::shared_ptr<PatchagePort> create_port(
- boost::shared_ptr<PatchageModule> parent,
- jack_port_t* port,
- PortID id);
+ PatchagePort* create_port(
+ PatchageModule& parent,
+ jack_port_t* port,
+ PortID id);
static void error_cb(const char* msg);
diff --git a/src/Patchage.cpp b/src/Patchage.cpp
index bfb067c..9dbc3c5 100644
--- a/src/Patchage.cpp
+++ b/src/Patchage.cpp
@@ -512,7 +512,7 @@ Patchage::update_state()
{
for (FlowCanvas::Canvas::Items::iterator i = _canvas->items().begin();
i != _canvas->items().end(); ++i) {
- SharedPtr<FlowCanvas::Module> module = PtrCast<FlowCanvas::Module>(*i);
+ FlowCanvas::Module* module = dynamic_cast<FlowCanvas::Module*>(*i);
if (module)
module->load_location();
}
@@ -628,12 +628,10 @@ Patchage::save_session(bool close)
script << "sleep 3" << endl;
script << endl;
- for (FlowCanvas::ConnectionList::const_iterator c = _canvas->connections().begin();
+ for (FlowCanvas::Canvas::Connections::const_iterator c = _canvas->connections().begin();
c != _canvas->connections().end(); ++c) {
- boost::shared_ptr<PatchagePort> src
- = boost::dynamic_pointer_cast<PatchagePort>((*c)->source().lock());
- boost::shared_ptr<PatchagePort> dst
- = boost::dynamic_pointer_cast<PatchagePort>((*c)->dest().lock());
+ PatchagePort* src = dynamic_cast<PatchagePort*>((*c)->source());
+ PatchagePort* dst = dynamic_cast<PatchagePort*>((*c)->dest());
if (!src || !dst || src->type() == ALSA_MIDI || dst->type() == ALSA_MIDI) {
continue;
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index a26e75d..279a852 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -42,14 +42,14 @@ PatchageCanvas::PatchageCanvas(Patchage* app, int width, int height)
{
}
-boost::shared_ptr<PatchageModule>
+PatchageModule*
PatchageCanvas::find_module(const string& name, ModuleType type)
{
const ModuleIndex::const_iterator i = _module_index.find(name);
if (i == _module_index.end())
- return boost::shared_ptr<PatchageModule>();
+ return NULL;
- boost::shared_ptr<PatchageModule> io_module;
+ PatchageModule* io_module = NULL;
for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == name; ++j) {
if (j->second->type() == type) {
return j->second;
@@ -62,10 +62,10 @@ PatchageCanvas::find_module(const string& name, ModuleType type)
return io_module;
}
-boost::shared_ptr<PatchagePort>
+PatchagePort*
PatchageCanvas::find_port(const PortID& id)
{
- boost::shared_ptr<PatchagePort> pp;
+ PatchagePort* pp = NULL;
PortIndex::iterator i = _port_index.find(id);
if (i != _port_index.end()) {
@@ -78,17 +78,17 @@ PatchageCanvas::find_port(const PortID& id)
if (id.type == PortID::JACK_ID) {
jack_port_t* jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id);
if (!jack_port)
- return boost::shared_ptr<PatchagePort>();
+ return NULL;
string module_name;
string port_name;
_app->jack_driver()->port_names(id, module_name, port_name);
- SharedPtr<PatchageModule> module = find_module(
+ PatchageModule* module = find_module(
module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output);
if (module)
- pp = PtrCast<PatchagePort>(module->get_port(port_name));
+ pp = dynamic_cast<PatchagePort*>(module->get_port(port_name));
if (pp)
index_port(id, pp);
@@ -98,10 +98,10 @@ PatchageCanvas::find_port(const PortID& id)
return pp;
}
-boost::shared_ptr<PatchagePort>
+PatchagePort*
PatchageCanvas::remove_port(const PortID& id)
{
- boost::shared_ptr<PatchagePort> port = find_port(id);
+ PatchagePort* const port = find_port(id);
if (!port)
return port;
@@ -116,29 +116,67 @@ PatchageCanvas::remove_port(const PortID& id)
return port;
}
-boost::shared_ptr<PatchagePort>
+void
+PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*))
+{
+ std::set<PatchageModule*> empty;
+ for (Items::iterator i = items().begin(); i != items().end(); ++i) {
+ PatchageModule* module = dynamic_cast<PatchageModule*>(*i);
+ if (!module)
+ continue;
+
+ FlowCanvas::Module::Ports ports = module->ports(); // copy
+ for (FlowCanvas::Module::Ports::iterator p = ports.begin();
+ p != ports.end(); ++p) {
+ if (pred(dynamic_cast<PatchagePort*>(*p))) {
+ delete *p;
+ }
+ }
+
+ if (module->num_ports() == 0) {
+ empty.insert(module);
+ }
+ }
+
+ for (PortIndex::iterator i = _port_index.begin();
+ i != _port_index.end();) {
+ PortIndex::iterator next = i;
+ ++next;
+ if (pred(i->second)) {
+ _port_index.erase(i);
+ }
+ i = next;
+ }
+
+ for (std::set<PatchageModule*>::iterator i = empty.begin();
+ i != empty.end(); ++i) {
+ delete *i;
+ }
+}
+
+PatchagePort*
PatchageCanvas::find_port_by_name(const std::string& client_name,
const std::string& port_name)
{
const ModuleIndex::const_iterator i = _module_index.find(client_name);
if (i == _module_index.end())
- return boost::shared_ptr<PatchagePort>();
+ return NULL;
for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == client_name; ++j) {
- SharedPtr<PatchagePort> port = PtrCast<PatchagePort>(j->second->get_port(port_name));
+ PatchagePort* port = dynamic_cast<PatchagePort*>(j->second->get_port(port_name));
if (port)
return port;
}
- return boost::shared_ptr<PatchagePort>();
+ return NULL;
}
void
-PatchageCanvas::connect(boost::shared_ptr<FlowCanvas::Connectable> port1,
- boost::shared_ptr<FlowCanvas::Connectable> port2)
+PatchageCanvas::connect(FlowCanvas::Connectable* port1,
+ FlowCanvas::Connectable* port2)
{
- boost::shared_ptr<PatchagePort> p1 = boost::dynamic_pointer_cast<PatchagePort>(port1);
- boost::shared_ptr<PatchagePort> p2 = boost::dynamic_pointer_cast<PatchagePort>(port2);
+ PatchagePort* p1 = dynamic_cast<PatchagePort*>(port1);
+ PatchagePort* p2 = dynamic_cast<PatchagePort*>(port2);
if (!p1 || !p2)
return;
@@ -157,18 +195,17 @@ PatchageCanvas::connect(boost::shared_ptr<FlowCanvas::Connectable> port1,
}
void
-PatchageCanvas::disconnect(boost::shared_ptr<FlowCanvas::Connectable> port1,
- boost::shared_ptr<FlowCanvas::Connectable> port2)
+PatchageCanvas::disconnect(FlowCanvas::Connectable* port1,
+ FlowCanvas::Connectable* port2)
{
- boost::shared_ptr<PatchagePort> input = boost::dynamic_pointer_cast<PatchagePort>(port1);
- boost::shared_ptr<PatchagePort> output = boost::dynamic_pointer_cast<PatchagePort>(port2);
-
+ PatchagePort* input = dynamic_cast<PatchagePort*>(port1);
+ PatchagePort* output = dynamic_cast<PatchagePort*>(port2);
if (!input || !output)
return;
if (input->is_output() && output->is_input()) {
// Damn, guessed wrong
- boost::shared_ptr<PatchagePort> swap = input;
+ PatchagePort* swap = input;
input = output;
output = swap;
}
@@ -199,13 +236,13 @@ PatchageCanvas::status_message(const string& msg)
}
void
-PatchageCanvas::add_module(const std::string& name, boost::shared_ptr<PatchageModule> module)
+PatchageCanvas::add_module(const std::string& name, PatchageModule* module)
{
_module_index.insert(std::make_pair(name, module));
// Join partners, if applicable
- boost::shared_ptr<PatchageModule> in_module;
- boost::shared_ptr<PatchageModule> out_module;
+ PatchageModule* in_module = NULL;
+ PatchageModule* out_module = NULL;
if (module->type() == Input) {
in_module = module;
out_module = find_module(name, Output);
@@ -220,14 +257,14 @@ PatchageCanvas::add_module(const std::string& name, boost::shared_ptr<PatchageMo
}
bool
-PatchageCanvas::remove_item(boost::shared_ptr<FlowCanvas::Item> i)
+PatchageCanvas::remove_item(FlowCanvas::Item* i)
{
// Remove item from canvas
const bool ret = FlowCanvas::Canvas::remove_item(i);
if (!ret)
return ret;
- SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(i);
+ PatchageModule* const module = dynamic_cast<PatchageModule*>(i);
if (!module)
return ret;
diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp
index b7ec3b2..e7e8214 100644
--- a/src/PatchageCanvas.hpp
+++ b/src/PatchageCanvas.hpp
@@ -42,38 +42,40 @@ class PatchageCanvas : public FlowCanvas::Canvas {
public:
PatchageCanvas(Patchage* _app, int width, int height);
- boost::shared_ptr<PatchageModule> find_module(const std::string& name, ModuleType type);
- boost::shared_ptr<PatchagePort> find_port(const PortID& id);
+ PatchageModule* find_module(const std::string& name, ModuleType type);
+ PatchagePort* find_port(const PortID& id);
- boost::shared_ptr<PatchagePort> find_port_by_name(const std::string& client_name,
- const std::string& port_name);
+ PatchagePort* find_port_by_name(const std::string& client_name,
+ const std::string& port_name);
- void connect(boost::shared_ptr<FlowCanvas::Connectable> port1,
- boost::shared_ptr<FlowCanvas::Connectable> port2);
+ void connect(FlowCanvas::Connectable* port1,
+ FlowCanvas::Connectable* port2);
- void disconnect(boost::shared_ptr<FlowCanvas::Connectable> port1,
- boost::shared_ptr<FlowCanvas::Connectable> port2);
+ void disconnect(FlowCanvas::Connectable* port1,
+ FlowCanvas::Connectable* port2);
void status_message(const std::string& msg);
- void index_port(const PortID& id, boost::shared_ptr<PatchagePort> port) {
+ void index_port(const PortID& id, PatchagePort* port) {
_port_index.insert(std::make_pair(id, port));
}
- void add_module(const std::string& name, boost::shared_ptr<PatchageModule> module);
- bool remove_item(boost::shared_ptr<FlowCanvas::Item> i);
+ void remove_ports(bool (*pred)(const PatchagePort*));
- boost::shared_ptr<PatchagePort> remove_port(const PortID& id);
+ void add_module(const std::string& name, PatchageModule* module);
+ bool remove_item(FlowCanvas::Item* i);
+
+ PatchagePort* remove_port(const PortID& id);
void destroy();
private:
Patchage* _app;
- typedef std::map< const PortID, boost::shared_ptr<PatchagePort> > PortIndex;
+ typedef std::map<const PortID, PatchagePort*> PortIndex;
PortIndex _port_index;
- typedef std::multimap< const std::string, boost::shared_ptr<PatchageModule> > ModuleIndex;
+ typedef std::multimap<const std::string, PatchageModule*> ModuleIndex;
ModuleIndex _module_index;
};
diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp
index e77de3f..d1afb1a 100644
--- a/src/PatchageEvent.cpp
+++ b/src/PatchageEvent.cpp
@@ -47,12 +47,11 @@ PatchageEvent::execute(Patchage* patchage)
_str = NULL;
} else if (_type == CLIENT_DESTRUCTION) {
- SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(
+ PatchageModule* module = dynamic_cast<PatchageModule*>(
patchage->canvas()->find_module(_str, InputOutput));
if (module) {
patchage->canvas()->remove_item(module);
- module.reset();
}
free(_str);
@@ -72,7 +71,7 @@ PatchageEvent::execute(Patchage* patchage)
}
if (driver) {
- SharedPtr<PatchagePort> port = driver->create_port_view(patchage, _port_1);
+ PatchagePort* port = driver->create_port_view(patchage, _port_1);
if (port)
patchage->enqueue_resize(port->module());
else
@@ -83,17 +82,17 @@ PatchageEvent::execute(Patchage* patchage)
} else if (_type == PORT_DESTRUCTION) {
- SharedPtr<PatchagePort> port = patchage->canvas()->remove_port(_port_1);
+ PatchagePort* port = patchage->canvas()->remove_port(_port_1);
if (port) {
- port.reset();
+ delete port;
} else {
Raul::error << "Unable to find port `" << _port_1 << "' to destroy" << endl;
}
} else if (_type == CONNECTION) {
- SharedPtr<PatchagePort> port_1 = patchage->canvas()->find_port(_port_1);
- SharedPtr<PatchagePort> port_2 = patchage->canvas()->find_port(_port_2);
+ PatchagePort* port_1 = patchage->canvas()->find_port(_port_1);
+ PatchagePort* port_2 = patchage->canvas()->find_port(_port_2);
if (!port_1)
Raul::error << "Unable to find port `" << _port_1 << "' to connect" << endl;
@@ -104,8 +103,8 @@ PatchageEvent::execute(Patchage* patchage)
} else if (_type == DISCONNECTION) {
- SharedPtr<PatchagePort> port_1 = patchage->canvas()->find_port(_port_1);
- SharedPtr<PatchagePort> port_2 = patchage->canvas()->find_port(_port_2);
+ PatchagePort* port_1 = patchage->canvas()->find_port(_port_1);
+ PatchagePort* port_2 = patchage->canvas()->find_port(_port_2);
if (!port_1)
Raul::error << "Unable to find port `" << _port_1 << "' to disconnect" << endl;
diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp
index 9cdcb7a..e19418b 100644
--- a/src/PatchageModule.cpp
+++ b/src/PatchageModule.cpp
@@ -112,14 +112,14 @@ PatchageModule::join()
}
void
-PatchageModule::add_port(boost::shared_ptr<FlowCanvas::Port> port)
+PatchageModule::add_port(FlowCanvas::Port* port)
{
FlowCanvas::Module::add_port(port);
update_menu();
}
void
-PatchageModule::remove_port(boost::shared_ptr<FlowCanvas::Port> port)
+PatchageModule::remove_port(FlowCanvas::Port* port)
{
FlowCanvas::Module::remove_port(port);
update_menu();
diff --git a/src/PatchageModule.hpp b/src/PatchageModule.hpp
index ebccbb5..2a58182 100644
--- a/src/PatchageModule.hpp
+++ b/src/PatchageModule.hpp
@@ -32,8 +32,8 @@ public:
PatchageModule(Patchage* app, const std::string& name, ModuleType type, double x=0, double y=0);
~PatchageModule();
- void add_port(boost::shared_ptr<FlowCanvas::Port> port);
- void remove_port(boost::shared_ptr<FlowCanvas::Port> port);
+ void add_port(FlowCanvas::Port* port);
+ void remove_port(FlowCanvas::Port* port);
void split();
void join();
diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp
index 8e4c188..47c1513 100644
--- a/src/PatchagePort.hpp
+++ b/src/PatchagePort.hpp
@@ -39,11 +39,11 @@
class PatchagePort : public FlowCanvas::Port
{
public:
- PatchagePort(boost::shared_ptr<FlowCanvas::Module> module,
- PortType type,
- const std::string& name,
- bool is_input,
- uint32_t color)
+ PatchagePort(FlowCanvas::Module& module,
+ PortType type,
+ const std::string& name,
+ bool is_input,
+ uint32_t color)
: Port(module, name, is_input, color)
, _type(type)
{