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

ossia / score / 41569965004

03 Nov 2026 03:04AM UTC coverage: 53.588% (+1.9%) from 51.66%
41569965004

push

github

jcelerier
ci: build the documentation on Ubuntu 24.04, which its deps script targets

ubuntu-latest is now 26.04, where ubuntu.noble.deps.sh's Qt package names
(libqt6websockets6-dev and the like) no longer exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPguhTJiZUHjuouE7tkj5

197270 of 368126 relevant lines covered (53.59%)

304198.31 hits per line

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

84.65
/src/plugins/score-plugin-engine/Execution/DocumentPlugin.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 "DocumentPlugin.hpp"
4

5
#include "BaseScenarioComponent.hpp"
6

7
#include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
8

9
#include <Scenario/Application/ScenarioActions.hpp>
10
#include <Scenario/Document/BaseScenario/BaseScenario.hpp>
11
#include <Scenario/Document/Event/EventExecution.hpp>
12
#include <Scenario/Document/Event/EventModel.hpp>
13
#include <Scenario/Document/Interval/IntervalExecution.hpp>
14
#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
15
#include <Scenario/Document/State/StateExecution.hpp>
16
#include <Scenario/Document/TimeSync/TimeSyncExecution.hpp>
17
#include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
18
#include <Scenario/Execution/score2OSSIA.hpp>
19

20
#include <Audio/AudioApplicationPlugin.hpp>
21
#include <Audio/AudioDevice.hpp>
22
#include <Audio/AudioTick.hpp>
23
#include <Audio/Settings/Model.hpp>
24
#include <Engine/ApplicationPlugin.hpp>
25
#include <Execution/DeviceAddresses.hpp>
26
#include <Execution/Settings/ExecutorModel.hpp>
27

28
#include <score/actions/ActionManager.hpp>
29
#include <score/model/ComponentUtils.hpp>
30
#include <score/plugins/documentdelegate/plugin/DocumentPlugin.hpp>
31
#include <score/tools/Bind.hpp>
32

33
#include <core/application/ApplicationSettings.hpp>
34
#include <core/document/Document.hpp>
35
#include <core/document/DocumentModel.hpp>
36

37
#include <ossia/audio/audio_protocol.hpp>
38
#include <ossia/dataflow/bench_map.hpp>
39
#include <ossia/detail/algorithms.hpp>
40
#include <ossia/dataflow/execution_state.hpp>
41
#include <ossia/dataflow/for_each_port.hpp>
42
#include <ossia/dataflow/graph/graph_interface.hpp>
43
#include <ossia/dataflow/graph_edge.hpp>
44
#include <ossia/dataflow/port.hpp>
45
#include <ossia/detail/flicks.hpp>
46
#include <ossia/detail/logger.hpp>
47
#include <ossia/editor/scenario/time_interval.hpp>
48
#include <ossia/network/common/path.hpp>
49

50
#include <QCoreApplication>
51
#include <QElapsedTimer>
52
#include <QTimer>
53

54
#include <atomic>
55
#include <thread>
56

