Store memory bug fixes (multiple ref ptr's to the same object, bad),

control panel fixes



git-svn-id: http://svn.drobilla.net/lad@32 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-06-12 04:48:20 +00:00
parent 0bb0e10b1c
commit e1666be60f
19 changed files with 58 additions and 58 deletions

View File

@ -101,6 +101,7 @@ public:
CountedPtr& operator=(const CountedPtr& copy)
{
if (this != &copy) {
assert(_counter != copy._counter);
release();
retain(copy._counter);
}
@ -112,6 +113,7 @@ public:
CountedPtr& operator=(const CountedPtr<Y>& y)
{
if (this != (CountedPtr*)&y) {
assert(_counter != y._counter);
release();
retain(y._counter);
}

View File

@ -81,22 +81,22 @@ NodeModel::set_path(const Path& p)
for (PortModelList::iterator i = m_ports.begin(); i != m_ports.end(); ++i)
(*i)->set_path(m_path + "/" + (*i)->name());
if (parent_patch() != NULL && old_path.length() > 0)
parent_patch()->rename_node(old_path, p);
//if (m_parent && old_path.length() > 0)
// parent_patch()->rename_node(old_path, p);
}
void
NodeModel::add_port(CountedPtr<PortModel> pm)
{
assert(pm);
assert(pm->name() != "");
assert(pm->path().length() > m_path.length());
assert(pm->path().substr(0, m_path.length()) == m_path);
assert(pm->parent() == NULL);
assert(pm->parent().get() == this);
assert(!get_port(pm->name()));
m_ports.push_back(pm);
pm->set_parent(this);
new_port_sig.emit(pm);
}

View File

@ -33,7 +33,6 @@ using std::cout; using std::cerr; using std::endl;
namespace LibOmClient {
class PatchModel;
class PluginModel;
@ -71,8 +70,6 @@ public:
float y() const { return m_y; }
void y(float a) { m_y = a; }
PatchModel* parent_patch() const { return (PatchModel*)m_parent; }
// Signals
sigc::signal<void, CountedPtr<PortModel> > new_port_sig;

View File

@ -25,7 +25,7 @@
#include <cassert>
#include <sigc++/sigc++.h>
#include "util/Path.h"
#include "util/CountedPtr.h"
using std::string; using std::map; using std::find;
using std::cout; using std::cerr; using std::endl;
using Om::Path;
@ -55,8 +55,8 @@ public:
inline const Path& path() const { return m_path; }
virtual void set_path(const Path& p) { m_path = p; }
ObjectModel* parent() const { return m_parent; }
virtual void set_parent(ObjectModel* p) { m_parent = p; }
CountedPtr<ObjectModel> parent() const { return m_parent; }
virtual void set_parent(CountedPtr<ObjectModel> p) { m_parent = p; }
ObjectController* controller() const { return m_controller; }
@ -69,9 +69,9 @@ public:
// Signals
sigc::signal<void, const string&, const string&> metadata_update_sig;
protected:
Path m_path;
ObjectModel* m_parent;
ObjectController* m_controller;
Path m_path;
CountedPtr<ObjectModel> m_parent;
ObjectController* m_controller; // FIXME: remove
map<string,string> m_metadata;

View File

@ -359,8 +359,8 @@ PatchLibrarian::load_patch(PatchModel* pm, bool wait, bool existing)
{
string filename = pm->filename();
string additional_path = (pm->parent() == NULL)
? "" : ((PatchModel*)pm->parent())->filename();
string additional_path = (!pm->parent())
? "" : ((PatchModel*)pm->parent().get())->filename();
additional_path = additional_path.substr(0, additional_path.find_last_of("/"));
filename = find_file(pm->filename(), additional_path);
@ -409,7 +409,7 @@ PatchLibrarian::load_patch(PatchModel* pm, bool wait, bool existing)
if ((!xmlStrcmp(cur->name, (const xmlChar*)"name"))) {
if (load_name) {
assert(key != NULL);
if (pm->parent() != NULL) {
if (pm->parent()) {
path = pm->parent()->base_path() + string((char*)key);
} else {
path = string("/") + string((char*)key);

View File

@ -63,11 +63,10 @@ PatchModel::add_node(CountedPtr<NodeModel> nm)
{
assert(nm);
assert(nm->name().find("/") == string::npos);
assert(nm->parent() == NULL);
assert(nm->parent().get() == this);
assert(m_nodes.find(nm->name()) == m_nodes.end());
m_nodes[nm->name()] = nm;//CountedPtr<NodeModel>(nm);
nm->set_parent(this);
m_nodes[nm->name()] = nm;
new_node_sig.emit(nm);
}
@ -222,9 +221,9 @@ PatchModel::remove_connection(const string& src_port_path, const string& dst_por
bool
PatchModel::polyphonic() const
{
return (m_parent == NULL)
return (!m_parent)
? (m_poly > 1)
: (m_poly > 1) && m_poly == parent_patch()->poly() && m_poly > 1;
: (m_poly > 1) && m_poly == ((PatchModel*)m_parent.get())->poly() && m_poly > 1;
}

View File

@ -207,11 +207,13 @@ Store::new_node_event(const string& plugin_type, const string& plugin_uri, const
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent());
if (pi != m_objects.end()) {
PatchModel* parent = dynamic_cast<PatchModel*>((*pi).second.get());
if (parent)
CountedPtr<PatchModel> parent = (*pi).second;
if (parent) {
n->set_parent(parent);
parent->add_node(n);
else
} else {
cerr << "ERROR: new node with no parent" << endl;
}
}
}
}
@ -251,7 +253,8 @@ Store::new_port_event(const string& path, const string& type, bool is_output)
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(p->path().parent());
if (pi != m_objects.end()) {
NodeModel* parent = dynamic_cast<NodeModel*>((*pi).second.get());
CountedPtr<NodeModel> parent = (*pi).second;
p->set_parent(parent);
if (parent)
parent->add_port(p);
else

View File

@ -17,9 +17,6 @@
#ifndef STORE_H
#define STORE_H
// FIXME: for CountedPtr
#define WITH_RTTI
#include <cassert>
#include <string>
#include <map>

View File

@ -82,14 +82,10 @@ LV2Plugin::instantiate()
Port* port = NULL;
for (size_t j=0; j < m_num_ports; ++j) {
// LV2 shortnames are guaranteed to be unique
// LV2 shortnames are guaranteed to be unique, valid C identifiers
port_name = (char*)slv2_port_get_symbol(m_lv2_plugin, j);
string::size_type slash_index;
// Replace all slashes with "-" (so they don't screw up paths)
while ((slash_index = port_name.find("/")) != string::npos)
port_name[slash_index] = '-';
assert(port_name.find("/") == string::npos);
port_path = path() + "/" + port_name;

View File

@ -73,7 +73,7 @@ ControlInterface::new_patch_model(PatchModel* const pm)
pm->plugin(plugin);
}*/
assert(pm->parent() == NULL);
assert(!pm->parent());
PatchController* patch = new PatchController(pm);
//Store::instance().add_object(patch);
//_app->patch_tree()->add_patch(patch);

View File

@ -56,7 +56,7 @@ ControlPanel::init(NodeController* node, size_t poly)
assert(node != NULL);
assert(poly > 0);
const CountedPtr<NodeModel> node_model = node->node_model();
const CountedPtr<NodeModel> node_model(node->node_model());
if (poly > 1) {
m_voice_spinbutton->set_range(0, poly - 1);
@ -66,9 +66,14 @@ ControlPanel::init(NodeController* node, size_t poly)
for (PortModelList::const_iterator i = node_model->ports().begin();
i != node_model->ports().end(); ++i) {
PortController* pc = (PortController*)(*i)->controller();
assert(pc != NULL);
add_port(pc);
// FIXME:
if (*i) {
PortController* pc = (PortController*)((*i)->controller());
assert(pc != NULL);
add_port(pc);
} else {
cerr << "WTF?\n";
}
}
m_callback_enabled = true;

View File

@ -91,7 +91,7 @@ Controller::create_patch_from_model(const PatchModel* pm)
//int id = get_next_request_id();
//set_wait_response_id(id);
create_patch_from_model(pm);
if (pm->parent() != NULL) {
if (pm->parent()) {
// wait_for_response();
char temp_buf[16];
snprintf(temp_buf, 16, "%f", pm->x());

View File

@ -6,7 +6,7 @@ MAINTAINERCLEANFILES = Makefile.in
sharefilesdir = $(pkgdatadir)
dist_sharefiles_DATA = om_gtk.glade om-icon.png
AM_CXXFLAGS = -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -I$(top_srcdir)/src/common -I$(top_srcdir)/src/libs/client -DPKGDATADIR=\"$(pkgdatadir)\" @GTKMM_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @LOSC_CFLAGS@ @LASH_CFLAGS@ @FLOWCANVAS_CFLAGS@
AM_CXXFLAGS = -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -I$(top_srcdir)/src/common -I$(top_srcdir)/src/libs/client -DPKGDATADIR=\"$(pkgdatadir)\" @GTKMM_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @LOSC_CFLAGS@ @LASH_CFLAGS@ @FLOWCANVAS_CFLAGS@ -DWITH_RTTI
om_gtk_LDADD = @GTKMM_LIBS@ @LIBGLADEMM_LIBS@ @GNOMECANVASMM_LIBS@ @LOSC_LIBS@ @LASH_LIBS@ @FLOWCANVAS_LIBS@ ../../libs/client/libomclient.la
om_gtk_DEPENDENCIES = ../../libs/client/libomclient.la

View File

@ -79,8 +79,6 @@ NewSubpatchWindow::name_changed()
void
NewSubpatchWindow::ok_clicked()
{
cerr << "FIXME new subpatch\n";
/*
PatchModel* pm = new PatchModel(
m_patch_controller->model()->base_path() + m_name_entry->get_text(),
m_poly_spinbutton->get_value_as_int());
@ -100,7 +98,6 @@ NewSubpatchWindow::ok_clicked()
pm->set_metadata("module-y", temp_buf);
Controller::instance().create_patch_from_model(pm);
hide();
*/
}

View File

@ -53,7 +53,8 @@ NodeController::NodeController(CountedPtr<NodeModel> model)
for (PortModelList::const_iterator i = node_model()->ports().begin();
i != node_model()->ports().end(); ++i) {
assert(!(*i)->controller());
assert((*i)->parent() == model.get());
assert((*i)->parent());
assert((*i)->parent().get() == node_model().get());
// FIXME: leak
PortController* const pc = new PortController(*i);
assert((*i)->controller() == pc); // PortController() does this
@ -193,7 +194,8 @@ NodeController::metadata_update(const string& key, const string& value)
void
NodeController::add_port(CountedPtr<PortModel> pm)
{
assert(pm->parent() == node_model().get());
assert(pm->parent().get() == node_model().get());
assert(pm->parent() == node_model());
assert(node_model()->get_port(pm->name()) == pm);
cout << "[NodeController] Adding port " << pm->path() << endl;
@ -225,9 +227,9 @@ NodeController::show_control_window()
{
size_t poly = 1;
if (node_model()->polyphonic())
poly = node_model()->parent_patch()->poly();
poly = ((PatchModel*)node_model()->parent().get())->poly();
if (m_control_window == NULL)
if (!m_control_window)
m_control_window = new NodeControlWindow(this, poly);
if (m_control_window->control_panel()->num_controls() > 0)
@ -245,7 +247,7 @@ NodeController::on_menu_destroy()
void
NodeController::show_rename_window()
{
assert(node_model()->parent() != NULL);
assert(node_model()->parent());
// FIXME: will this be magically cleaned up?
RenameWindow* win = NULL;
@ -265,6 +267,8 @@ NodeController::show_rename_window()
void
NodeController::on_menu_clone()
{
cerr << "FIXME: clone broken\n";
/*
assert(node_model());
//assert(m_parent != NULL);
//assert(m_parent->model() != NULL);
@ -295,6 +299,7 @@ NodeController::on_menu_clone()
nm->x(node_model()->x() + 20);
nm->y(node_model()->y() + 20);
Controller::instance().create_node_from_model(nm);
*/
}

View File

@ -60,7 +60,6 @@ PatchController::PatchController(CountedPtr<PatchModel> model)
m_module_y(0)
{
assert(model->path().length() > 0);
assert(model->parent() == NULL);
assert(model->controller() == this); // NodeController() does this
/* FIXME if (model->path() != "/") {
@ -168,13 +167,13 @@ PatchController::destroy()
//Store::instance().remove_object(this);
// Delete self from parent (this will delete model)
if (patch_model()->parent() != NULL) {
/*if (patch_model()->parent() != NULL) {
PatchController* const parent = (PatchController*)patch_model()->parent()->controller();
assert(parent != NULL);
parent->remove_node(name());
} else {
//delete m_model;
}
}*/
}
@ -419,7 +418,7 @@ PatchController::add_node(CountedPtr<NodeModel> nm)
cerr << "ADD NODE\n";
assert(nm);
assert(nm->parent() == m_patch_model.get());
assert(nm->parent() == m_patch_model);
assert(nm->path().parent() == m_patch_model->path());
/*if (patch_model()->get_node(nm->name()) != NULL) {
@ -506,7 +505,7 @@ void
PatchController::add_port(CountedPtr<PortModel> pm)
{
assert(pm);
assert(pm->parent() == NULL);
assert(!pm->parent());
//cerr << "[PatchController] Adding port " << pm->path() << endl;

View File

@ -68,7 +68,7 @@ PatchTreeWindow::add_patch(PatchController* pc)
{
const CountedPtr<PatchModel> pm = pc->patch_model();
if (pm->parent() == NULL) {
if (!pm->parent()) {
Gtk::TreeModel::iterator iter = m_patch_treestore->append();
Gtk::TreeModel::Row row = *iter;
if (pm->path() == "/") {

View File

@ -30,7 +30,7 @@ PortController::PortController(CountedPtr<PortModel> model)
m_control_panel(NULL)
{
assert(model);
assert(model->parent() != NULL);
assert(model->parent());
assert(model->controller() == NULL);
model->set_controller(this);
@ -54,7 +54,7 @@ PortController::remove_from_store()
void
PortController::destroy()
{
assert(m_model->parent() != NULL);
assert(m_model->parent());
NodeController* parent = (NodeController*)m_model->parent()->controller();
assert(parent != NULL);

View File

@ -75,7 +75,7 @@ SubpatchModule::on_double_click(GdkEventButton* event)
void
SubpatchModule::browse_to_patch()
{
assert(m_patch->model()->parent() != NULL);
assert(m_patch->model()->parent());
PatchController* pc = (PatchController*)m_patch->model()->parent()->controller();
assert(pc != NULL);
assert(pc->window() != NULL);