Skip to content

Commit

Permalink
[max] Fix repetition filter eventually causing messages to stop being…
Browse files Browse the repository at this point in the history
… sent
  • Loading branch information
jcelerier committed Nov 25, 2022
1 parent ae488c9 commit fea5e67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/ossia-max/src/matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ matcher::~matcher()
}
node = nullptr;
}

struct set_local_mute {
bool& m;
set_local_mute(bool& mute): m{mute} {
m = true;
}
~set_local_mute() { m = false; }
};
void matcher::output_value(ossia::value v)
{
if(owner->m_otype == object_class::param || owner->m_otype == object_class::remote)
Expand All @@ -130,7 +136,7 @@ void matcher::output_value(ossia::value v)

if(!owner->m_local_mute)
{
owner->m_local_mute = true;
set_local_mute lm{owner->m_local_mute};

auto param = node->get_parameter();
auto filtered
Expand Down Expand Up @@ -162,7 +168,6 @@ void matcher::output_value(ossia::value v)
value_visitor<object_base> vm;
vm.x = (object_base*)owner;
val.apply(vm);
owner->m_local_mute = false;
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/ossia-max/src/object_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,21 +920,25 @@ void object_base::push_parameter_value(
ossia::net::parameter_base* param, const ossia::value& val)
{
std::unique_lock<std::mutex> lock{param_locks_mutex};
auto it = ossia::find_if(param_locks, [param](auto& p) { return p.second == param; });
auto it = ossia::find_if(param_locks, [param](const auto& p) { return p.second == param; });

if(it == param_locks.end())
{
int64_t r = param_locks_counter++;
param_locks.emplace_back(r, param);
param_locks_mutex.unlock();
lock.unlock();

if(!m_local_mute)
{
param->push_value(val);
}

param_locks_mutex.lock();
auto rm_it = ossia::find_if(param_locks, [r](auto& p) { return p.first == r; });
param_locks.erase(rm_it);
lock.lock();
assert(!param_locks.empty());
if(param_locks.back().first == r)
param_locks.pop_back();
else if(auto rm_it = ossia::find_if(param_locks, [r](const auto& p) { return p.first == r; }); rm_it != param_locks.end())
param_locks.erase(rm_it);
}
}

Expand Down

0 comments on commit fea5e67

Please sign in to comment.