• 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

85.19
/src/plugins/score-plugin-library/Library/ProcessWidget.cpp
1
#include "ProcessWidget.hpp"
2

3
#include <Process/ApplicationPlugin.hpp>
4
#include <Process/PresetTree.hpp>
5
#include <Process/Process.hpp>
6
#include <Process/PreviewSettings.hpp>
7
#include <Process/ProcessList.hpp>
8

9
#include <Library/PresetFile.hpp>
10
#include <Library/ItemModelFilterLineEdit.hpp>
11
#include <Library/LibraryWidget.hpp>
12
#include <Library/PresetItemModel.hpp>
13
#include <Library/ProcessesItemModel.hpp>
14
#include <Library/RecursiveFilterProxy.hpp>
15

16
#include <score/application/GUIApplicationContext.hpp>
17
#include <score/document/DocumentInterface.hpp>
18
#include <score/selection/SelectionDispatcher.hpp>
19
#include <score/selection/SelectionStack.hpp>
20
#include <score/widgets/Pixmap.hpp>
21
#include <score/tools/File.hpp>
22
#include <score/widgets/HelpInteraction.hpp>
23
#include <score/widgets/MarginLess.hpp>
24

25
#include <core/view/FixedTabWidget.hpp>
26
#include <core/view/Window.hpp>
27

28
#include <ossia/detail/algorithms.hpp>
29
#include <ossia/detail/math.hpp>
30

31
#include <QApplication>
32
#include <QLabel>
33
#include <QLineEdit>
34
#include <QMainWindow>
35
#include <QScrollArea>
36
#include <QTimer>
37
#include <QPushButton>
38
#include <QSettings>
39
#include <QShortcut>
40
#include <QSortFilterProxyModel>
41
#include <QToolButton>
42
#include <QVBoxLayout>
43

