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

ossia / libossia / 45061331480

22 Nov 2026 07:32PM UTC coverage: 56.861% (+2.9%) from 54.011%
45061331480

Pull #988

github

web-flow
Merge 200fd19ef into 3ad59e1db
Pull Request #988: ossia-max: ossia.v8connector, parameters declared by a v8 script

2254 of 2484 new or added lines in 8 files covered. (90.74%)

780 existing lines in 17 files now uncovered.

37613 of 66149 relevant lines covered (56.86%)

189595.5 hits per line

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

58.33
/src/ossia/dataflow/execution_state.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include "execution_state.hpp"
4

5
#include <ossia/audio/audio_protocol.hpp>
6
#include <ossia/dataflow/dataflow.hpp>
7
#include <ossia/dataflow/exec_state_facade.hpp>
8
#include <ossia/dataflow/execution/default_policy.hpp>
9
#include <ossia/dataflow/execution/direct_policy.hpp>
10
#include <ossia/dataflow/execution/execution_policy.hpp>
11
#include <ossia/dataflow/execution/merged_policy.hpp>
12
#include <ossia/dataflow/execution/ordered_policy.hpp>
13
#include <ossia/dataflow/execution/priorized_policy.hpp>
14
#include <ossia/dataflow/execution/pull_visitors.hpp>
15
#include <ossia/dataflow/port.hpp>
16
#include <ossia/dataflow/token_request.hpp>
17
#include <ossia/detail/logger.hpp>
18
#include <ossia/network/base/message_queue.hpp>
19

20
#include <libremidi/libremidi.hpp>
21

22
#include <algorithm>
23

