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

ossia / score / 44990834010

22 Nov 2026 05:46AM UTC coverage: 61.818% (+0.2%) from 61.617%
44990834010

push

github

jcelerier
UI: the main window opens centred on the screen under the mouse and fits a 4K screen at 300%

The window was sized from the primary screen, while Qt opens it on the
screen under the mouse. When it did not fit there, Qt left it at logical
0,0, which a screen of another scale maps outside the desktop
(x=-10248 on a 100% primary with 300% screens beside it). It is now sized
from the screen it opens on and placed at its centre, with room kept for
the title bar, and on Wayland for a panel the compositor does not report:
three quarters of the screen, but at least 1000x680 when the screen allows.

The inspector and the object tree ask for 200 and 100 px instead of 400
and 160, so the window's minimum height drops from 744 to 484 logical px.
The start screen's header shrinks from 220 to 140 px on a window shorter
than 640, so the start screen fits down to 560: a 4K screen at 300% leaves
about 590 under the macOS menu bar, dock and title bar.

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

266655 of 799939 branches covered (33.33%)

36 of 38 new or added lines in 4 files covered. (94.74%)

3164 existing lines in 91 files now uncovered.

271878 of 439807 relevant lines covered (61.82%)

767748.57 hits per line

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

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

3
#include <LocalTree/LocalTreeDocumentPlugin.hpp>
4

5
#include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
6
#include <Explorer/Explorer/DeviceExplorerModel.hpp>
7
#include <Explorer/Explorer/DeviceExplorerWidget.hpp>
8

9
#include <Scenario/Application/ScenarioActions.hpp>
10
#include <Scenario/Application/ScenarioApplicationPlugin.hpp>
11
#include <Scenario/Document/BaseScenario/BaseScenario.hpp>
12
#include <Scenario/Document/Interval/IntervalExecution.hpp>
13
#include <Scenario/Document/Interval/IntervalModel.hpp>
14
#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
15
#include <Scenario/Document/ScenarioDocument/ScenarioDocumentPresenter.hpp>
16
#include <Scenario/Execution/score2OSSIA.hpp>
17
#include <Scenario/Process/ScenarioExecution.hpp>
18
#include <Scenario/Process/ScenarioModel.hpp>
19

20
#include <Audio/AudioApplicationPlugin.hpp>
21
#include <Audio/Settings/Model.hpp>
22
#include <Execution/Clock/ClockFactory.hpp>
23
#include <Execution/DocumentPlugin.hpp>
24
#include <Execution/Settings/ExecutorModel.hpp>
25

26
#include <score/actions/ActionManager.hpp>
27
#include <score/model/ComponentUtils.hpp>
28
#include <score/tools/Bind.hpp>
29
#include <score/widgets/MessageBox.hpp>
30

31
#include <core/application/ApplicationSettings.hpp>
32
#include <core/document/Document.hpp>
33
#include <core/presenter/DocumentManager.hpp>
34

35
#include <ossia/dataflow/execution_state.hpp>
36
#include <ossia/editor/scenario/time_interval.hpp>
37
#include <ossia/editor/state/state.hpp>
38

39
#include <QGuiApplication>
40
#include <QMainWindow>
41

42
#include <Transport/DocumentPlugin.hpp>
43
#include <Transport/TransportInterface.hpp>
44

45
#include <wobjectimpl.h>
46
W_OBJECT_IMPL(Execution::ExecutionController)
13,743 !
47

48
/**
49
 * Execution state-machine explanation:
50
 *
51
 * * There are multiple sources for what controls the transport:
52
 * - From the GUI
53
 * - From the local tree or remote control plug-in
54
 * - From an external software (e.g. JACK transport)
55
 * - Automatically (e.g. --autoplay argument on command-line)
56
 *
57
 * * No matter the transport source, if there's a GUI its state must be consistent
58
 *   with what happens.
59
 *
60
 * Thus:
61
 * * The do_*** functions are requests
62
 * * The trigger_*** functions will perform the action and set the GUI state correctly
63
 * * The on_*** contain the actual implementation of the transport operation
64
 *
65
 * Notes on QAction:
66
 * * QAction::toggle(); -> will send toggled(true/false);
67
 * * QAction::trigger(); -> will send toggled(true/false); triggered(true/false);
68
 * * QAction::check(b); -> will send toggled(b);
69
 * * GUI: like QAction::trigger
70
 *
71
 * Thus, triggered can be used to differentiate between
72
 * * called from the GUI
73
 * * called from the software
74
 *
75
 * Example of call sequence:
76
 *
77
 * * Pressing the "global play button" (stop -> play):
78
 *   -> QAction::toggled(true)
79
 *     -> GUI changes (see TransportActions ctor)
80
 *   -> QAction::triggered(true)
81
 *     -> ApplicationPlugin::request_play_global(true)
82
 *     -> TransportInterface::requestPlay()
83
 *   -> the transport implementation eventually sends the "play()" signal
84
 *     -> &ApplicationPlugin::trigger_play_global
85
 *
86
 * * Pressing the "global play button" (play -> pause):
87
 *   -> QAction::toggled(false)
88
 *     -> GUI changes (see TransportActions ctor)
89
 *   -> QAction::triggered(false)
90
 *     -> ApplicationPlugin::request_play_global(false)
91
 *     -> TransportInterface::requestPause()
92
 *   -> the transport implementation eventually sends the "pause()" signal
93
 *     -> &ApplicationPlugin::trigger_pause()
94
 *
95
 * * Playing with "play from here":
96
 *   -> ApplicationPlugin::request_play(true, t)
97
 *   -> TransportInterface::requestTransport(t)
98
 *   -> TransportInterface::requestPlay
99
 *   -> The transport implementation eventually sends the "transport()" signal
100
 *     -> ??
101
 *   -> The transport implementation eventually sends the "play()" signal
102
 *     -> &ApplicationPlugin::trigger_play_global
103
 *
104
 * * Starting the transport from QJackCtl with a GUI
105
 *   -> the transport implementation eventually sends the "play()" signal
106
 *     -> &ApplicationPlugin::trigger_play_global
107
 *
108
 * * Starting the transport from QJackCtl without a GUI
109
 *   -> the transport implementation eventually sends the "play()" signal
110
 *     -> &ApplicationPlugin::trigger_play_global
111
 *
112
 * * Receiving a "/play" message to the local tree with a GUI
113
 *   -> ApplicationPlugin::request_play
114
 *   -> TransportInterface::requestPlay
115
 *   -> The transport implementation eventually sends the "play()" signal
116
 *     -> &ApplicationPlugin::trigger_play_global
117
 *
118
 * * Receiving a "/play" message to the local tree without a GUI
119
 */
