• 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

89.22
/src/plugins/score-lib-process/Effect/EffectLayer.cpp
1
#include "EffectLayer.hpp"
2

3
#include <Process/ApplicationPlugin.hpp>
4
#include <Process/Commands/LoadPreset.hpp>
5
#include <Process/Commands/LoadPresetCommandFactory.hpp>
6
#include <Process/Dataflow/CableCopy.hpp>
7
#include <Process/Focus/FocusDispatcher.hpp>
8
#include <Process/Process.hpp>
9
#include <Process/ProcessList.hpp>
10
#include <Process/ProcessMimeSerialization.hpp>
11
#include <Process/PresetTree.hpp>
12
#include <Process/Script/EditorOverlay.hpp>
13
#include <Process/Style/Pixmaps.hpp>
14
#include <Process/UIPlacement.hpp>
15

16
#include <score/selection/SelectionDispatcher.hpp>
17
#include <score/application/GUIApplicationContext.hpp>
18
#include <score/command/Dispatchers/CommandDispatcher.hpp>
19
#include <score/document/DocumentContext.hpp>
20
#include <score/graphics/GraphicWidgets.hpp>
21
#include <score/model/EntitySerialization.hpp>
22
#include <score/model/path/PathSerialization.hpp>
23
#include <score/plugins/documentdelegate/DocumentDelegateView.hpp>
24
#include <score/plugins/panel/PanelDelegate.hpp>
25
#include <score/selection/SelectionStack.hpp>
26
#include <score/widgets/HelpInteraction.hpp>
27
#include <score/widgets/SetIcons.hpp>
28

29
#include <core/document/Document.hpp>
30
#include <core/document/DocumentView.hpp>
31
#include <core/view/CentralViewStack.hpp>
32
#include <core/view/FixedTabWidget.hpp>
33
#include <core/view/Window.hpp>
34

35
#include <ossia/detail/algorithms.hpp>
36
#include <ossia/detail/hash_map.hpp>
37
#include <ossia/detail/thread.hpp>
38

39
#include <QActionGroup>
40
#include <QDialogButtonBox>
41
#include <QMenu>
42
#include <QPointer>
43
#include <QToolButton>
44

