Skip to content

Commit

Permalink
[ossia-max] keep parameter value when changing parent address
Browse files Browse the repository at this point in the history
fix #441
  • Loading branch information
avilleret committed Apr 18, 2019
1 parent d4cfb57 commit b21e0f5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
32 changes: 27 additions & 5 deletions OSSIA/ossia-max/src/model.cpp
Expand Up @@ -66,18 +66,15 @@ void* model::create(t_symbol* name, long argc, t_atom* argv)
return nullptr;
}

// parse arguments
long attrstart = attr_args_offset(argc, argv);

// check name argument
x->m_name = _sym_nothing;
if (attrstart && argv)
if (argc > 0 && argv)
{
if (atom_gettype(argv) == A_SYM)
{
x->m_name = atom_getsym(argv);
x->m_addr_scope = ossia::net::get_address_scope(x->m_name->s_name);
}
}
}

if (x->m_name == _sym_nothing)
Expand All @@ -88,6 +85,7 @@ void* model::create(t_symbol* name, long argc, t_atom* argv)
}

// process attr args, if any
long attrstart = attr_args_offset(argc, argv);
attr_args_process(x, argc - attrstart, argv + attrstart);

// we need to delay registration because object may use patcher hierarchy
Expand Down Expand Up @@ -253,13 +251,37 @@ void model::register_children()

bool model::unregister()
{
save_children_state();

m_matchers.clear();

register_children();

return true;
}

void model::save_children_state()
{
for(auto& m : m_matchers)
{
for(auto x : ossia_max::instance().parameters.reference() )
{
if(x->m_parent_node == m->get_node())
{
x->save_values();
}
}

for(auto x : ossia_max::instance().models.reference() )
{
if(x->m_parent_node == m->get_node())
{
x->save_children_state();
}
}
}
}

ossia::safe_set<model*>& model::quarantine()
{
return ossia_max::instance().model_quarantine;
Expand Down
1 change: 1 addition & 0 deletions OSSIA/ossia-max/src/model.hpp
Expand Up @@ -19,6 +19,7 @@ class model : public node_base
bool do_registration(const std::vector<std::shared_ptr<t_matcher>>& nodes);
bool unregister();
void register_children();
void save_children_state();

static ossia::safe_set<model*>& quarantine();

Expand Down
3 changes: 3 additions & 0 deletions OSSIA/ossia-max/src/object_base.hpp
Expand Up @@ -13,6 +13,8 @@

#include <concurrentqueue.h>

#include <map>

#define OSSIA_MAX_MAX_ATTR_SIZE 256

namespace ossia
Expand Down Expand Up @@ -189,6 +191,7 @@ struct object_base

protected:
ossia::optional<ossia::traversal::path> m_path;
std::map<std::string, ossia::value> m_value_map;
};

#pragma mark -
Expand Down
16 changes: 16 additions & 0 deletions OSSIA/ossia-max/src/parameter.cpp
Expand Up @@ -268,6 +268,22 @@ bool parameter::unregister()
return true;
}

void parameter::save_values()
{
if(!m_matchers.empty())
{
m_value_map.clear();
for(const auto& m : m_matchers)
{
auto n = m->get_node();
if(auto p = n->get_parameter())
{
m_value_map[n->get_name()] = p->value();
}
}
}
}

ossia::safe_set<parameter *> &parameter::quarantine()
{
return ossia_max::instance().parameter_quarantine;
Expand Down
1 change: 1 addition & 0 deletions OSSIA/ossia-max/src/parameter.hpp
Expand Up @@ -16,6 +16,7 @@ class parameter : public parameter_base
bool register_node(const std::vector<std::shared_ptr<t_matcher>>& node);
bool do_registration(const std::vector<std::shared_ptr<t_matcher>>& node);
bool unregister();
void save_values();

static ossia::safe_set<parameter*>& quarantine();

Expand Down
17 changes: 13 additions & 4 deletions OSSIA/ossia-max/src/parameter_base.cpp
Expand Up @@ -262,19 +262,28 @@ void parameter_base::push_default_value(parameter_base* x)

if (!x->m_mute)
{
for (auto& m : x->m_node_selection)
for (auto m : x->m_node_selection)
{
if(!m->is_zombie())
{
node = m->get_node();
auto param = node->get_parameter();

auto def_val = ossia::net::get_default_value(*node);
if (def_val)
auto it = x->m_value_map.find(node->get_name());
if(it != x->m_value_map.end())
{
param->push_value(*def_val);
param->push_value(it->second);
trig_output_value(node);
}
else
{
auto def_val = ossia::net::get_default_value(*node);
if (def_val)
{
param->push_value(*def_val);
trig_output_value(node);
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions OSSIA/ossia-max/src/remote.cpp
Expand Up @@ -130,13 +130,13 @@ void remote::assist(remote* x, void* b, long m, long a, char* s)
switch(a)
{
case 0:
sprintf(s, "deferred outlet with set prefix (for connecting to UI object), %l", a);
sprintf(s, "deferred outlet with set prefix (for connecting to UI object), %ld", a);
break;
case 1:
sprintf(s, "raw outlet, %l", a);
sprintf(s, "raw outlet, %ld", a);
break;
case 2:
sprintf(s, "dump outlet, %l", a);
sprintf(s, "dump outlet, %ld", a);
break;
default:
break;
Expand Down

0 comments on commit b21e0f5

Please sign in to comment.