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

ossia / score / 40987115292

30 Oct 2026 01:27AM UTC coverage: 51.229% (+2.1%) from 49.178%
40987115292

push

github

jcelerier
avendish: main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

179452 of 350293 relevant lines covered (51.23%)

175809.48 hits per line

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

84.62
/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)
42,831 ✔
60
namespace Execution
61
{
62
DocumentPlugin::ContextData::ContextData(const score::DocumentContext& ctx)
6,508 ✔
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,492 ✔
78
    : score::DocumentPlugin{ctx, "OSSIADocumentPlugin", parent}
1,492 ✔
79
    , settings{ctx.app.settings<Execution::Settings::Model>()}
1,492 ✔
80
    , m_ctxData{std::make_shared<ContextData>(ctx)}
81
{
1,492 ✔
82
  m_ctxData->context.alias = m_ctxData;
1,492 ✔
83
  makeGraph();
1,492 ✔
84
  auto& devs = ctx.plugin<Explorer::DeviceDocumentPlugin>();
1,492 ✔
85
  local_device = devs.list().localDevice();
1,492 ✔
86
  if(auto dev = devs.list().audioDevice())
1,492 ✔
87
  {
88
    audio_device = static_cast<Dataflow::AudioDevice*>(dev);
×
89
  }
×
90
  else
91
  {
92
    audio_device = new Dataflow::AudioDevice(
2,984 ✔
93
        {Dataflow::AudioProtocolFactory::static_concreteKey(), "audio", {}});
1,492 ✔
94
    ctx.plugin<Explorer::DeviceDocumentPlugin>().list().setAudioDevice(audio_device);
1,492 ✔
95
  }
96

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

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

110
void DocumentPlugin::recreateBase()
484 ✔
111
{
112
  m_base = std::make_shared<BaseScenarioElement>(m_ctxData->context, this);
484 ✔
113
  connect(
484 ✔
114
      m_base.get(), &Execution::BaseScenarioElement::finished, this,
484 ✔
115
      [this] {
484 ✔
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
}
484 ✔
126

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

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

150
      devs->list().setAudioDevice(nullptr);
1,492 ✔
151
    }
1,492 ✔
152
  }
1,492 ✔
153
  if(audio_device)
1,492 ✔
154
    delete audio_device;
1,492 ✔
155
  if(m_ctxData)
1,492 ✔
156
  {
157
    m_ctxData->context.alias.reset();
1,492 ✔
158
  }
1,492 ✔
159
}
2,984 ✔
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
43,235 ✔
165
{
166
  try
167
  {
168
    cmd();
43,235 ✔
169
  }
43,235 ✔
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
}
43,236 ✔
179

180
void DocumentPlugin::ContextData::processEditCommands()
4,934,225 ✔
181
{
182
  ExecutionCommand cmd;
4,934,225 ✔
183
  GCCommand gc;
4,934,225 ✔
184
  bool ok = false;
4,934,225 ✔
185
  bool gc_ok = false;
4,934,225 ✔
186
  do
4,934,225 ✔
187
  {
188
    if((ok = m_editionQueue.try_dequeue(cmd)))
5,008,007 ✔
189
      runEditCommand(cmd);
43,235 ✔
190

191
    if((gc_ok = m_gcQueue.try_dequeue(gc)))
5,008,007 ✔
192
      gc();
39,297 ✔
193
  } while(ok || gc_ok);
5,008,007 ✔
194
}
4,934,225 ✔
195

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

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

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

212
  initExecState();
351 ✔
213

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

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

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

243
bool DocumentPlugin::registerDevice(ossia::net::device_base* d)
3,410 ✔
244
{
245
  if(!d)
3,410 ✔
246
    return false;
13 ✔
247
  if(m_ctxData->execState)
3,397 ✔
248
  {
249
    if(ossia::contains(m_ctxData->execState->edit_devices(), d))
3,197 ✔
250
      return false;
1,494 ✔
251
    m_ctxData->execState->register_device(d);
1,703 ✔
252

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

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

267
  m_ctxData->execState->unregister_device(d);
1,494 ✔
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,494 ✔
275

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

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

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

299
void DocumentPlugin::waitForExecutionQueue()
1,494 ✔
300
{
301
  if(!m_base || !m_base->active())
1,494 ✔
302
    return;
1,494 ✔
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,494 ✔
319

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

325
  static const Execution::Settings::SchedulingPolicies sched_t;
1,976 ✔
326
  static const Execution::Settings::OrderingPolicies order_t;
1,976 ✔
327
  static const Execution::Settings::MergingPolicies merge_t;
1,976 ✔
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();
1,976 ✔
334

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

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

346
  execState.reset();
1,976 ✔
347

348
  initExecState();
1,976 ✔
349

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

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

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

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

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

398
  opt.scheduling = ossia::graph_setup_options::StaticFixed;
1,976 ✔
399
  execGraph = ossia::make_graph(opt);
1,976 ✔
400
}
1,976 ✔
401

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

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

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

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

427
  makeGraph();
484 ✔
428

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

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

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

444
  m_tid = startTimer(32);
484 ✔
445
  started();
484 ✔
446
}
484 ✔
447

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

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

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

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

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

504
  cleared();
5,016 ✔
505
}
5,016 ✔
506

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

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

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

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

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

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

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

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

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

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

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

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

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

622
void DocumentPlugin::requestExpressionUpdate()
94,997 ✔
623
{
624
  if(!m_base || m_expressionUpdatePending)
94,997 ✔
625
    return;
94,698 ✔
626
  m_expressionUpdatePending = true;
299 ✔
627
  QTimer::singleShot(0, this, [this] {
598 ✔
628
    m_expressionUpdatePending = false;
299 ✔
629
    updateDeviceExpressions();
299 ✔
630
  });
299 ✔
631
}
94,997 ✔
632

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

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

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