• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 45465485304

24 Nov 2026 06:59PM UTC coverage: 62.1% (+0.3%) from 61.818%
45465485304

Pull #2302

github

web-flow
Merge 52aaaa0b4 into ef0dd3ce5
Pull Request #2302: Mixer: a console of strips with meters, and the execution reporting back without stopping the audio

268210 of 802082 branches covered (33.44%)

1579 of 2302 new or added lines in 45 files covered. (68.59%)

123 existing lines in 22 files now uncovered.

274219 of 441577 relevant lines covered (62.1%)

766034.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.83
/src/plugins/score-lib-process/Process/ExecutionSetup.cpp
1
#include <State/Address.hpp>
2

3
#include <Process/Dataflow/Cable.hpp>
4
#include <Process/Dataflow/Port.hpp>
5
#include <Process/ExecutionContext.hpp>
6
#include <Process/ExecutionFunctions.hpp>
7
#include <Process/ExecutionSetup.hpp>
8
#include <Process/ExecutionTransaction.hpp>
9
#include <Process/Process.hpp>
10

11
#include <LocalTree/ScriptableProcessComponent.hpp>
12

13
#include <QPointer>
14
#include <QTimer>
15

16
#include <ossia/dataflow/execution_state.hpp>
17
#include <ossia/dataflow/for_each_port.hpp>
18
#include <ossia/dataflow/graph/graph_interface.hpp>
19
#include <ossia/dataflow/graph_edge.hpp>
20
#include <ossia/dataflow/graph_node.hpp>
21
#include <ossia/dataflow/port.hpp>
22
#include <ossia/editor/scenario/time_process.hpp>
23
#include <ossia/network/common/destination_qualifiers.hpp>
24