120

121
namespace Execution
122
{
123
ExecutionController::ExecutionController(const score::GUIApplicationContext& ctx)
19,736 ✔
124
    : context{ctx}
4,934 ✔
125
    , m_scenario{ctx.guiApplicationPlugin<Scenario::ScenarioApplicationPlugin>()}
4,934 !
126
    , m_actions{m_scenario.transportActions()}
4,934 !
127
{
4,934 ✔
128
  if(ctx.applicationSettings.gui)
4,934 ✔
129
  {
130
    auto& acts = ctx.actions;
4,812 ✔
131
    using namespace Actions;
132
    connect(
4,812 !
133
        acts.action<Play>().action(), &QAction::triggered, this,
4,812 !
134
        &ExecutionController::request_play_local, Qt::QueuedConnection);
4,812 ✔
135

136
    connect(
4,812 !
137
        acts.action<PlayGlobal>().action(), &QAction::triggered, this,
4,812 !
138
        &ExecutionController::request_play_global, Qt::QueuedConnection);
4,812 ✔
139

140
    connect(
4,812 !
141
        acts.action<Stop>().action(), &QAction::triggered, this,
4,812 !
142
        &ExecutionController::request_stop, Qt::QueuedConnection);
4,812 ✔
143

144
    connect(
4,812 !
145
        acts.action<Reinitialize>().action(), &QAction::triggered, this,
4,812 !
146
        &ExecutionController::trigger_reinitialize, Qt::QueuedConnection);
4,812 ✔
147

148
    connect(
4,812 !
149
        &m_scenario.execution(), &Scenario::ScenarioExecution::playAtDate, this,
4,812 !
150
        qOverload<TimeVal>(&ExecutionController::request_play_from_here));
4,812 ✔
151
    connect(
4,812 !
152
        &m_scenario.execution(), &Scenario::ScenarioExecution::playIntervalAtDate,
4,812 !
153
        this, [this](Scenario::IntervalModel* itv, const TimeVal& t) {
4,812 ✔
154
      if(itv)
×
155
        request_play_from_here(*itv, t);
×
156
    });
×
157
    connect(
4,812 !
158
        &m_scenario.execution(), &Scenario::ScenarioExecution::beginScrub, this,
4,812 !
159
        &ExecutionController::request_begin_scrub);
4,812 ✔
160
    connect(
4,812 !
161
        &m_scenario.execution(), &Scenario::ScenarioExecution::scrub, this,
4,812 !
162
        &ExecutionController::request_scrub);
4,812 ✔
163
    connect(
4,812 !
164
        &m_scenario.execution(), &Scenario::ScenarioExecution::endScrub, this,
4,812 !
165
        &ExecutionController::request_end_scrub);
4,812 ✔
166
  }
4,812 ✔
167
}
4,934 ✔
168

169
ExecutionController::~ExecutionController()
4,933 ✔
170
{
4,933 ✔
171
  if(m_transport)
4,933 !
172
    m_transport->teardown();
4,933 !
173
}
4,933 ✔
174

175
TransportInterface& ExecutionController::transport() const noexcept
653 ✔
176
{
177
  return *m_transport;
653 ✔
178
}
179

180
void ExecutionController::request_play_global(bool b)
546 ✔
181
{
182
  if(b)
546 ✔
183
  {
184
    this->m_requestLocalPlay = false;
538 ✔
185
    m_transport->requestPlay();
538 ✔
186
  }
538 ✔
187
  else
188
  {
189
    m_transport->requestPause();
8 ✔
190
  }
191
}
546 ✔
192

193
void ExecutionController::request_play_local(bool b)
23 ✔
194
{
195
  if(b)
23 !
196
  {
197
    this->m_requestLocalPlay = true;
23 ✔
198
    m_transport->requestPlay();
23 ✔
199
  }
23 ✔
200
  else
201
  {
202
    m_transport->requestPause();
×
203
  }
204
}
23 ✔
205

206
void ExecutionController::request_play_interval(
3 ✔
207
    Scenario::IntervalModel& itv, exec_setup_fun setup, TimeVal t)
208
{
209
  m_intervalsToPlay.push_back({itv, std::move(setup), t});
3 !
210
  m_transport->requestPlay();
3 ✔
211
}
3 ✔
212

213
void ExecutionController::request_stop_interval(Scenario::IntervalModel& itv)
1 ✔
214
{
215
  stop_interval(itv);
1 ✔
216
}
1 ✔
217

218
void ExecutionController::request_stop()
7,011 ✔
219
{
220
  m_transport->requestStop();
7,011 ✔
221
}
7,011 ✔
222

223
void ExecutionController::trigger_play()
573 ✔
224
{
225
  if(!m_intervalsToPlay.empty())
573 ✔
226
  {
227
    m_actions.onPlayLocal();
3 ✔
228
    for(auto& to_play : m_intervalsToPlay)
6 ✔
229
      play_interval(to_play.interval, std::move(to_play.setup), to_play.t);
3 !
230
    m_intervalsToPlay.clear();
3 ✔
231
  }
3 ✔
232
  else if(this->m_requestLocalPlay)
570 ✔
233
  {
234
    m_actions.onPlayLocal();
23 ✔
235
    on_play_local(true);
23 ✔
236
  }
23 ✔
237
  else
238
  {
239
    m_actions.onPlayGlobal();
547 ✔
240
    on_play_global(true);
547 ✔
241
  }
242

243
  // Note: we set this here so that external "play" request are global
244
  // as it makes more sense:
245
  // local play is just for checking a sub-part of the score, but the external tools's times will
246
  // always be relative to the whole general score
247
  this->m_requestLocalPlay = false;
573 ✔
248
}
573 ✔
249

250
void ExecutionController::trigger_pause()
8 ✔
251
{
252
  m_actions.onPause();
8 ✔
253
  on_pause();
8 ✔
254
}
8 ✔
255

256
void ExecutionController::trigger_stop()
7,607 ✔
257
{
258
  m_actions.onStop();
7,607 ✔
259
  on_stop();
7,607 ✔
260

261
  // See note above
262
  this->m_requestLocalPlay = false;
7,607 ✔
263
}
7,607 ✔
264

265
void ExecutionController::trigger_reinitialize()
1 ✔
266
{
267
  m_actions.onStop();
1 ✔
268
  on_reinitialize();
1 ✔
269

270
  // See note above
271
  this->m_requestLocalPlay = false;
1 ✔
272
}
1 ✔
273

274
void ExecutionController::on_play_global(bool b)
547 ✔
275
{
276
  if(auto scenar = currentScenarioModel())
547 !
277
  {
278
    if(b)
547 !
279
    {
280
      play_interval(scenar->baseInterval(), {}, TimeVal::zero());
547 !
281
    }
547 ✔
282
    else
283
    {
284
      on_pause();
×
285
    }
286
  }
547 ✔
287
}
547 ✔
288

289
void ExecutionController::on_play_local(bool b, ::TimeVal t)
25 ✔
290
{
291
  if(auto scenar = currentScenarioPresenter();
25 !
292
     scenar && scenar->displayedElements.initialized())
25 !
293
  {
294
    if(b)
×
295
    {
296
      std::optional<TimeVal> startTime;
×
297
      auto& itv = scenar->displayedInterval();
×
298
      {
299
        if(itv.startMarker() != TimeVal::zero())
×
300
          startTime = itv.startMarker();
×
301
      }
302
      if(!startTime)
×
303
        if(t != TimeVal::zero())
×
304
          startTime = t;
×
305

306
      if(startTime && m_playing && m_clock)
×
307
      {
308
        if(m_clock->paused())
×
309
        {
310
          on_transport(*startTime);
×
311
        }
×
312
      }
×
313
      play_interval(scenar->displayedInterval(), {}, startTime ? *startTime : t);
×
314
    }
×
315
    else
316
    {
317
      on_pause();
×
318
    }
319
  }
×
320
  else if(auto scenar = currentScenarioModel(); scenar && b)
25 !
321
  {
322
    play_interval(scenar->baseInterval(), {}, t);
25 !
323
  }
25 ✔
324
  else
325
  {
326
    on_play_global(b);
×
327
  }
328
}
25 ✔
329

330
void ExecutionController::on_play_local(bool b)
23 ✔
331
{
332
  on_play_local(b, ::TimeVal::zero());
23 ✔
333
}
23 ✔
334

335
void ExecutionController::on_pause()
8 ✔
336
{
337
  ensure_audio_engine();
8 ✔
338

339
  if(m_clock)
8 ✔
340
  {
341
    m_clock->pause();
7 ✔
342
    m_paused = true;
7 ✔
343

344
    if(auto doc = currentDocument())
7 !
345
    {
346
      doc->context().execTimer.stop();
7 ✔
347

348
      if(auto transport_plug = doc->context().findPlugin<Transport::DocumentPlugin>())
7 !
349
        transport_plug->pause();
7 ✔
350
    }
7 ✔
351
  }
7 ✔
352
}
8 ✔
353

354
void ExecutionController::on_transport(TimeVal t)
3 ✔
355
{
356
  if(!m_clock)
3 ✔
357
    return;
2 ✔
358

359
  SCORE_ASSERT(m_clock->scenario);
1 !
360
  auto itv = m_clock->scenario->baseInterval().OSSIAInterval();
1 ✔
361
  if(!itv)
1 !
362
    return;
×
363

364
  auto& settings = context.settings<Execution::Settings::Model>();
1 !
365
  auto& ctx = m_clock->context;
1 ✔
366
  if(settings.getTransportValueCompilation())
1 !
367
  {
368
    auto execState = m_clock->context.execState;
×
369
    ctx.executionQueue.enqueue([execState, itv, time = m_clock->context.time(t)] {
×
370
      itv->offset(time);
×
371
      execState->commit();
×
372
    });
×
373
  }
×
374
  else
375
  {
376
    ctx.executionQueue.enqueue(
1 !
377
        [itv, time = m_clock->context.time(t)] { itv->transport(time); });
2 !
378
  }
379

380
  if(auto doc = currentDocument())
1 !
381
    if(auto transport_plug = doc->context().findPlugin<Transport::DocumentPlugin>())
2 !
382
      transport_plug->transport(t);
1 !
383
}
3 ✔
384

385
void ExecutionController::on_begin_scrub(TimeVal t)
×
386
{
387
  on_transport(t);
×
388
}
×
389

390
void ExecutionController::on_scrub(TimeVal t)
×
391
{
392
  on_transport(t);
×
393
}
×
394

395
void ExecutionController::on_end_scrub(TimeVal t)
×
396
{
397
  on_transport(t);
×
398
}
×
399

400
void ExecutionController::request_play_from_localtree(bool val)
×
401
{
402
  if(!m_playing && val)
×
403
  {
404
    // not playing, play requested
405
    request_play_local(val);
×
406
  }
×
407
  else if(m_playing)
×
408
  {
409
    if(m_paused == val)
×
410
    {
411
      // paused, play requested
412
      // or playing, pause requested
413
      request_play_local(val);
×
414
    }
×
415
  }
×
416
}
×
417

418
void ExecutionController::request_play_global_from_localtree(bool val)
×
419
{
420
  if(!m_playing && val)
×
421
  {
422
    // not playing, play requested
423
    request_play_global(val);
×
424
  }
×
425
  else if(m_playing)
×
426
  {
427
    if(m_paused == val)
×
428
    {
429
      // paused, play requested
430
      // or playing, pause requested
431
      request_play_global(val);
×
432
    }
×
433
  }
×
434
}
×
435

436
void ExecutionController::request_transport_from_localtree(TimeVal t)
2 ✔
437
{
438
  m_transport->requestTransport(t);
2 ✔
439
}
2 ✔
440

441
void ExecutionController::request_stop_from_localtree()
23 ✔
442
{
443
  trigger_stop();
23 ✔
444
}
23 ✔
445

446
void ExecutionController::request_reinitialize_from_localtree()
1 ✔
447
{
448
  trigger_reinitialize();
1 ✔
449
}
1 ✔
450

451
void ExecutionController::request_play_from_here(TimeVal t)
3 ✔
452
{
453
  if(m_clock)
3 ✔
454
  {
455
    m_transport->requestTransport(t);
1 ✔
456
  }
1 ✔
457
  else
458
  {
459
    on_play_local(true, t);
2 ✔
460

461
    // Syncs the transport buttons; actions only exist with a GUI.
462
    // FIXME this ends up calling play_interval again...
463
    if(this->context.applicationSettings.gui)
2 !
464
    {
465
      auto act = this->context.actions.action<Actions::Play>().action();
×
466
      act->trigger();
×
467
    }
×
468
  }
469
}
3 ✔
470

471
void ExecutionController::request_play_from_here(
4 ✔
472
    Scenario::IntervalModel& itv, TimeVal t)
473
{
474
  auto model = currentScenarioModel();
4 ✔
475
  const Scenario::IntervalModel* root = model ? &model->baseInterval() : nullptr;
4 !
476
  if(&itv == root)
4 !
477
    return request_play_from_here(t);
×
478

479
  if(!m_clock)
4 ✔
480
  {
481
    request_play_interval(itv, {}, t);
2 !
482
    return;
2 ✔
483
  }
484

485
  // The interval the clock plays; transport dates are relative to it.
486
  const Scenario::IntervalModel* played
2 ✔
487
      = m_clock->scenario ? &m_clock->scenario->baseInterval().scoreInterval() : root;
2 !
488
  if(&itv == played)
2 !
489
  {
490
    m_transport->requestTransport(t);
×
491
    return;
×
492
  }
493

494
  // The parent interval is running: restart only this interval at t.
495
  if(auto scenar = qobject_cast<Scenario::ProcessModel*>(itv.parent()))
2 !
496
  {
497
    auto parent = qobject_cast<Scenario::IntervalModel*>(scenar->parent());
2 ✔
498
    auto comp = score::findComponent<Execution::ScenarioComponentBase>(scenar->components());
2 ✔
499
    if(parent && parent->executing() && comp)
2 !
500
    {
501
      comp->playIntervalFrom(itv, t);
2 ✔
502
      return;
2 ✔
503
    }
504
  }
×
505

506
  // Otherwise transport the played interval to t, expressed in its time base.
507
  TimeVal date = t;
×
508
  const Scenario::IntervalModel* cur = &itv;
×
509
  while(cur && cur != played)
×
510
  {
511
    date += cur->date();
×
512
    cur = Scenario::closestParentInterval(cur->parent());
×
513
  }
514
  if(cur)
×
515
    m_transport->requestTransport(date);
×
516
}
4 ✔
517

518
void ExecutionController::request_begin_scrub(TimeVal t)
×
519
{
520
  if(m_clock)
×
521
  {
522
    m_transport->requestBeginScrub(t);
×
523
  }
×
524
  else
525
  {
526
    on_play_local(true, t);
×
527

528
    // FIXME this ends up calling play_interval again...
529
    if(this->context.applicationSettings.gui)
×
530
    {
531
      auto act = this->context.actions.action<Actions::Play>().action();
×
532
      act->trigger();
×
533
    }
×
534
  }
535
}
×
536

537
void ExecutionController::request_scrub(TimeVal t)
×
538
{
539
  if(m_clock)
×
540
  {
541
    m_transport->requestScrub(t);
×
542
  }
×
543
}
×
544

545
void ExecutionController::request_end_scrub(TimeVal t)
×
546
{
547
  if(m_clock)
×
548
  {
549
    m_transport->requestEndScrub(t);
×
550
  }
×
551
}
×
552

553
void ExecutionController::ensure_audio_engine()
584 ✔
554
{
555
  auto& audio_engine = this->context.guiApplicationPlugin<Audio::ApplicationPlugin>();
584 ✔
556
  if(!audio_engine.audio)
584 !
557
  {
558
    if(this->context.mainWindow)
×
559
    {
560
      score::warning(
×
561
          this->context.mainWindow, tr("Cannot play"),
×
562
          tr("Cannot start playback. It looks like the audio engine is not "
×
563
             "running.\n"
564
             "Check the audio settings in the software settings to ensure "
565
             "that a sound card "
566
             "is correctly configured.\n\n"
567
             "Check Settings > Audio > Device in particular. "
568
             "The power-on icon at the bottom of the transport toolbar will "
569
             "light up when the engine is running."));
570
      return;
×
571
    }
572
    else
573
    {
574
      qFatal("Cannot playback without an audio engine set up");
×
575
    }
576
  }
577
}
584 ✔
578

579
void ExecutionController::play_interval(
575 ✔
580
    Scenario::IntervalModel& cst, exec_setup_fun setup_fun, TimeVal t)
581
{
582
  auto doc = currentDocument();
575 ✔
583
  if(!doc)
575 !
584
    return;
×
585

586
  auto& ctx = doc->context();
575 ✔
587

588
  auto exec_plug = ctx.findPlugin<Execution::DocumentPlugin>();
575 ✔
589
  if(!exec_plug)
575 !
590
    return;
×
591

592
  ensure_audio_engine();
575 ✔
593

594
  if(m_playing)
575 ✔
595
  {
596
    SCORE_ASSERT(bool(m_clock));
31 !
597
    if(m_clock->paused())
31 ✔
598
    {
599
      m_clock->resume();
7 ✔
600
      m_paused = false;
7 ✔
601
    }
7 ✔
602
    else
603
    {
604
      // We are playing an interval while we are already executing.
605
      if(auto scenar = qobject_cast<Scenario::ProcessModel*>(cst.parent()))
24 ✔
606
      {
607
        auto exec_comp = score::findComponent<Execution::ScenarioComponentBase>(
1 ✔
608
            scenar->components());
1 ✔
609
        if(exec_comp)
1 !
610
        {
611
          exec_comp->playInterval(cst);
1 ✔
612
        }
1 ✔
613
        return;
1 ✔
614
      }
615
    }
616
  }
30 ✔
617
  else
618
  {
619
    // Here we stop the listening when we start playing the scenario.
620
    // Get all the selected nodes
621
    if(auto explorer = Explorer::try_deviceExplorerFromObject(*doc))
544 !
622
    {
623
      // Disable listening for everything
624
      if(explorer && !exec_plug->settings.getExecutionListening())
544 !
625
      {
626
        explorer->deviceModel().listening().stop();
×
627
      }
×
628

629
      if(this->context.applicationSettings.gui)
544 ✔
630
      {
631
        if(auto w = Explorer::findDeviceExplorerWidgetInstance(this->context))
468 ✔
632
        {
633
          w->setEditable(false);
294 ✔
634
        }
294 ✔
635
      }
468 ✔
636
    }
544 ✔
637

638
    // Ignores the top-level condition / triggers if any
639
    bool forcePlay{};
544 ✔
640
    if(this->context.applicationSettings.gui)
544 ✔
641
    {
642
      forcePlay = qApp->keyboardModifiers() & Qt::ControlModifier;
468 ✔
643
    }
468 ✔
644
    exec_plug->reload(forcePlay, cst);
544 ✔
645

646
    auto& c = exec_plug->context();
544 ✔
647
    m_clock = makeClock(c);
544 ✔
648

649
    if(setup_fun)
544 !
650
    {
651
      exec_plug->runAllCommands();
×
652
      SCORE_ASSERT(exec_plug->baseScenario());
×
653
      setup_fun(c, *exec_plug->baseScenario());
×
654
      exec_plug->runAllCommands();
×
655
    }
×
656

657
    m_clock->play(t);
544 ✔
658
    m_paused = false;
544 ✔
659
  }
660

661
  m_playing = true;
574 ✔
662
  m_playingDocument = &ctx.document;
574 ✔
663
  context.guiApplicationPlugin<Audio::ApplicationPlugin>().setPlayingDocument(&ctx.document);
574 ✔
664
  ctx.execTimer.start();
574 ✔
665

666
  if(auto transport_plug = ctx.findPlugin<Transport::DocumentPlugin>())
574 !
667
    transport_plug->play();
574 ✔
668

669
  playStarted();
574 ✔
670
}
575 ✔
671

672
void ExecutionController::stop_interval(Scenario::IntervalModel& cst)
1 ✔
673
{
674
  auto doc = currentDocument();
1 ✔
675
  if(!doc)
1 !
676
    return;
×
677

678
  auto& ctx = doc->context();
1 ✔
679

680
  auto exec_plug = ctx.findPlugin<Execution::DocumentPlugin>();
1 ✔
681
  if(!exec_plug)
1 !
682
    return;
×
683

684
  ensure_audio_engine();
1 ✔
685

686
  if(m_playing)
1 !
687
  {
688
    // We are stopping an interval while we are already executing.
689
    if(auto scenar = qobject_cast<Scenario::ProcessModel*>(cst.parent()))
1 !
690
    {
691
      auto exec_comp
1 ✔
692
          = score::findComponent<Execution::ScenarioComponentBase>(scenar->components());
1 ✔
693
      if(exec_comp)
1 !
694
      {
695
        exec_comp->stopInterval(cst);
1 ✔
696
      }
1 ✔
697
    }
1 ✔
698
  }
1 ✔
699
}
1 ✔
700

701
TimeVal ExecutionController::execution_time() const
17,870 ✔
702
{
703
  if(m_clock)
17,870 ✔
704
  {
705
    SCORE_ASSERT(m_clock->scenario);
4,645 !
706
    auto& itv = m_clock->scenario->baseInterval().scoreInterval().duration;
4,645 ✔
707
    return TimeVal(itv.defaultDuration() * itv.playPercentage());
4,645 ✔
708
  }
709
  return TimeVal::zero();
13,225 ✔
710
}
17,870 ✔
711

712
bool ExecutionController::has_execution() const noexcept
17,259 ✔
713
{
714
  return bool(m_clock);
17,259 ✔
715
}
716

717
const Scenario::IntervalModel* ExecutionController::execution_interval() const
17,259 ✔
718
{
719
  if(m_clock && m_clock->scenario)
17,259 !
720
    return &m_clock->scenario->baseInterval().scoreInterval();
4,035 ✔
721

722
  // A document stays the current one while it closes, and events are
723
  // processed in between: by then its model has no root interval any more.
724
  if(auto doc = currentDocument())
13,224 ✔
725
    if(auto scenar
8,536 ✔
726
       = score::IDocument::try_modelDelegate<Scenario::ScenarioDocumentModel>(*doc);
8,536 ✔
727
       scenar && !scenar->closing())
8,536 !
728
      return &scenar->baseInterval();
6,811 ✔
729
  return nullptr;
6,413 ✔
730
}
17,259 ✔
731

732
void ExecutionController::on_record(::TimeVal t)
1 ✔
733
{
734
  // Playback can start while a recording waits for its first message.
735
  if(m_playing)
1 !
UNCOV
736
    return;
×
737

738
  // TODO have a on_exit handler to properly stop the scenario.
739
  if(auto scenar = currentScenarioModel())
1 !
740
  {
741
    if(auto exec_plug = scenar->context().findPlugin<Execution::DocumentPlugin>())
1 !
742
    {
743
      // Listening isn't stopped here.
744
      exec_plug->reload(false, scenar->baseInterval());
1 ✔
745
      m_clock = makeClock(exec_plug->context());
1 ✔
746
      m_clock->play(t);
1 ✔
747

748
      scenar->context().execTimer.start();
1 ✔
749
      m_playing = true;
1 ✔
750
      m_playingDocument = &scenar->context().document;
1 ✔
751
      context.guiApplicationPlugin<Audio::ApplicationPlugin>().setPlayingDocument(
2 ✔
752
          &scenar->context().document);
1 ✔
753
      m_paused = false;
1 ✔
754

755
      if(auto transport_plug = scenar->context().findPlugin<Transport::DocumentPlugin>())
1 !
756
        transport_plug->play();
1 ✔
757
      playStarted();
1 ✔
758
    }
1 ✔
759
  }
1 ✔
760
}
1 ✔
761

762
void ExecutionController::on_stop()
7,608 ✔
763
{
764
  LocalTree::DocumentPlugin* tree{};
7,608 ✔
765
  if(auto doc = currentDocument())
7,608 ✔
766
    tree = doc->context().findPlugin<LocalTree::DocumentPlugin>();
5,411 ✔
767
  if(tree)
7,608 ✔
768
    tree->beginRecall(LocalTree::Recall::Stop);
5,411 ✔
769

770
  bool wasplaying = m_playing;
7,608 ✔
771
  m_playing = false;
7,608 ✔
772
  m_paused = false;
7,608 ✔
773

774
  stop_clock();
7,608 ✔
775

776
  if(wasplaying)
7,608 ✔
777
    send_end_state();
545 ✔
778

779
  reset_after_stop();
7,608 ✔
780

781
  if(tree)
7,608 ✔
782
    tree->endRecall(LocalTree::Recall::Stop);
5,411 ✔
783

784
  m_playingDocument = nullptr;
7,608 ✔
785
  context.guiApplicationPlugin<Audio::ApplicationPlugin>().setPlayingDocument(nullptr);
7,608 ✔
786

787
  if(wasplaying)
7,608 ✔
788
    playStopped();
545 ✔
789
}
7,608 ✔
790

791
void ExecutionController::stop_clock()
7,608 ✔
792
{
793
  if(m_clock)
7,608 ✔
794
  {
795
    auto clock = std::move(m_clock);
545 ✔
796
    m_clock.reset();
545 ✔
797
    if(auto scenar = currentScenarioModel())
545 !
798
      if(auto exec_plug = scenar->context().findPlugin<Execution::DocumentPlugin>();
545 !
799
         bool(exec_plug))
1,090 ✔
800
      {
801
        try
802
        {
803
          clock->stop();
545 !
804
        }
545 ✔
805
        catch(...)
806
        {
UNCOV
807
          qDebug() << "Error while stopping the clock. There is likely an audio "
×
808
                      "hardware issue.";
UNCOV
809
        }
×
810
      }
545 ✔
811
  }
545 ✔
812
}
7,608 ✔
813

814
void ExecutionController::send_end_state()
545 ✔
815
{
816
  if(auto doc = currentDocument())
545 !
817
  {
818
    auto& ctx = doc->context();
545 ✔
819
    if(auto exec_plug = ctx.findPlugin<Execution::DocumentPlugin>())
545 !
820
    {
821
      exec_plug->playStopState();
545 ✔
822
    }
545 ✔
823
  }
545 ✔
824
}
545 ✔
825
void ExecutionController::reset_after_stop()
7,608 ✔
826
{
827
  if(auto doc = currentDocument())
7,608 ✔
828
  {
829
    auto& ctx = doc->context();
5,411 ✔
830
    ctx.execTimer.stop();
5,411 ✔
831

832
    if(auto transport_plug = ctx.findPlugin<Transport::DocumentPlugin>())
5,411 !
833
      transport_plug->stop();
5,411 ✔
834

835
    if(auto exec_plug = ctx.findPlugin<Execution::DocumentPlugin>())
5,411 !
836
    {
837
      exec_plug->clear();
5,411 ✔
838
    }
5,411 ✔
839
    else
840
    {
UNCOV
841
      return;
×
842
    }
843

844
    // If we can we resume listening
845
    if(!context.docManager.preparingNewDocument())
5,411 ✔
846
    {
847
      auto explorer = Explorer::try_deviceExplorerFromObject(*doc);
4,187 ✔
848
      if(explorer)
4,187 !
849
        explorer->deviceModel().listening().restore();
4,187 ✔
850
    }
4,187 ✔
851
  }
5,411 ✔
852

853
  auto scenar = currentScenarioModel();
7,608 ✔
854
  if(!scenar || scenar->closing())
7,608 ✔
855
    return;
2,825 ✔
856
  QTimer::singleShot(
4,783 !
857
      50, this,
858
      [this, itv = QPointer<Scenario::IntervalModel>{&scenar->baseInterval()}] {
9,051 ✔
859
    if(itv)
4,268 ✔
860
      reset_edition(*itv);
1,630 ✔
861
      });
4,268 ✔
862
}
7,608 ✔
863

864
void ExecutionController::reset_edition(Scenario::IntervalModel& base)
1,630 ✔
865
{
866
  // Reset edition for the device explorer
867
  if(context.applicationSettings.gui)
1,630 ✔
868
  {
869
    if(auto w = Explorer::findDeviceExplorerWidgetInstance(context))
1,607 ✔
870
    {
871
      w->setEditable(true);
1,122 ✔
872
    }
1,122 ✔
873
  }
1,607 ✔
874

875
  // FIXME uuuugh have an event in scenario instead (or better, move this
876
  // in process)
877
  base.reset();
1,630 ✔
878
  base.executionEvent(Scenario::IntervalExecutionEvent::Finished);
1,630 ✔
879
}
1,630 ✔
880

881
void ExecutionController::on_reinitialize()
1 ✔
882
{
883
  // TODO to be more precise, we should stop the execution, but keep
884
  // the execution_state alive until the last message is sent
885
  if(auto scenar = currentScenarioModel())
1 !
886
  {
887
    auto& ctx = scenar->context();
1 ✔
888
    auto& doc = ctx.document;
1 ✔
889
    auto exec_plug = ctx.findPlugin<Execution::DocumentPlugin>();
1 ✔
890
    if(!exec_plug)
1 !
UNCOV
891
      return;
×
892

893
    auto explorer = Explorer::try_deviceExplorerFromObject(doc);
1 ✔
894

895
    // Disable listening for everything
896
    if(explorer)
1 !
897
      if(!ctx.app.settings<Execution::Settings::Model>().getExecutionListening())
1 !
UNCOV
898
        explorer->deviceModel().listening().stop();
×
899

900
    // If we can we resume listening
901
    if(explorer)
1 !
902
      if(!context.docManager.preparingNewDocument())
2 !
903
        explorer->deviceModel().listening().restore();
1 ✔
904

905
    on_stop();
1 ✔
906

907
    LocalTree::StateRecall recall{ctx, *exec_plug};
1 ✔
908
    exec_plug->playStartState();
1 !
909
  }
1 ✔
910
}
1 ✔
911

912
void ExecutionController::init_transport()
4,934 ✔
913
{
914
  if(m_transport)
4,934 !
UNCOV
915
    m_transport->teardown();
×
916

917
  auto& s = context.settings<Execution::Settings::Model>();
4,934 ✔
918
  m_transport = s.getTransport();
4,934 ✔
919
  SCORE_ASSERT(m_transport);
4,934 !
920
  m_transport->setup();
4,934 ✔
921
  connect(
4,934 ✔
922
      m_transport, &Execution::TransportInterface::play, this,
4,934 ✔
923
      &ExecutionController::trigger_play);
4,934 ✔
924
  connect(
4,934 ✔
925
      m_transport, &Execution::TransportInterface::pause, this,
4,934 ✔
926
      &ExecutionController::trigger_pause);
4,934 ✔
927
  connect(
4,934 ✔
928
      m_transport, &Execution::TransportInterface::stop, this,
4,934 ✔
929
      &ExecutionController::trigger_stop);
4,934 ✔
930
  connect(
4,934 ✔
931
      m_transport, &Execution::TransportInterface::transport, this,
4,934 ✔
932
      &ExecutionController::on_transport);
4,934 ✔
933
  connect(
4,934 ✔
934
      m_transport, &Execution::TransportInterface::beginScrub, this,
4,934 ✔
935
      &ExecutionController::on_begin_scrub);
4,934 ✔
936
  connect(
4,934 ✔
937
      m_transport, &Execution::TransportInterface::scrub, this,
4,934 ✔
938
      &ExecutionController::on_scrub);
4,934 ✔
939
  connect(
4,934 ✔
940
      m_transport, &Execution::TransportInterface::endScrub, this,
4,934 ✔
941
      &ExecutionController::on_end_scrub);
4,934 ✔
942

943
  auto& audio_settings = this->context.settings<Audio::Settings::Model>();
4,934 ✔
944
  con(audio_settings, &Audio::Settings::Model::JackTransportChanged, this,
9,868 ✔
945
      &ExecutionController::init_transport, Qt::UniqueConnection);
4,934 ✔
946

947
  con(audio_settings, &Audio::Settings::Model::changed, this,
9,868 ✔
948
      &ExecutionController::on_audioSettingsChanged,
4,934 ✔
949
      Qt::ConnectionType(Qt::DirectConnection | Qt::UniqueConnection));
4,934 ✔
950

951
  // Restarting the engine from its action, rebinding it to another
952
  // document's audio device, the device failing: synchronous, so that the
953
  // execution is stopped before the engine changes.
954
  con(context.guiApplicationPlugin<Audio::ApplicationPlugin>(),
9,868 ✔
955
      &Audio::ApplicationPlugin::engineAboutToChange, this,
4,934 ✔
956
      &ExecutionController::on_audioSettingsChanged,
4,934 ✔
957
      Qt::ConnectionType(Qt::DirectConnection | Qt::UniqueConnection));
4,934 ✔
958
}
4,934 ✔
959

960
void ExecutionController::on_audioSettingsChanged()
4,478 ✔
961
{
962
  // The engine is about to be restarted, which tears the audio device tree
963
  // down under the graph. Stopping here is synchronous, hence done before the
964
  // audio plug-in's queued restart.
965
  if(m_playing)
4,478 ✔
966
    trigger_stop();
16 ✔
967
}
4,478 ✔
968

969
Scenario::ScenarioDocumentModel* ExecutionController::currentScenarioModel()
8,731 ✔
970
{
971
  if(auto doc = currentDocument())
8,731 ✔
972
  {
973
    return score::IDocument::try_modelDelegate<Scenario::ScenarioDocumentModel>(*doc);
6,534 ✔
974
  }
975
  return nullptr;
2,197 ✔
976
}
8,731 ✔
977

978
Scenario::ScenarioDocumentPresenter* ExecutionController::currentScenarioPresenter()
25 ✔
979
{
980
  if(auto doc = currentDocument())
25 !
981
  {
982
    return score::IDocument::try_presenterDelegate<Scenario::ScenarioDocumentPresenter>(
25 ✔
983
        *doc);
25 ✔
984
  }
UNCOV
985
  return nullptr;
×
986
}
25 ✔
987

988
score::Document* ExecutionController::currentDocument() const
38,325 ✔
989
{
990
  if(m_playingDocument)
38,325 ✔
991
    return m_playingDocument;
2,798 ✔
992
  return context.documents.currentDocument();
35,527 ✔
993
}
38,325 ✔
994

995
std::unique_ptr<Execution::Clock>
996
ExecutionController::makeClock(const Execution::Context& ctx)
545 ✔
997
{
998
  auto& s = context.settings<Execution::Settings::Model>();
545 ✔
999
  auto clk = s.makeClock(ctx);
545 ✔
1000
  SCORE_ASSERT(clk->scenario);
545 !
1001
  auto& itv = clk->scenario->baseInterval().interval();
545 !
1002
  con(itv, &IdentifiedObjectAbstract::identified_object_destroying, this,
1,090 !
1003
      [this] { trigger_stop(); });
1,090 ✔
1004
  return clk;
545 ✔
1005
}
545 ✔
1006

1007
}
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