24
namespace ossia
25
{
26
execution_state::execution_state() {
2,112 ✔
27
  m_policy = std::make_unique<merged_execution_state_policy>();
2,112 ✔
28
}
2,112 ✔
29

30
execution_state::~execution_state() { }
2,112 ✔
31

32
void execution_state::set_policy(const tick_setup_options& opt)
×
33
{
34
  switch(opt.commit)
×
35
  {
36
#if !defined(OSSIA_FREESTANDING)
37
    case tick_setup_options::Default:
×
38
      m_policy = std::make_unique<default_execution_state_policy>();
×
39
      return;
×
40
    case tick_setup_options::Ordered:
×
41
      m_policy = std::make_unique<ordered_execution_state_policy>();
×
42
      return;
×
43
    case tick_setup_options::Priorized:
×
44
      m_policy = std::make_unique<priorized_execution_state_policy>();
×
45
      return;
×
46
#endif
47
    case tick_setup_options::Merged:
×
48
      m_policy = std::make_unique<merged_execution_state_policy>();
×
49
      return;
×
50
#if !defined(OSSIA_FREESTANDING)
51
    case tick_setup_options::MergedThreaded:
×
52
      m_policy = std::make_unique<threaded_merged_execution_state_policy>();
×
53
      return;
×
54
    case tick_setup_options::DirectThreaded:
×
55
      m_policy = std::make_unique<direct_execution_state_policy>();
×
56
      return;
×
57
#endif
58
  }
59
}
60

61
void execution_state::clear_devices()
×
62
{
63
  m_devices_edit.clear();
×
64
  m_devices_exec.clear();
×
65
}
×
66

67
void execution_state::register_device(net::device_base* d)
51 ✔
68
{
69
  if(d)
51 ✔
70
  {
71
    m_devices_edit.push_back(d);
51 ✔
72
    ossia::net::midi::midi_stream* midi{};
51 ✔
73
#if defined(OSSIA_PROTOCOL_MIDI)
74
    midi = dynamic_cast<ossia::net::midi::midi_stream*>(&d->get_protocol());
51 ✔
75
#endif
76
    m_device_change_queue.enqueue({device_operation::REGISTER, d, midi});
51 ✔
77
  }
78
}
51 ✔
79

80
void execution_state::unregister_device(net::device_base* d)
42 ✔
81
{
82
  if(d)
42 ✔
83
  {
84
    ossia::remove_erase(m_devices_edit, d);
42 ✔
85
    ossia::net::midi::midi_stream* midi{};
42 ✔
86
#if defined(OSSIA_PROTOCOL_MIDI)
87
    midi = dynamic_cast<ossia::net::midi::midi_stream*>(&d->get_protocol());
42 ✔
88
#endif
89
    m_device_change_queue.enqueue({device_operation::UNREGISTER, d, midi});
42 ✔
90
  }
91
}
42 ✔
92

93
void execution_state::register_parameter(net::parameter_base& p)
9 ✔
94
{
95
  auto device = &p.get_node().get_device();
9 ✔
96
  for(auto& q : m_valueQueues)
9 ✔
97
  {
98
    if(&q.device == device)
9 ✔
99
    {
100
      q.reg(p);
9 ✔
101
      break;
9 ✔
102
    }
103
  }
104
}
9 ✔
105

106
void execution_state::unregister_parameter(net::parameter_base& p)
6 ✔
107
{
108
  auto device = &p.get_node().get_device();
6 ✔
109
  for(auto& q : m_valueQueues)
6 ✔
110
  {
111
    if(&q.device == device)
6 ✔
112
    {
113
      q.unreg(p);
6 ✔
114
      break;
6 ✔
115
    }
116
  }
117
}
6 ✔
118

119
void execution_state::register_midi_parameter(net::midi::midi_stream& p)
10 ✔
120
{
121
#if defined(OSSIA_PROTOCOL_MIDI)
122
  p.enable_registration();
10 ✔
123
  auto it = m_receivedMidi.find(&p);
10 ✔
124
  if(it == m_receivedMidi.end())
10 ✔
125
  {
126
    m_receivedMidi.insert({&p, received_midi_state{.messages = {}, .count = 1}});
10 ✔
127
  }
128
  else
129
  {
130
    it->second.count++;
×
131
  }
132
#endif
133
}
10 ✔
134

135
void execution_state::register_midi_inlet(
10 ✔
136
    const ossia::inlet& port, net::midi::midi_stream& p)
137
{
138
  // One registration per inlet: registering it again replaces the first.
139
  auto [it, inserted] = m_midiInlets.try_emplace(&port, midi_inlet_binding{&p, {}});
10 ✔
140
  if(!inserted)
10 ✔
141
  {
142
    unregister_midi_parameter(it->second.stream);
×
143
    if(it->second.stream != &p)
×
UNCOV
144
      release_midi_input(port, it->second);
×
145
    it->second.stream = &p;
×
146
  }
147
  register_midi_parameter(p);
10 ✔
148
}
10 ✔
149

150
void execution_state::track_midi_input(const ossia::inlet& in, std::size_t from)
21 ✔
151
{
152
  auto& messages = static_cast<const ossia::midi_inlet&>(in).data.messages;
21 ✔
153
  if(messages.size() <= from)
21 ✔
154
    return;
2 ✔
155
  if(auto it = m_midiInlets.find(&in); it != m_midiInlets.end())
19 ✔
156
    it->second.held.track(messages.data() + from, messages.data() + messages.size());
19 ✔
157
}
158

159
void execution_state::release_midi_input(
10 ✔
160
    const ossia::inlet& in, midi_inlet_binding& b)
161
{
162
  // The inlet is only const for the sake of the registration interface: it
163
  // belongs to a node of the graph this state executes.
164
  auto& port = const_cast<ossia::midi_inlet&>(static_cast<const ossia::midi_inlet&>(in));
10 ✔
165
  b.held.release(port.data.messages);
10 ✔
166
  b.held.clear();
10 ✔
167
}
10 ✔
168

169
void execution_state::unregister_midi_parameter(net::midi::midi_stream* p)
7 ✔
170
{
171
  // Pointer identity only: the stream may already be destroyed.
172
#if defined(OSSIA_PROTOCOL_MIDI)
173
  auto it = m_receivedMidi.find(p);
7 ✔
174
  if(it != m_receivedMidi.end())
7 ✔
175
  {
176
    it->second.count--;
7 ✔
177
    if(it->second.count <= 0)
7 ✔
178
    {
179
      m_receivedMidi.erase(it);
7 ✔
180
      // TODO p.disable_registration();
181
    }
182
  }
183
#endif
184
}
7 ✔
185

186
void execution_state::receive_new_values()
380 ✔
187
{
188
  for(auto& mq : m_valueQueues)
483 ✔
189
  {
190
    ossia::received_value recv;
103 ✔
191
    while(mq.try_dequeue(recv))
110 ✔
192
      m_receivedValues[recv.address].push_back(recv.value);
14 ✔
193
  }
103 ✔
194
}
380 ✔
195

196
void execution_state::get_new_values()
380 ✔
197
{
198
  for(auto it = m_receivedValues.begin(), end = m_receivedValues.end(); it != end; ++it)
383 ✔
199
    it->second.clear();
3 ✔
200

201
  receive_new_values();
380 ✔
202

203
  for(auto it = m_receivedMidi.begin(), end = m_receivedMidi.end(); it != end; ++it)
399 ✔
204
  {
205
    auto& [proto, state] = *it;
19 ✔
206

207
    auto midi = proto->midi_in();
19 ✔
208
    auto& input_messages = proto->messages;
19 ✔
209
    auto& port = state.messages;
19 ✔
210
    libremidi::ump msg;
19 ✔
211
    port.clear();
19 ✔
212

213
    // A port that only sends has nothing to read back, and no clock to time it
214
    // against. init_midi_timings() skips it for the same reason.
215
    if(!midi)
19 ✔
216
      continue;
×
217

218
    port.reserve(input_messages.size_approx());
19 ✔
219
    if(midi->get_current_api() == libremidi::API::JACK_MIDI)
19 ✔
220
    {
221
      // FIXME make it sample-accurate for pipewire & jack_ump too
222
      // sample-accurate, see MIDIDevice.cpp in score
UNCOV
223
      while(input_messages.try_dequeue(msg))
×
224
      {
UNCOV
225
        port.push_back(msg);
×
226
      }
227
    }
228
    else
229
    {
230
      // Adapt the Absolute timestamps
231
      const auto cur_t = state.current_buffer_start;
19 ✔
232
      const auto prev_t = state.last_buffer_start;
19 ✔
233
      const double timestamp_mult = cur_t > prev_t ? 1. / (cur_t - prev_t) : 0.;
19 ✔
234

235
      while(input_messages.try_dequeue(msg))
47 ✔
236
      {
237
        msg.timestamp = this->bufferSize * ((msg.timestamp - prev_t) * timestamp_mult);
28 ✔
238
        if(msg.timestamp >= bufferSize)
28 ✔
UNCOV
239
          msg.timestamp = this->bufferSize - 1;
×
240
        if(msg.timestamp < 0)
28 ✔
UNCOV
241
          msg.timestamp = 0;
×
242

243
        port.push_back(msg);
56 ✔
244
      }
245
    }
246
  }
247
}
380 ✔
248

249
void execution_state::register_port(const inlet& port)
20 ✔
250
{
251
  if(auto vp = port.target<ossia::value_port>())
20 ✔
252
  {
253
    if(vp->is_event)
9 ✔
254
    {
255
      if(auto addr = port.address.target<ossia::net::parameter_base*>())
18 ✔
256
      {
257
        register_parameter(**addr);
9 ✔
258
      }
UNCOV
259
      else if(auto p = port.address.target<ossia::traversal::path>())
×
260
      {
UNCOV
261
        std::vector<ossia::net::node_base*> roots{};
×
262

UNCOV
263
        for(auto n : m_devices_exec)
×
UNCOV
264
          roots.push_back(&n->get_root_node());
×
265

UNCOV
266
        ossia::traversal::apply(*p, roots);
×
UNCOV
267
        for(auto n : roots)
×
268
          if(auto param = n->get_parameter())
×
UNCOV
269
            register_parameter(*param);
×
UNCOV
270
      }
×
271
    }
272
  }
273
#if defined(OSSIA_PROTOCOL_MIDI)
274
  else if(port.target<ossia::midi_port>())
11 ✔
275
  {
276
    if(auto addr = port.address.target<ossia::net::node_base*>())
22 ✔
277
    {
278
      if(auto midi_addr = dynamic_cast<ossia::net::midi::midi_stream*>(
10 ✔
279
             &(*addr)->get_device().get_protocol()))
20 ✔
280
      {
281
        register_midi_inlet(port, *midi_addr);
10 ✔
282
      }
283
    }
284
    else if(auto addr = port.address.target<ossia::net::parameter_base*>())
2 ✔
285
    {
286
      if(auto midi_addr = dynamic_cast<ossia::net::midi::midi_stream*>(
1 ✔
287
             &(*addr)->get_node().get_device().get_protocol()))
2 ✔
288
      {
UNCOV
289
        register_midi_inlet(port, *midi_addr);
×
290
      }
291
    }
292
  }
293
#endif
294
}
20 ✔
295

296
void execution_state::register_port(const outlet& port)
9 ✔
297
{
298
#if defined(OSSIA_PROTOCOL_MIDI)
299
  if(port.which() != ossia::midi_port::which)
9 ✔
300
    return;
×
301

302
  midi_outlet_binding binding;
9 ✔
303
  if(auto addr = port.address.target<ossia::net::node_base*>())
18 ✔
304
  {
305
    binding.stream = dynamic_cast<ossia::net::midi::midi_stream*>(
9 ✔
306
        &(*addr)->get_device().get_protocol());
9 ✔
307
    if(binding.stream)
9 ✔
308
      if(auto chan = binding.stream->stream_channel(**addr))
9 ✔
309
        binding.channel = *chan;
×
310
  }
UNCOV
311
  else if(auto addr = port.address.target<ossia::net::parameter_base*>())
×
312
  {
UNCOV
313
    binding.stream = dynamic_cast<ossia::net::midi::midi_stream*>(
×
UNCOV
314
        &(*addr)->get_node().get_device().get_protocol());
×
315
  }
316

317
  if(binding.stream)
9 ✔
318
    m_midiOutlets.insert_or_assign(&port, binding);
9 ✔
319
#endif
320
}
321

322
void execution_state::unregister_port(const inlet& port)
16 ✔
323
{
324
  if(auto vp = port.target<ossia::value_port>())
16 ✔
325
  {
326
    if(vp->is_event)
6 ✔
327
    {
328
      if(auto addr = port.address.target<ossia::net::parameter_base*>())
12 ✔
329
      {
330
        unregister_parameter(**addr);
6 ✔
331
      }
UNCOV
332
      else if(auto p = port.address.target<ossia::traversal::path>())
×
333
      {
UNCOV
334
        std::vector<ossia::net::node_base*> roots{};
×
335

UNCOV
336
        for(auto n : m_devices_exec)
×
UNCOV
337
          roots.push_back(&n->get_root_node());
×
338

UNCOV
339
        ossia::traversal::apply(*p, roots);
×
UNCOV
340
        for(auto n : roots)
×
UNCOV
341
          if(auto param = n->get_parameter())
×
UNCOV
342
            unregister_parameter(*param);
×
343
      }
×
344
    }
345
  }
346
#if defined(OSSIA_PROTOCOL_MIDI)
347
  else if(port.target<ossia::midi_port>())
10 ✔
348
  {
349
    if(auto it = m_midiInlets.find(&port); it != m_midiInlets.end())
10 ✔
350
    {
351
      unregister_midi_parameter(it->second.stream);
7 ✔
352
      release_midi_input(port, it->second);
7 ✔
353
      m_midiInlets.erase(it);
7 ✔
354
    }
355
  }
356
#endif
357
}
16 ✔
358

359
void execution_state::unregister_port(const outlet& port)
11 ✔
360
{
361
#if defined(OSSIA_PROTOCOL_MIDI)
362
  if(port.which() != ossia::midi_port::which)
11 ✔
UNCOV
363
    return;
×
364

365
  // The port leaves its device, which still plays the notes it was sent.
366
  release_held_notes(port);
11 ✔
367
  m_midiOutlets.erase(&port);
11 ✔
368
#endif
369
}
370

371
void execution_state::release_held_notes(const outlet& port)
22 ✔
372
{
373
#if defined(OSSIA_PROTOCOL_MIDI)
374
  if(port.which() != ossia::midi_port::which)
22 ✔
375
    return;
15 ✔
376

377
  auto it = m_midiOutlets.find(&port);
22 ✔
378
  if(it == m_midiOutlets.end())
22 ✔
379
    return;
15 ✔
380

381
  const auto& held = static_cast<const ossia::midi_outlet&>(port).held;
7 ✔
382
  if(!(port.scope & port::scope_t::both) || held.empty())
7 ✔
UNCOV
383
    return;
×
384

385
  // Straight to the stream rather than through the tick's state: the port may
386
  // be about to be destroyed, and nothing may keep a reference to it.
387
  const auto [stream, channel] = it->second;
7 ✔
388
  ossia::midi_port offs;
7 ✔
389
  held.release(offs.messages);
7 ✔
390
  for(libremidi::ump& m : offs.messages)
28 ✔
391
  {
392
    if(channel > 0)
7 ✔
UNCOV
393
      m.data[0] = (m.data[0] & ~uint32_t(0x000F0000))
×
UNCOV
394
                  | (uint32_t((channel - 1) & 0x0F) << 16);
×
395
    stream->push_value(m);
7 ✔
396
  }
397
#endif
398
}
7 ✔
399

400
void execution_state::apply_device_changes()
446 ✔
401
{
402
  device_operation op;
446 ✔
403
  ossia::small_vector<device_operation, 8> flattened;
446 ✔
404
  while(m_device_change_queue.try_dequeue(op))
538 ✔
405
  {
406
    flattened.push_back(op);
92 ✔
407
  }
408

409
  if(flattened.empty())
446 ✔
410
    return;
370 ✔
411

412
  // The ports reading a removed device's stream are reset without being
413
  // unregistered: its entry goes with the device, even one registered and
414
  // removed within the same batch. A stream registered again later in the
415
  // batch (the same device coming back, or a new one allocated where the old
416
  // one was) keeps it: inlets may already be bound to it.
417
  for(std::size_t i = 0; i < flattened.size(); ++i)
168 ✔
418
  {
419
    const auto& op = flattened[i];
92 ✔
420
    if(op.operation != device_operation::UNREGISTER || !op.midi)
92 ✔
421
      continue;
64 ✔
422
    const bool back = std::any_of(
84 ✔
423
        flattened.begin() + i + 1, flattened.end(), [&](const device_operation& o) {
84 ✔
424
      return o.operation == device_operation::REGISTER && o.midi == op.midi;
8 ✔
425
    });
426
    if(back)
28 ✔
UNCOV
427
      continue;
×
428
    m_receivedMidi.erase(op.midi);
28 ✔
429
    for(auto it = m_midiInlets.begin(); it != m_midiInlets.end();)
32 ✔
430
    {
431
      if(it->second.stream == op.midi)
4 ✔
432
      {
433
        // Whatever was held on the device is not going to be let go of there.
434
        release_midi_input(*it->first, it->second);
3 ✔
435
        it = m_midiInlets.erase(it);
3 ✔
436
      }
437
      else
438
        ++it;
1 ✔
439
    }
440
    for(auto it = m_midiOutlets.begin(); it != m_midiOutlets.end();)
35 ✔
441
    {
442
      if(it->second.stream == op.midi)
7 ✔
443
        it = m_midiOutlets.erase(it);
7 ✔
444
      else
UNCOV
445
        ++it;
×
446
    }
447
  }
448

449
  // We must first check for devices that were registered and unregistered
450
  // afterwards. IMPORTANT: here we must *not* use iterators, but indices to
451
  // prevent invalidation issues. Likewise, since the size of the vec changes,
452
  // it must be rechecked at each loop iteration !
453
  for(std::size_t i = 0; i < flattened.size();)
168 ✔
454
  {
455
    auto& first = flattened[i];
92 ✔
456
    if(first.operation == device_operation::REGISTER)
92 ✔
457
    {
458
      bool erased = false;
50 ✔
459
      for(std::size_t j = i + 1; j < flattened.size(); ++j)
58 ✔
460
      {
461
        if(flattened[j].operation == device_operation::UNREGISTER
8 ✔
462
           && flattened[j].device == first.device)
8 ✔
463
        {
UNCOV
464
          erased = true;
×
UNCOV
465
          flattened.erase(flattened.begin() + j);
×
UNCOV
466
          flattened.erase(flattened.begin() + i);
×
467

UNCOV
468
          break;
×
469
        }
470
      }
471

472
      if(erased)
50 ✔
473
      {
474
        // i does not increase here as the previous element was removed
UNCOV
475
        continue;
×
476
      }
477
      else
478
      {
479
        ++i;
50 ✔
480
        continue;
50 ✔
481
      }
482
    }
483
    else
484
    {
485
      ++i;
42 ✔
486
      continue;
42 ✔
487
    }
488
  }
489

490
  for(auto& op : flattened)
336 ✔
491
  {
492
    switch(op.operation)
92 ✔
493
    {
494
      case device_operation::REGISTER: {
50 ✔
495
        m_devices_exec.push_back(op.device);
50 ✔
496
        m_valueQueues.emplace_back(*op.device);
50 ✔
497
        break;
50 ✔
498
      }
499
      case device_operation::UNREGISTER: {
42 ✔
500
        ossia::remove_erase(m_devices_exec, op.device);
42 ✔
501
        auto it = ossia::find_if(
42 ✔
502
            m_valueQueues, [&](auto& mq) { return &mq.device == op.device; });
83 ✔
503
        if(it != m_valueQueues.end())
42 ✔
504
          m_valueQueues.erase(it);
39 ✔
505

506
        break;
42 ✔
507
      }
508
    }
509
  }
510
}
446 ✔
511

512
void execution_state::init_midi_timings()
380 ✔
513
{
514
  for(auto& [proto, state] : m_receivedMidi)
399 ✔
515
  {
516
    if(auto m = proto->midi_in())
19 ✔
517
    {
518
      state.last_buffer_start = state.current_buffer_start;
19 ✔
519
      state.current_buffer_start = m->absolute_timestamp();
19 ✔
520
    }
521
  }
522
}
380 ✔
523

524
void execution_state::begin_tick()
380 ✔
525
{
526
  // Before anything reads the MIDI streams: those of the devices removed
527
  // since may be destroyed already.
528
  apply_device_changes();
380 ✔
529
  init_midi_timings();
380 ✔
530
  m_policy->clear_local_state();
380 ✔
531
  get_new_values();
380 ✔
532

533
  // Allow non-audio-protocol devices to refresh their audio buffers
534
  for(auto& dev : m_devices_exec)
966 ✔
535
    dev->get_protocol().pre_tick(bufferSize);
103 ✔
536
}
380 ✔
537

UNCOV
538
void execution_state::reset()
×
539
{
540
  // TODO unregister everything ?
UNCOV
541
  m_policy->clear_local_state();
×
UNCOV
542
  clear_devices();
×
UNCOV
543
  m_valueQueues.clear();
×
UNCOV
544
  m_receivedValues.clear();
×
UNCOV
545
  m_receivedMidi.clear();
×
UNCOV
546
  m_midiInlets.clear();
×
UNCOV
547
  m_midiOutlets.clear();
×
548
}
×
549

550
void execution_state::advance_tick(std::size_t t)
×
551
{
552
#if defined(OSSIA_PROTOCOL_AUDIO)
553
  /*
554
        for (auto& elt : st.m_audioState)
555
        {
556
          auto addr = dynamic_cast<audio_parameter*>(elt.first);
557
          if(addr)
558
          {
559
            for(auto& chan : addr->audio)
560
            {
561
              if(!chan.empty())
562
              {
563
                chan = chan.subspan(1);
564
              }
565
            }
566
          }
567
        }
568
        */
569

570
  for(auto& dev : m_devices_exec)
×
571
  {
UNCOV
572
    auto& proto = dev->get_protocol();
×
573
    if(auto ap = dynamic_cast<ossia::audio_protocol*>(&proto))
×
574
    {
575
      ap->advance_tick(t);
×
576
    }
577
  }
578
#endif
UNCOV
579
}
×
580

581
namespace
582
{
583
// Follows what a MIDI inlet is given from its address in one copy
584
struct midi_input_scope
585
{
586
  const inlet& in;
587
  const bool midi = in.which() == ossia::midi_port::which;
588
  const std::size_t from
589
      = midi ? static_cast<const ossia::midi_inlet&>(in).data.messages.size() : 0;
590
};
591
}
592

593
void execution_state::find_and_copy(net::parameter_base& addr, inlet& in)
15 ✔
594
{
595
  const midi_input_scope scope{in};
15 ✔
596
  if(!m_policy->find_and_copy(addr, in))
15 ✔
597
  {
598
    if(in.scope & port::scope_t::global)
12 ✔
599
      in.visit(global_pull_visitor{*this, addr});
12 ✔
600
  }
601
  if(scope.midi)
15 ✔
UNCOV
602
    track_midi_input(in, scope.from);
×
603
}
15 ✔
604

605
void execution_state::copy_from_global(net::parameter_base& addr, inlet& in)
7 ✔
606
{
607
  if(in.scope & port::scope_t::global)
7 ✔
608
  {
609
    const midi_input_scope scope{in};
7 ✔
610
    in.visit(global_pull_visitor{*this, addr});
7 ✔
611
    if(scope.midi)
7 ✔
612
      track_midi_input(in, scope.from);
1 ✔
613
  }
614
}
7 ✔
615

616
void execution_state::copy_from_global_node(net::node_base& node, inlet& in)
20 ✔
617
{
618
  if(in.scope & port::scope_t::global)
20 ✔
619
  {
620
    const midi_input_scope scope{in};
20 ✔
621
    in.visit(global_pull_node_visitor{*this, node});
20 ✔
622
    if(scope.midi)
20 ✔
623
      track_midi_input(in, scope.from);
20 ✔
624
  }
625
}
20 ✔
626

UNCOV
627
bool execution_state::in_local_scope(net::parameter_base& other) const
×
628
{
UNCOV
629
  return m_policy->in_local_scope(other);
×
630
}
631

632
void execution_state::commit()
384 ✔
633
{
634
  m_policy->commit();
384 ✔
635
}
384 ✔
636
void execution_state::insert(
32 ✔
637
    ossia::net::parameter_base& dest, const ossia::value_port& v)
638
{
639
  m_policy->insert(dest, std::move(v));
32 ✔
640
}
32 ✔
UNCOV
641
void execution_state::insert(ossia::audio_parameter& dest, const ossia::audio_port& v)
×
642
{
UNCOV
643
  m_policy->insert(dest, std::move(v));
×
UNCOV
644
}
×
UNCOV
645
void execution_state::insert(
×
646
    ossia::net::midi::midi_parameter& dest, const ossia::midi_port& v)
647
{
648
  m_policy->insert(dest, std::move(v));
×
UNCOV
649
}
×
650

651
int exec_state_facade::sampleRate() const noexcept
251,252 ✔
652
{
653
  return impl->sampleRate;
251,252 ✔
654
}
655

656
int exec_state_facade::bufferSize() const noexcept
502,544 ✔
657
{
658
  return impl->bufferSize;
502,544 ✔
659
}
660

661
int exec_state_facade::setupBufferSize() const noexcept
×
662
{
UNCOV
663
  return impl->setupBufferSize();
×
664
}
665

666
double exec_state_facade::modelToSamples() const noexcept
753,890 ✔
667
{
668
  return impl->modelToSamplesRatio;
753,890 ✔
669
}
670

UNCOV
671
double exec_state_facade::samplesToModel() const noexcept
×
672
{
UNCOV
673
  return impl->samplesToModelRatio;
×
674
}
675

UNCOV
676
int exec_state_facade::inputLatency() const noexcept
×
677
{
678
  return impl->inputLatency;
×
679
}
680

UNCOV
681
int exec_state_facade::outputLatency() const noexcept
×
682
{
683
  return impl->outputLatency;
×
684
}
685

686
int64_t exec_state_facade::samplesSinceStart() const noexcept
×
687
{
688
  return impl->samples_since_start;
×
689
}
690

UNCOV
691
double exec_state_facade::startDate() const noexcept
×
692
{
UNCOV
693
  return impl->start_date;
×
694
}
695

UNCOV
696
double exec_state_facade::currentDate() const noexcept
×
697
{
UNCOV
698
  return impl->cur_date;
×
699
}
700

701
ossia::net::node_base* exec_state_facade::find_node(std::string_view name) const noexcept
×
702
{
UNCOV
703
  return impl->find_node(name);
×
704
}
705

706
auto exec_state_facade::timings(const token_request& t) const noexcept -> sample_timings
3,404 ✔
707
{
708
  sample_timings tm;
709
  static constexpr double speed_epsilon = 0.01;
710

711
  if(t.start_sample >= 0 && t.length_sample >= 0)
3,404 ✔
712
  {
713
    [[likely]];
1,259 ✔
714
    // The producer of the token knew which samples of the buffer it stands
715
    // for, and that knowledge cannot be reconstructed from the flick-quantised
716
    // model dates - carrying it is the point. Clamp defensively: a span must
717
    // never reach outside the buffer.
718
    tm.start_sample = t.start_sample;
1,259 ✔
719
    tm.length = t.length_sample;
1,259 ✔
720
    if(tm.start_sample > impl->bufferSize)
1,259 ✔
721
    {
722
      [[unlikely]];
×
723
      ossia::logger().error(
×
724
          "token start_sample > bufferSize: {} > {}", tm.start_sample,
725
          impl->bufferSize);
×
726
      return {};
×
727
    }
728
    if(tm.start_sample + tm.length > impl->bufferSize)
1,259 ✔
729
    {
UNCOV
730
      [[unlikely]];
×
731
      ossia::logger().error(
×
732
          "token start_sample + length_sample > bufferSize: {} + {} > {}",
733
          tm.start_sample, tm.length, impl->bufferSize);
×
UNCOV
734
      tm.length = impl->bufferSize - tm.start_sample;
×
735
    }
736
    return tm;
1,259 ✔
737
  }
738

739
  if(t.speed > speed_epsilon || t.speed < -speed_epsilon)
2,145 ✔
740
  {
741
    [[likely]];
2,144 ✔
742
    tm.start_sample = t.physical_start(impl->modelToSamplesRatio);
2,144 ✔
743

744
    const auto tick_dur = t.physical_write_duration(impl->modelToSamplesRatio);
2,144 ✔
745
    auto max_dur = int64_t(impl->bufferSize - tm.start_sample);
2,144 ✔
746
    if(max_dur < 0)
2,144 ✔
UNCOV
747
      max_dur = 0;
×
748

749
    tm.length = std::min(tick_dur, max_dur);
2,144 ✔
750
  }
2,144 ✔
751
  else
752
  {
753
    tm.start_sample = 0;
1 ✔
754
    tm.length = 0;
1 ✔
755
    return tm;
1 ✔
756
  }
757
  if(tm.start_sample < 0)
2,144 ✔
758
  {
759
    [[unlikely]];
×
760
    ossia::logger().error("tm.start_sample < 0: {}", tm.start_sample);
×
UNCOV
761
    return {};
×
762
  }
763
  if(tm.start_sample >= impl->bufferSize)
2,144 ✔
764
  {
765
    [[unlikely]];
×
766
    ossia::logger().error(
×
767
        "tm.start_sample >= impl->bufferSize: {} >= {}", tm.start_sample,
768
        impl->bufferSize);
×
UNCOV
769
    return {};
×
770
  }
771
  if(tm.length < 0)
2,144 ✔
772
  {
UNCOV
773
    [[unlikely]];
×
774
    ossia::logger().error("tm.length < 0: {}", tm.length);
×
775
    return {};
×
776
  }
777
  if(tm.start_sample + tm.length > impl->bufferSize)
2,144 ✔
778
  {
UNCOV
779
    [[unlikely]];
×
UNCOV
780
    ossia::logger().error(
×
781
        "tm.start_sample + tm.length > impl->bufferSize: {} + {} > {}", tm.start_sample,
UNCOV
782
        tm.length, impl->bufferSize);
×
UNCOV
783
    return {};
×
784
  }
785
  return tm;
2,144 ✔
786
}
787

UNCOV
788
void exec_state_facade::insert(audio_parameter& dest, const audio_port& v)
×
789
{
UNCOV
790
  impl->insert(dest, v);
×
UNCOV
791
}
×
792

UNCOV
793
void exec_state_facade::insert(net::midi::midi_parameter& dest, const midi_port& v)
×
794
{
UNCOV
795
  impl->insert(dest, v);
×
UNCOV
796
}
×
797

798
std::vector<ossia::net::node_base*>
UNCOV
799
exec_state_facade::list_destinations(const destination_t& address)
×
800
{
UNCOV
801
  return ossia::list_destinations(address, impl->exec_devices());
×
802
}
803

804
ossia::net::node_base*
UNCOV
805
exec_state_facade::get_first_destination(const destination_t& address)
×
806
{
UNCOV
807
  return ossia::get_first_destination(address, impl->exec_devices());
×
808
}
809

UNCOV
810
std::vector<ossia::net::node_base*> list_destinations(
×
811
    const destination_t& address,
812
    const ossia::small_vector<ossia::net::device_base*, 4>& devices)
813
{
UNCOV
814
  std::vector<ossia::net::node_base*> ret;
×
UNCOV
815
  switch(address.which().index())
×
816
  {
817
    // ossia::net::parameter_base*
UNCOV
818
    case destination_t::index_of<ossia::net::parameter_base*>().index(): {
×
UNCOV
819
      auto addr = *address.target<ossia::net::parameter_base*>();
×
UNCOV
820
      if(addr)
×
821
      {
UNCOV
822
        ret.push_back(&addr->get_node());
×
UNCOV
823
        break;
×
824
      }
UNCOV
825
      break;
×
826
    }
827

828
      // ossia::traversal::path
UNCOV
829
    case destination_t::index_of<ossia::traversal::path>().index(): {
×
UNCOV
830
      std::vector<ossia::net::node_base*> roots{};
×
831

UNCOV
832
      for(auto n : devices)
×
UNCOV
833
        roots.push_back(&n->get_root_node());
×
834

UNCOV
835
      auto& p = *address.target<ossia::traversal::path>();
×
UNCOV
836
      ossia::traversal::apply(p, roots);
×
837

UNCOV
838
      for(auto n : roots)
×
UNCOV
839
        ret.push_back(n);
×
UNCOV
840
      break;
×
UNCOV
841
    }
×
842

843
      // ossia::net::node_base*
UNCOV
844
    case destination_t::index_of<ossia::net::node_base*>().index(): {
×
UNCOV
845
      ret.push_back(*address.target<ossia::net::node_base*>());
×
UNCOV
846
      break;
×
847
    }
UNCOV
848
    default:
×
UNCOV
849
      break;
×
850
  }
UNCOV
851
  return ret;
×
UNCOV
852
}
×
853

UNCOV
854
ossia::net::node_base* get_first_destination(
×
855
    const destination_t& address,
856
    const ossia::small_vector<ossia::net::device_base*, 4>& devices)
857
{
UNCOV
858
  switch(address.which().index())
×
859
  {
860
    // ossia::net::parameter_base*
UNCOV
861
    case destination_t::index_of<ossia::net::parameter_base*>().index(): {
×
UNCOV
862
      auto addr = *address.target<ossia::net::parameter_base*>();
×
UNCOV
863
      if(addr)
×
UNCOV
864
        return &addr->get_node();
×
UNCOV
865
      break;
×
866
    }
867

868
      // ossia::traversal::path
UNCOV
869
    case destination_t::index_of<ossia::traversal::path>().index(): {
×
UNCOV
870
      std::vector<ossia::net::node_base*> roots{};
×
871

UNCOV
872
      for(auto n : devices)
×
UNCOV
873
        roots.push_back(&n->get_root_node());
×
874

UNCOV
875
      auto& p = *address.target<ossia::traversal::path>();
×
UNCOV
876
      ossia::traversal::apply(p, roots);
×
877

UNCOV
878
      for(auto n : roots)
×
UNCOV
879
        return n;
×
UNCOV
880
      break;
×
UNCOV
881
    }
×
882

883
      // ossia::net::node_base*
UNCOV
884
    case destination_t::index_of<ossia::net::node_base*>().index(): {
×
UNCOV
885
      return *address.target<ossia::net::node_base*>();
×
886
    }
UNCOV
887
    default:
×
UNCOV
888
      break;
×
889
  }
UNCOV
890
  return nullptr;
×
891
}
892
}
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