25
namespace Execution
26
{
27

28
namespace
29
{
30
struct ContextEnqueuer
31
{
32
  SetupContext& self;
33
  template <typename F>
34
  void operator()(F&& f)
70,913 ✔
35
  {
36
    static_assert(std::is_nothrow_move_constructible_v<F>);
37
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
70,913 ✔
38
    self.context.executionQueue.enqueue(std::move(f));
70,913 ✔
39
  }
70,913 ✔
40
};
41
struct VectorEnqueuer
42
{
43
  Transaction& vec;
44
  template <typename F>
45
  void operator()(F&& f)
13,622 ✔
46
  {
47
    static_assert(std::is_nothrow_move_constructible_v<F>);
48
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
13,622 ✔
49
    vec.push_back(std::move(f));
13,622 ✔
50
  }
13,622 ✔
51
};
52

53
// Changed from lambda to explicit struct to improve debuggability
54
static auto enqueue_in_context(SetupContext& self) noexcept
14,071 ✔
55
{
56
  return ContextEnqueuer{self};
14,071 ✔
57
}
58

59
static auto enqueue_in_vector(Transaction& vec) noexcept
3,912 ✔
60
{
61
  return VectorEnqueuer{vec};
3,912 ✔
62
}
63
}
64
ossia::net::node_base*
65
findNode(const ossia::execution_state& st, const State::Address& addr)
6,115 ✔
66
{
67
  auto& devs = st.edit_devices();
6,115 ✔
68
  auto dev_p = ossia::find_if(
6,115 !
69
      devs, [d = addr.device.toStdString()](auto& dev) { return dev->get_name() == d; });
14,106 ✔
70
  if(dev_p == devs.end())
6,115 ✔
71
    return nullptr;
30 ✔
72
  return ossia::net::find_node(
6,085 !
73
      (*dev_p)->get_root_node(), addr.path.join("/").toStdString());
6,085 !
74
}
6,115 ✔
75

76
std::optional<ossia::destination> makeDestination(
36 ✔
77
    const ossia::execution_state& devices, const State::AddressAccessor& addr)
78
{
79
  auto n = findNode(devices, addr.address);
36 ✔
80
  if(!n)
36 ✔
81
    return {};
24 ✔
82

83
  auto p = n->get_parameter();
12 ✔
84
  if(!p)
12 !
85
    return {};
×
86

87
  auto& qual = addr.qualifiers.get();
12 ✔
88
  return ossia::destination{*p, qual.accessors, qual.unit};
12 ✔
89
}
36 ✔
90

91
template <typename Impl>
92
void SetupContext::disconnect_cable_impl(const Process::Cable& c, Impl&& impl)
1,470 ✔
93
{
94
  if(!context.created) {
1,470 !
95
    return;
1,424 ✔
96
  }
97
  auto it = m_cables.find(c.id());
46 ✔
98
  if(it != m_cables.end())
46 !
99
  {
100
    impl([cable = it->second, graph = context.execGraph] {
78 !
101
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
32 ✔
102
      graph->disconnect(cable);
32 ✔
103
    });
32 ✔
104
    // The edge is gone from the graph: a later connectCable() for the same
105
    // id makes a new one, and whoever asks whether the cable is wired up
106
    // (a node rebuilding its ports) must not find this one.
107
    m_cables.erase(it);
46 ✔
108
  }
46 ✔
109
}
1,470 ✔
110

111
template <typename Impl>
112
void SetupContext::connect_cable_impl(Process::Cable& cable, Impl&& impl)
2,816 ✔
113
{
114
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
2,816 ✔
115
  if(!context.created) {
2,816 !
116
    return;
1,343 ✔
117
  }
118
  ossia::node_ptr source_node{}, sink_node{};
1,473 ✔
119
  ossia::outlet_ptr source_port{};
1,473 ✔
120
  ossia::inlet_ptr sink_port{};
1,473 ✔
121
  if(auto port_src = cable.source().try_find(context.doc))
1,473 !
122
  {
123
    auto it = outlets.find(port_src);
1,473 !
124
    if(it != outlets.end())
1,473 !
125
    {
126
      source_node = it->second.first;
1,473 ✔
127
      source_port = it->second.second;
1,473 ✔
128
    }
1,473 ✔
129
  }
1,473 ✔
130
  if(auto port_snk = cable.sink().try_find(context.doc))
1,473 !
131
  {
132
    auto it = inlets.find(port_snk);
1,473 !
133
    if(it != inlets.end())
1,473 !
134
    {
135
      sink_node = it->second.first;
1,473 ✔
136
      sink_port = it->second.second;
1,473 ✔
137
    }
1,473 ✔
138
  }
1,473 ✔
139

140
  if(source_node && sink_node && source_port && sink_port)
1,473 !
141
  {
142
    ossia::edge_ptr edge;
1,473 ✔
143
    switch(cable.type())
1,473 !
144
    {
145
      case Process::CableType::ImmediateStrict: {
146
        edge = context.execGraph->allocate_edge(
×
147
            ossia::immediate_strict_connection{}, std::move(source_port),
×
148
            std::move(sink_port), std::move(source_node), std::move(sink_node));
×
149
        break;
×
150
      }
151
      case Process::CableType::ImmediateGlutton: {
152
        edge = context.execGraph->allocate_edge(
2,946 !
153
            ossia::immediate_glutton_connection{}, std::move(source_port),
1,473 ✔
154
            std::move(sink_port), std::move(source_node), std::move(sink_node));
1,473 ✔
155
        break;
1,473 ✔
156
      }
157
      case Process::CableType::DelayedStrict: {
158
        edge = context.execGraph->allocate_edge(
×
159
            ossia::delayed_strict_connection{}, std::move(source_port),
×
160
            std::move(sink_port), std::move(source_node), std::move(sink_node));
×
161
        break;
×
162
      }
163
      case Process::CableType::DelayedGlutton: {
164
        edge = context.execGraph->allocate_edge(
×
165
            ossia::delayed_glutton_connection{}, std::move(source_port),
×
166
            std::move(sink_port), std::move(source_node), std::move(sink_node));
×
167
        break;
×
168
      }
169
    }
170

171
    m_cables[cable.id()] = edge;
1,473 !
172
    impl([edge, graph = context.execGraph]() mutable {
2,932 !
173
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
1,459 ✔
174
      graph->connect(std::move(edge));
1,459 !
175
    });
1,459 ✔
176
  }
1,473 ✔
177
}
2,816 ✔
178

179
// Pushed once, when the node is registered; the address machinery never touches
180
// `type` afterwards.
181
template <typename T, typename Impl>
182
static void set_declared_unit_impl(
62,347 ✔
183
    const Process::Port& proc_port, const T& port, Impl&& append)
184
{
185
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
62,347 ✔
186
  const ossia::unit_t& u = proc_port.unit().get();
62,347 ✔
187
  if(!u)
62,347 !
188
    return;
62,320 ✔
189

190
  append([port, u] {
54 !
191
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
27 ✔
192
    if(ossia::value_port* dat = port->template target<ossia::value_port>())
27 !
193
    {
194
      // A unit the node declared is more precise than the widget's and wins; a
195
      // plain value type does not.
196
      if(!dat->type.target<ossia::unit_t>())
27 !
197
        dat->type = u;
1 ✔
198
    }
27 ✔
199
  });
27 ✔
200
}
62,347 ✔
201

202
// Without an explicit address, a scriptable port uses its published parameter
203
static State::AddressAccessor effectiveAddress(const Process::Port& port)
62,463 ✔
204
{
205
  if(port.address().isSet())
62,463 ✔
206
    return port.address();
1,453 ✔
207
  return State::AddressAccessor{LocalTree::scriptableAddress(port)};
61,010 ✔
208
}
62,463 ✔
209

210
template <typename Port_T, typename OssiaPort_T, typename Impl>
211
void SetupContext::bind_address(
62,347 ✔
212
    Port_T& proc_port, const OssiaPort_T& ossia_port,
213
    const std::shared_ptr<ossia::graph_node>& node, RegisteredPorts::connections& cons,
214
    Impl&& impl)
215
{
216
  for(auto& con : cons)
62,350 !
217
    QObject::disconnect(con);
3 ✔
218
  cons.clear();
62,347 ✔
219

220
  // The ossia port is looked up when this runs: a queued call can arrive after
221
  // a program change has replaced the one the port was bound with.
222
  auto rebind = [this, port = QPointer<Process::Port>{&proc_port}] {
62,414 ✔
223
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
67 ✔
224
    if(port)
67 !
225
      this->rebind(port.data());
66 ✔
226
  };
67 ✔
227
  cons.push_back(connect(&proc_port, &Process::Port::addressChanged, this, rebind));
62,347 !
228
  // Queued: the namespace updates the published address on these signals too
229
  cons.push_back(connect(
124,694 !
230
      &proc_port, &Process::Port::scriptableChanged, this, rebind, Qt::QueuedConnection));
62,347 ✔
231
  cons.push_back(connect(
124,694 !
232
      &proc_port, &Process::Port::exposedChanged, this, rebind, Qt::QueuedConnection));
62,347 ✔
233
  if(auto proc = Process::parentProcess(&proc_port))
62,347 !
234
    cons.push_back(connect(
113,758 !
235
        proc, &Process::ProcessModel::scriptableChanged, this, rebind,
56,879 ✔
236
        Qt::QueuedConnection));
237
  follow_published();
62,347 !
238
  set_declared_unit_impl(proc_port, ossia_port, impl);
62,347 !
239

240
  // Also registers the port with the execution state once the address resolves.
241
  set_destination_impl(context, effectiveAddress(proc_port), ossia_port, node, impl);
62,347 !
242
}
62,347 ✔
243

244
template <typename Impl>
245
void SetupContext::register_inlet_impl(
52,182 ✔
246
    Process::Inlet& proc_port, const ossia::inlet_ptr& ossia_port,
247
    const std::shared_ptr<ossia::graph_node>& node, Impl&& impl)
248
{
249
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
52,182 ✔
250
  SCORE_ASSERT(node);
52,182 !
251
  SCORE_ASSERT(ossia_port);
52,182 !
252

253
  bind_address(
52,182 ✔
254
      proc_port, ossia_port, node, runtime_connections[node].inlets[proc_port.id()], impl);
52,182 ✔
255

256
  inlets.insert({&proc_port, std::make_pair(node, ossia_port)});
52,182 !
257
}
52,182 ✔
258

259
template <typename Impl>
260
void SetupContext::register_node_impl(
12,691 ✔
261
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
262
    const std::shared_ptr<ossia::graph_node>& node, Impl&& exec)
263
{
264
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
12,691 ✔
265
  if(node)
12,691 !
266
  {
267
    std::weak_ptr<ossia::graph_interface> wg = context.execGraph;
12,691 ✔
268
    exec([wg, node = node]() mutable {
25,265 !
269
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
12,574 ✔
270
      if(auto g = wg.lock())
25,148 !
271
        g->add_node(std::move(node));
12,574 !
272
    });
12,574 ✔
273

274
    const std::size_t proc_n_inlets = proc_inlets.size();
12,691 ✔
275
    const std::size_t proc_n_outlets = proc_outlets.size();
12,691 ✔
276

277
    const std::size_t ossia_n_inlets = node->root_inputs().size();
12,691 ✔
278
    const std::size_t ossia_n_outlets = node->root_outputs().size();
12,691 ✔
279

280
    std::size_t n_inlets = std::min(proc_n_inlets, ossia_n_inlets);
12,691 ✔
281
    std::size_t n_outlets = std::min(proc_n_outlets, ossia_n_outlets);
12,691 ✔
282

283
    for(std::size_t i = 0; i < n_inlets; i++)
56,297 ✔
284
    {
285
      register_inlet_impl(*proc_inlets[i], node->root_inputs()[i], node, exec);
43,606 !
286
    }
43,606 ✔
287

288
    for(std::size_t i = 0; i < n_outlets; i++)
22,704 ✔
289
    {
290
      register_outlet_impl(*proc_outlets[i], node->root_outputs()[i], node, exec);
10,013 !
291
    }
10,013 ✔
292
  }
12,691 ✔
293
}
12,691 ✔
294

295
void SetupContext::register_node(
6,650 ✔
296
    const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node)
297
{
298
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
6,650 ✔
299
  register_node(proc.inlets(), proc.outlets(), node);
6,650 ✔
300
  proc_map[node.get()] = &proc;
6,650 ✔
301
}
6,650 ✔
302

303
void SetupContext::unregister_node(
6,655 ✔
304
    const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node)
305
{
306
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
6,655 ✔
307
  unregister_node(proc.inlets(), proc.outlets(), node);
6,655 ✔
308
  proc_map.erase(node.get());
6,655 ✔
309
}
6,655 ✔
310

311
void SetupContext::register_node(
×
312
    const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node,
313
    Transaction& vec)
314
{
315
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
316
  register_node(proc.inlets(), proc.outlets(), node, vec);
×
317
  proc_map[node.get()] = &proc;
×
318
}
×
319

320
void SetupContext::unregister_node(
×
321
    const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node,
322
    Transaction& vec)
323
{
324
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
325
  unregister_node(proc.inlets(), proc.outlets(), node, vec);
×
326
  proc_map.erase(node.get());
×
327
}
×
328

329
static bool hasPort(const ossia::graph_node& node, const ossia::inlet* port) noexcept
52,063 ✔
330
{
331
  return ossia::any_of_inlet(node, [port](const ossia::inlet& p) { return &p == port; });
626,558 ✔
332
}
333
static bool hasPort(const ossia::graph_node& node, const ossia::outlet* port) noexcept
13,987 ✔
334
{
335
  return ossia::any_of_outlet(node, [port](const ossia::outlet& p) { return &p == port; });
31,572 ✔
336
}
337

338
template <typename T, typename Impl>
339
void set_destination_impl(
62,463 ✔
340
    const Context& plug, const State::AddressAccessor& address, const T& port,
341
    const std::shared_ptr<ossia::graph_node>& owner, Impl&& enqueue)
342
{
343
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
62,463 ✔
344
  if(plug.retired)
62,463 !
345
    return;
×
346

347
  // The commands run later on the execution thread and only hold the raw
348
  // ossia port: by then an edit (undo/redo, a program change) may have
349
  // removed the node or the port. Skip them when the port's node is gone or no
350
  // longer has it. The port is captured once, here, and handed to the command:
351
  // the whole closure has to fit an ExecutionCommand.
352
  auto append = [&enqueue, &owner, port]<typename F>(F&& f) {
124,923 ✔
353
    if(!owner)
62,460 !
354
    {
355
      enqueue([f = std::forward<F>(f), port]() mutable { f(port); });
×
356
      return;
×
357
    }
358
    enqueue([f = std::forward<F>(f), wn = std::weak_ptr{owner}, port]() mutable {
124,626 !
359
      auto n = wn.lock();
62,166 ✔
360
      if(!n || !hasPort(*n, port))
62,166 !
361
        return;
×
362
      f(port);
62,166 !
363
    });
62,166 !
364
  };
62,460 ✔
365
  auto& s = plug.execState;
62,463 ✔
366
  auto& g = plug.execGraph;
62,463 ✔
367
  if(!g)
62,463 !
368
    return;
×
369

370
  if(address.address.device.isEmpty())
62,463 ✔
371
  {
372
    append([ws = std::weak_ptr{s}, wg = std::weak_ptr{g}](const T& port) {
118,792 !
373
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
59,254 ✔
374
      auto s = ws.lock();
59,254 ✔
375
      if(!s)
59,254 !
376
        return;
×
377
      auto g = wg.lock();
59,254 ✔
378
      if(!g)
59,254 !
379
        return;
×
380
      if(port->address)
59,254 !
381
      {
382
        s->unregister_port(*port);
7 !
383
        port->address = {};
7 ✔
384
        if(ossia::value_port* dat = port->template target<ossia::value_port>())
7 !
385
        {
386
          dat->address_unit = {};
7 ✔
387
          dat->index = {};
7 ✔
388
        }
7 ✔
389
        g->mark_dirty();
7 !
390
      }
7 ✔
391
    });
59,254 !
392
    return;
59,538 ✔
393
  }
394

395
  auto& qual = address.qualifiers.get();
2,925 ✔
396
  if(auto n = findNode(*plug.execState, address.address))
2,925 !
397
  {
398
    auto p = n->get_parameter();
2,922 ✔
399
    if(p)
2,922 !
400
    {
401
      append([ws = std::weak_ptr{s}, p, qual = qual, wg = std::weak_ptr{g}](const T& port) {
5,830 !
402
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
2,910 ✔
403
        auto s = ws.lock();
2,910 ✔
404
        if(!s)
2,910 !
405
          return;
×
406
        auto g = wg.lock();
2,910 ✔
407
        if(!g)
2,910 !
408
          return;
×
409
        s->unregister_port(*port);
2,910 !
410
        port->address = p;
2,910 ✔
411
        if(ossia::value_port* dat = port->template target<ossia::value_port>())
2,910 !
412
        {
413
          // Unconditionally, like the index: dropping the qualifier has to give
414
          // the process's declaration back.
415
          dat->address_unit = qual.unit;
1,470 ✔
416
          dat->index = qual.accessors;
1,470 !
417
        }
1,470 ✔
418
        s->register_port(*port);
2,910 !
419
        g->mark_dirty();
2,910 !
420
      });
2,910 !
421
    }
2,920 ✔
422
    else
423
    {
424
      append([ws = std::weak_ptr{s}, n, wg = std::weak_ptr{g}](const T& port) {
4 !
425
        auto s = ws.lock();
2 ✔
426
        if(!s)
2 !
427
          return;
×
428
        auto g = wg.lock();
2 ✔
429
        if(!g)
2 !
430
          return;
×
431
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
2 !
432
        s->unregister_port(*port);
2 !
433
        port->address = n;
2 ✔
434
        s->register_port(*port);
2 !
435
        g->mark_dirty();
2 !
436
      });
2 !
437
    }
438
  }
2,922 ✔
439
  else if(auto ad = address.address.toString_unsafe().toStdString();
3 !
440
          ossia::traversal::is_pattern(ad))
6 !
441
  {
442
    // OPTIMIZEME
443
    auto path = ossia::traversal::make_path(ad);
×
444
    if(path)
×
445
    {
446
      append([ws = std::weak_ptr{s}, p = *path, wg = std::weak_ptr{g}](const T& port) mutable {
×
447
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
448
        auto s = ws.lock();
×
449
        if(!s)
×
450
          return;
×
451
        auto g = wg.lock();
×
452
        if(!g)
×
453
          return;
×
454
        s->unregister_port(*port);
×
455
        port->address = std::move(p);
×
456
        if(ossia::value_port* dat = port->template target<ossia::value_port>())
×
457
        {
458
          dat->address_unit = {};
×
459
          dat->index.clear();
×
460
        }
×
461
        s->register_port(*port);
×
462
        g->mark_dirty();
×
463
      });
×
464
    }
×
465
    else
466
    {
467
      append([ws = std::weak_ptr{s}, n, wg = std::weak_ptr{g}](const T& port) {
×
468
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
469
        auto s = ws.lock();
×
470
        if(!s)
×
471
          return;
×
472
        auto g = wg.lock();
×
473
        if(!g)
×
474
          return;
×
475
        s->unregister_port(*port);
×
476
        port->address = {};
×
477
        if(ossia::value_port* dat = port->template target<ossia::value_port>())
×
478
        {
479
          dat->address_unit = {};
×
480
          dat->index.clear();
×
481
        }
×
482
        s->register_port(*port);
×
483
        g->mark_dirty();
×
484
      });
×
485
    }
486
  }
×
487
}
62,463 ✔
488

489
void SetupContext::set_destination(
×
490
    const State::AddressAccessor& address, const ossia::inlet_ptr& port)
491
{
492
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
493
  set_destination_impl(context, address, port, {}, enqueue_in_context(*this));
×
494
}
×
495

496
void SetupContext::set_destination(
×
497
    const State::AddressAccessor& address, const ossia::outlet_ptr& port)
498
{
499
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
500
  set_destination_impl(context, address, port, {}, enqueue_in_context(*this));
×
501
}
×
502

503
void SetupContext::register_inlet(
×
504
    Process::Inlet& inlet, const ossia::inlet_ptr& exec,
505
    const std::shared_ptr<ossia::graph_node>& node)
506
{
507
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
508
  register_inlet_impl(inlet, exec, node, enqueue_in_context(*this));
×
509
}
×
510
void SetupContext::register_outlet(
×
511
    Process::Outlet& outlet, const ossia::outlet_ptr& exec,
512
    const std::shared_ptr<ossia::graph_node>& node)
513
{
514
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
515
  register_outlet_impl(outlet, exec, node, enqueue_in_context(*this));
×
516
}
×
517

518
void SetupContext::register_node(
11,089 ✔
519
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
520
    const std::shared_ptr<ossia::graph_node>& node)
521
{
522
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
11,089 ✔
523
  register_node_impl(proc_inlets, proc_outlets, node, enqueue_in_context(*this));
11,089 ✔
524
}
11,089 ✔
525

526
void SetupContext::register_node(
1,602 ✔
527
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
528
    const std::shared_ptr<ossia::graph_node>& node, Transaction& vec)
529
{
530
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
1,602 ✔
531
  register_node_impl(proc_inlets, proc_outlets, node, enqueue_in_vector(vec));
1,602 ✔
532
}
1,602 ✔
533

534
void SetupContext::register_inlet(
738 ✔
535
    Process::Inlet& inlet, const ossia::inlet_ptr& exec,
536
    const std::shared_ptr<ossia::graph_node>& node, Transaction& vec)
537
{
538
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
738 ✔
539
  register_inlet_impl(inlet, exec, node, enqueue_in_vector(vec));
738 ✔
540
}
738 ✔
541
void SetupContext::register_outlet(
152 ✔
542
    Process::Outlet& outlet, const ossia::outlet_ptr& exec,
543
    const std::shared_ptr<ossia::graph_node>& node, Transaction& vec)
544
{
545
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
152 ✔
546
  register_outlet_impl(outlet, exec, node, enqueue_in_vector(vec));
152 ✔
547
}
152 ✔
548

549
void SetupContext::on_cableCreated(Process::Cable& c)
1,412 ✔
550
{
551
  if(context.retired)
1,412 !
552
    return;
×
553
  connectCable(c);
1,412 ✔
554
}
1,412 ✔
555

556
void SetupContext::on_cableRemoved(const Process::Cable& c)
1,454 ✔
557
{
558
  if(context.retired)
1,454 !
559
    return;
×
560
  removeCable(c);
1,454 ✔
561
}
1,454 ✔
562

563
void SetupContext::connectCable(Process::Cable& c)
1,412 ✔
564
{
565
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
1,412 ✔
566
  connect_cable_impl(c, enqueue_in_context(*this));
1,412 ✔
567
}
1,412 ✔
568

569
void SetupContext::connectCable(Process::Cable& c, Transaction& vec)
1,404 ✔
570
{
571
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
1,404 ✔
572
  connect_cable_impl(c, enqueue_in_vector(vec));
1,404 ✔
573
}
1,404 ✔
574

575
void SetupContext::removeCable(const Process::Cable& c)
1,454 ✔
576
{
577
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
1,454 ✔
578
  disconnect_cable_impl(c, enqueue_in_context(*this));
1,454 ✔
579
}
1,454 ✔
580

581
void SetupContext::removeCable(const Process::Cable& c, Transaction& vec)
16 ✔
582
{
583
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
16 ✔
584
  disconnect_cable_impl(c, enqueue_in_vector(vec));
16 ✔
585
}
16 ✔
586

587
// What a process sends goes through its outlet's pan and upmix, which follow
588
// the model. Its gain is registered with the outlet, below.
589
template <typename Impl>
590
void SetupContext::register_mixing_impl(
3,919 ✔
591
    Process::AudioOutlet& proc_port, ossia::audio_outlet& out,
592
    const std::shared_ptr<ossia::graph_node>& node, Impl&& impl)
593
{
594
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
3,919 ✔
595
  auto* o = &out;
3,919 ✔
596
  const auto weights = proc_port.pan();
3,919 ✔
597
  impl([node, o, pan = ossia::pan_weight(weights.begin(), weights.end()),
7,797 !
598
        mode = proc_port.upmixMode(), chans = proc_port.upmixChannels()]() mutable {
7,838 ✔
599
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
3,878 ✔
600
    // A swap: the previous weights are freed with this closure, off the audio
601
    // thread.
602
    std::swap(o->pan, pan);
3,878 ✔
603
    o->upmix = ossia::audio_outlet::upmix_mode(mode);
3,878 ✔
604
    o->upmix_channels = chans;
3,878 ✔
605
  });
3,878 ✔
606

607
  auto& ports = runtime_connections[node];
3,919 !
608
  ports.disconnectMixing(proc_port.id());
3,919 !
609
  auto& cons = ports.mixing[proc_port.id()];
3,919 !
610
  auto& q = context.executionQueue;
3,919 ✔
611
  cons[0] = connect(
3,919 !
612
      &proc_port, &Process::AudioOutlet::panChanged, this,
3,919 ✔
613
      [&q, node, o](const auto& w) {
3,920 ✔
614
    q.enqueue([node, o, pan = ossia::pan_weight(w.begin(), w.end())]() mutable {
2 !
615
      std::swap(o->pan, pan);
1 ✔
616
    });
1 ✔
617
  });
1 ✔
618
  auto upmix = [&q, node, o, port = &proc_port] {
3,921 ✔
619
    q.enqueue([node, o, mode = port->upmixMode(), chans = port->upmixChannels()] {
4 !
620
      o->upmix = ossia::audio_outlet::upmix_mode(mode);
2 ✔
621
      o->upmix_channels = chans;
2 ✔
622
    });
2 ✔
623
  };
2 ✔
624
  cons[1] = connect(&proc_port, &Process::AudioOutlet::upmixModeChanged, this, upmix);
3,919 !
625
  cons[2] = connect(&proc_port, &Process::AudioOutlet::upmixChannelsChanged, this, upmix);
3,919 !
626
}
3,919 ✔
627

628
template <typename Impl>
629
void SetupContext::register_outlet_impl(
10,165 ✔
630
    Process::Outlet& proc_port, const ossia::outlet_ptr& ossia_port,
631
    const std::shared_ptr<ossia::graph_node>& node, Impl&& impl)
632
{
633
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
10,165 ✔
634
  SCORE_ASSERT(node);
10,165 !
635
  SCORE_ASSERT(ossia_port);
10,165 !
636
  auto& cons = runtime_connections[node].outlets[proc_port.id()];
10,165 ✔
637
  bind_address(proc_port, ossia_port, node, cons, impl);
10,165 ✔
638

639
  if(auto audio = qobject_cast<Process::AudioOutlet*>(&proc_port);
10,165 !
640
     audio && ossia_port->which() == ossia::audio_port::which)
10,165 !
641
    register_mixing_impl(
3,919 ✔
642
        *audio, *static_cast<ossia::audio_outlet*>(ossia_port), node, impl);
3,919 ✔
643

644
  outlets.insert({&proc_port, std::make_pair(node, ossia_port)});
10,165 !
645

646
  // The gain trim of every audio output, process or interval, scales what it
647
  // sends. The commands hold the node weakly and check that it still owns the
648
  // port when they run, as in set_destination_impl.
649
  if(auto audio = qobject_cast<Process::AudioOutlet*>(&proc_port);
10,165 !
650
     audio && ossia_port->which() == ossia::audio_port::which)
10,165 !
651
  {
652
    auto exec = static_cast<ossia::audio_outlet*>(ossia_port);
3,919 ✔
653
    impl([exec, wn = std::weak_ptr{node}, g = audio->gain()]() noexcept {
7,797 !
654
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
3,878 !
655
      if(auto n = wn.lock(); n && hasPort(*n, exec))
7,756 !
656
        exec->gain = g;
3,878 ✔
657
    });
3,878 ✔
658
    cons.push_back(connect(
7,838 !
659
        audio, &Process::AudioOutlet::gainChanged, this, [this, audio](double g) {
3,925 ✔
660
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
6 ✔
661
      if(context.retired)
6 !
662
        return;
×
663
      // The ossia port is looked up when this runs, as in rebind()
664
      auto it = outlets.find(audio);
6 ✔
665
      if(it == outlets.end() || !it->second.second
12 !
666
         || it->second.second->which() != ossia::audio_port::which)
6 !
667
        return;
×
668
      auto exec = static_cast<ossia::audio_outlet*>(it->second.second);
6 ✔
669
      context.executionQueue.enqueue(
12 !
670
          [exec, wn = std::weak_ptr{it->second.first}, g]() noexcept {
12 ✔
671
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
6 !
672
        if(auto n = wn.lock(); n && hasPort(*n, exec))
12 !
673
          exec->gain = g;
6 ✔
674
      });
6 ✔
675
    }));
6 ✔
676
  }
3,919 ✔
677

678
  proc_port.mapExecution(
20,330 ✔
679
      *ossia_port, [&](Process::Inlet& model_inl, ossia::inlet& ossia_inl) {
18,003 ✔
680
        register_inlet_impl(model_inl, &ossia_inl, node, impl);
7,838 ✔
681
      });
7,838 ✔
682

683
  // Unneeded : the execution_state only needs inlets to be registered,
684
  // in order to set up data value queues from the network thread
685

686
  // std::weak_ptr<ossia::execution_state> ws = context.execState;
687
  // impl([ws, ossia_port] {
688
  //   if (auto state = ws.lock())
689
  //     state->register_outlet(*ossia_port);
690
  // });
691
}
10,165 ✔
692

693
void SetupContext::unregister_inlet(
×
694
    const Process::Inlet& proc_port, const std::shared_ptr<ossia::graph_node>& node)
695
{
696
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
697
  if(node)
×
698
  {
699
    auto& runtime_connection = runtime_connections[node].inlets;
×
700
    auto it = runtime_connection.find(proc_port.id());
×
701
    if(it != runtime_connection.end())
×
702
    {
703
      for(auto& con : it->second)
×
704
        QObject::disconnect(con);
×
705
      runtime_connection.erase(it);
×
706
    }
×
707

708
    auto ossia_port_it = inlets.find(const_cast<Process::Inlet*>(&proc_port));
×
709
    if(ossia_port_it != inlets.end())
×
710
    {
711
      std::weak_ptr<ossia::execution_state> ws = context.execState;
×
712
      context.executionQueue.enqueue([ws, ossia_port = ossia_port_it->second.second] {
×
713
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
714
        if(auto state = ws.lock())
×
715
          state->unregister_port(*ossia_port);
×
716
      });
×
717

718
      inlets.erase(ossia_port_it);
×
719
    }
×
720
  }
×
721
  else
722
  {
723
    inlets.erase(const_cast<Process::Inlet*>(&proc_port));
×
724
  }
725
}
×
726

727
void SetupContext::unregister_outlet(
×
728
    const Process::Outlet& proc_port, const std::shared_ptr<ossia::graph_node>& node)
729
{
730
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
731
  if(node)
×
732
  {
733
    auto& runtime_connection = runtime_connections[node].outlets;
×
734
    auto it = runtime_connection.find(proc_port.id());
×
735
    if(it != runtime_connection.end())
×
736
    {
737
      for(auto& con : it->second)
×
738
        QObject::disconnect(con);
×
739
      runtime_connection.erase(it);
×
740
    }
×
NEW
741
    runtime_connections[node].disconnectMixing(proc_port.id());
×
742

743
    proc_port.forChildInlets([&](Process::Inlet& model_inl) {
×
744
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
745
      unregister_inlet(model_inl, node);
×
746
    });
×
747
  }
×
748

749
  outlets.erase(const_cast<Process::Outlet*>(&proc_port));
×
750
}
×
751

752
void SetupContext::unregister_inlet(
×
753
    const Process::Inlet& proc_port, const std::shared_ptr<ossia::graph_node>& node,
754
    Transaction& commands)
755
{
756
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
757
  if(node)
×
758
  {
759
    auto& runtime_connection = runtime_connections[node].inlets;
×
760
    auto it = runtime_connection.find(proc_port.id());
×
761
    if(it != runtime_connection.end())
×
762
    {
763
      for(auto& con : it->second)
×
764
        QObject::disconnect(con);
×
765
      runtime_connection.erase(it);
×
766
    }
×
767

768
    auto ossia_port_it = inlets.find(const_cast<Process::Inlet*>(&proc_port));
×
769
    if(ossia_port_it != inlets.end())
×
770
    {
771
      std::weak_ptr<ossia::execution_state> ws = context.execState;
×
772
      commands.push_back([ws, ossia_port = ossia_port_it->second.second] {
×
773
        OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
774
        if(auto state = ws.lock())
×
775
          state->unregister_port(*ossia_port);
×
776
      });
×
777

778
      inlets.erase(ossia_port_it);
×
779
    }
×
780
  }
×
781
  else
782
  {
783
    inlets.erase(const_cast<Process::Inlet*>(&proc_port));
×
784
  }
785
}
×
786

787
void SetupContext::unregister_outlet(
×
788
    const Process::Outlet& proc_port, const std::shared_ptr<ossia::graph_node>& node,
789
    Transaction& commands)
790
{
791
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
792
  if(node)
×
793
  {
794
    auto& runtime_connection = runtime_connections[node].outlets;
×
795
    auto it = runtime_connection.find(proc_port.id());
×
796
    if(it != runtime_connection.end())
×
797
    {
798
      for(auto& con : it->second)
×
799
        QObject::disconnect(con);
×
800
      runtime_connection.erase(it);
×
801
    }
×
NEW
802
    runtime_connections[node].disconnectMixing(proc_port.id());
×
803

804
    proc_port.forChildInlets([&](Process::Inlet& model_inl) {
×
805
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
806
      unregister_inlet(model_inl, node);
×
807
    });
×
808
  }
×
809

810
  outlets.erase(const_cast<Process::Outlet*>(&proc_port));
×
811
}
×
812

813
void SetupContext::replace_node(
×
814
    const std::shared_ptr<ossia::time_process>& process,
815
    const std::shared_ptr<ossia::graph_node>& node, Transaction& commands)
816
{
817
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
818
  commands.push_back([p = process, n = node]() mutable {
×
819
    OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
820
    using namespace std;
821
    swap(p->node, n);
×
822
  });
×
823
}
×
824

825
void SetupContext::unregister_node(
11,660 ✔
826
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
827
    const std::shared_ptr<ossia::graph_node>& node)
828
{
829
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
11,660 ✔
830
  if(node)
11,660 !
831
  {
832
    std::weak_ptr<ossia::graph_interface> wg = context.execGraph;
11,660 ✔
833
    std::weak_ptr<ossia::execution_state> ws = context.execState;
11,660 ✔
834
    context.executionQueue.enqueue([wg, ws, node = node] mutable {
15,681 !
835
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
4,021 ✔
836
      if(auto s = ws.lock())
8,042 !
837
      {
838
        ossia::for_each_inlet(*node, [&](auto& p) { s->unregister_port(p); });
20,304 ✔
839
        ossia::for_each_outlet(*node, [&](auto& p) { s->unregister_port(p); });
7,468 ✔
840
      }
4,021 ✔
841

842
      if(auto g = wg.lock())
8,042 !
843
        g->remove_node(node);
4,021 !
844

845
      node->clear();
4,021 ✔
846
    });
4,021 ✔
847

848
    runtime_connections[node].clear();
11,660 !
849
    runtime_connections.erase(node);
11,660 !
850

851
    proc_map.erase(node.get());
11,660 !
852
  }
11,660 ✔
853

854
  for(auto ptr : proc_inlets)
54,951 ✔
855
    inlets.erase(ptr);
43,291 ✔
856
  for(auto ptr : proc_outlets)
21,360 ✔
857
    outlets.erase(ptr);
9,700 ✔
858
}
11,660 ✔
859

860
void SetupContext::unregister_node(
×
861
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
862
    const std::shared_ptr<ossia::graph_node>& node, Transaction& vec)
863
{
864
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
×
865
  if(node)
×
866
  {
867
    std::weak_ptr<ossia::graph_interface> wg = context.execGraph;
×
868
    std::weak_ptr<ossia::execution_state> ws = context.execState;
×
869
    vec.push_back([wg, ws, node] {
×
870
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
×
871
      if(auto s = ws.lock())
×
872
      {
873
        ossia::for_each_inlet(*node, [&](auto& p) { s->unregister_port(p); });
×
874
        ossia::for_each_outlet(*node, [&](auto& p) { s->unregister_port(p); });
×
875
      }
×
876

877
      if(auto g = wg.lock())
×
878
        g->remove_node(node);
×
879
      node->clear();
×
880
    });
×
881

882
    runtime_connections[node].clear();
×
883
    runtime_connections.erase(node);
×
884

885
    proc_map.erase(node.get());
×
886
  }
×
887

888
  for(auto ptr : proc_inlets)
×
889
    inlets.erase(ptr);
×
890
  for(auto ptr : proc_outlets)
×
891
    outlets.erase(ptr);
×
892
}
×
893

894
void SetupContext::unregister_node_soft(
108 ✔
895
    const Process::Inlets& proc_inlets, const Process::Outlets& proc_outlets,
896
    const std::shared_ptr<ossia::graph_node>& node, Transaction& vec)
897
{
898
  OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Ui);
108 ✔
899
  if(node)
108 !
900
  {
901
    std::weak_ptr<ossia::execution_state> ws = context.execState;
108 ✔
902
    vec.push_back([ws, node] {
215 ✔
903
      OSSIA_ENSURE_CURRENT_THREAD_KIND(ossia::thread_type::Audio);
107 ✔
904
      if(auto s = ws.lock())
214 !
905
      {
906
        ossia::for_each_inlet(*node, [&](auto& p) { s->unregister_port(p); });
850 ✔
907
        ossia::for_each_outlet(*node, [&](auto& p) { s->unregister_port(p); });
226 ✔
908
      }
107 ✔
909
    });
107 ✔
910
    runtime_connections[node].clear();
108 !
911
    runtime_connections.erase(node);
108 !
912

913
    proc_map.erase(node.get());
108 !
914
  }
108 ✔
915

916
  for(auto ptr : proc_inlets)
824 ✔
917
    inlets.erase(ptr);
716 ✔
918
  for(auto ptr : proc_outlets)
254 ✔
919
    outlets.erase(ptr);
146 ✔
920
}
108 ✔
921

