• 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

74.28
/src/plugins/score-plugin-engine/Execution/Telemetry.cpp
1
#include "Telemetry.hpp"
2

3
#include <Process/Dataflow/Port.hpp>
4
#include <Process/Process.hpp>
5

6
#include <Scenario/Settings/ScenarioSettingsModel.hpp>
7

8
#include <Audio/Settings/Model.hpp>
9
#include <Execution/DocumentPlugin.hpp>
10
#include <Execution/Settings/ExecutorModel.hpp>
11

12
#include <score/application/GUIApplicationContext.hpp>
13
#include <score/document/DocumentContext.hpp>
14
#include <score/tools/Bind.hpp>
15

16
#include <ossia/audio/audio_parameter.hpp>
17
#include <ossia/dataflow/graph_node.hpp>
18
#include <ossia/dataflow/port.hpp>
19

20
#include <QTimer>
21

22
#include <algorithm>
23

24
#include <wobjectimpl.h>
25

26
W_OBJECT_IMPL(Execution::Telemetry)
3,023 !
27

28
namespace Execution
29
{
30
using ossia::telemetry::tap_kind;
31

32
Telemetry::Telemetry(const score::DocumentContext& ctx, DocumentPlugin& plug)
4,388 !
33
    : m_context{ctx}
2,194 ✔
34
    , m_plugin{plug}
2,194 ✔
35
{
2,194 ✔
36
  auto& scenar = ctx.app.settings<Scenario::Settings::Model>();
2,194 !
37
  con(scenar, &Scenario::Settings::Model::ExecutionUpdateChanged, this, [this](bool) {
2,196 !
38
    if(!m_running)
2 !
NEW
39
      return;
×
40
    if(enabled())
2 ✔
41
      rebuild();
1 ✔
42
    else
43
      teardown();
1 ✔
44
  });
2 ✔
45
  con(ctx.coarseUpdateTimer, &QTimer::timeout, this, &Telemetry::read);
2,194 !
46
}
2,194 ✔
47

48
Telemetry::~Telemetry()
2,194 ✔
NEW
49
{
×
50
  for(auto& s : m_subs)
4,367 ✔
51
    if(s.param)
2,173 !
NEW
52
      s.param->meter.store(nullptr, std::memory_order_release);
×
53
}
2,194 ✔
54

55
bool Telemetry::enabled() const noexcept
1,371 ✔
56
{
57
  return m_context.app.settings<Scenario::Settings::Model>().getExecutionUpdate();
1,371 !
58
}
59

60
uint64_t Telemetry::publishInterval() const noexcept
1,370 ✔
61
{
62
  const auto rate = m_context.app.settings<Audio::Settings::Model>().getRate();
1,370 !
63
  const auto ms = std::max(1, m_context.coarseUpdateTimer.interval());
1,370 !
64
  return std::max<uint64_t>(1, uint64_t(rate) * ms / 1000);
1,370 !
65
}
66

67
Telemetry::Meter Telemetry::subscribe(
6,624 ✔
68
    tap_kind kind, const Process::Port* port, bool inlet,
69
    ossia::virtual_audio_parameter* param)
70
{
71
  for(std::size_t i = 0; i < m_subs.size(); i++)
10,148 ✔
72
  {
73
    auto& s = m_subs[i];
7,904 ✔
74
    if(s.users > 0 && s.kind == kind && s.port == port && s.inlet == inlet
7,904 ✔
75
       && s.param == param)
4,380 !
76
    {
77
      s.users++;
4,380 ✔
78
      return {int(i), s.generation};
4,380 ✔
79
    }
80
  }
3,524 ✔
81

82
  int index{};
2,244 ✔
83
  if(!m_free.empty())
2,244 ✔
84
  {
85
    index = m_free.back();
71 ✔
86
    m_free.pop_back();
71 ✔
87
  }
71 ✔
88
  else
89
  {
90
    index = int(m_subs.size());
2,173 ✔
91
    m_subs.emplace_back();
2,173 ✔
92
  }
93

94
  static uint32_t generations = 0;
95
  auto& s = m_subs[index];
2,244 ✔
96
  s = Subscription{};
2,244 ✔
97
  s.kind = kind;
2,244 ✔
98
  s.port = port;
2,244 ✔
99
  s.inlet = inlet;
2,244 ✔
100
  s.generation = ++generations;
2,244 ✔
101
  s.users = 1;
2,244 ✔
102
  s.param = param;
2,244 ✔
103

104
  if(m_arena)
2,244 ✔
105
  {
106
    if(std::size_t(index) < m_arena->meter_capacity())
2 !
107
      attach(index);
2 ✔
108
    else
NEW
109
      rebuild();
×
110
  }
2 ✔
111
  return {index, s.generation};
2,244 ✔
112
}
6,624 ✔
113

114
Telemetry::Meter Telemetry::meterOutlet(const Process::AudioOutlet& outlet)
48 ✔
115
{
116
  return subscribe(tap_kind::node, &outlet, false);
48 ✔
117
}
118

NEW
119
Telemetry::Meter Telemetry::meterInlet(const Process::AudioInlet& inlet)
×
120
{
NEW
121
  return subscribe(tap_kind::node, &inlet, true);
×
122
}
123

124
Telemetry::Meter Telemetry::meterHardwareInputs()
3,285 ✔
125
{
126
  return subscribe(tap_kind::hardware_inputs, nullptr, false);
3,285 ✔
127
}
128

129
Telemetry::Meter Telemetry::meterHardwareOutputs()
3,288 ✔
130
{
131
  return subscribe(tap_kind::hardware_outputs, nullptr, false);
3,288 ✔
132
}
133

134
Telemetry::Meter Telemetry::meterVirtualPort(ossia::virtual_audio_parameter& port)
3 ✔
135
{
136
  return subscribe(tap_kind::node, nullptr, false, &port);
3 ✔
137
}
138

139
void Telemetry::forgetUnder(const ossia::net::node_base& root)
5,048 ✔
140
{
141
  // Called while the nodes and their parameters still exist.
142
  for(std::size_t i = 0; i < m_subs.size(); i++)
7,417 ✔
143
  {
144
    auto& s = m_subs[i];
2,369 ✔
145
    if(!s.param)
2,369 ✔
146
      continue;
2,366 ✔
147
    for(auto n = &s.param->get_node(); n; n = n->get_parent())
5 !
148
    {
149
      if(n == &root)
5 ✔
150
      {
151
        detach(int(i));
3 ✔
152
        s.param = nullptr;
3 ✔
153
        break;
3 ✔
154
      }
155
    }
2 ✔
156
  }
3 ✔
157
}
5,048 ✔
158

159
void Telemetry::release(Meter m)
6,607 ✔
160
{
161
  if(!m || std::size_t(m.index) >= m_subs.size())
6,607 !
NEW
162
    return;
×
163
  auto& s = m_subs[m.index];
6,607 ✔
164
  if(s.generation != m.generation || s.users == 0)
6,607 !
NEW
165
    return;
×
166
  if(--s.users > 0)
6,607 ✔
167
    return;
4,372 ✔
168

169
  detach(m.index);
2,235 ✔
170
  s = Subscription{};
2,235 ✔
171
  m_free.push_back(m.index);
2,235 ✔
172
}
6,607 ✔
173

174
const ossia::telemetry::meter_levels* Telemetry::levels(Meter m) const noexcept
44,179 ✔
175
{
176
  if(!m_arena || !m || std::size_t(m.index) >= m_subs.size())
44,179 !
177
    return nullptr;
26,507 ✔
178
  const auto& sub = m_subs[m.index];
17,672 ✔
179
  if(sub.users == 0 || sub.generation != m.generation)
17,672 !
180
    return nullptr;
1 ✔
181
  const auto& meters = m_arena->latest().meters;
17,671 ✔
182
  if(std::size_t(m.index) >= meters.size())
17,671 !
NEW
183
    return nullptr;
×
184
  const auto& slot = meters[m.index];
17,671 ✔
185
  if(slot.generation != m.generation || slot.levels.ticks == 0)
17,671 !
186
    return nullptr;
3 ✔
187
  return &slot.levels;
17,668 ✔
188
}
44,179 ✔
189

190
int Telemetry::sampleRate() const noexcept
3 ✔
191
{
192
  return m_arena ? m_arena->latest().sample_rate : 0;
3 !
193
}
194

195
Telemetry::Playhead
196
Telemetry::registerPlayhead(std::shared_ptr<ossia::telemetry::playhead_tap> tap)
1,600 ✔
197
{
198
  int index{};
1,600 ✔
199
  if(!m_freePlayheads.empty())
1,600 ✔
200
  {
201
    index = m_freePlayheads.back();
743 ✔
202
    m_freePlayheads.pop_back();
743 ✔
203
  }
743 ✔
204
  else
205
  {
206
    index = int(m_playheads.size());
857 ✔
207
    m_playheads.emplace_back();
857 ✔
208
  }
209

210
  static uint32_t generations = 0;
211
  auto& p = m_playheads[index];
1,600 ✔
212
  p = PlayheadSub{std::move(tap), ++generations, false};
1,600 ✔
213

214
  if(m_arena)
1,600 ✔
215
  {
216
    if(std::size_t(index) < m_arena->playhead_capacity())
76 !
217
      attachPlayhead(index);
76 ✔
218
    else
NEW
219
      rebuild();
×
220
  }
76 ✔
221
  return {index, p.generation};
1,600 ✔
222
}
223

224
void Telemetry::attachPlayhead(int index)
1,602 ✔
225
{
226
  auto& ctx = m_plugin.contextData();
1,602 ✔
227
  auto& p = m_playheads[index];
1,602 ✔
228
  if(!ctx || !m_arena || p.attached || !p.tap)
1,602 !
NEW
229
    return;
×
230
  ctx->m_execQueue.enqueue(
3,204 !
231
      [arena = m_arena, index, gen = p.generation, tap = p.tap]() mutable {
3,181 ✔
232
    arena->attach_playhead(index, gen, tap);
1,579 ✔
233
  });
1,579 ✔
234
  p.attached = true;
1,602 ✔
235
}
1,602 ✔
236

237
void Telemetry::release(Playhead h)
2,851 ✔
238
{
239
  if(!h || std::size_t(h.index) >= m_playheads.size())
2,851 !
240
    return;
1,251 ✔
241
  auto& p = m_playheads[h.index];
1,600 ✔
242
  if(p.generation != h.generation || !p.tap)
1,600 !
NEW
243
    return;
×
244

245
  auto& ctx = m_plugin.contextData();
1,600 ✔
246
  if(ctx && m_arena && p.attached)
1,600 !
247
  {
248
    ctx->m_execQueue.enqueue(
954 !
249
        [arena = m_arena, index = h.index,
478 ✔
250
         tap = std::shared_ptr<ossia::telemetry::playhead_tap>{}]() mutable {
477 ✔
251
      arena->attach_playhead(index, 0, tap);
1 ✔
252
    });
1 ✔
253
  }
477 ✔
254
  p = PlayheadSub{};
1,600 ✔
255
  m_freePlayheads.push_back(h.index);
1,600 ✔
256
}
2,851 ✔
257

258
const ossia::telemetry::playhead_slot* Telemetry::playhead(Playhead h) const noexcept
11,604 ✔
259
{
260
  if(!m_arena || !h || std::size_t(h.index) >= m_playheads.size())
11,604 !
261
    return nullptr;
1,596 ✔
262
  if(m_playheads[h.index].generation != h.generation)
10,008 !
NEW
263
    return nullptr;
×
264
  const auto& slots = m_arena->latest().playheads;
10,008 ✔
265
  if(std::size_t(h.index) >= slots.size() || slots[h.index].generation != h.generation)
10,008 !
266
    return nullptr;
12 ✔
267
  return &slots[h.index];
9,996 ✔
268
}
11,604 ✔
269

NEW
270
double Telemetry::cpuLoad(const Process::ProcessModel& proc) const noexcept
×
271
{
NEW
272
  if(!m_arena)
×
NEW
273
    return -1.;
×
NEW
274
  auto it = m_benchOfProcess.find(&proc);
×
NEW
275
  if(it == m_benchOfProcess.end())
×
NEW
276
    return -1.;
×
NEW
277
  const auto& f = m_arena->latest();
×
NEW
278
  const auto i = std::size_t(it->second);
×
NEW
279
  if(i >= f.benches.size() || f.benches[i].generation != m_benches[i].generation)
×
NEW
280
    return -1.;
×
NEW
281
  return f.load(f.benches[i]);
×
NEW
282
}
×
283

284
bool Telemetry::benchEnabled() const noexcept
12,862 ✔
285
{
286
  auto& ctx = m_plugin.contextData();
12,862 ✔
287
  return ctx && ctx->bench && m_plugin.settings.getBench();
12,862 !
288
}
289

290
bool Telemetry::syncBenches()
11,492 ✔
291
{
292
  auto& ctx = m_plugin.contextData();
11,492 ✔
293
  if(!m_arena || !benchEnabled())
11,492 !
294
    return true;
11,492 ✔
295

NEW
296
  const auto& procs = ctx->setupContext.proc_map;
×
297

298
  // Nodes that left the graph give their slot back. The node itself is gone
299
  // or going: only the arena lets go of the tap.
NEW
300
  for(std::size_t i = 0; i < m_benches.size(); i++)
×
301
  {
NEW
302
    auto& b = m_benches[i];
×
NEW
303
    if(!b.node)
×
NEW
304
      continue;
×
NEW
305
    auto it = procs.find(b.node);
×
NEW
306
    if(it != procs.end() && it->second == b.process)
×
NEW
307
      continue;
×
308

NEW
309
    ctx->m_execQueue.enqueue(
×
NEW
310
        [arena = m_arena, i, tap = std::shared_ptr<ossia::telemetry::bench_tap>{}]() mutable {
×
NEW
311
      arena->attach_bench(i, 0, tap);
×
NEW
312
    });
×
NEW
313
    m_benchOfNode.erase(b.node);
×
NEW
314
    if(auto p = m_benchOfProcess.find(b.process.data());
×
NEW
315
       p != m_benchOfProcess.end() && p->second == int(i))
×
NEW
316
      m_benchOfProcess.erase(p);
×
NEW
317
    b = Bench{};
×
NEW
318
    m_freeBenches.push_back(int(i));
×
NEW
319
  }
×
320

321
  // New nodes get a slot and a tap. A node still in proc_map has not been
322
  // removed yet, and its removal will be queued after this.
323
  static uint32_t generations = 0;
NEW
324
  for(const auto& [node, proc] : procs)
×
325
  {
NEW
326
    if(!node || !proc)
×
NEW
327
      continue;
×
NEW
328
    if(m_benchOfNode.contains(node))
×
NEW
329
      continue;
×
330

NEW
331
    int index{};
×
NEW
332
    if(!m_freeBenches.empty())
×
333
    {
NEW
334
      index = m_freeBenches.back();
×
NEW
335
      m_freeBenches.pop_back();
×
NEW
336
    }
×
337
    else
338
    {
NEW
339
      index = int(m_benches.size());
×
NEW
340
      m_benches.emplace_back();
×
341
    }
NEW
342
    if(std::size_t(index) >= m_arena->bench_capacity())
×
NEW
343
      return false;
×
344

NEW
345
    auto& b = m_benches[index];
×
NEW
346
    b.node = node;
×
NEW
347
    b.process = proc;
×
NEW
348
    b.generation = ++generations;
×
NEW
349
    m_benchOfNode[node] = index;
×
NEW
350
    m_benchOfProcess[proc] = index;
×
351

NEW
352
    auto tap = std::make_shared<ossia::telemetry::bench_tap>();
×
NEW
353
    ctx->m_execQueue.enqueue(
×
NEW
354
        [arena = m_arena, index, gen = b.generation, in_arena = tap, in_node = tap,
×
NEW
355
         n = const_cast<ossia::graph_node*>(node)]() mutable {
×
NEW
356
      arena->attach_bench(index, gen, in_arena);
×
NEW
357
      std::swap(n->bench_tap, in_node);
×
NEW
358
    });
×
NEW
359
  }
×
NEW
360
  return true;
×
361
}
11,492 ✔
362

363
void Telemetry::reportBenches()
7,646 ✔
364
{
365
  if(!m_arena)
7,646 !
NEW
366
    return;
×
367
  const auto& f = m_arena->latest();
7,646 ✔
368
  for(std::size_t i = 0; i < m_benches.size() && i < f.benches.size(); i++)
7,646 !
369
  {
NEW
370
    const auto& b = m_benches[i];
×
NEW
371
    if(b.process && f.benches[i].generation == b.generation)
×
NEW
372
      const_cast<Process::ProcessModel*>(b.process.data())
×
NEW
373
          ->benchmark(100. * f.load(f.benches[i]));
×
NEW
374
  }
×
375
}
7,646 ✔
376

377
void Telemetry::executionStarted()
1,369 ✔
378
{
379
  m_running = true;
1,369 ✔
380
  if(enabled())
1,369 !
381
    rebuild();
1,369 ✔
382
}
1,369 ✔
383

384
void Telemetry::executionStopped()
8,177 ✔
385
{
386
  // The graph goes away with its outlets and its context: nothing to detach.
387
  // The virtual ports stay, and must forget the taps before the arena goes.
388
  for(auto& s : m_subs)
17,083 ✔
389
    if(s.param)
8,906 ✔
390
      s.param->meter.store(nullptr, std::memory_order_release);
3 ✔
391
  m_running = false;
8,177 ✔
392
  m_arena.reset();
8,177 ✔
393
  m_benches.clear();
8,177 ✔
394
  m_freeBenches.clear();
8,177 ✔
395
  m_benchOfNode.clear();
8,177 ✔
396
  m_benchOfProcess.clear();
8,177 ✔
397
  for(auto& p : m_playheads)
11,913 ✔
398
    p.attached = false;
3,736 ✔
399
  for(auto& s : m_subs)
17,083 ✔
400
  {
401
    s.attached = false;
8,906 ✔
402
    s.node.reset();
8,906 ✔
403
    s.ossia_inlet = nullptr;
8,906 ✔
404
    s.ossia_outlet = nullptr;
8,906 ✔
405
  }
406
  updated();
8,177 ✔
407
}
8,177 ✔
408

409
void Telemetry::rebuild()
1,370 ✔
410
{
411
  auto& ctx = m_plugin.contextData();
1,370 ✔
412
  if(!ctx)
1,370 !
NEW
413
    return;
×
414

415
  // The views keep what they show until the new arena's first frame.
416
  teardown(false);
1,370 ✔
417

418
  const std::size_t capacity = std::max<std::size_t>(64, 2 * m_subs.size());
1,370 ✔
419
  const std::size_t benches
1,370 ✔
420
      = benchEnabled()
1,370 !
NEW
421
            ? std::max<std::size_t>(
×
NEW
422
                  64, 2 * std::max(m_benches.size(), ctx->setupContext.proc_map.size()))
×
423
            : 0;
424
  const std::size_t playheads = std::max<std::size_t>(256, 2 * m_playheads.size());
1,370 ✔
425
  m_arena = std::make_shared<ossia::telemetry::arena>(capacity, benches, playheads);
1,370 ✔
426
  m_arena->set_publish_interval(publishInterval());
1,370 ✔
427

428
  ctx->m_execQueue.enqueue(
2,740 !
429
      [c = std::weak_ptr{ctx}, arena = m_arena]() mutable {
2,740 ✔
430
    // The previous arena, if any, leaves with this closure.
431
    if(auto ctx = c.lock())
2,740 !
432
      std::swap(ctx->telemetry, arena);
1,370 ✔
433
  });
1,370 ✔
434

435
  for(std::size_t i = 0; i < m_subs.size(); i++)
2,993 ✔
436
    if(m_subs[i].users > 0)
3,244 ✔
437
      attach(i);
1,621 ✔
438

439
  for(std::size_t i = 0; i < m_playheads.size(); i++)
2,896 ✔
440
  {
441
    m_playheads[i].attached = false;
1,526 ✔
442
    attachPlayhead(int(i));
1,526 ✔
443
  }
1,526 ✔
444

445
  // Every slot of the new arena starts empty.
446
  m_benches.clear();
1,370 ✔
447
  m_freeBenches.clear();
1,370 ✔
448
  m_benchOfNode.clear();
1,370 ✔
449
  m_benchOfProcess.clear();
1,370 ✔
450
  syncBenches();
1,370 ✔
451
}
1,370 ✔
452

453
void Telemetry::teardown(bool notify)
1,371 ✔
454
{
455
  auto& ctx = m_plugin.contextData();
1,371 ✔
456
  if(ctx && m_arena)
1,371 !
457
  {
458
    for(std::size_t i = 0; i < m_subs.size(); i++)
3 ✔
459
      detach(i);
2 ✔
460

461
    ctx->m_execQueue.enqueue(
2 !
462
        [c = std::weak_ptr{ctx}, arena = std::shared_ptr<ossia::telemetry::arena>{}]() mutable {
2 ✔
463
      if(auto ctx = c.lock())
2 !
464
        std::swap(ctx->telemetry, arena);
1 ✔
465
    });
1 ✔
466
  }
1 ✔
467
  m_arena.reset();
1,371 ✔
468
  for(auto& p : m_playheads)
2,898 ✔
469
    p.attached = false;
1,527 ✔
470
  if(notify)
1,371 ✔
471
    updated();
1 ✔
472
}
1,371 ✔
473

474
void Telemetry::attach(int index)
1,624 ✔
475
{
476
  auto& ctx = m_plugin.contextData();
1,624 ✔
477
  auto& s = m_subs[index];
1,624 ✔
478
  if(!ctx || !m_arena || s.attached || s.users == 0)
1,624 !
NEW
479
    return;
×
480

481
  // Made once it is known where it goes: read() retries until then.
482
  std::shared_ptr<ossia::telemetry::meter_tap> tap;
1,624 ✔
483
  if(s.kind == tap_kind::node && s.inlet)
1,624 !
484
  {
NEW
485
    if(!s.port)
×
NEW
486
      return;
×
NEW
487
    auto& inlets = ctx->setupContext.inlets;
×
NEW
488
    auto it = inlets.find(
×
NEW
489
        static_cast<Process::Inlet*>(const_cast<Process::Port*>(s.port.data())));
×
NEW
490
    if(it == inlets.end() || !it->second.first || !it->second.second
×
NEW
491
       || it->second.second->which() != ossia::audio_port::which)
×
NEW
492
      return; // Not executing yet: read() retries.
×
493

NEW
494
    tap = std::make_shared<ossia::telemetry::meter_tap>();
×
NEW
495
    auto node = it->second.first;
×
NEW
496
    auto in = static_cast<ossia::audio_inlet*>(it->second.second);
×
NEW
497
    s.node = node;
×
NEW
498
    s.ossia_inlet = in;
×
NEW
499
    ctx->m_execQueue.enqueue(
×
NEW
500
        [arena = m_arena, index, gen = s.generation, in_arena = tap, in_port = tap,
×
NEW
501
         node = std::move(node), in]() mutable {
×
NEW
502
      arena->attach(index, gen, tap_kind::node, in_arena);
×
NEW
503
      std::swap(in->meter, in_port);
×
NEW
504
    });
×
NEW
505
  }
×
506
  else if(s.kind == tap_kind::node && !s.param)
1,624 ✔
507
  {
508
    if(!s.port)
6 ✔
509
      return;
1 ✔
510
    auto& outlets = ctx->setupContext.outlets;
5 ✔
511
    auto it = outlets.find(
10 !
512
        static_cast<Process::Outlet*>(const_cast<Process::Port*>(s.port.data())));
5 ✔
513
    if(it == outlets.end() || !it->second.first || !it->second.second
10 !
514
       || it->second.second->which() != ossia::audio_port::which)
5 !
NEW
515
      return; // Not executing yet: read() retries.
×
516

517
    tap = std::make_shared<ossia::telemetry::meter_tap>();
5 !
518
    auto node = it->second.first;
5 ✔
519
    auto out = static_cast<ossia::audio_outlet*>(it->second.second);
5 ✔
520
    s.node = node;
5 ✔
521
    s.ossia_outlet = out;
5 ✔
522
    ctx->m_execQueue.enqueue(
10 !
523
        [arena = m_arena, index, gen = s.generation, in_arena = tap, in_port = tap,
20 ✔
524
         node = std::move(node), out]() mutable {
10 ✔
525
      arena->attach(index, gen, tap_kind::node, in_arena);
5 ✔
526
      std::swap(out->meter, in_port);
5 ✔
527
    });
5 ✔
528
  }
5 ✔
529
  else if(s.param)
1,618 ✔
530
  {
531
    // A virtual port: the parameter only gets the address of the tap, which
532
    // the arena owns from the next tick on and the closure until then.
533
    tap = std::make_shared<ossia::telemetry::meter_tap>();
3 !
534
    auto* raw = tap.get();
3 ✔
535
    ctx->m_execQueue.enqueue(
6 !
536
        [arena = m_arena, index, gen = s.generation,
6 ✔
537
         in_arena = std::move(tap)]() mutable {
3 ✔
538
      arena->attach(index, gen, tap_kind::node, in_arena);
3 ✔
539
    });
3 ✔
540
    s.param->meter.store(raw, std::memory_order_release);
3 ✔
541
  }
3 ✔
542
  else
543
  {
544
    tap = std::make_shared<ossia::telemetry::meter_tap>();
1,615 !
545
    ctx->m_execQueue.enqueue(
3,230 !
546
        [arena = m_arena, index, gen = s.generation, kind = s.kind,
3,230 ✔
547
         in_arena = std::move(tap)]() mutable {
1,615 ✔
548
      arena->attach(index, gen, kind, in_arena);
1,615 ✔
549
    });
1,615 ✔
550
  }
551
  s.attached = true;
1,623 ✔
552
}
1,624 ✔
553

554
void Telemetry::detach(int index)
2,240 ✔
555
{
556
  auto& ctx = m_plugin.contextData();
2,240 ✔
557
  auto& s = m_subs[index];
2,240 ✔
558
  // The tap stays alive until the closure below has run on the audio thread,
559
  // which is after anything that read this address is done with it.
560
  if(s.param)
2,240 ✔
561
    s.param->meter.store(nullptr, std::memory_order_release);
3 ✔
562
  if(!ctx || !m_arena || !s.attached)
2,240 !
563
    return;
2,232 ✔
564

565
  auto node = s.node.lock();
8 ✔
566
  ctx->m_execQueue.enqueue(
16 !
567
      [arena = m_arena, index, node = std::move(node), in = s.ossia_inlet,
31 ✔
568
       out = s.ossia_outlet, from_arena = std::shared_ptr<ossia::telemetry::meter_tap>{},
16 ✔
569
       from_port = std::shared_ptr<ossia::telemetry::meter_tap>{}]() mutable {
8 ✔
570
    arena->attach(index, 0, tap_kind::none, from_arena);
7 ✔
571
    if(node && in)
7 !
NEW
572
      std::swap(in->meter, from_port);
×
573
    else if(node && out)
7 !
574
      std::swap(out->meter, from_port);
1 ✔
575
  });
7 ✔
576
  s.attached = false;
8 ✔
577
  s.node.reset();
8 ✔
578
  s.ossia_inlet = nullptr;
8 ✔
579
  s.ossia_outlet = nullptr;
8 ✔
580
}
2,240 ✔
581

582
void Telemetry::read()
25,660 ✔
583
{
584
  if(!m_arena)
25,660 ✔
585
    return;
15,538 ✔
586

587
  for(std::size_t i = 0; i < m_subs.size(); i++)
18,577 ✔
588
    if(m_subs[i].users > 0 && !m_subs[i].attached)
8,456 ✔
589
      attach(i);
1 ✔
590

591
  if(!syncBenches())
10,122 !
592
  {
593
    // More process nodes than the arena has room for.
NEW
594
    rebuild();
×
NEW
595
    return;
×
596
  }
597

598
  if(m_arena->consume())
10,122 ✔
599
  {
600
    reportBenches();
7,646 ✔
601
    updated();
7,646 ✔
602
  }
7,646 ✔
603
}
25,660 ✔
604
}
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