45
#include <wobjectimpl.h>
46
W_OBJECT_IMPL(Process::EffectLayerPresenter)
×
47
namespace Process
48
{
49

50
EffectLayerView::EffectLayerView(QGraphicsItem* parent)
163 ✔
51
    : Process::LayerView{parent}
163 ✔
52
{
163 ✔
53
}
54

55
EffectLayerView::~EffectLayerView() { }
174 ✔
56

57
void EffectLayerView::setWidth(qreal val, qreal defaultWidth)
462 ✔
58
{
59
  m_defaultWidth = defaultWidth;
462 ✔
60
  LayerView::setWidth(val);
462 ✔
61
}
462 ✔
62

63
void EffectLayerView::paint_impl(QPainter*) const { }
75 ✔
64

65
EffectLayerPresenter::EffectLayerPresenter(
162 ✔
66
    const ProcessModel& model, Process::EffectLayerView* view, const Context& ctx,
67
    QObject* parent)
68
    : LayerPresenter{model, view, ctx, parent}
162 ✔
69
    , m_view{view}
162 ✔
70
{
162 ✔
71
  putToFront();
162 ✔
72
}
162 ✔
73

74
EffectLayerPresenter::~EffectLayerPresenter() { }
308 ✔
75

76
void EffectLayerPresenter::setWidth(qreal val, qreal defaultWidth)
462 ✔
77
{
78
  m_view->setWidth(val, defaultWidth);
462 ✔
79
}
462 ✔
80

81
void EffectLayerPresenter::setHeight(qreal val)
462 ✔
82
{
83
  m_view->setHeight(val);
462 ✔
84
}
462 ✔
85

86
void EffectLayerPresenter::putToFront()
169 ✔
87
{
88
  m_view->setVisible(true);
169 ✔
89
}
169 ✔
90

91
void EffectLayerPresenter::putBehind()
×
92
{
93
  m_view->setVisible(false);
×
94
}
×
95

96
void EffectLayerPresenter::on_zoomRatioChanged(ZoomRatio) { }
422 ✔
97

98
void EffectLayerPresenter::parentGeometryChanged() { }
443 ✔
99

100
void EffectLayerPresenter::fillContextMenu(
×
101
    QMenu& menu, QPoint pos, QPointF scenepos, const LayerContextMenuManager& mgr)
102
{
103
}
×
104

105
QGraphicsItem* makeScriptButton(
2,529 ✔
106
    ProcessModel& effect, const score::DocumentContext& context, QObject* self,
107
    QGraphicsItem* root)
108
{
109
  auto& pixmaps = Process::Pixmaps::instance();
2,529 ✔
110
  auto& facts = context.app.interfaces<Process::LayerFactoryList>();
2,529 ✔
111
  auto fact = facts.findDefaultFactory(effect);
2,529 ✔
112
  if(effect.flags() & Process::ProcessFlags::ScriptEditingSupported)
2,529 ✔
113
  {
114
    auto ui_btn = new score::QGraphicsPixmapToggle{
818 ✔
115
        pixmaps.show_script_on, pixmaps.show_script_off, root};
409 ✔
116
    ui_btn->setToolTip(
818 ✔
117
        QObject::tr("Show/hide UI\nShow the process's script editor for JS, shaders, etc."));
409 ✔
118
    QObject::connect(
409 ✔
119
        ui_btn, &score::QGraphicsPixmapToggle::toggled, self,
409 ✔
120
        [=, &effect, &context](bool b) {
410 ✔
121
      // The button takes the click the process would have been selected by
122
      score::SelectionDispatcher{context.selectionStack}.select(effect);
1 ✔
123
      Process::setupScriptUI(effect, *fact, context, b);
1 ✔
124
    });
1 ✔
125

126
    if(effect.scriptUI)
409 ✔
127
      ui_btn->setState(true);
5 ✔
128
    QObject::connect(
409 ✔
129
        &effect, &Process::ProcessModel::scriptUIVisible, ui_btn,
409 ✔
130
        [=](bool v) { ui_btn->setState(v); });
539 ✔
131
    QObject::connect(
409 ✔
132
        ui_btn, &score::QGraphicsPixmapToggle::contextMenuRequested, self,
409 ✔
133
        [&effect, &context](QPoint pos) {
409 ✔
134
      QMenu menu;
×
135
      fillPlacementMenu(menu, effect, context, ProcessUIKind::ScriptEditor);
×
136
      menu.exec(pos);
×
137
    });
×
138
    return ui_btn;
409 ✔
139
  }
140
  return nullptr;
2,120 ✔
141
}
2,529 ✔
142

143
namespace
144
{
145
score::View* mainView() noexcept
72 ✔
146
{
147
  return qobject_cast<score::View*>(score::GUIAppContext().mainWindow);
72 ✔
148
}
149

150
score::CentralViewStack* centralViews(const score::DocumentContext& ctx) noexcept
92 ✔
151
{
152
  if(auto v = ctx.document.view())
92 ✔
153
    return &v->centralViews();
92 ✔
154
  return nullptr;
×
155
}
92 ✔
156

157
void showAsWindow(QWidget* win)
27 ✔
158
{
159
#if defined(__EMSCRIPTEN__)
160
  // Qt for wasm reports ShowIsFullScreen unconditionally, and QWidget::show()
161
  // acts on it exactly as QWindow::show() does: the window covers the page and
162
  // loses the frame Qt draws for it, leaving no way to close or move it.
163
  // Also, without an OS window manager the window would otherwise open
164
  // behind / unfocused: the first click on "Compile" would only activate it.
165
  win->setWindowFlag(Qt::WindowStaysOnTopHint, true);
166
  win->showNormal();
167
#else
168
  win->show();
27 ✔
169
#endif
170
  win->raise();
27 ✔
171
  win->activateWindow();
27 ✔
172
}
27 ✔
173

174
QString kindName(ProcessUIKind kind)
195 ✔
175
{
176
  return kind == ProcessUIKind::ScriptEditor ? QObject::tr("code") : QObject::tr("UI");
195 ✔
177
}
178

179
// "My script (code)", "My script (UI)": a process can have both open
180
QString processTitle(const Process::ProcessModel& proc, ProcessUIKind kind)
195 ✔
181
{
182
  auto n = proc.prettyName();
195 ✔
183
  if(n.isEmpty())
195 ✔
184
    n = proc.metadata().getLabel();
×
185
  return QStringLiteral("%1 (%2)").arg(n, kindName(kind));
195 ✔
186
}
195 ✔
187

188
/**
189
 * Bookkeeping attached to a process UI widget: where it is and the
190
 * connections that placement made, undone when it moves.
191
 * Deleted with the widget.
192
 */
193
class PlacedUI final : public QObject
194
{
195
public:
196
  PlacedUI(QWidget* win, UIPlacement p, ProcessUIKind k)
216 ✔
197
      : QObject{win}
108 ✔
198
      , placement{p}
108 ✔
199
      , kind{k}
108 ✔
200
  {
108 ✔
201
    setObjectName(QStringLiteral("PlacedUI"));
108 ✔
202
  }
108 ✔
203

204
  ~PlacedUI()
119 ✔
205
  {
11 ✔
206
    for(auto& c : connections)
274 ✔
207
      QObject::disconnect(c);
166 ✔
208
  }
119 ✔
209

210
  UIPlacement placement;
211
  ProcessUIKind kind;
212
  //! The widget put in the central stack: an overlay host, or the UI itself
213
  QPointer<QWidget> host;
214
  std::vector<QMetaObject::Connection> connections;
215
};
216

217
PlacedUI* placedState(QWidget* win)
205 ✔
218
{
219
  if(!win)
205 ✔
220
    return nullptr;
×
221
  for(auto child : win->children())
995 ✔
222
    if(auto state = dynamic_cast<PlacedUI*>(child))
887 ✔
223
      return state;
97 ✔
224
  return nullptr;
108 ✔
225
}
205 ✔
226

227
//! The placement asked for this process, or the user's default
228
UIPlacement placementFor(const Process::ProcessModel& proc, ProcessUIKind kind)
108 ✔
229
{
230
  switch(kind)
108 ✔
231
  {
232
    case ProcessUIKind::ScriptEditor:
233
      return UIPlacementSettings::fromString(
84 ✔
234
          proc.scriptEditorPlacement(), UIPlacementSettings::scriptEditorPlacement());
84 ✔
235
    case ProcessUIKind::ExternalUI: {
236
      // Only UIs made of plain widgets / Qt Quick can live inside the main
237
      // window; plug-ins owning a native window keep opening separately.
238
      if(!(proc.flags() & Process::ProcessFlags::ExternalUIEmbeddable))
24 ✔
239
        return UIPlacement::Window;
×
240
      return UIPlacementSettings::fromString(
24 ✔
241
          proc.processUIPlacement(), UIPlacementSettings::processUIPlacement());
24 ✔
242
    }
243
  }
244
  return UIPlacement::Window;
×
245
}
108 ✔
246

247
void showPlacementMenu(
3 ✔
248
    Process::ProcessModel& proc, const score::DocumentContext& ctx, ProcessUIKind kind,
249
    QPoint globalPos)
250
{
251
  QMenu menu;
3 ✔
252
  fillPlacementMenu(menu, proc, ctx, kind);
3 ✔
253
  menu.exec(globalPos);
3 ✔
254
}
3 ✔
255

256
//! A menu button in the editor's own button row, so that it can be moved
257
//! from wherever it is, including from a separate window.
258
void addPlacementButton(
84 ✔
259
    QWidget* win, Process::ProcessModel& proc, const score::DocumentContext& ctx,
260
    ProcessUIKind kind)
261
{
262
  auto bbox = win->findChild<QDialogButtonBox*>();
84 ✔
263
  if(!bbox)
84 ✔
264
    return;
×
265
  if(bbox->findChild<QToolButton*>(QStringLiteral("PlacementButton")))
84 ✔
266
    return;
15 ✔
267

268
  auto btn = new QToolButton{bbox};
69 ✔
269
  btn->setObjectName(QStringLiteral("PlacementButton"));
69 ✔
270
  btn->setAutoRaise(true);
69 ✔
271
  btn->setPopupMode(QToolButton::InstantPopup);
69 ✔
272
  btn->setIcon(makeIcons(
138 ✔
273
      QStringLiteral(":/icons/undock_on.png"), QStringLiteral(":/icons/undock_off.png"),
69 ✔
274
      QStringLiteral(":/icons/undock_off.png")));
69 ✔
275
  btn->setToolTip(QObject::tr("Where this editor opens"));
69 ✔
276
  score::setHelp(
69 ✔
277
      btn, QObject::tr(
69 ✔
278
               "Open the editor in a separate window, in the side panel or in "
279
               "the central view. Remembered for this process, and becomes "
280
               "the default for the others."));
281

282
  auto menu = new QMenu{btn};
69 ✔
283
  QObject::connect(menu, &QMenu::aboutToShow, btn, [menu, &proc, &ctx, kind] {
69 ✔
284
    // Rebuilt on every opening; the action groups are not among what
285
    // clear() deletes.
286
    qDeleteAll(menu->findChildren<QActionGroup*>(QString{}, Qt::FindDirectChildrenOnly));
×
287
    menu->clear();
×
288
    fillPlacementMenu(*menu, proc, ctx, kind);
×
289
  });
×
290
  btn->setMenu(menu);
69 ✔
291
  bbox->addButton(btn, QDialogButtonBox::HelpRole);
69 ✔
292
}
84 ✔
293

294
//! The document's background when it shows one (a Background device, a
295
//! watched texture port)
296
QWidget* backgroundPreview(const score::DocumentContext& ctx)
12 ✔
297
{
298
  if(auto docView = ctx.document.view())
12 ✔
299
  {
300
    auto& delegate = docView->viewDelegate();
12 ✔
301
    if(delegate.activeBackgroundRenderer())
12 ✔
302
      return new DocumentBackgroundPreview{delegate};
10 ✔
303
  }
2 ✔
304
  return nullptr;
2 ✔
305
}
12 ✔
306

307
//! What a central code editor is drawn over: the document's background, when
308
//! asked for and when the document shows one
309
QWidget* makePreview(const score::DocumentContext& ctx)
36 ✔
310
{
311
  switch(UIPlacementSettings::scriptEditorPreview())
36 ✔
312
  {
313
    case PreviewSource::Background:
314
      return backgroundPreview(ctx);
12 ✔
315
    case PreviewSource::None:
316
      return nullptr;
24 ✔
317
  }
318
  return nullptr;
×
319
}
36 ✔
320

321
/**
322
 * Puts a UI created for a process (script editor, custom UI) where the
323
 * user wants it. The widget is expected to delete itself on close
324
 * (Qt::WA_DeleteOnClose): the panels it gets docked into watch for that.
325
 */
326
void placeProcessUI(
108 ✔
327
    QWidget* win, Process::ProcessModel& proc, const score::DocumentContext& ctx,
328
    UIPlacement placement, ProcessUIKind kind)
329
{
330
  const char* icon = kind == ProcessUIKind::ScriptEditor ? "script" : "new_window";
108 ✔
331
  const auto title = [&proc, kind] { return processTitle(proc, kind); };
303 ✔
332

333
  delete placedState(win);
108 ✔
334
  auto state = new PlacedUI{win, placement, kind};
108 ✔
335
  state->host = win;
108 ✔
336

337
  win->setWindowTitle(title());
108 ✔
338
  if(kind == ProcessUIKind::ScriptEditor)
108 ✔
339
    addPlacementButton(win, proc, ctx, kind);
84 ✔
340

341
  switch(placement)
108 ✔
342
  {
343
    case UIPlacement::Central: {
344
      auto views = centralViews(ctx);
47 ✔
345
      if(!views)
47 ✔
346
        break;
×
347

348
      QWidget* host = win;
47 ✔
349
      if(kind == ProcessUIKind::ScriptEditor)
47 ✔
350
      {
351
        if(auto preview = makePreview(ctx))
36 ✔
352
        {
353
          host = new EditorOverlayHost{win, preview};
10 ✔
354
        }
10 ✔
355
      }
36 ✔
356
      state->host = host;
47 ✔
357

358
      views->addView(
94 ✔
359
          host, title(), QIcon{QStringLiteral(":/icons/%1_on.png").arg(icon)});
47 ✔
360
      views->showView(host);
47 ✔
361

362
      state->connections.push_back(
47 ✔
363
          QObject::connect(
47 ✔
364
              &proc.metadata(), &score::ModelMetadata::NameChanged, win,
47 ✔
365
              [host, title, v = QPointer<score::CentralViewStack>{views}] {
48 ✔
366
        if(v)
1 ✔
367
          v->setViewTitle(host, title());
1 ✔
368
      }));
1 ✔
369
      state->connections.push_back(
94 ✔
370
          QObject::connect(
47 ✔
371
              views, &score::CentralViewStack::viewContextMenuRequested, win,
47 ✔
372
              [host, &proc, &ctx, kind](QWidget* v, QPoint pos) {
48 ✔
373
        if(v == host)
1 ✔
374
          showPlacementMenu(proc, ctx, kind, pos);
1 ✔
375
      }));
1 ✔
376
      return;
47 ✔
377
    }
378
    case UIPlacement::SidePanel: {
379
      auto view = mainView();
36 ✔
380
      if(!view)
36 ✔
381
        break;
×
382

383
      auto act = view->addRightPanel(
72 ✔
384
          win, score::PanelStatus{
72 ✔
385
                   false, true, Qt::RightDockWidgetArea, -100000, title(), icon,
36 ✔
386
                   QKeySequence{}});
36 ✔
387
      view->showRightPanel(win);
36 ✔
388

389
      state->connections.push_back(
72 ✔
390
          QObject::connect(
36 ✔
391
              &proc.metadata(), &score::ModelMetadata::NameChanged, win,
36 ✔
392
              [win, act = QPointer<QAction>{act}, view = QPointer<score::View>{view},
37 ✔
393
               title] {
36 ✔
394
        if(!act)
1 ✔
395
          return;
×
396
        act->setText(title());
1 ✔
397
        act->setIconText(title());
1 ✔
398
        act->setToolTip(title());
1 ✔
399
        // The pane's title only follows the current tab when it is shown
400
        if(view && act->isChecked())
1 ✔
401
          view->showRightPanel(win);
1 ✔
402
      }));
1 ✔
403
      state->connections.push_back(
72 ✔
404
          QObject::connect(
36 ✔
405
              view->rightTabs, &score::FixedTabWidget::tabContextMenuRequested, win,
36 ✔
406
              [win, &proc, &ctx, kind](QWidget* tab, QPoint pos) {
38 ✔
407
        if(tab == win)
2 ✔
408
          showPlacementMenu(proc, ctx, kind, pos);
2 ✔
409
      }));
2 ✔
410
      return;
36 ✔
411
    }
412
    case UIPlacement::Window:
413
      break;
25 ✔
414
  }
415

416
  state->placement = UIPlacement::Window;
25 ✔
417
  showAsWindow(win);
25 ✔
418
}
108 ✔
419

420
//! Takes a process UI out of wherever placeProcessUI put it, without closing it
421
void detachProcessUI(QWidget* win, const score::DocumentContext& ctx)
97 ✔
422
{
423
  auto state = placedState(win);
97 ✔
424
  if(!state)
97 ✔
425
  {
426
    if(!win->isWindow())
×
427
      win->setParent(nullptr);
×
428
    return;
×
429
  }
430

431
  const QPointer<QWidget> host = state->host;
97 ✔
432
  switch(state->placement)
97 ✔
433
  {
434
    case UIPlacement::Central: {
435
      if(auto views = centralViews(ctx); views && host)
41 ✔
436
      {
437
        if(host == win)
41 ✔
438
        {
439
          views->removeView(win);
33 ✔
440
        }
33 ✔
441
        else if(auto overlay = qobject_cast<EditorOverlayHost*>(host.data()))
8 ✔
442
        {
443
          // The host closes itself once its editor is gone; its tab goes
444
          // now rather than with its deferred deletion
445
          if(overlay->editor() == win)
8 ✔
446
            overlay->releaseEditor();
8 ✔
447
          if(host)
8 ✔
448
            views->removeView(host);
8 ✔
449
        }
8 ✔
450
      }
41 ✔
451
      break;
41 ✔
452
    }
453
    case UIPlacement::SidePanel: {
454
      if(auto view = mainView())
34 ✔
455
        view->removeRightPanel(win);
34 ✔
456
      win->setParent(nullptr);
34 ✔
457
      break;
34 ✔
458
    }
459
    case UIPlacement::Window:
460
      win->hide();
22 ✔
461
      break;
22 ✔
462
  }
463
  delete state;
97 ✔
464
}
97 ✔
465

466
//! Brings back an already opened process UI in front of the user
467
void raiseProcessUI(QWidget* win, const score::DocumentContext& ctx)
6 ✔
468
{
469
  if(win->isWindow())
6 ✔
470
  {
471
    showAsWindow(win);
2 ✔
472
  }
2 ✔
473
  else if(auto views = centralViews(ctx))
4 ✔
474
  {
475
    if(auto view = views->viewContaining(win))
4 ✔
476
      views->showView(view);
2 ✔
477
    else if(auto main = mainView())
2 ✔
478
      main->showRightPanel(win);
2 ✔
479
  }
4 ✔
480
  else if(auto view = mainView())
×
481
  {
482
    view->showRightPanel(win);
×
483
  }
×
484
}
6 ✔
485

486
//! Closes a process UI, making sure it is gone when this returns.
487
//! True when the UI left the bookkeeping to us: the pointer was still set
488
//! after its close, and got reset here.
489
bool closeProcessUI(QWidget*& slot, const score::DocumentContext& ctx)
82 ✔
490
{
491
  auto win = slot;
82 ✔
492
  if(!win)
82 ✔
493
    return false;
1 ✔
494

495
  // close() lets the widget notify that it is going away (the script
496
  // dialogs and the plug-in windows reset the process's pointer themselves)
497
  // and, with WA_DeleteOnClose, schedules its deletion. UIs that only hide
498
  // on close (the Pd wrapper for instance) are deleted here.
499
  const QPointer<QWidget> alive = win;
81 ✔
500
  win->close();
81 ✔
501
  const bool resetHere = (slot == win);
81 ✔
502
  if(resetHere)
81 ✔
503
    slot = nullptr;
22 ✔
504
  if(!alive)
81 ✔
505
    return resetHere;
×
506

507
  // Out of its tab right away, not once the deferred deletion has run
508
  detachProcessUI(alive, ctx);
81 ✔
509
  if(alive && !alive->testAttribute(Qt::WA_DeleteOnClose))
81 ✔
510
    delete alive.data();
81 ✔
511
  return resetHere;
81 ✔
512
}
82 ✔
513
}
514

515
void setupScriptUI(
132 ✔
516
    Process::ProcessModel& proc, const Process::LayerFactory& fact,
517
    const score::DocumentContext& ctx, bool show)
518
{
519
  if(!show)
132 ✔
520
  {
521
    closeProcessUI(proc.scriptUI, ctx);
60 ✔
522
    return;
60 ✔
523
  }
524

525
  if(auto win = proc.scriptUI)
72 ✔
526
  {
527
    raiseProcessUI(win, ctx);
3 ✔
528
    return;
3 ✔
529
  }
530

531
  auto win = fact.makeScriptUI(proc, ctx, nullptr);
69 ✔
532
  if(!win)
69 ✔
533
    return;
×
534

535
  proc.scriptUI = win;
69 ✔
536
  win->setAttribute(Qt::WA_DeleteOnClose);
69 ✔
537

538
  placeProcessUI(
69 ✔
539
      win, proc, ctx, placementFor(proc, ProcessUIKind::ScriptEditor),
69 ✔
540
      ProcessUIKind::ScriptEditor);
541
  proc.scriptUIVisible(true);
69 ✔
542
}
132 ✔
543

544
void setupExternalUI(
48 ✔
545
    Process::ProcessModel& proc, const Process::LayerFactory& fact,
546
    const score::DocumentContext& ctx, bool show)
547
{
548
  if(!show)
48 ✔
549
  {
550
    // A UI that does not report its own closing (a window container: its
551
    // cleanup only runs with the deferred deletion, once the pointer is
552
    // gone) gets reported here.
553
    if(closeProcessUI(proc.externalUI, ctx))
22 ✔
554
      proc.externalUIVisible(false);
22 ✔
555
    return;
22 ✔
556
  }
557

558
  if(auto win = proc.externalUI)
26 ✔
559
  {
560
    raiseProcessUI(win, ctx);
3 ✔
561
    return;
3 ✔
562
  }
563

564
  auto win = fact.makeExternalUI(proc, ctx, nullptr);
23 ✔
565
  if(!win)
23 ✔
566
    return;
×
567

568
  proc.externalUI = win;
23 ✔
569
  placeProcessUI(
23 ✔
570
      win, proc, ctx, placementFor(proc, ProcessUIKind::ExternalUI),
23 ✔
571
      ProcessUIKind::ExternalUI);
572
  proc.externalUIVisible(true);
23 ✔
573
}
48 ✔
574

575
void moveProcessUI(
17 ✔
576
    Process::ProcessModel& proc, const score::DocumentContext& ctx, ProcessUIKind kind,
577
    const QString& placement)
578
{
579
  // What gets stored ends up in the document: only known names
580
  if(!placement.isEmpty() && !UIPlacementSettings::names().contains(placement))
17 ✔
581
    return;
1 ✔
582

583
  // An explicit choice is kept for this process and becomes the default
584
  // for the others; "default" makes this process follow it again.
585
  QWidget* win{};
16 ✔
586
  switch(kind)
16 ✔
587
  {
588
    case ProcessUIKind::ScriptEditor:
589
      proc.setScriptEditorPlacement(placement);
15 ✔
590
      if(!placement.isEmpty())
15 ✔
591
        UIPlacementSettings::setScriptEditorPlacement(
14 ✔
592
            UIPlacementSettings::fromString(
14 ✔
593
                placement, UIPlacementSettings::scriptEditorPlacement()));
14 ✔
594
      win = proc.scriptUI;
15 ✔
595
      break;
15 ✔
596
    case ProcessUIKind::ExternalUI:
597
      proc.setProcessUIPlacement(placement);
1 ✔
598
      if(!placement.isEmpty())
1 ✔
599
        UIPlacementSettings::setProcessUIPlacement(
1 ✔
600
            UIPlacementSettings::fromString(
1 ✔
601
                placement, UIPlacementSettings::processUIPlacement()));
1 ✔
602
      win = proc.externalUI;
1 ✔
603
      break;
1 ✔
604
  }
605
  if(!win)
16 ✔
606
    return;
×
607

608
  const auto target = placementFor(proc, kind);
16 ✔
609
  detachProcessUI(win, ctx);
16 ✔
610
  placeProcessUI(win, proc, ctx, target, kind);
16 ✔
611
}
17 ✔
612

613
void fillPlacementMenu(
5 ✔
614
    QMenu& menu, Process::ProcessModel& proc, const score::DocumentContext& ctx,
615
    ProcessUIKind kind)
616
{
617
  const bool isEditor = kind == ProcessUIKind::ScriptEditor;
5 ✔
618
  auto title = menu.addAction(
10 ✔
619
      isEditor ? QObject::tr("Open the editor in") : QObject::tr("Open the UI in"));
5 ✔
620
  title->setEnabled(false);
5 ✔
621

622
  if(!isEditor && !(proc.flags() & Process::ProcessFlags::ExternalUIEmbeddable))
5 ✔
623
  {
624
    auto note = menu.addAction(QObject::tr("This UI can only open in its own window"));
1 ✔
625
    note->setEnabled(false);
1 ✔
626
    return;
1 ✔
627
  }
628

629
  const QString& current
4 ✔
630
      = isEditor ? proc.scriptEditorPlacement() : proc.processUIPlacement();
4 ✔
631
  const auto userDefault = isEditor ? UIPlacementSettings::scriptEditorPlacement()
4 ✔
632
                                    : UIPlacementSettings::processUIPlacement();
×
633
  const auto displayName = [](UIPlacement p) {
20 ✔
634
    switch(p)
16 ✔
635
    {
636
      case UIPlacement::Window:
637
        return QObject::tr("Separate window");
4 ✔
638
      case UIPlacement::SidePanel:
639
        return QObject::tr("Side panel");
7 ✔
640
      case UIPlacement::Central:
641
        return QObject::tr("Central view");
5 ✔
642
    }
643
    return QString{};
×
644
  };
16 ✔
645

646
  auto group = new QActionGroup{&menu};
4 ✔
647
  group->setExclusive(true);
4 ✔
648
  const auto addChoice = [&](const QString& text, const QString& value) {
20 ✔
649
    auto act = menu.addAction(text);
16 ✔
650
    act->setCheckable(true);
16 ✔
651
    act->setChecked(value == current);
16 ✔
652
    group->addAction(act);
16 ✔
653
    QObject::connect(act, &QAction::triggered, &menu, [&proc, &ctx, kind, value] {
17 ✔
654
      moveProcessUI(proc, ctx, kind, value);
1 ✔
655
    });
1 ✔
656
  };
16 ✔
657

658
  addChoice(QObject::tr("Default (%1)").arg(displayName(userDefault)), QString{});
4 ✔
659
  const auto& names = UIPlacementSettings::names();
4 ✔
660
  for(int i = 0; i < names.size(); i++)
16 ✔
661
    addChoice(displayName(static_cast<UIPlacement>(i)), names[i]);
12 ✔
662

663
  if(!isEditor)
4 ✔
664
    return;
×
665

666
  // What the editor is drawn over in the central view
667
  menu.addSeparator();
4 ✔
668
  auto previewTitle = menu.addAction(QObject::tr("Behind the editor"));
4 ✔
669
  previewTitle->setEnabled(false);
4 ✔
670
  const auto previewName = [](PreviewSource p) {
12 ✔
671
    switch(p)
8 ✔
672
    {
673
      case PreviewSource::Background:
674
        return QObject::tr("Document background, without chrome");
4 ✔
675
      case PreviewSource::None:
676
        return QObject::tr("Nothing: a plain editor");
4 ✔
677
    }
678
    return QString{};
×
679
  };
8 ✔
680
  const auto currentPreview = UIPlacementSettings::scriptEditorPreview();
4 ✔
681
  auto previewGroup = new QActionGroup{&menu};
4 ✔
682
  previewGroup->setExclusive(true);
4 ✔
683
  for(auto src : {PreviewSource::Background, PreviewSource::None})
12 ✔
684
  {
685
    auto act = menu.addAction(previewName(src));
8 ✔
686
    act->setCheckable(true);
8 ✔
687
    act->setChecked(src == currentPreview);
8 ✔
688
    previewGroup->addAction(act);
8 ✔
689
    QObject::connect(act, &QAction::triggered, &menu, [&proc, &ctx, src] {
8 ✔
690
      UIPlacementSettings::setScriptEditorPreview(src);
×
691
      // Applied right away to an open central editor
692
      auto win = proc.scriptUI;
×
693
      auto state = placedState(win);
×
694
      if(!win || !state || state->placement != UIPlacement::Central)
×
695
        return;
×
696
      detachProcessUI(win, ctx);
×
697
      placeProcessUI(win, proc, ctx, UIPlacement::Central, ProcessUIKind::ScriptEditor);
×
698
    });
×
699
  }
700
}
5 ✔
701

702
void setupScriptUI(
131 ✔
703
    Process::ProcessModel& proc, const score::DocumentContext& ctx, bool show)
704
{
705
  if(!(proc.flags() & Process::ProcessFlags::ScriptEditingSupported))
131 ✔
706
    return;
×
707

708
  auto& facts = ctx.app.interfaces<Process::LayerFactoryList>();
131 ✔
709
  auto fact = facts.findDefaultFactory(proc);
131 ✔
710
  if(!fact)
131 ✔
711
    return;
×
712

713
  setupScriptUI(proc, *fact, ctx, show);
131 ✔
714
}
131 ✔
715

716
void setupExternalUI(
50 ✔
717
    Process::ProcessModel& proc, const score::DocumentContext& ctx, bool show)
718
{
719
  auto& facts = ctx.app.interfaces<Process::LayerFactoryList>();
50 ✔
720

721
  auto fact = facts.findDefaultFactory(proc);
50 ✔
722
  if(!fact || !fact->hasExternalUI(proc, ctx))
50 ✔
723
    return;
2 ✔
724

725
  setupExternalUI(proc, *fact, ctx, show);
48 ✔
726
}
50 ✔
727

728
QGraphicsItem* makeExternalUIButton(
5,286 ✔
729
    ProcessModel& effect, const score::DocumentContext& context, QObject* self,
730
    QGraphicsItem* root)
731
{
732
  auto& pixmaps = Process::Pixmaps::instance();
5,286 ✔
733
  auto& facts = context.app.interfaces<Process::LayerFactoryList>();
5,286 ✔
734
  auto fact = facts.findDefaultFactory(effect);
5,286 ✔
735
  if(fact && fact->hasExternalUI(effect, context))
5,286 ✔
736
  {
737
    auto ui_btn = new score::QGraphicsPixmapToggle{
140 ✔
738
        pixmaps.show_ui_on, pixmaps.show_ui_off, root};
70 ✔
739
    ui_btn->setToolTip(
140 ✔
740
        QObject::tr(
70 ✔
741
            "Show/hide UI\nShow the process's interface for instance for VSTs "
742
            "or script editor for JS, etc."));
743
    QObject::connect(
70 ✔
744
        ui_btn, &score::QGraphicsPixmapToggle::toggled, self,
70 ✔
745
        [=, &effect, &context](bool b) {
70 ✔
746
      Process::setupExternalUI(effect, *fact, context, b);
×
747
    });
×
748

749
    if(effect.externalUI)
70 ✔
750
      ui_btn->setState(true);
1 ✔
751
    QObject::connect(
70 ✔
752
        &effect, &Process::ProcessModel::externalUIVisible, ui_btn,
70 ✔
753
        [=](bool v) { ui_btn->setState(v); });
115 ✔
754
    QObject::connect(
70 ✔
755
        ui_btn, &score::QGraphicsPixmapToggle::contextMenuRequested, self,
70 ✔
756
        [&effect, &context](QPoint pos) {
70 ✔
757
      QMenu menu;
×
758
      fillPlacementMenu(menu, effect, context, ProcessUIKind::ExternalUI);
×
759
      menu.exec(pos);
×
760
    });
×
761
    return ui_btn;
70 ✔
762
  }
763
  return nullptr;
5,216 ✔
764
}
5,286 ✔
765

766
score::QGraphicsDraggablePixmap* makePresetButton(
2,546 ✔
767
    const ProcessModel& proc, const score::DocumentContext& context, QObject* self,
768
    QGraphicsItem* root)
769
{
770
  auto& pixmaps = Process::Pixmaps::instance();
2,546 ✔
771
  auto ui_btn
2,546 ✔
772
      = new score::QGraphicsDraggablePixmap{pixmaps.preset_on, pixmaps.preset_off, root};
2,546 ✔
773
  ui_btn->setToolTip(
5,092 ✔
774
      QObject::tr(
2,546 ✔
775
          "Presets\nClick to browse them in the library, where they load into "
776
          "this process. Drag to the library to save the current preset. Drag "
777
          "to a scenario or a state for a cue of the current values of the "
778
          "controls; hold Ctrl when dropping to choose what to drop. The mouse's "
779
          "Forward and Back buttons step through the presets in the library's "
780
          "order."));
781
  ui_btn->createDrag = [&proc, &context](QMimeData& mime) {
2,552 ✔
782
    // Dropped on a state or in a scenario it makes a cue; elsewhere a copy
783
    std::vector<const ProcessModel*> dragged{&proc};
6 ✔
784
    const auto& sel = context.selectionStack.currentSelection();
6 ✔
785
    if(ossia::any_of(sel, [&](const auto& obj) { return obj.data() == &proc; }))
13 ✔
786
      for(const auto& obj : sel)
6 ✔
787
        if(auto p = qobject_cast<const ProcessModel*>(obj.data()); p && p != &proc)
4 ✔
788
          dragged.push_back(p);
4 ✔
789

790
    QByteArray data;
6 ✔
791
    {
792
      JSONReader r;
6 ✔
793
      r.stream.StartObject();
6 ✔
794
      copyProcess(r, proc);
6 ✔
795
      r.obj["Path"] = score::IDocument::path(proc);
6 ✔
796
      r.obj["View"] = QStringLiteral("Nodal");
6 ✔
797
      r.stream.Key("Copy");
6 ✔
798
      r.stream.StartObject();
6 ✔
799
      copyProcesses(r, dragged, context);
6 ✔
800
      r.stream.EndObject();
6 ✔
801
      r.stream.EndObject();
6 ✔
802
      data = r.toByteArray();
6 ✔
803
    }
6 ✔
804

805
    mime.setData(score::mime::layerdata(), data);
6 ✔
806
    mime.setData(score::mime::processpreset(), proc.savePreset().toJson());
6 ✔
807
  };
6 ✔
808

809
  ui_btn->click = [&proc, &context](Qt::MouseButton btn, QPointF screenPos) {
2,569 ✔
810
    auto& pplug = context.app.applicationPlugin<Process::ApplicationPlugin>();
23 ✔
811

812
    switch(btn)
23 ✔
813
    {
814
      default:
815
        break;
×
816
      case Qt::LeftButton:
817
        pplug.showPresets(&proc);
11 ✔
818
        break;
11 ✔
819

820
      case Qt::ForwardButton:
821
      case Qt::BackButton: {
822
        const auto builtins = proc.builtinPresets();
12 ✔
823
        const PresetTree tree{proc, pplug.presets, builtins};
12 ✔
824
        // Step from the current preset, in the library's order
825
        const auto ordered = tree.ordered();
12 ✔
826
        const int n = std::ssize(ordered);
12 ✔
827
        if(n < 2)
12 ✔
828
          return;
×
829

830
        int i = -1;
12 ✔
831
        for(int j = 0; j < n; j++)
52 ✔
832
          if(isCurrentPreset(proc, *ordered[std::size_t(j)]))
51 ✔
833
          {
834
            i = j;
11 ✔
835
            break;
11 ✔
836
          }
837

838
        if(i < 0)
12 ✔
839
          // None loaded from here yet: start at the relevant end
840
          i = (btn == Qt::ForwardButton) ? 0 : (n - 1);
1 ✔
841
        else if(btn == Qt::ForwardButton)
11 ✔
842
          i = (i + 1) % n;
9 ✔
843
        else
844
          i = (i - 1 + n) % n;
2 ✔
845

846
        loadPreset(proc, *ordered[std::size_t(i)], context);
12 ✔
847
        break;
12 ✔
848
      }
12 ✔
849
    }
850
  };
23 ✔
851

852
  return ui_btn;
2,546 ✔
853
}
×
854

855
void copyProcess(JSONReader& r, const Process::ProcessModel& proc)
7 ✔
856
{
857
  const auto& ctx = score::IDocument::documentContext(proc);
7 ✔
858

859
  std::vector<const Process::ProcessModel*> vp{&proc};
7 ✔
860
  std::vector<Path<Process::ProcessModel>> vpath{proc};
7 ✔
861
  // Object is not created here but in SlotHeader
862
  r.obj["PID"] = ossia::get_pid();
7 ✔
863
  r.obj["Document"] = ctx.document.id();
7 ✔
864
  // Document identifiers repeat across open documents
865
  r.obj["OriginDocument"] = score::IDocument::copyOrigin(ctx.document);
7 ✔
866
  r.obj["Process"] = proc;
7 ✔
867
  r.obj["Cables"] = Process::cablesToCopy(vp, vpath, ctx);
7 ✔
868
}
7 ✔
869

870
void copyProcesses(
15 ✔
871
    JSONReader& r, const std::vector<const Process::ProcessModel*>& processes,
872
    const score::DocumentContext& ctx)
873
{
874
  r.obj["Processes"] = processes;
15 ✔
875
  r.obj["Cables"] = Process::cablesToCopy(processes, ctx);
15 ✔
876
  r.stream.Key("ProcessPaths");
15 ✔
877
  r.stream.StartArray();
15 ✔
878
  for(auto proc : processes)
33 ✔
879
    r.readFrom(score::IDocument::unsafe_path(*proc));
18 ✔
880
  r.stream.EndArray();
15 ✔
881
  r.obj["OriginDocument"] = score::IDocument::copyOrigin(ctx.document);
15 ✔
882
}
15 ✔
883
}
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