922
SetupContext::SetupContext(Context& other) noexcept
10,374 !
923
    : context{other}
10,374 ✔
924
{
20,748 ✔
925
}
10,374 ✔
926

927
void SetupContext::follow_published()
62,347 ✔
928
{
929
  if(m_followsPublished)
62,347 ✔
930
    return;
60,975 ✔
931
  m_followsPublished = true;
1,372 ✔
932
  // Rebinds ports published after setup, e.g. restored by undo during playback
933
  if(auto tree = context.doc.findPlugin<LocalTree::ScriptableTreeBase>())
1,372 !
934
    connect(tree, &LocalTree::ScriptableTreeBase::published, this, [this](QObject* object) {
1,444 ✔
935
      QTimer::singleShot(0, this, [this, object = QPointer<QObject>{object}] {
144 !
936
        if(object)
72 !
937
          rebind(object.data());
72 ✔
938
      });
72 ✔
939
    });
72 ✔
940
}
62,347 ✔
941

942
void SetupContext::rebind(QObject* port)
138 ✔
943
{
944
  if(context.retired)
138 !
945
    return;
×
946
  if(auto in = qobject_cast<Process::Inlet*>(port))
138 ✔
947
  {
948
    if(auto it = inlets.find(in); it != inlets.end())
87 !
949
      set_destination_impl(
87 !
950
          context, effectiveAddress(*in), it->second.second, it->second.first,
87 ✔
951
          enqueue_in_context(*this));
87 ✔
952
  }
87 ✔
953
  else if(auto out = qobject_cast<Process::Outlet*>(port))
51 ✔
954
  {
955
    if(auto it = outlets.find(out); it != outlets.end())
29 !
956
      set_destination_impl(
29 !
957
          context, effectiveAddress(*out), it->second.second, it->second.first,
29 ✔
958
          enqueue_in_context(*this));
29 ✔
959
  }
29 ✔
960
}
138 ✔
961

962
SetupContext::~SetupContext() { }
10,372 ✔
963

964
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc