Fixed Patchage dynamic reconnection.

git-svn-id: http://svn.drobilla.net/lad@166 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-10-14 05:51:23 +00:00
parent d3639f2abe
commit 4fccf65944
9 changed files with 94 additions and 58 deletions

View File

@ -41,14 +41,14 @@ CXXFLAGS="$CXXFLAGS -pipe -fmessage-length=139 -fdiagnostics-show-location=every
CFLAGS="$CFLAGS -pipe -fmessage-length=139 -fdiagnostics-show-location=every-line"
# Boost shared_ptr debugging
pointer_debug="no"
AC_ARG_ENABLE(pointer_debug,
[AS_HELP_STRING(--enable-pointer-debug, [Enable smart pointer debugging (no)])],
[pointer_debug="$enableval"])
if test "$pointer_debug" = "yes"; then
CFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
CXXFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
fi
#pointer_debug="no"
#AC_ARG_ENABLE(pointer_debug,
# [AS_HELP_STRING(--enable-pointer-debug, [Enable smart pointer debugging (no)])],
# [pointer_debug="$enableval"])
#if test "$pointer_debug" = "yes"; then
# CFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
# CXXFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
#fi
PKG_CHECK_MODULES(GTKMM, gtkmm-2.4)
PKG_CHECK_MODULES(GNOMECANVASMM, libgnomecanvasmm-2.6)

View File

@ -47,6 +47,7 @@ public:
inline boost::shared_ptr<Port> get_port(const string& name) const;
void add_port(boost::shared_ptr<Port> port);
void remove_port(boost::shared_ptr<Port> port);
boost::shared_ptr<Port> remove_port(const string& name);
boost::shared_ptr<Port> port_at(double x, double y);
@ -82,8 +83,6 @@ public:
int base_color() const { return 0x1F2A3CFF; }
protected:
void remove_port(boost::shared_ptr<Port> port);
bool module_event(GdkEvent* event);
bool is_within(const Gnome::Canvas::Rect& rect);

View File

@ -412,8 +412,8 @@ FlowCanvas::are_connected(boost::shared_ptr<const Port> port1, boost::shared_ptr
ConnectionList::const_iterator c;
for (c = m_connections.begin(); c != m_connections.end(); ++c) {
boost::shared_ptr<Port> src = (*c)->source().lock();
boost::shared_ptr<Port> dst = (*c)->dest().lock();
const boost::shared_ptr<Port> src = (*c)->source().lock();
const boost::shared_ptr<Port> dst = (*c)->dest().lock();
if (!src || !dst)
continue;
@ -432,8 +432,8 @@ FlowCanvas::get_connection(boost::shared_ptr<Port> port1, boost::shared_ptr<Port
assert(port2);
for (ConnectionList::iterator i = m_connections.begin(); i != m_connections.end(); ++i) {
boost::shared_ptr<Port> src = (*i)->source().lock();
boost::shared_ptr<Port> dst = (*i)->dest().lock();
const boost::shared_ptr<Port> src = (*i)->source().lock();
const boost::shared_ptr<Port> dst = (*i)->dest().lock();
if (!src || !dst)
continue;
@ -482,8 +482,8 @@ FlowCanvas::add_connection(boost::shared_ptr<Port> port1, boost::shared_ptr<Port
bool
FlowCanvas::add_connection(boost::shared_ptr<Connection> c)
{
boost::shared_ptr<Port> src = c->source().lock();
boost::shared_ptr<Port> dst = c->dest().lock();
const boost::shared_ptr<Port> src = c->source().lock();
const boost::shared_ptr<Port> dst = c->dest().lock();
if (src && dst) {
src->add_connection(c);
@ -505,10 +505,16 @@ FlowCanvas::remove_connection(boost::shared_ptr<Connection> connection)
ConnectionList::iterator i = find(m_connections.begin(), m_connections.end(), connection);
if (i != m_connections.end()) {
boost::shared_ptr<Connection> c = *i;
const boost::shared_ptr<Connection> c = *i;
const boost::shared_ptr<Port> src = c->source().lock();
const boost::shared_ptr<Port> dst = c->dest().lock();
c->source().lock()->remove_connection(c);
c->dest().lock()->remove_connection(c);
if (src)
src->remove_connection(c);
if (dst)
dst->remove_connection(c);
m_connections.erase(i);
}
@ -532,8 +538,12 @@ FlowCanvas::destroy_all_flagged_connections()
if ((*c)->flagged()) {
ConnectionList::iterator next = c;
++next;
(*c)->source().lock()->remove_connection(*c);
(*c)->dest().lock()->remove_connection(*c);
const boost::shared_ptr<Port> src = (*c)->source().lock();
const boost::shared_ptr<Port> dst = (*c)->dest().lock();
if (src)
src->remove_connection(*c);
if (dst)
dst->remove_connection(*c);
m_connections.erase(c);
c = next;
} else {
@ -551,8 +561,12 @@ FlowCanvas::destroy_all_connections()
m_remove_objects = false;
for (ConnectionList::iterator c = m_connections.begin(); c != m_connections.end(); ++c) {
(*c)->source().lock()->remove_connection(*c);
(*c)->dest().lock()->remove_connection(*c);
const boost::shared_ptr<Port> src = (*c)->source().lock();
const boost::shared_ptr<Port> dst = (*c)->dest().lock();
if (src)
src->remove_connection(*c);
if (dst)
dst->remove_connection(*c);
}
m_connections.clear();
@ -898,18 +912,20 @@ FlowCanvas::connection_drag_handler(GdkEvent* event)
if (p) {
boost::shared_ptr<Module> m = p->module().lock();
if (p != m_selected_port) {
if (snapped_port)
snapped_port->set_highlighted(false);
p->set_highlighted(true);
snapped_port = p;
if (m) {
if (p != m_selected_port) {
if (snapped_port)
snapped_port->set_highlighted(false);
p->set_highlighted(true);
snapped_port = p;
}
drag_module->property_x() = m->property_x().get_value();
drag_module->m_module_box.property_x2() = m->m_module_box.property_x2().get_value();
drag_module->property_y() = m->property_y().get_value();
drag_module->m_module_box.property_y2() = m->m_module_box.property_y2().get_value();
drag_port->property_x() = p->property_x().get_value();
drag_port->property_y() = p->property_y().get_value();
}
drag_module->property_x() = m->property_x().get_value();
drag_module->m_module_box.property_x2() = m->m_module_box.property_x2().get_value();
drag_module->property_y() = m->property_y().get_value();
drag_module->m_module_box.property_y2() = m->m_module_box.property_y2().get_value();
drag_port->property_x() = p->property_x().get_value();
drag_port->property_y() = p->property_y().get_value();
} else { // off the port now, unsnap
if (snapped_port)
snapped_port->set_highlighted(false);
@ -939,18 +955,20 @@ FlowCanvas::connection_drag_handler(GdkEvent* event)
if (p && p->is_input() != m_connect_port->is_input()) {
boost::shared_ptr<Module> m = p->module().lock();
p->set_highlighted(true);
snapped_port = p;
snapped = true;
// Make drag module and port exactly the same size/loc as the snapped
drag_module->move_to(m->property_x().get_value(), m->property_y().get_value());
drag_module->set_width(m->width());
drag_module->set_height(m->height());
drag_port->property_x() = p->property_x().get_value();
drag_port->property_y() = p->property_y().get_value();
// Make the drag port as wide as the snapped port so the connection coords are the same
drag_port->m_rect.property_x2() = p->m_rect.property_x2().get_value();
drag_port->m_rect.property_y2() = p->m_rect.property_y2().get_value();
if (m) {
p->set_highlighted(true);
snapped_port = p;
snapped = true;
// Make drag module and port exactly the same size/loc as the snapped
drag_module->move_to(m->property_x().get_value(), m->property_y().get_value());
drag_module->set_width(m->width());
drag_module->set_height(m->height());
drag_port->property_x() = p->property_x().get_value();
drag_port->property_y() = p->property_y().get_value();
// Make the drag port as wide as the snapped port so the connection coords are the same
drag_port->m_rect.property_x2() = p->m_rect.property_x2().get_value();
drag_port->m_rect.property_y2() = p->m_rect.property_y2().get_value();
}
} else {
drag_module->property_x() = x;
drag_module->property_y() = y - 7; // FIXME: s#7#cursor_height/2#

View File

@ -98,6 +98,16 @@ if test "$strict" = "yes"; then
CXXFLAGS="$CXXFLAGS -ansi -Wall -Wextra -Wno-unused-parameter -Wconversion -Winit-self -Woverloaded-virtual -Wsign-promo"
fi
# Boost shared_ptr debugging
pointer_debug="no"
AC_ARG_ENABLE(pointer_debug,
[AS_HELP_STRING(--enable-pointer-debug, [Enable smart pointer debugging (no)])],
[pointer_debug="$enableval"])
if test "$pointer_debug" = "yes"; then
CFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
CXXFLAGS+=" -DBOOST_SP_ENABLE_DEBUG_HOOKS"
fi
# Bolt on a few specific flags to CXXFLAGS that should always be used
CXXFLAGS="$CXXFLAGS -pipe -Wall -fmessage-length=139 -fdiagnostics-show-location=every-line"
CFLAGS="$CFLAGS -pipe -Wall -fmessage-length=139 -fdiagnostics-show-location=every-line"

View File

@ -73,7 +73,7 @@ AlsaDriver::attach(bool /*launch_daemon*/)
void
AlsaDriver::detach()
{
if (m_seq != NULL) {
if (m_seq) {
pthread_cancel(m_refresh_thread);
pthread_join(m_refresh_thread, NULL);
snd_seq_close(m_seq);

View File

@ -75,12 +75,12 @@ JackDriver::attach(bool launch_daemon)
void
JackDriver::detach()
{
if (m_client != NULL) {
if (m_client) {
jack_deactivate(m_client);
jack_client_close(m_client);
m_client = NULL;
signal_detached.emit();
destroy_all_ports();
signal_detached.emit();
m_app->status_message("[JACK] Detached");
}
}
@ -97,12 +97,12 @@ JackDriver::destroy_all_ports()
for (PortVector::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) {
port.reset();
m->second->remove_port(port);
}
}
if (m->second->ports().empty())
m->second.reset();
m_app->canvas()->remove_module(m->second->name());
}
}
@ -144,8 +144,8 @@ JackDriver::refresh()
if (m_client == NULL) {
// Shutdown
if (m_is_dirty) {
signal_detached.emit();
destroy_all_ports();
signal_detached.emit();
}
m_is_dirty = false;
m_mutex.unlock();

View File

@ -67,7 +67,6 @@ LashDriver::attach(bool launch_daemon)
void
LashDriver::detach()
{
// FIXME: send some notification that we're gone??
m_client = NULL;
m_app->status_message("[LASH] Detached");
signal_detached.emit();

View File

@ -28,6 +28,8 @@
#include "LashDriver.h"
#endif
// FIXME: include to avoid undefined reference to boost SP debug hooks stuff
#include <raul/SharedPtr.h>
Patchage::Patchage(int argc, char** argv)
:
@ -47,6 +49,8 @@ Patchage::Patchage(int argc, char** argv)
m_state_manager = new StateManager();
m_canvas = boost::shared_ptr<PatchageFlowCanvas>(new PatchageFlowCanvas(this, 1600*2, 1200*2));
m_jack_driver = new JackDriver(this);
m_jack_driver->signal_detached.connect(sigc::mem_fun(this, &Patchage::queue_refresh));
#ifdef HAVE_ALSA
m_alsa_driver = new AlsaDriver(this);
#endif
@ -108,6 +112,7 @@ Patchage::Patchage(int argc, char** argv)
xml->get_widget("zoom_normal_but", m_zoom_normal_button);
update_state();
m_main_paned->set_position(m_main_paned->get_height() - 20);
m_canvas_scrolledwindow->add(*m_canvas);
//m_canvas_scrolledwindow->signal_event().connect(sigc::mem_fun(m_canvas, &FlowCanvas::scroll_event_handler));
@ -142,7 +147,6 @@ Patchage::Patchage(int argc, char** argv)
m_menu_help_about->signal_activate().connect( sigc::mem_fun(this, &Patchage::menu_help_about));
attach_menu_items();
m_main_paned->set_position(m_main_paned->get_height() - 20);
m_canvas->show();
}
@ -231,15 +235,16 @@ Patchage::update_state()
for (ModuleMap::iterator i = m_canvas->modules().begin(); i != m_canvas->modules().end(); ++i)
(*i).second->load_location();
cerr << "[Patchage] Resizing window: (" << m_state_manager->get_window_size().x
<< "," << m_state_manager->get_window_size().y << ")" << endl;
//cerr << "[Patchage] Resizing window: (" << m_state_manager->get_window_size().x
// << "," << m_state_manager->get_window_size().y << ")" << endl;
m_main_window->resize(
static_cast<int>(m_state_manager->get_window_size().x),
static_cast<int>(m_state_manager->get_window_size().y));
cerr << "[Patchage] Moving window: (" << m_state_manager->get_window_location().x
<< "," << m_state_manager->get_window_location().y << ")" << endl;
//cerr << "[Patchage] Moving window: (" << m_state_manager->get_window_location().x
// << "," << m_state_manager->get_window_location().y << ")" << endl;
m_main_window->move(
static_cast<int>(m_state_manager->get_window_location().x),
static_cast<int>(m_state_manager->get_window_location().y));

View File

@ -51,6 +51,11 @@ namespace boost {
#include <boost/shared_ptr.hpp>
#ifdef BOOST_AC_USE_PTHREADS
#error "Boost is using mutex locking for pointer reference counting."
#error "This is VERY slow. Please report your platform."
#endif
#define SharedPtr boost::shared_ptr
#define PtrCast boost::dynamic_pointer_cast