44
namespace Library
45
{
46
class InfoWidget final : public QScrollArea
47
{
48
public:
49
  InfoWidget(QWidget* parent)
5,966 ✔
50
      : QScrollArea{parent}
2,983 ✔
51
  {
2,983 ✔
52
    // A long description scrolls rather than taking the presets' room
53
    setWidgetResizable(true);
2,983 ✔
54
    setFrameShape(QFrame::NoFrame);
2,983 ✔
55
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
2,983 ✔
56
    setMaximumHeight(160);
2,983 ✔
57
    auto content = new QWidget;
2,983 ✔
58
    auto lay = new score::MarginLess<QVBoxLayout>{content};
2,983 ✔
59
    lay->setAlignment(Qt::AlignTop);
2,983 ✔
60
    lay->setContentsMargins(6, 6, 6, 6);
2,983 ✔
61
    QFont f;
2,983 ✔
62
    f.setBold(true);
2,983 ✔
63
    m_name.setFont(f);
2,983 ✔
64
    m_name.setAlignment(Qt::AlignTop);
2,983 ✔
65
    lay->addWidget(&m_name);
2,983 ✔
66
    lay->addWidget(&m_author);
2,983 ✔
67
    m_author.setWordWrap(true);
2,983 ✔
68
    m_author.setAlignment(Qt::AlignTop);
2,983 ✔
69
    lay->addWidget(&m_io);
2,983 ✔
70
    lay->addWidget(&m_description);
2,983 ✔
71
    m_description.setWordWrap(true);
2,983 ✔
72
    m_description.setAlignment(Qt::AlignTop);
2,983 ✔
73
    lay->addWidget(&m_tags);
2,983 ✔
74
    m_tags.setWordWrap(true);
2,983 ✔
75
    m_tags.setAlignment(Qt::AlignTop);
2,983 ✔
76
    m_documentationLink.setAlignment(Qt::AlignBottom);
2,983 ✔
77
    lay->addStretch(2);
2,983 ✔
78
    lay->addWidget(&m_documentationLink);
2,983 ✔
79
    setWidget(content);
2,983 ✔
80
    setVisible(false);
2,983 ✔
81
  }
2,983 ✔
82

83
  //! As tall as its text, up to its maximum, past which it scrolls
84
  QSize sizeHint() const override
×
85
  {
86
    int h = 0;
×
87
    if(auto w = widget())
×
88
    {
89
      // Wrapped text is as tall as the width it wraps in
90
      const int width = viewport()->width();
×
91
      h = w->hasHeightForWidth() && width > 0 ? w->heightForWidth(width)
×
92
                                               : w->sizeHint().height();
×
93
      h += 2 * frameWidth();
×
94
    }
×
95
    return {QScrollArea::sizeHint().width(), std::min(h, maximumHeight())};
×
96
  }
97

98
  void setData(const std::optional<ProcessData>& d)
12 ✔
99
  {
100
    updateGeometry();
12 ✔
101
    m_author.setText(QString{});
12 ✔
102
    m_description.setText(QString{});
12 ✔
103
    m_io.setText(QString{});
12 ✔
104
    m_tags.setText(QString{});
12 ✔
105
    m_documentationLink.clear();
12 ✔
106

107
    if(d)
12 ✔
108
    {
109
      if(auto f
12 ✔
110
         = score::GUIAppContext().interfaces<Process::ProcessFactoryList>().get(d->key))
12 ✔
111
      {
112
        setVisible(true);
11 ✔
113
        auto desc = f->descriptor(d->customData);
11 ✔
114

115
        if(!d->prettyName.isEmpty())
11 ✔
116
          m_name.setText(d->prettyName);
11 ✔
117
        else
118
          m_name.setText(desc.prettyName);
×
119

120
        if(!desc.author.isEmpty())
11 ✔
121
          m_author.setText(tr("Provided by ") + desc.author);
11 ✔
122
        else
123
          m_author.setText(tr("Author unknown"));
×
124

125
        if(!desc.description.isEmpty())
11 ✔
126
          m_description.setText(desc.description);
11 ✔
127

128
        QString io;
11 ✔
129
        if(desc.inlets)
11 ✔
130
        {
131
          io += QString::number(desc.inlets->size()) + tr(" input");
9 ✔
132
          if(desc.inlets->size() > 1)
9 ✔
133
            io += "s";
9 ✔
134
        }
9 ✔
135
        if(desc.inlets && desc.outlets)
11 ✔
136
          io += ", ";
9 ✔
137
        if(desc.outlets)
11 ✔
138
        {
139
          io += QString::number(desc.outlets->size()) + tr(" output");
11 ✔
140
          if(desc.outlets->size() > 1)
11 ✔
141
            io += "s";
×
142
        }
11 ✔
143
        m_io.setText(io);
11 ✔
144
        if(!desc.tags.empty())
11 ✔
145
        {
146
          m_tags.setText(tr("Tags: ") + desc.tags.join(", "));
×
147
        }
×
148

149
        if(!desc.documentationLink.isEmpty())
11 ✔
150
        {
151
          QString linkText = "Explore the documentation";
11 ✔
152
          QString iconPath = ":/icons/undock_on.png";
11 ✔
153
          QString iconHtml = "<img src=\"" + iconPath + "\" width=\"16\" height=\"16\" style=\"vertical-align:middle;\" />";
11 ✔
154
          QString fullLink = "<a href=\"" + desc.documentationLink.toString() + "\">" + linkText + " " + iconHtml + "</a>";
11 ✔
155
          m_documentationLink.setTextFormat(Qt::RichText);
11 ✔
156
          m_documentationLink.setText(fullLink);
11 ✔
157
          m_documentationLink.setOpenExternalLinks(true);
11 ✔
158
        }
11 ✔
159

160
        return;
161
      }
11 ✔
162
    }
1 ✔
163

164
    setVisible(false);
1 ✔
165
  }
12 ✔
166

167
  QLabel m_name;
168
  QLabel m_io;
169
  QLabel m_description;
170
  QLabel m_author;
171
  QLabel m_tags;
172
  QLabel m_documentationLink;
173
};
174

175
ProcessWidget::ProcessWidget(const score::GUIApplicationContext& ctx, QWidget* parent)
5,966 ✔
176
    : QWidget{parent}
2,983 ✔
177
    , m_processModel{new ProcessesItemModel{ctx, this}}
2,983 ✔
178
    , m_presetModel{new PresetItemModel{ctx, this}}
2,983 ✔
179
    , m_preview{this}
180
{
2,983 ✔
181
  auto slay = new score::MarginLess<QVBoxLayout>{this};
2,983 ✔
182
  setLayout(slay);
2,983 ✔
183

184
  setStatusTip(
2,983 ✔
185
      QObject::tr("This panel shows the available processes.\n"
2,983 ✔
186
                  "They can be drag'n'dropped in the score, in intervals, "
187
                  "and sometimes in effect chains."));
188

189
  {
190
    m_notice.setWordWrap(true);
2,983 ✔
191
    m_notice.setTextFormat(Qt::RichText);
2,983 ✔
192
    m_notice.setTextInteractionFlags(Qt::TextBrowserInteraction);
2,983 ✔
193
    m_notice.setOpenExternalLinks(false);
2,983 ✔
194
    m_notice.setContentsMargins(4, 4, 4, 4);
2,983 ✔
195
    m_notice.hide();
2,983 ✔
196
    slay->addWidget(&m_notice);
2,983 ✔
197
    connect(&m_notice, &QLabel::linkActivated, this, [this](const QString&) {
2,984 ✔
198
      if(m_noticeAction)
1 ✔
199
        m_noticeAction();
1 ✔
200
    });
1 ✔
201
  }
202

203
  QLineEdit* filter{};
2,983 ✔
204

205
  {
206
    auto processFilterProxy = new ProcessFilterProxy{this};
2,983 ✔
207
    processFilterProxy->setSourceModel(m_processModel);
2,983 ✔
208
    processFilterProxy->setFilterKeyColumn(0);
2,983 ✔
209
    filter = new ItemModelFilterLineEdit{*processFilterProxy, m_tv, this};
2,983 ✔
210
    m_processFilter = filter;
2,983 ✔
211
    slay->addWidget(filter);
2,983 ✔
212
    slay->addWidget(&m_tv, 3);
2,983 ✔
213
    m_tv.setModel(processFilterProxy);
2,983 ✔
214
    m_tv.setStatusTip(statusTip());
2,983 ✔
215
    m_tv.setUniformRowHeights(true);
2,983 ✔
216
    setup_treeview(m_tv);
2,983 ✔
217
  }
218

219
  {
220
    auto lay = new score::MarginLess<QHBoxLayout>{&m_targetBar};
2,983 ✔
221
    lay->setContentsMargins(4, 2, 2, 2);
2,983 ✔
222
    m_targetLabel.setTextFormat(Qt::PlainText);
2,983 ✔
223
    // A browser's preview toggle: lit while presets load as they are browsed
224
    auto audition = new QPushButton{&m_targetBar};
2,983 ✔
225
    audition->setCheckable(true);
2,983 ✔
226
    audition->setFlat(true);
2,983 ✔
227
    audition->setMinimumWidth(24);
2,983 ✔
228
    audition->setMaximumWidth(24);
2,983 ✔
229
    const auto onIcon = QIcon{score::get_pixmap(":/icons/headphones_on.png")};
2,983 ✔
230
    const auto offIcon = QIcon{score::get_pixmap(":/icons/headphones_off.png")};
2,983 ✔
231
    const auto showAudition = [=, this](bool on) {
14,919 ✔
232
      audition->setIcon(on ? onIcon : offIcon);
2,987 ✔
233
      audition->setToolTip(
5,974 ✔
234
          on ? tr("Presets load as you move through them. Click to only load "
2,987 ✔
235
                  "one on Enter or a double-click.")
236
             : tr("Presets load on Enter or a double-click. Click to load them "
2 ✔
237
                  "as you move through them."));
238
    };
2,987 ✔
239
    m_auditionEnabled = QSettings{}.value("Library/AuditionPresets", true).toBool();
2,983 ✔
240
    audition->setChecked(m_auditionEnabled);
2,983 ✔
241
    showAudition(m_auditionEnabled);
2,983 ✔
242
    connect(audition, &QPushButton::toggled, this, [this, showAudition](bool on) {
2,987 ✔
243
      m_auditionEnabled = on;
4 ✔
244
      QSettings{}.setValue("Library/AuditionPresets", on);
4 ✔
245
      showAudition(on);
4 ✔
246
      // What is heard is kept
247
      m_audition.commit();
4 ✔
248
      m_presetModel->refreshCurrent();
4 ✔
249
    });
4 ✔
250
    lay->addWidget(audition);
2,983 ✔
251
    lay->addWidget(&m_targetLabel, 1);
2,983 ✔
252
    auto save = new QToolButton{&m_targetBar};
2,983 ✔
253
    save->setText(tr("Save"));
2,983 ✔
254
    save->setToolTip(
2,983 ✔
255
        tr("Save the process's current state as a preset, in the selected folder"));
2,983 ✔
256
    connect(save, &QToolButton::clicked, this, [this] {
2,983 ✔
257
      if(auto proc = m_presetModel->target())
×
258
        m_presetModel->savePreset(
×
259
            *proc, m_presetModel->folderPath(m_presets.currentIndex()).join('/'));
×
260
    });
×
261
    lay->addWidget(save);
2,983 ✔
262
    auto close = new QToolButton{&m_targetBar};
2,983 ✔
263
    close->setIcon(QIcon{score::get_pixmap(":/icons/close_off.png")});
2,983 ✔
264
    close->setAutoRaise(true);
2,983 ✔
265
    close->setToolTip(tr("Stop loading the presets into this process"));
2,983 ✔
266
    connect(close, &QToolButton::clicked, this, &ProcessWidget::clearTarget);
2,983 ✔
267
    lay->addWidget(close);
2,983 ✔
268
    m_targetBar.hide();
2,983 ✔
269
    slay->addWidget(&m_targetBar);
2,983 ✔
270
  }
2,983 ✔
271

272
  {
273
    auto search = new QLineEdit{this};
2,983 ✔
274
    search->setPlaceholderText(tr("Search presets"));
2,983 ✔
275
    search->setClearButtonEnabled(true);
2,983 ✔
276
    connect(search, &QLineEdit::textChanged, m_presetModel, &PresetItemModel::setFilterText);
2,983 ✔
277
    slay->addWidget(search);
2,983 ✔
278
    m_presets.setPresetModel(m_presetModel);
2,983 ✔
279
    slay->addWidget(&m_presets, 2);
2,983 ✔
280
  }
281

282
  slay->addWidget(&m_preview);
2,983 ✔
283
  {
284
    auto previewLay = new score::MarginLess<QHBoxLayout>{&m_preview};
2,983 ✔
285
    m_preview.setLayout(previewLay);
2,983 ✔
286
    m_preview.hide();
2,983 ✔
287
  }
288

289
  // Turning previews off has to reach the thumbnail already on screen, not wait
290
  // for the next selection. Both handlers share m_previewChild, so rebuild the
291
  // one that is actually showing: re-announcing the tree selection would
292
  // destroy a preset preview and clear state nothing asked to clear.
293
  con(Process::PreviewSettings::instance(), &Process::PreviewSettings::enabledChanged,
5,966 ✔
294
      this, [this](bool) {
2,983 ✔
295
    if(m_presetModel->preset(m_presets.currentIndex()) && m_refreshPresetPreview)
×
296
      m_refreshPresetPreview();
×
297
    else if(auto* sm = m_tv.selectionModel(); sm && !sm->selectedIndexes().isEmpty())
×
298
      m_tv.reselect();
×
299
  });
×
300

301
  auto infoWidg = new InfoWidget{this};
2,983 ✔
302
  score::setHelp(infoWidg, statusTip());
2,983 ✔
303
  slay->addWidget(infoWidg);
2,983 ✔
304

305
  connect(
2,983 ✔
306
      &m_tv, &ProcessTreeView::selected, this,
2,983 ✔
307
      [this, infoWidg, filter](const std::optional<Library::ProcessData>& pdata) {
2,995 ✔
308
#if defined(_WIN32)
309
    const bool filter_had_focus = filter->hasFocus();
310
    const bool tree_had_focus = m_tv.hasFocus();
311
#endif
312
    m_preview.hide();
12 ✔
313

314
    // Update info widget
315
    infoWidg->setData(pdata);
12 ✔
316

317
    // Another process chosen by the user: its presets no longer load into
318
    // the one whose button opened them
319
    if(!m_choosingTarget)
12 ✔
320
      if(auto t = m_presetModel->target(); t && (!pdata || pdata->key != t->concreteKey()))
3 ✔
321
        clearTarget();
1 ✔
322

323
    // Its presets
324
    if(pdata)
12 ✔
325
      m_presetModel->setProcess(Process::ProcessIdentifier{pdata->key, pdata->customData});
12 ✔
326
    else
327
      m_presetModel->setProcess(std::nullopt);
×
328

329
    // Update the preview
330
    delete m_previewChild;
12 ✔
331
    m_previewChild = nullptr;
12 ✔
332
    if(pdata)
12 ✔
333
    {
334
      if(QFile::exists(pdata->customData))
12 ✔
335
      {
336
        for(auto lib : libraryInterface(pdata->customData))
×
337
        {
338
          if((m_previewChild = lib->previewWidget(pdata->customData, &m_preview)))
×
339
          {
340
            m_preview.layout()->addWidget(m_previewChild);
×
341
            m_preview.show();
×
342
            break;
×
343
          }
344
        }
345
      }
×
346
    }
12 ✔
347

348
#if defined(_WIN32)
349
    for(int i = 0; i < 100; i++)
350
    {
351
      QTimer::singleShot(i, this, [=, this] {
352
        if(filter_had_focus)
353
          filter->setFocus();
354
        else if(tree_had_focus)
355
          m_tv.setFocus();
356
      });
357
    }
358
#endif
359
  });
12 ✔
360

361
  connect(
2,983 ✔
362
      &m_presets, &PresetTreeView::selected, this,
2,983 ✔
363
      [this, filter](const std::optional<Process::Preset>& selected) {
2,996 ✔
364
    if(!selected)
13 ✔
365
      return;
×
366

367
    // Heard at once in the process the presets load into
368
    if(auto proc = m_presetModel->target(); proc && m_auditionEnabled)
13 ✔
369
      if(m_audition.preview(*proc, *selected))
24 ✔
370
        m_presetModel->refreshCurrent();
12 ✔
371

372
#if defined(_WIN32)
373
    const bool filter_had_focus = filter->hasFocus();
374
    const bool tree_had_focus = m_tv.hasFocus();
375
#endif
376

377
    m_preview.hide();
13 ✔
378
    delete m_previewChild;
13 ✔
379
    m_previewChild = nullptr;
13 ✔
380

381
    const auto& preset = *selected;
13 ✔
382

383
    const auto buildPreview = [this](const Process::Preset& p) {
26 ✔
384
      delete m_previewChild;
13 ✔
385
      m_previewChild = nullptr;
13 ✔
386
      for(auto& lib : score::GUIAppContext().interfaces<LibraryInterfaceList>())
390 ✔
387
      {
388
        if((m_previewChild = lib.previewWidget(p, &m_preview)))
377 ✔
389
        {
390
          m_preview.layout()->addWidget(m_previewChild);
×
391
          m_preview.show();
×
392
          break;
×
393
        }
394
      }
395
    };
13 ✔
396
    buildPreview(preset);
13 ✔
397
    m_refreshPresetPreview = [this, buildPreview, p = preset] { buildPreview(p); };
13 ✔
398
#if defined(_WIN32)
399
    for(int i = 0; i < 100; i++)
400
    {
401
      QTimer::singleShot(i, this, [=, this] {
402
        if(filter_had_focus)
403
          filter->setFocus();
404
        else if(tree_had_focus)
405
          m_tv.setFocus();
406
      });
407
    }
408
#endif
409
  });
13 ✔
410
  m_presets.setMinimumHeight(100);
2,983 ✔
411

412
  auto& presetLib = ctx.applicationPlugin<Process::ApplicationPlugin>();
2,983 ✔
413
  con(presetLib, &Process::ApplicationPlugin::savePreset, this,
5,966 ✔
414
      [&](const Process::ProcessModel* proc) {
2,983 ✔
415
    SCORE_ASSERT(proc);
×
416
    this->m_presetModel->savePreset(*proc);
×
417
  });
×
418
  con(presetLib, &Process::ApplicationPlugin::showPresets, this,
5,966 ✔
419
      [this](const Process::ProcessModel* proc) {
2,994 ✔
420
    if(proc)
11 ✔
421
      showPresets(*proc);
11 ✔
422
  });
11 ✔
423
  con(presetLib, &Process::ApplicationPlugin::currentPresetChanged, this,
5,966 ✔
424
      [this](const Process::ProcessModel* proc) {
2,985 ✔
425
    if(proc && proc == m_presetModel->target())
2 ✔
426
    {
427
      m_presetModel->refreshCurrent();
2 ✔
428
      m_presets.showCurrentPreset();
2 ✔
429
    }
2 ✔
430
  });
2 ✔
431
  connect(
2,983 ✔
432
      &m_presets, &PresetTreeView::loadRequested, this,
2,983 ✔
433
      [this](const Process::Preset& preset) {
2,986 ✔
434
    auto proc = m_presetModel->target();
3 ✔
435
    if(!proc)
3 ✔
436
      return;
×
437
    // The one being heard is kept; another is loaded as it is
438
    if(m_audition.active() && Process::isCurrentPreset(*proc, preset))
3 ✔
439
      m_audition.commit();
2 ✔
440
    else
441
    {
442
      m_audition.commit();
1 ✔
443
      Process::loadPreset(*proc, preset, score::IDocument::documentContext(*proc));
1 ✔
444
    }
445
    m_presetModel->refreshCurrent();
3 ✔
446
  });
3 ✔
447
  connect(&m_presets, &PresetTreeView::cancelRequested, this, [this] {
2,984 ✔
448
    if(!m_audition.active())
1 ✔
449
      return;
×
450
    m_audition.rollback();
1 ✔
451
    m_presetModel->refreshCurrent();
1 ✔
452
    m_presets.showCurrentPreset();
1 ✔
453
  });
1 ✔
454
  // Doing anything else keeps what is heard: a click elsewhere takes the
455
  // focus before it acts
456
  con(*qApp, &QApplication::focusChanged, this, [this](QWidget*, QWidget* now) {
3,250 ✔
457
    if(m_audition.active() && now != &m_presets && !m_presets.isAncestorOf(now))
267 ✔
458
      m_audition.commit();
1 ✔
459
  });
267 ✔
460
}
×
461

462
void ProcessWidget::raisePanel()
11 ✔
463
{
464
  // Wherever the panel is docked
465
  if(auto view = qobject_cast<score::View*>(score::GUIAppContext().mainWindow))
11 ✔
466
    for(auto tabs : {view->leftTabs, view->rightTabs, view->bottomTabs})
44 ✔
467
      if(tabs)
33 ✔
468
        tabs->showTab(this);
44 ✔
469
}
11 ✔
470

471
void ProcessWidget::showPresets(const Process::ProcessModel& proc)
11 ✔
472
{
473
  m_audition.commit();
11 ✔
474
  raisePanel();
11 ✔
475

476
  // Its entry in the process tree, which a search there could hide
477
  auto idx = m_processModel->find(proc.concreteKey(), proc.effect());
11 ✔
478
  if(auto proxy = qobject_cast<QSortFilterProxyModel*>(m_tv.model()))
11 ✔
479
  {
480
    if(!proxy->mapFromSource(idx).isValid() && m_processFilter)
11 ✔
481
      m_processFilter->clear();
×
482
    idx = proxy->mapFromSource(idx);
11 ✔
483
  }
11 ✔
484
  m_choosingTarget = true;
11 ✔
485
  if(idx.isValid())
11 ✔
486
  {
487
    for(auto p = idx.parent(); p.isValid(); p = p.parent())
33 ✔
488
      m_tv.expand(p);
22 ✔
489
    m_tv.setCurrentIndex(idx);
11 ✔
490
    // Once the rows just opened are laid out
491
    QTimer::singleShot(0, &m_tv, [this] {
22 ✔
492
      m_tv.scrollTo(m_tv.currentIndex(), QAbstractItemView::PositionAtCenter);
11 ✔
493
    });
11 ✔
494
  }
11 ✔
495
  m_choosingTarget = false;
11 ✔
496

497
  // The presets are those of this very process: its script, its plug-in
498
  m_presetModel->setTarget(&proc);
11 ✔
499
  score::GUIAppContext().applicationPlugin<Process::ApplicationPlugin>().setPresetTarget(
22 ✔
500
      &proc);
11 ✔
501
  disconnect(m_targetGone);
11 ✔
502
  m_targetGone = connect(&proc, &QObject::destroyed, this, [this] { clearTarget(); });
20 ✔
503

504
  // It is the one selected while its presets load into it; deselected, the
505
  // library is browsed for any process again
506
  auto& sel = score::IDocument::documentContext(proc).selectionStack;
11 ✔
507
  score::SelectionDispatcher{sel}.select(proc);
11 ✔
508
  disconnect(m_targetDeselected);
11 ✔
509
  m_targetDeselected = connect(
11 ✔
510
      &sel, &score::SelectionStack::currentSelectionChanged, this,
11 ✔
511
      [this](const Selection&, const Selection&) {
15 ✔
512
    // Once what deselected it is done: undoing its creation deselects it on
513
    // the way, which must not put anything in the history meanwhile
514
    QTimer::singleShot(0, this, [this] {
8 ✔
515
      auto t = m_presetModel->target();
4 ✔
516
      if(!t)
4 ✔
517
        return;
3 ✔
518
      const auto now
519
          = score::IDocument::documentContext(*t).selectionStack.currentSelection();
1 ✔
520
      if(!ossia::any_of(now, [t](const auto& obj) { return obj.data() == t; }))
1 ✔
521
        clearTarget();
1 ✔
522
    });
4 ✔
523
  });
4 ✔
524
  const auto name = proc.metadata().getLabel().isEmpty() ? proc.metadata().getName()
11 ✔
525
                                                         : proc.metadata().getLabel();
×
526
  m_targetLabel.setText(tr("Presets: %1").arg(name));
11 ✔
527
  m_targetBar.show();
11 ✔
528
  m_presets.showCurrentPreset();
11 ✔
529
  m_presets.setFocus();
11 ✔
530
}
11 ✔
531

532
void ProcessWidget::clearTarget()
11 ✔
533
{
534
  m_audition.commit();
11 ✔
535
  disconnect(m_targetGone);
11 ✔
536
  disconnect(m_targetDeselected);
11 ✔
537
  score::GUIAppContext().applicationPlugin<Process::ApplicationPlugin>().setPresetTarget(
11 ✔
538
      nullptr);
539
  m_presetModel->setTarget(nullptr);
11 ✔
540
  m_targetBar.hide();
11 ✔
541
}
11 ✔
542

543
void ProcessWidget::setNotice(const QString& html, std::function<void()> onActivated)
2 ✔
544
{
545
  m_noticeAction = std::move(onActivated);
2 ✔
546
  m_notice.setText(html);
2 ✔
547
  m_notice.setVisible(!html.isEmpty());
2 ✔
548
}
2 ✔
549

550
ProcessWidget::~ProcessWidget() { }
5,964 ✔
551

552
QSet<QString> PresetLibraryHandler::acceptedFiles() const noexcept
14,936 ✔
553
{
554
  return {"scp"};
14,936 ✔
555
}
556

557
QSet<QString> PresetLibraryHandler::acceptedMimeTypes() const noexcept
5,966 ✔
558
{
559
  return {score::mime::processpreset()};
5,966 ✔
560
}
561

562
void PresetLibraryHandler::setup(
3,004 ✔
563
    ProcessesItemModel& model, const score::GUIApplicationContext& ctx)
564
{
565
  presetLib = &ctx.applicationPlugin<Process::ApplicationPlugin>();
3,004 ✔
566
  processes = &ctx.interfaces<Process::ProcessFactoryList>();
3,004 ✔
567
  // Called at each scan of the library, which reads every preset again
568
  presetLib->clearPresets();
3,004 ✔
569
}
3,004 ✔
570

571
void PresetLibraryHandler::addPath(std::string_view path)
25 ✔
572
{
573
  QFile f{QString::fromUtf8(path.data(), path.length())};
25 ✔
574

575
  if(!f.open(QIODevice::ReadOnly))
25 ✔
576
    return;
×
577

578
  if(auto p = Process::Preset::fromJson(*processes, score::mapAsByteArray(f)))
50 ✔
579
  {
580
    p->path = f.fileName();
25 ✔
581
    presetLib->addPreset(std::move(*p));
25 ✔
582
  }
25 ✔
583
}
25 ✔
584

585
bool PresetLibraryHandler::onDrop(
×
586
    const QMimeData& mime, int row, int column, const QDir& parent)
587
{
588
  if(!mime.hasFormat(score::mime::processpreset()))
×
589
    return false;
×
590

591
  const auto data = mime.data(score::mime::processpreset());
×
592
  auto json = readJson(data);
×
593
  if(!json.IsObject() || !json.HasMember("Name") || !json["Name"].IsString())
×
594
    return true;
×
595

596
  // A name, not a path out of the folder it is dropped in
597
  const auto basename = QFileInfo{JsonValue{json["Name"]}.toString()}.fileName();
×
598
  if(basename.isEmpty())
×
599
    return false;
×
600
  const QString filename
601
      = score::addUniqueSuffix(parent.absolutePath() + "/" + basename + ".scp");
×
602
  return writePresetData(filename, data);
×
603
}
×
604

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