57
#include <wobjectimpl.h>
58
W_REGISTER_ARGTYPE(ossia::bench_map)
59
W_OBJECT_IMPL(Execution::DocumentPlugin)
48,108 ✔
60
namespace Execution
61
{
62
DocumentPlugin::ContextData::ContextData(const score::DocumentContext& ctx)
6,635 ✔
63
    : setupContext{context}
64
    , context
65
{
66
  {}, ctx, m_created, {}, {}, m_execQueue, m_editionQueue, m_gcQueue, setupContext,
67
      execGraph, execState
68
#if(__cplusplus > 201703L) && !defined(_MSC_VER)
69
      ,
70
  {
71
    ossia::disable_init
72
  }
73
#endif
74
}
75
{
76
}
×
77
DocumentPlugin::DocumentPlugin(const score::DocumentContext& ctx, QObject* parent)
1,530 ✔
78
    : score::DocumentPlugin{ctx, "OSSIADocumentPlugin", parent}
1,530 ✔
79
    , settings{ctx.app.settings<Execution::Settings::Model>()}
1,530 ✔
80
    , m_ctxData{std::make_shared<ContextData>(ctx)}
81
{
1,530 ✔
82
  m_ctxData->context.alias = m_ctxData;
1,530 ✔
83
  makeGraph();
1,530 ✔
84
  auto& devs = ctx.plugin<Explorer::DeviceDocumentPlugin>();
1,530 ✔
85
  local_device = devs.list().localDevice();
1,530 ✔
86
  if(auto dev = devs.list().audioDevice())
1,530 ✔
87
  {
88
    audio_device = static_cast<Dataflow::AudioDevice*>(dev);
×
89
  }
×
90
  else
91
  {
92
    audio_device = new Dataflow::AudioDevice(
3,060 ✔
93
        {Dataflow::AudioProtocolFactory::static_concreteKey(), "audio", {}});
1,530 ✔
94
    ctx.plugin<Explorer::DeviceDocumentPlugin>().list().setAudioDevice(audio_device);
1,530 ✔
95
  }
96

97
  devs.list().apply([this](auto& d) { on_deviceAdded(&d); });
4,594 ✔
98
  con(devs.list(), &Device::DeviceList::deviceAdded, this,
1,530 ✔
99
      &DocumentPlugin::on_deviceAdded);
1,530 ✔
100
  con(devs.list(), &Device::DeviceList::deviceRemoved, this, [this](auto* dev) {
1,575 ✔
101
    if(auto d = dev->getDevice())
45 ✔
102
      onDeviceChanged(d, nullptr);
33 ✔
103
  });
45 ✔
104

105
  connect(
1,530 ✔
106
      this, &DocumentPlugin::finished, this, &DocumentPlugin::on_finished,
107
      Qt::DirectConnection);
108
}
×
109

110
void DocumentPlugin::recreateBase()
490 ✔
111
{
112
  m_base = std::make_shared<BaseScenarioElement>(m_ctxData->context, this);
490 ✔
113
  connect(
490 ✔
114
      m_base.get(), &Execution::BaseScenarioElement::finished, this,
490 ✔
115
      [this] {
490 ✔
116
    auto& app = context().doc.app;
×
117
    // The transport actions only exist with a GUI: headless (--no-gui),
118
    // looking up Actions::Stop throws out_of_range.
119
    if(app.applicationSettings.gui)
×
120
      app.actions.action<Actions::Stop>().action()->trigger();
×
121
    else
122
      app.guiApplicationPlugin<Engine::ApplicationPlugin>().execution().request_stop();
×
123
      },
×
124
      Qt::QueuedConnection);
125
}
490 ✔
126

127
DocumentPlugin::~DocumentPlugin()
3,060 ✔
128
{
1,530 ✔
129
  if(m_base)
1,530 ✔
130
  {
131
    if(m_base->active())
×
132
    {
133
      m_base->baseInterval().stop();
×
134
      clear();
×
135
    }
×
136
  }
×
137

138
  if(audio_device)
1,530 ✔
139
  {
140
    if(auto devs = context().doc.findPlugin<Explorer::DeviceDocumentPlugin>())
1,530 ✔
141
    {
142
      const auto& rootNode = devs->explorer().rootNode();
1,530 ✔
143
      auto it = ossia::find_if(rootNode, [&](const Device::Node& val) {
1,763 ✔
144
        return val.is<Device::DeviceSettings>()
466 ✔
145
               && val.get<Device::DeviceSettings>().name == audio_device->name();
233 ✔
146
      });
147
      if(it != rootNode.end())
1,530 ✔
148
        devs->updateProxy.removeDevice(audio_device->settings());
×
149

150
      devs->list().setAudioDevice(nullptr);
1,530 ✔
151
    }
1,530 ✔
152
  }
1,530 ✔
153
  if(audio_device)
1,530 ✔
154
    delete audio_device;
1,530 ✔
155
  if(m_ctxData)
1,530 ✔
156
  {
157
    m_ctxData->context.alias.reset();
1,530 ✔
158
  }
1,530 ✔
159
}
3,060 ✔
160

161
// An edit command runs arbitrary UI code on behalf of the audio thread: one
162
// that fails must not unwind through the event loop (which aborts the
163
// application) nor starve the commands queued after it.
164
static void runEditCommand(ExecutionCommand& cmd) noexcept
51,079 ✔
165
{
166
  try
167
  {
168
    cmd();
51,079 ✔
169
  }
51,079 ✔
170
  catch(const std::exception& e)
171
  {
172
    qCritical() << "Execution: an edit command failed:" << e.what();
1 ✔
173
  }
1 ✔
174
  catch(...)
175
  {
176
    qCritical() << "Execution: an edit command failed (non-std exception)";
×
177
  }
1 ✔
178
}
51,080 ✔
179

180
void DocumentPlugin::ContextData::processEditCommands()
4,931,035 ✔
181
{
182
  ExecutionCommand cmd;
4,931,035 ✔
183
  GCCommand gc;
4,931,035 ✔
184
  bool ok = false;
4,931,035 ✔
185
  bool gc_ok = false;
4,931,035 ✔
186
  do
4,931,035 ✔
187
  {
188
    if((ok = m_editionQueue.try_dequeue(cmd)))
5,013,063 ✔
189
      runEditCommand(cmd);
51,079 ✔
190

191
    if((gc_ok = m_gcQueue.try_dequeue(gc)))
5,013,063 ✔
192
      gc();
39,209 ✔
193
  } while(ok || gc_ok);
5,013,063 ✔
194
}
4,931,035 ✔
195

196
void DocumentPlugin::processEditCommands()
1,027,891 ✔
197
{
198
  m_ctxData->processEditCommands();
1,027,891 ✔
199
}
1,027,891 ✔
200

201
void DocumentPlugin::on_finished()
352 ✔
202
{
203
  if(m_tid != -1)
352 ✔
204
  {
205
    killTimer(m_tid);
352 ✔
206
    m_tid = -1;
352 ✔
207
  }
352 ✔
208

209
  processEditCommands();
352 ✔
210
  clear();
352 ✔
211

212
  initExecState();
352 ✔
213

214
  for(auto& v : m_ctxData->setupContext.runtime_connections)
352 ✔
215
  {
216
    v.second.clear();
×
217
  }
218
  m_ctxData->setupContext.runtime_connections.clear();
352 ✔
219
}
352 ✔
220

221
void DocumentPlugin::initExecState()
2,372 ✔
222
{
223
  m_ctxData->execState = std::make_shared<ossia::execution_state>();
2,372 ✔
224
  auto& list
2,372 ✔
225
      = score::DocumentPlugin::context().plugin<Explorer::DeviceDocumentPlugin>().list();
2,372 ✔
226
  local_device = list.localDevice();
2,372 ✔
227
  if(audio_device)
2,372 ✔
228
    m_ctxData->execState->register_device(audio_device->getDevice());
842 ✔
229
  if(local_device)
2,372 ✔
230
    m_ctxData->execState->register_device(local_device->getDevice());
2,372 ✔
231
  for(auto dev : list.devices())
2,513 ✔
232
  {
233
    registerDevice(dev->getDevice());
141 ✔
234
  }
235
  m_ctxData->execState->apply_device_changes();
2,372 ✔
236
}
2,372 ✔
237

238
void DocumentPlugin::timerEvent(QTimerEvent* event)
6,539 ✔
239
{
240
  processEditCommands();
6,539 ✔
241
}
6,539 ✔
242

243
bool DocumentPlugin::registerDevice(ossia::net::device_base* d)
3,486 ✔
244
{
245
  if(!d)
3,486 ✔
246
    return false;
13 ✔
247
  if(m_ctxData->execState)
3,473 ✔
248
  {
249
    if(ossia::contains(m_ctxData->execState->edit_devices(), d))
3,273 ✔
250
      return false;
1,532 ✔
251
    m_ctxData->execState->register_device(d);
1,741 ✔
252

253
    if(m_base && m_base->active())
1,741 ✔
254
      d->get_protocol().start_execution();
25 ✔
255
    return true;
1,741 ✔
256
  }
257
  return false;
200 ✔
258
}
3,486 ✔
259

260
bool DocumentPlugin::unregisterDevice(ossia::net::device_base* d)
3,481 ✔
261
{
262
  if(!m_ctxData->execState)
3,481 ✔
263
    return false;
1,949 ✔
264
  if(!ossia::contains(m_ctxData->execState->edit_devices(), d))
1,532 ✔
265
    return false;
×
266

267
  m_ctxData->execState->unregister_device(d);
1,532 ✔
268

269
  // Ports keep raw pointers into the device tree and must be dropped from the
270
  // execution thread. The cleanup is queued, so by the time it runs this
271
  // device - and any other removed since - may be destroyed: snapshot the
272
  // addresses here and match on pointer identity below. One set for both kinds
273
  // also keeps the capture within the 128-byte ExecutionCommand budget.
274
  auto owned = deviceAddresses(*d);
1,532 ✔
275

276
  m_ctxData->context.executionQueue.enqueue(
3,064 ✔
277
      [wg = std::weak_ptr{m_ctxData->execGraph}, owned = std::move(owned)]() noexcept {
1,532 ✔
278
    if(auto g = wg.lock())
×
279
      clearAddresses(g->get_nodes(), owned);
×
280
  });
×
281
  return true;
1,532 ✔
282
}
3,481 ✔
283

284
void DocumentPlugin::updateDeviceExpressions()
1,594 ✔
285
{
286
  if(!m_base)
1,594 ✔
287
    return;
1,533 ✔
288

289
  auto& model = score::DocumentPlugin::context().document.model();
61 ✔
290
  for(auto ts : model.findChildren<Scenario::TimeSyncModel*>())
219 ✔
291
    if(auto c = score::findComponent<TimeSyncComponent>(ts->components()))
158 ✔
292
      if(c->OSSIATimeSync())
72 ✔
293
        c->updateTrigger();
36 ✔
294
  for(auto ev : model.findChildren<Scenario::EventModel*>())
219 ✔
295
    if(auto c = score::findComponent<EventComponent>(ev->components()))
158 ✔
296
      c->updateCondition();
36 ✔
297
}
1,594 ✔
298

299
void DocumentPlugin::waitForExecutionQueue()
1,532 ✔
300
{
301
  if(!m_base || !m_base->active())
1,532 ✔
302
    return;
1,532 ✔
303

304
  auto done = std::make_shared<std::atomic_bool>(false);
×
305
  m_ctxData->context.executionQueue.enqueue([done] { *done = true; });
×
306

307
  // The execution thread drains its queue every tick; the audio thread never
308
  // waits on this.
309
  QElapsedTimer t;
×
310
  t.start();
×
311
  while(!*done && t.elapsed() < 1000)
×
312
  {
313
    std::this_thread::yield();
×
314
    processEditCommands();
×
315
  }
316
  if(!*done)
×
317
    qDebug() << "Device removal: the execution thread did not answer in time";
×
318
}
1,532 ✔
319

320
void DocumentPlugin::makeGraph()
2,020 ✔
321
{
322
  using namespace ossia;
323
  auto& audiosettings = this->m_context.app.settings<Audio::Settings::Model>();
2,020 ✔
324

325
  static const Execution::Settings::SchedulingPolicies sched_t;
2,020 ✔
326
  static const Execution::Settings::OrderingPolicies order_t;
2,020 ✔
327
  static const Execution::Settings::MergingPolicies merge_t;
2,020 ✔
328

329
  // note: cas qui n'ont pas de sens: dynamic avec les cas ou on append les
330
  // valeurs. parallel avec dynamic il manque le cas "default score order" il
331
  // manque le log pour dynamic
332

333
  auto sched = settings.getScheduling();
2,020 ✔
334

335
  auto& execGraph = m_ctxData->execGraph;
2,020 ✔
336
  auto& execState = m_ctxData->execState;
2,020 ✔
337
  auto& bench = m_ctxData->bench;
2,020 ✔
338

339
  if(execGraph)
2,020 ✔
340
  {
341
    SCORE_SOFT_ASSERT(!execGraph); // "execGraph should always be unset here");
×
342
    execGraph->clear();
×
343
  }
×
344
  execGraph.reset();
2,020 ✔
345

346
  execState.reset();
2,020 ✔
347

348
  initExecState();
2,020 ✔
349

350
  execState->bufferSize = audiosettings.getBufferSize();
2,020 ✔
351
  execState->maxBufferSize = execState->bufferSize;
2,020 ✔
352
  execState->sampleRate = audiosettings.getRate();
2,020 ✔
353
  if(auto& audio = m_context.app.guiApplicationPlugin<Audio::ApplicationPlugin>().audio)
2,020 ✔
354
  {
355
    execState->inputLatency = audio->effective_input_latency;
565 ✔
356
    execState->outputLatency = audio->effective_output_latency;
565 ✔
357
  }
565 ✔
358

359
  // Publish audio clock state for video frame pacing
360
  Audio::execution_samples.store(0, std::memory_order_relaxed);
2,020 ✔
361
  Audio::execution_sample_rate.store(audiosettings.getRate(), std::memory_order_relaxed);
2,020 ✔
362
  execState->modelToSamplesRatio
2,020 ✔
363
      = audiosettings.getRate() / ossia::flicks_per_second<double>;
2,020 ✔
364
  execState->samplesToModelRatio
2,020 ✔
365
      = ossia::flicks_per_second<double> / audiosettings.getRate();
2,020 ✔
366
  execState->samples_since_start = 0;
2,020 ✔
367
  execState->start_date = 0; // TODO set it in the first callback
2,020 ✔
368
  execState->cur_date = execState->start_date;
2,020 ✔
369

370
  auto& p = ossia::audio_buffer_pool::instance();
2,020 ✔
371
  for(int i = 0; i < 500; i++)
1,012,020 ✔
372
  {
373
    auto v = p.acquire();
1,010,000 ✔
374
    v.reserve(execState->bufferSize);
1,010,000 ✔
375
    p.release(std::move(v));
1,010,000 ✔
376
  }
1,010,000 ✔
377

378
  ossia::graph_setup_options opt;
2,020 ✔
379
  opt.parallel = settings.getParallel();
2,020 ✔
380
  opt.parallel_threads = settings.getThreads();
2,020 ✔
381
  if(settings.getLogging())
2,020 ✔
382
    opt.log = ossia::logger_ptr();
×
383
  if(settings.getBench())
2,020 ✔
384
  {
385
    bench = std::make_shared<bench_map>();
×
386
    opt.bench = bench;
×
387
    opt.bench->clear();
×
388
  }
×
389

390
  if(sched == sched_t.StaticFixed)
2,020 ✔
391
    opt.scheduling = ossia::graph_setup_options::StaticFixed;
×
392
  else if(sched == sched_t.StaticBFS)
2,020 ✔
393
    opt.scheduling = ossia::graph_setup_options::StaticBFS;
×
394
  else if(sched == sched_t.StaticTC)
2,020 ✔
395
    opt.scheduling = ossia::graph_setup_options::StaticTC;
2,020 ✔
396
  else if(sched == sched_t.Dynamic)
×
397
    opt.scheduling = ossia::graph_setup_options::Dynamic;
×
398

399
  opt.scheduling = ossia::graph_setup_options::StaticFixed;
2,020 ✔
400
  execGraph = ossia::make_graph(opt);
2,020 ✔
401
}
2,020 ✔
402

403
void DocumentPlugin::reload(bool forcePlay, Scenario::IntervalModel& cst)
490 ✔
404
{
405
  if(m_base)
490 ✔
406
  {
407
    if(m_base->active())
×
408
    {
409
      m_base->baseInterval().stop();
×
410
    }
×
411
  }
×
412
  clear();
490 ✔
413

414
  const score::DocumentContext& ctx = m_context;
490 ✔
415
  auto& settings = ctx.app.settings<Execution::Settings::Model>();
490 ✔
416

417
  SCORE_ASSERT(m_ctxData);
490 ✔
418
  m_ctxData->context.time = settings.makeTimeFunction(ctx);
490 ✔
419
  m_ctxData->context.reverseTime = settings.makeReverseTimeFunction(ctx);
490 ✔
420

421
  // Notify devices that they have to start running stuff, polling frames, etc.
422
  auto& devs = m_context.plugin<Explorer::DeviceDocumentPlugin>();
490 ✔
423
  devs.list().apply([](const Device::DeviceInterface& d) {
1,525 ✔
424
    if(auto dev = d.getDevice())
1,035 ✔
425
      dev->get_protocol().start_execution();
1,031 ✔
426
  });
1,035 ✔
427

428
  makeGraph();
490 ✔
429

430
  auto parent = dynamic_cast<Scenario::ScenarioInterface*>(cst.parent());
490 ✔
431
  SCORE_ASSERT(parent);
490 ✔
432

433
  recreateBase();
490 ✔
434
  m_base->init(forcePlay, BaseScenarioRefContainer{cst, *parent});
490 ✔
435
  m_ctxData->m_created = true;
490 ✔
436

437
  auto& model = context().doc.model<Scenario::ScenarioDocumentModel>();
490 ✔
438
  Transaction t{m_ctxData->context};
490 ✔
439
  for(auto& cable : model.cables)
771 ✔
440
  {
441
    m_ctxData->setupContext.connectCable(cable, t);
281 ✔
442
  }
443
  t.run_all();
490 ✔
444

445
  m_tid = startTimer(32);
490 ✔
446
  started();
490 ✔
447
}
490 ✔
448

449
void DocumentPlugin::clear()
5,105 ✔
450
{
451
  if(m_ctxData)
5,105 ✔
452
  {
453
    m_ctxData->setupContext.inlets.clear();
5,105 ✔
454
    m_ctxData->setupContext.outlets.clear();
5,105 ✔
455
    m_ctxData->setupContext.m_cables.clear();
5,105 ✔
456
    m_ctxData->setupContext.proc_map.clear();
5,105 ✔
457
  }
5,105 ✔
458
  // TODO do this in some shared object instead.
459
  m_base.reset();
5,105 ✔
460

461
  if(m_ctxData)
5,105 ✔
462
  {
463
    for(int i = 0; i < 100; i++)
515,605 ✔
464
    {
465
      processEditCommands();
510,500 ✔
466
      std::this_thread::yield();
510,500 ✔
467
    }
510,500 ✔
468
  }
5,105 ✔
469
  if(m_ctxData)
5,105 ✔
470
  {
471
    m_ctxData->m_created = false;
5,105 ✔
472
    if(m_ctxData)
5,105 ✔
473
      for(int i = 0; i < 100; i++)
515,605 ✔
474
      {
475
        processEditCommands();
510,500 ✔
476
        std::this_thread::yield();
510,500 ✔
477
        std::atomic_thread_fence(std::memory_order_seq_cst);
510,500 ✔
478
      }
515,605 ✔
479
  }
5,105 ✔
480
  // Releasing m_ctxData rarely destroys it: the tick holds a strong reference.
481
  // Mark it retired so it stops acting on its stale state while it survives.
482
  if(m_ctxData)
5,105 ✔
483
  {
484
    m_ctxData->context.retired = true;
5,105 ✔
485
    if(m_ctxData->execState)
5,105 ✔
486
      m_ctxData->execState->clear_devices();
2,306 ✔
487
  }
5,105 ✔
488

489
  m_ctxData.reset();
5,105 ✔
490
  m_ctxData = std::make_shared<ContextData>(this->m_context);
5,105 ✔
491
  m_ctxData->context.alias = m_ctxData;
5,105 ✔
492

493
  auto& model = this->m_context.model<Scenario::ScenarioDocumentModel>();
5,105 ✔
494
  model.cables.mutable_added.connect<&SetupContext::on_cableCreated>(
10,210 ✔
495
      m_ctxData->setupContext);
5,105 ✔
496
  model.cables.removing.connect<&SetupContext::on_cableRemoved>(m_ctxData->setupContext);
5,105 ✔
497

498
  // Notify devices that they have to stop running stuff, polling frames, etc.
499
  auto& devs = m_context.plugin<Explorer::DeviceDocumentPlugin>();
5,105 ✔
500
  devs.list().apply([](const Device::DeviceInterface& d) {
15,659 ✔
501
    if(auto dev = d.getDevice())
10,554 ✔
502
      dev->get_protocol().stop_execution();
10,448 ✔
503
  });
10,554 ✔
504

505
  cleared();
5,105 ✔
506
}
5,105 ✔
507

508
void DocumentPlugin::on_documentClosing()
1,530 ✔
509
{
510
  if(m_base && m_base->active())
1,530 ✔
511
  {
512
    m_base->baseInterval().stop();
123 ✔
513
    m_context.app.guiApplicationPlugin<Engine::ApplicationPlugin>()
123 ✔
514
        .execution()
123 ✔
515
        .request_stop();
123 ✔
516
    clear();
123 ✔
517
  }
123 ✔
518
  m_ctxData->execState.reset();
1,530 ✔
519
}
1,530 ✔
520

521
const std::shared_ptr<BaseScenarioElement>& DocumentPlugin::baseScenario() const noexcept
1,666 ✔
522
{
523
  return m_base;
1,666 ✔
524
}
525

526
void DocumentPlugin::playStartState()
3 ✔
527
{
528
  auto scenar = score::IDocument::try_get<Scenario::ScenarioDocumentModel>(
3 ✔
529
      this->m_context.document);
3 ✔
530
  if(!scenar)
3 ✔
531
    return;
×
532
  auto& sm = scenar->baseScenario().startState();
3 ✔
533

534
  Engine::score_to_ossia::play_state_from_ui(sm, this->context());
3 ✔
535
}
3 ✔
536

537
void DocumentPlugin::playStopState()
354 ✔
538
{
539
  auto scenar = score::IDocument::try_get<Scenario::ScenarioDocumentModel>(
354 ✔
540
      this->m_context.document);
354 ✔
541
  if(!scenar)
354 ✔
542
    return;
×
543
  auto& sm = scenar->baseScenario().endState();
354 ✔
544
  Engine::score_to_ossia::play_state_from_ui(sm, this->context());
354 ✔
545
}
354 ✔
546

547
bool DocumentPlugin::isPlaying() const
1,515 ✔
548
{
549
  if(m_base)
1,515 ✔
550
    return m_base->active();
283 ✔
551
  return false;
1,232 ✔
552
}
1,515 ✔
553

554
const ExecutionController& DocumentPlugin::executionController() const noexcept
354 ✔
555
{
556
  return m_context.app.guiApplicationPlugin<Engine::ApplicationPlugin>().execution();
354 ✔
557
}
558

559
std::shared_ptr<ossia::audio_protocol> DocumentPlugin::audioProto()
352 ✔
560
{
561
  auto dev = audio_device->sharedDevice();
352 ✔
562
  auto proto
352 ✔
563
      = &static_cast<ossia::audio_protocol&>(audio_device->getDevice()->get_protocol());
352 ✔
564

565
  return std::shared_ptr<ossia::audio_protocol>(dev, proto);
352 ✔
566
}
352 ✔
567

568
void DocumentPlugin::runAllCommands() const
1,312 ✔
569
{
570
  std::atomic_thread_fence(std::memory_order_seq_cst);
1,312 ✔
571
  ExecutionCommand com;
1,312 ✔
572
  while(m_ctxData->m_execQueue.try_dequeue(com))
6,818 ✔
573
    com();
5,506 ✔
574
}
1,312 ✔
575

576
void DocumentPlugin::registerAction(ExecutionAction& act)
1,530 ✔
577
{
578
  m_actions.push_back(&act);
1,530 ✔
579
}
1,530 ✔
580

581
void DocumentPlugin::slot_bench(ossia::bench_map b, int64_t ns)
×
582
{
583
  for(const auto& p : b)
×
584
  {
585
    if(p.second)
×
586
    {
587
      auto proc = m_ctxData->setupContext.proc_map.find(p.first);
×
588
      if(proc != m_ctxData->setupContext.proc_map.end())
×
589
      {
590
        if(proc->second)
×
591
        {
592
          const_cast<Process::ProcessModel*>(proc->second)
×
593
              ->benchmark(100. * *p.second / (double)ns);
×
594
        }
×
595
      }
×
596
    }
×
597
  }
598
}
×
599

600
void DocumentPlugin::on_deviceAdded(Device::DeviceInterface* dev)
3,339 ✔
601
{
602
  // Also for an unconnected device: its ossia device arrives later through
603
  // deviceChanged.
604
  connect(
3,339 ✔
605
      dev, &Device::DeviceInterface::deviceChanged, this,
3,339 ✔
606
      &DocumentPlugin::onDeviceChanged);
607
  // Most devices destroy their nodes before they say the device changed.
608
  connect(
3,339 ✔
609
      dev, &Device::DeviceInterface::deviceClearing, this,
3,339 ✔
610
      [this](ossia::net::device_base* d) { onDeviceChanged(d, nullptr); });
3,552 ✔
611
  // A device that comes back gets its nodes after it says it changed, and some
612
  // only learn their namespace later on.
613
  connect(
3,339 ✔
614
      dev, &Device::DeviceInterface::pathAdded, this,
3,339 ✔
615
      &DocumentPlugin::requestExpressionUpdate);
616
  connect(
3,339 ✔
617
      dev, &Device::DeviceInterface::namespaceUpdated, this,
3,339 ✔
618
      &DocumentPlugin::requestExpressionUpdate);
619
  if(auto d = dev->getDevice())
3,339 ✔
620
    onDeviceChanged(nullptr, d);
3,251 ✔
621
}
3,339 ✔
622

623
void DocumentPlugin::requestExpressionUpdate()
78,480 ✔
624
{
625
  if(!m_base || m_expressionUpdatePending)
78,480 ✔
626
    return;
78,418 ✔
627
  m_expressionUpdatePending = true;
62 ✔
628
  QTimer::singleShot(0, this, [this] {
124 ✔
629
    m_expressionUpdatePending = false;
62 ✔
630
    updateDeviceExpressions();
62 ✔
631
  });
62 ✔
632
}
78,480 ✔
633

634
void DocumentPlugin::onDeviceChanged(
7,292 ✔
635
    ossia::net::device_base* old_dev, ossia::net::device_base* new_dev)
636
{
637
  const bool removed = old_dev && unregisterDevice(old_dev);
7,292 ✔
638
  const bool added = new_dev && registerDevice(new_dev);
7,292 ✔
639

640
  // Triggers and conditions resolve their addresses once: those on this
641
  // device are false while it is gone, and work again when it comes back.
642
  if(removed)
7,292 ✔
643
  {
644
    updateDeviceExpressions();
1,532 ✔
645

646
    // The old device's nodes are destroyed when this returns: the execution
647
    // thread must release the ports and expressions pointing into them first.
648
    waitForExecutionQueue();
1,532 ✔
649
  }
1,532 ✔
650
  else if(added)
5,760 ✔
651
  {
652
    requestExpressionUpdate();
1,614 ✔
653
  }
1,614 ✔
654
}
7,292 ✔
655
}
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