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

ossia / score / 45465485304

24 Nov 2026 06:59PM UTC coverage: 62.1% (+0.3%) from 61.818%
45465485304

Pull #2302

github

web-flow
Merge 52aaaa0b4 into ef0dd3ce5
Pull Request #2302: Mixer: a console of strips with meters, and the execution reporting back without stopping the audio

268210 of 802082 branches covered (33.44%)

1579 of 2302 new or added lines in 45 files covered. (68.59%)

123 existing lines in 22 files now uncovered.

274219 of 441577 relevant lines covered (62.1%)

766034.2 hits per line

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

79.98
/src/plugins/score-lib-process/Process/Dataflow/Port.cpp
1
#include "Port.hpp"
2

3
#include <Process/Dataflow/Cable.hpp>
4
#include <Process/Dataflow/ControlWidgets.hpp>
5
#include <Process/Dataflow/PortFactory.hpp>
6
#include <Process/Dataflow/PortItem.hpp>
7
#include <Process/Dataflow/PortListWidget.hpp>
8
#include <Process/Dataflow/PortSerialization.hpp>
9
#include <Process/Dataflow/PrettyPortName.hpp>
10
#include <Process/Dataflow/WidgetInlets.hpp>
11
#include <Process/ProcessContext.hpp>
12

13
#include <LocalTree/ScriptableReference.hpp>
14

15
#include <score/application/GUIApplicationContext.hpp>
16

17
#include <core/document/Document.hpp>
18
#include <score/document/DocumentInterface.hpp>
19
#include <score/graphics/GraphicsLayout.hpp>
20
#include <score/graphics/RectItem.hpp>
21
#include <score/graphics/TextItem.hpp>
22
#include <score/model/path/PathSerialization.hpp>
23
#include <score/plugins/SerializableHelpers.hpp>
24

25
#include <ossia/dataflow/port.hpp>
26
#include <ossia/detail/algorithms.hpp>
27
#include <ossia/detail/small_vector.hpp>
28
#include <ossia/network/common/destination_qualifiers.hpp>
29

30
#include <ossia-qt/name_utils.hpp>
31
#include <ossia-qt/value_metatypes.hpp>
32

33
#include <QDebug>
34
#include <QIODevice>
35
#include <QSignalBlocker>
36

37
#include <wobjectimpl.h>
38
W_OBJECT_IMPL(Process::Port)
704,819 !
39
W_OBJECT_IMPL(Process::Inlet)
5 !
40
W_OBJECT_IMPL(Process::Outlet)
×
41
W_OBJECT_IMPL(Process::ValueInlet)
333,932 !
42
W_OBJECT_IMPL(Process::ValueOutlet)
890,691 !
43
W_OBJECT_IMPL(Process::AudioInlet)
379,576 !
44
W_OBJECT_IMPL(Process::AudioOutlet)
410,148 !
45
W_OBJECT_IMPL(Process::MidiInlet)
81,162 !
46
W_OBJECT_IMPL(Process::MidiOutlet)
86,912 !
47
W_OBJECT_IMPL(Process::ControlInlet)
990,584 !
48
W_OBJECT_IMPL(Process::ControlOutlet)
4,404 !
49
namespace Process
50
{
51
MODEL_METADATA_IMPL_CPP(Inlet)
×
52
MODEL_METADATA_IMPL_CPP(Outlet)
×
53
MODEL_METADATA_IMPL_CPP(ValueInlet)
6,202 !
54
MODEL_METADATA_IMPL_CPP(ValueOutlet)
20,294 !
55
MODEL_METADATA_IMPL_CPP(AudioInlet)
35,826 !
56
MODEL_METADATA_IMPL_CPP(AudioOutlet)
32,079 !
57
MODEL_METADATA_IMPL_CPP(MidiInlet)
4,557 !
58
MODEL_METADATA_IMPL_CPP(MidiOutlet)
4,204 !
59
MODEL_METADATA_IMPL_CPP(ControlInlet)
42,913 !
60
MODEL_METADATA_IMPL_CPP(ControlOutlet)
141 !
61

62
Port::~Port() { }
152,332 ✔
63

64
Port::Port(Id<Port> c, const QString& name, QObject* parent)
216,340 ✔
65
    : IdentifiedObject<Port>{std::move(c), name, parent}
108,170 ✔
66
{
216,340 ✔
67
}
108,170 ✔
68

69
Port::Port(DataStream::Deserializer& vis, QObject* parent)
43,918 ✔
70
    : IdentifiedObject{vis, parent}
21,959 ✔
71
{
43,918 ✔
72
  vis.writeTo(*this);
21,959 !
73
}
21,959 ✔
74
Port::Port(JSONObject::Deserializer& vis, QObject* parent)
44,406 ✔
75
    : IdentifiedObject{vis, parent}
22,203 ✔
76
{
44,406 ✔
77
  vis.writeTo(*this);
22,203 !
78
}
22,203 ✔
79
Port::Port(DataStream::Deserializer&& vis, QObject* parent)
×
80
    : IdentifiedObject{vis, parent}
×
81
{
×
82
  vis.writeTo(*this);
×
83
}
×
84
Port::Port(JSONObject::Deserializer&& vis, QObject* parent)
×
85
    : IdentifiedObject{vis, parent}
×
86
{
×
87
  vis.writeTo(*this);
×
88
}
×
89

90
void Port::addCable(const Cable& c)
2,914 ✔
91
{
92
  for(auto& old_c : m_cables)
3,856 ✔
93
  {
94
    auto& old_c_last_fragment = old_c.unsafePath().vec().back();
942 ✔
95
    if(bool cable_already_in_port = c.id().val() == old_c_last_fragment.id())
942 !
96
    {
97
      SCORE_SOFT_ASSERT(!cable_already_in_port);
×
98
      c.resetCache();
×
99
      cablesChanged();
×
100
      return;
×
101
    }
102
  }
103

104
  c.resetCache();
2,914 ✔
105
  m_cables.push_back(c);
2,914 !
106
  cablesChanged();
2,914 ✔
107
}
2,914 ✔
108

109
void Port::takeCables(Port&& c)
511 ✔
110
{
111
  // TODO how do we reset their cache
112
  m_cables = std::move(c.cables());
511 ✔
113
  cablesChanged();
511 ✔
114
  c.cablesChanged();
511 ✔
115
}
511 ✔
116

117
const QString& Port::visualName() const noexcept
74,150 ✔
118
{
119
  if(Q_LIKELY(!m_name.isEmpty()))
74,150 ✔
120
    return m_name;
74,117 ✔
121
  else
122
    return m_exposed;
33 ✔
123
}
74,150 ✔
124

125
QString displayName(const Port& port)
73,088 ✔
126
{
127
  if(const auto& name = port.visualName(); !name.isEmpty())
73,088 ✔
128
    return name;
73,056 ✔
129

130
  const bool in = qobject_cast<const Inlet*>(&port);
32 ✔
131
  switch(port.type())
32 !
132
  {
133
    case PortType::Audio:
134
      return in ? QStringLiteral("Audio In") : QStringLiteral("Audio Out");
×
135
    case PortType::Midi:
136
      return in ? QStringLiteral("MIDI In") : QStringLiteral("MIDI Out");
×
137
    case PortType::Texture:
138
      return in ? QStringLiteral("Texture In") : QStringLiteral("Texture Out");
3 !
139
    case PortType::Geometry:
140
      return in ? QStringLiteral("Geometry In") : QStringLiteral("Geometry Out");
×
141
    case PortType::Message:
29 ✔
142
    default:
143
      return in ? QStringLiteral("Value In") : QStringLiteral("Value Out");
29 !
144
  }
145
}
73,088 ✔
146

147
const QString& Port::visualDescription() const noexcept
×
148
{
149
  if(!m_description.isEmpty())
×
150
    return m_description;
×
151
  else if(Q_LIKELY(!m_name.isEmpty()))
×
152
    return m_name;
×
153
  else
154
    return m_exposed;
×
155
}
×
156

157
void Port::removeCable(const Path<Cable>& c)
2,360 ✔
158
{
159
  auto it = ossia::find(m_cables, c);
2,360 ✔
160
  if(it != m_cables.end())
2,360 ✔
161
  {
162
    m_cables.erase(it);
2,358 ✔
163
    cablesChanged();
2,358 ✔
164
  }
2,358 ✔
165
}
2,360 ✔
166

167
const QString& Port::name() const noexcept
613,730 ✔
168
{
169
  return m_name;
613,730 ✔
170
}
171
const QString& Port::exposed() const noexcept
164,023 ✔
172
{
173
  if(!m_exposed.isEmpty())
164,023 ✔
174
    return m_exposed;
163,993 ✔
175
  else
176
    return m_name;
30 ✔
177
}
164,023 ✔
178
const QString& Port::description() const noexcept
143,372 ✔
179
{
180
  return m_description;
143,372 ✔
181
}
182

183
Device::FullAddressAccessorSettings Port::settings() const noexcept
×
184
{
185
  Device::FullAddressAccessorSettings set;
×
186
  set.address = this->m_address;
×
187
  return set;
×
188
}
×
189

190
void Port::setSettings(const Device::FullAddressAccessorSettings& set) noexcept
×
191
{
192
  setAddress(set.address);
×
193
}
×
194

195
const State::AddressAccessor& Port::address() const noexcept
1,434,273 ✔
196
{
197
  return m_address;
1,434,273 ✔
198
}
199

200
const State::Unit& Port::unit() const noexcept
64,245 ✔
201
{
202
  return m_unit;
64,245 ✔
203
}
204

205
void Port::setUnit(State::Unit u) noexcept
1 ✔
206
{
207
  m_unit = std::move(u);
1 ✔
208
}
1 ✔
209

210
const std::vector<Path<Cable>>& Port::cables() const noexcept
99,171 ✔
211
{
212
  return m_cables;
99,171 ✔
213
}
214

215
static QString exposedFor(const QString& name)
127,327 ✔
216
{
217
  QString exposed = name.toLower();
127,327 ✔
218
  ossia::net::sanitize_name(exposed);
127,327 !
219
  return exposed;
127,327 ✔
220
}
127,327 ✔
221

222
void Port::setName(const QString& name)
144,014 ✔
223
{
224
  if(m_name == name)
144,014 ✔
225
    return;
26,301 ✔
226

227
  if(name.isEmpty())
117,713 !
228
  {
229
    qDebug() << "Warning: tried to create a port with an empty name";
×
230
    return;
×
231
  }
232

233
  const bool exposedFollowsName = m_exposed.isEmpty() || m_exposed == exposedFor(m_name);
117,713 ✔
234
  m_name = name;
117,713 ✔
235
  if(exposedFollowsName)
117,713 ✔
236
    setExposed(exposedFor(m_name));
117,709 !
237
  nameChanged(m_name);
117,713 ✔
238
}
144,014 ✔
239

240
void Port::setScriptable(bool b)
3,029 ✔
241
{
242
  if(m_scriptable == b)
3,029 ✔
243
    return;
2,943 ✔
244
  m_scriptable = b;
86 ✔
245
  scriptableChanged(b);
86 ✔
246
}
3,029 ✔
247

248
void Port::setExposed(const QString& exposed)
120,820 ✔
249
{
250
  if(m_exposed == exposed)
120,820 ✔
251
    return;
2,898 ✔
252

253
  if(exposed.isEmpty())
117,922 !
254
  {
255
    qDebug() << "Warning: tried to create a port with an empty exposed name";
×
256
    return;
×
257
  }
258

259
  m_exposed = exposed;
117,922 ✔
260
  exposedChanged(m_exposed);
117,922 ✔
261
}
120,820 ✔
262

263
void Port::resetExposed()
×
264
{
265
  if(m_exposed.isEmpty())
×
266
    return;
×
267
  m_exposed.clear();
×
268
  exposedChanged(m_name);
×
269
}
×
270

271
void Port::setDescription(const QString& description)
34,017 ✔
272
{
273
  if(m_description == description)
34,017 ✔
274
    return;
4,032 ✔
275

276
  m_description = description;
29,985 ✔
277
  descriptionChanged(m_description);
29,985 ✔
278
}
34,017 ✔
279

280
void Port::setAddress(const State::AddressAccessor& address)
2,445 ✔
281
{
282
  auto next = address;
2,445 ✔
283
  if(auto doc = score::IDocument::try_documentFromObject(*this))
2,445 ✔
284
    LocalTree::anchor(next.address, doc->context());
1,980 !
285

286
  const auto& a = m_address.address.anchor;
2,445 ✔
287
  const auto& b = next.address.anchor;
2,445 ✔
288
  if(m_address == next && bool(a) == bool(b)
2,445 !
289
     && (!a || (a->target == b->target && a->member == b->member)))
553 !
290
    return;
547 ✔
291

292
  m_address = std::move(next);
1,898 ✔
293
  addressChanged(m_address);
1,898 !
294
}
2,445 ✔
295

296
QByteArray Port::saveData() const noexcept
637 ✔
297
{
298
  QByteArray arr;
637 ✔
299
  {
300
    QDataStream p{&arr, QIODevice::WriteOnly};
637 !
301
    DataStreamInput ip{p};
637 ✔
302
    ip << m_cables << m_address;
637 !
303
    savePublication(ip);
637 !
304
  }
637 ✔
305
  return arr;
637 ✔
306
}
637 ✔
307

308
void Port::loadData(const QByteArray& arr, PortLoadDataFlags flags) noexcept
528 ✔
309
{
310
  QDataStream p{arr};
528 !
311
  DataStreamOutput op{p};
528 ✔
312
  op >> m_cables >> m_address;
528 !
313
  loadPublication(op);
528 !
314
}
528 ✔
315

316
// Every port type serializes its cables, its address and then this, so
317
// that data saved from one port type can be loaded into another.
318
void Port::savePublication(DataStreamInput& s) const
3,117 ✔
319
{
320
  s << m_scriptable << m_exposed;
3,117 ✔
321
}
3,117 ✔
322

323
void Port::loadPublication(DataStreamOutput& s)
2,553 ✔
324
{
325
  bool scriptable{};
2,553 ✔
326
  QString exposed;
2,553 ✔
327
  s >> scriptable >> exposed;
2,553 !
328
  if(!exposed.isEmpty())
2,553 ✔
329
    setExposed(exposed);
2,549 !
330
  setScriptable(scriptable);
2,553 !
331
}
2,553 ✔
332

333
///////////////////////////////
334
/// Inlet
335
///////////////////////////////
336

337
Inlet::~Inlet() { }
132,884 ✔
338

339
void Inlet::setupExecution(ossia::inlet&, QObject* exec_context) const noexcept { }
63 ✔
340

341
Inlet::Inlet(const QString& name, Id<Process::Port> c, QObject* parent)
93,698 ✔
342
    : Port{std::move(c), QStringLiteral("Inlet"), parent}
93,698 !
343
{
93,698 ✔
344
  setName(name);
93,698 !
345
}
93,698 ✔
346

347
Inlet::Inlet(DataStream::Deserializer& vis, QObject* parent)
19,528 ✔
348
    : Port{vis, parent}
19,528 ✔
349
{
19,528 ✔
350
  vis.writeTo(*this);
19,528 !
351
}
19,528 ✔
352
Inlet::Inlet(JSONObject::Deserializer& vis, QObject* parent)
19,658 ✔
353
    : Port{vis, parent}
19,658 ✔
354
{
19,658 ✔
355
  vis.writeTo(*this);
19,658 !
356
}
19,658 ✔
357
Inlet::Inlet(DataStream::Deserializer&& vis, QObject* parent)
×
358
    : Port{vis, parent}
×
359
{
×
360
  vis.writeTo(*this);
×
361
}
×
362
Inlet::Inlet(JSONObject::Deserializer&& vis, QObject* parent)
×
363
    : Port{vis, parent}
×
364
{
×
365
  vis.writeTo(*this);
×
366
}
×
367

368
void Inlet::forChildInlets(const smallfun::function<void(Inlet&)>& f) const noexcept { }
×
369

370
void Inlet::mapExecution(
×
371
    ossia::inlet& exec,
372
    const smallfun::function<void(Inlet&, ossia::inlet&)>& f) const noexcept
373
{
374
}
×
375

376
ControlInlet::ControlInlet(const QString& name, Id<Process::Port> c, QObject* parent)
83,433 ✔
377
    : Inlet{name, std::move(c), parent}
83,433 !
378
{
83,433 ✔
379
}
83,433 ✔
380

381
ControlInlet::~ControlInlet() { }
136,202 ✔
382

383
ControlInlet::ControlInlet(
35,632 ✔
384
    DataStream::Deserializer& vis, QObject* parent, bool skip_this)
385
    : Inlet{vis, parent}
17,816 ✔
386
{
17,816 ✔
387
  if(!skip_this)
17,816 ✔
388
    vis.writeTo(*this);
17,743 !
389
}
17,816 ✔
390
ControlInlet::ControlInlet(
35,266 ✔
391
    JSONObject::Deserializer& vis, QObject* parent, bool skip_this)
392
    : Inlet{vis, parent}
17,633 ✔
393
{
17,633 ✔
394
  if(!skip_this)
17,633 ✔
395
    vis.writeTo(*this);
17,565 !
396
}
17,633 ✔
397
ControlInlet::ControlInlet(
×
398
    DataStream::Deserializer&& vis, QObject* parent, bool skip_this)
399
    : Inlet{vis, parent}
×
400
{
×
401
  if(!skip_this)
×
402
    vis.writeTo(*this);
×
403
}
×
404
ControlInlet::ControlInlet(
×
405
    JSONObject::Deserializer&& vis, QObject* parent, bool skip_this)
406
    : Inlet{vis, parent}
×
407
{
×
408
  if(!skip_this)
×
409
    vis.writeTo(*this);
×
410
}
×
411

412
QByteArray ControlInlet::saveData() const noexcept
2,266 ✔
413
{
414
  QByteArray arr;
2,266 ✔
415
  {
416
    QDataStream p{&arr, QIODevice::WriteOnly};
2,266 !
417
    DataStreamInput ip{p};
2,266 ✔
418
    ip << m_cables << m_address;
2,266 !
419
    savePublication(ip);
2,266 !
420
    ip << true << m_value;
2,266 !
421
  }
2,266 ✔
422
  return arr;
2,266 ✔
423
}
2,266 ✔
424

425
void ControlInlet::loadData(const QByteArray& arr, PortLoadDataFlags flags) noexcept
1,934 ✔
426
{
427
  QDataStream p{arr};
1,934 !
428
  DataStreamOutput op{p};
1,934 ✔
429
  bool has_value{};
1,934 ✔
430

431
  op >> m_cables >> m_address;
1,934 !
432
  loadPublication(op);
1,934 !
433
  op >> has_value;
1,934 !
434
  if(!((uint32_t)flags & (uint32_t)PortLoadDataFlags::ReloadValue))
1,934 ✔
435
    has_value = false;
773 ✔
436

437
  if(has_value)
1,934 ✔
438
  {
439
    ossia::value value;
1,161 ✔
440
    op >> value;
1,161 !
441
    {
442
      const QSignalBlocker blocker{this};
1,161 ✔
443
      setValue(value);
1,161 !
444
    }
1,161 ✔
445
    valueChanged(m_value);
1,161 !
446
  }
1,161 ✔
447
}
1,934 ✔
448

449
void ControlInlet::setValue(const ossia::value& value)
133,771 ✔
450
{
451
  if(value != m_value || m_value.get_type() == ossia::val_type::IMPULSE
133,771 ✔
452
     || value.get_type() == ossia::val_type::IMPULSE)
49,464 ✔
453
  {
454
    m_value = value;
85,135 ✔
455
    valueChanged(value);
85,135 ✔
456
  }
85,135 ✔
457
}
133,771 ✔
458

459
void ControlInlet::setInit(const ossia::value& value)
67,830 ✔
460
{
461
  if(value != m_init)
67,830 ✔
462
  {
463
    m_init = value;
67,532 ✔
464
    initChanged(value);
67,532 ✔
465
  }
67,532 ✔
466
}
67,830 ✔
467

468
Outlet::~Outlet() { }
19,448 ✔
469

470
void Outlet::setupExecution(ossia::outlet&, QObject* exec_context) const noexcept { }
×
471

472
Outlet::Outlet(const QString& name, Id<Process::Port> c, QObject* parent)
14,472 ✔
473
    : Port{std::move(c), QStringLiteral("Outlet"), parent}
14,472 !
474
{
14,472 ✔
475
  setName(name);
14,472 !
476
}
14,472 ✔
477

478
Outlet::Outlet(DataStream::Deserializer& vis, QObject* parent)
2,431 ✔
479
    : Port{vis, parent}
2,431 ✔
480
{
2,431 ✔
481
  vis.writeTo(*this);
2,431 !
482
}
2,431 ✔
483
Outlet::Outlet(JSONObject::Deserializer& vis, QObject* parent)
2,545 ✔
484
    : Port{vis, parent}
2,545 ✔
485
{
2,545 ✔
486
  vis.writeTo(*this);
2,545 !
487
}
2,545 ✔
488
Outlet::Outlet(DataStream::Deserializer&& vis, QObject* parent)
×
489
    : Port{vis, parent}
×
490
{
×
491
  vis.writeTo(*this);
×
492
}
×
493
Outlet::Outlet(JSONObject::Deserializer&& vis, QObject* parent)
×
494
    : Port{vis, parent}
×
495
{
×
496
  vis.writeTo(*this);
×
497
}
×
498

499
void Outlet::forChildInlets(const smallfun::function<void(Inlet&)>& f) const noexcept { }
×
500

501
void Outlet::mapExecution(
6,216 ✔
502
    ossia::outlet& exec,
503
    const smallfun::function<void(Inlet&, ossia::inlet&)>& f) const noexcept
504
{
505
}
6,216 ✔
506

507
AudioInlet::~AudioInlet() { }
17,701 ✔
508

509
AudioInlet::AudioInlet(const QString& name, Id<Process::Port> c, QObject* parent)
6,615 ✔
510
    : Inlet{name, std::move(c), parent}
6,615 !
511
{
6,615 ✔
512
}
6,615 ✔
513

514
AudioInlet::AudioInlet(DataStream::Deserializer& vis, QObject* parent)
871 ✔
515
    : Inlet{vis, parent}
871 ✔
516
{
871 ✔
517
  vis.writeTo(*this);
871 !
518
}
871 ✔
519
AudioInlet::AudioInlet(JSONObject::Deserializer& vis, QObject* parent)
1,366 ✔
520
    : Inlet{vis, parent}
1,366 ✔
521
{
1,366 ✔
522
  vis.writeTo(*this);
1,366 !
523
}
1,366 ✔
524
AudioInlet::AudioInlet(DataStream::Deserializer&& vis, QObject* parent)
×
525
    : Inlet{vis, parent}
×
526
{
×
527
  vis.writeTo(*this);
×
528
}
×
529
AudioInlet::AudioInlet(JSONObject::Deserializer&& vis, QObject* parent)
×
530
    : Inlet{vis, parent}
×
531
{
×
532
  vis.writeTo(*this);
×
533
}
×
534

535
namespace
536
{
537
// (1 + outlet id) * 10000 + k, the id scheme saved documents already carry.
538
// avnd dynamic outlets have ids above 1000000, where this overflows int: the
539
// product is computed modulo 2^32 so that saved documents keep their ids,
540
// without the UB.
541
Id<Process::Port> subPortId(const Id<Process::Port>& outlet, int k) noexcept
12,538 ✔
542
{
543
  return Id<Process::Port>{
12,538 ✔
544
      int32_t(uint32_t(1 + outlet.val()) * 10000u + uint32_t(k))};
12,538 ✔
545
}
546
}
547

548
AudioOutlet::~AudioOutlet() { }
17,129 ✔
549

550
AudioOutlet::AudioOutlet(const QString& name, Id<Process::Port> c, QObject* parent)
6,269 ✔
551
    : Outlet{name, std::move(c), parent}
6,269 !
552
    , gainInlet{std::make_unique<ControlInlet>("Gain", subPortId(c, 0), this)}
6,269 !
553
    , panInlet{std::make_unique<ControlInlet>("Pan", subPortId(c, 1), this)}
6,269 !
554
    , m_gain{1.}
6,269 ✔
555
    , m_pan{1., 1.}
6,269 !
556
{
6,269 ✔
557
  gainInlet->setDomain(ossia::domain{ossia::domain_base<float>{0., 1.}});
6,269 !
558
}
6,269 ✔
559

560
AudioOutlet::AudioOutlet(DataStream::Deserializer& vis, QObject* parent)
2,532 ✔
561
    : Outlet{vis, parent}
844 ✔
562
{
844 ✔
563
  vis.writeTo(*this);
844 !
564
}
844 ✔
565
AudioOutlet::AudioOutlet(JSONObject::Deserializer& vis, QObject* parent)
4,362 ✔
566
    : Outlet{vis, parent}
1,454 ✔
567
{
1,454 ✔
568
  vis.writeTo(*this);
1,454 !
569
}
1,454 ✔
570
AudioOutlet::AudioOutlet(DataStream::Deserializer&& vis, QObject* parent)
×
571
    : Outlet{vis, parent}
×
572
{
×
573
  vis.writeTo(*this);
×
574
}
×
575
AudioOutlet::AudioOutlet(JSONObject::Deserializer&& vis, QObject* parent)
×
576
    : Outlet{vis, parent}
×
577
{
×
578
  vis.writeTo(*this);
×
579
}
×
580

581
void AudioOutlet::forChildInlets(
×
582
    const smallfun::function<void(Inlet&)>& f) const noexcept
583
{
584
  f(*gainInlet);
×
585
  f(*panInlet);
×
586
}
×
587

588
void AudioOutlet::mapExecution(
3,919 ✔
589
    ossia::outlet& exec,
590
    const smallfun::function<void(Inlet&, ossia::inlet&)>& f) const noexcept
591
{
592
  auto audio_exec = safe_cast<ossia::audio_outlet*>(&exec);
3,919 !
593
  f(*gainInlet, audio_exec->gain_inlet);
3,919 !
594
  f(*panInlet, audio_exec->pan_inlet);
3,919 !
595
}
3,919 ✔
596

597
QByteArray AudioOutlet::saveData() const noexcept
68 ✔
598
{
599
  QByteArray arr;
68 ✔
600
  {
601
    QDataStream p{&arr, QIODevice::WriteOnly};
68 !
602
    DataStreamInput ip{p};
68 ✔
603
    ip << Port::saveData() << m_gain << m_pan << m_propagate << m_upmixMode
136 !
604
       << m_upmixChannels;
68 !
605
  }
68 ✔
606
  return arr;
68 ✔
607
}
68 ✔
608

609
void AudioOutlet::loadData(const QByteArray& arr, PortLoadDataFlags flags) noexcept
62 ✔
610
{
611
  QByteArray pdata;
62 ✔
612
  QDataStream p{arr};
62 !
613
  DataStreamOutput op{p};
62 ✔
614
  op >> pdata >> m_gain >> m_pan >> m_propagate;
62 !
615
  // Data saved before the upmix existed ends here.
616
  if(!p.atEnd())
62 !
617
    op >> m_upmixMode >> m_upmixChannels;
62 !
618
  Port::loadData(pdata, flags);
62 ✔
619
  propagateChanged(m_propagate);
62 !
620
}
62 ✔
621

622
bool AudioOutlet::propagate() const
6,236 ✔
623
{
624
  return m_propagate;
6,236 ✔
625
}
626

627
void AudioOutlet::setPropagate(bool propagate)
6,441 ✔
628
{
629
  if(m_propagate == propagate)
6,441 ✔
630
    return;
38 ✔
631

632
  m_propagate = propagate;
6,403 ✔
633
  propagateChanged(m_propagate);
6,403 ✔
634
}
6,441 ✔
635

636
double AudioOutlet::gain() const
4,150 ✔
637
{
638
  return m_gain;
4,150 ✔
639
}
640

641
void AudioOutlet::setGain(double gain)
30 ✔
642
{
643
  if(m_gain == gain)
30 !
644
    return;
×
645

646
  m_gain = gain;
30 ✔
647
  gainChanged(m_gain);
30 ✔
648
}
30 ✔
649

650
Process::pan_weight AudioOutlet::pan() const
3,967 ✔
651
{
652
  return m_pan;
3,967 ✔
653
}
654

655
void AudioOutlet::setPan(Process::pan_weight pan)
4 ✔
656
{
657
  if(m_pan == pan)
4 !
658
    return;
×
659

660
  m_pan = pan;
4 ✔
661
  panChanged(m_pan);
4 !
662
}
4 ✔
663

664
void AudioOutlet::setUpmixMode(int m)
4 ✔
665
{
666
  if(m_upmixMode == m)
4 !
NEW
667
    return;
×
668

669
  m_upmixMode = m;
4 ✔
670
  upmixModeChanged(m);
4 ✔
671
}
4 ✔
672

673
void AudioOutlet::setUpmixChannels(int c)
4 ✔
674
{
675
  if(m_upmixChannels == c)
4 !
NEW
676
    return;
×
677

678
  m_upmixChannels = c;
4 ✔
679
  upmixChannelsChanged(c);
4 ✔
680
}
4 ✔
681

682
MidiInlet::~MidiInlet() { }
2,905 ✔
683

684
MidiInlet::MidiInlet(const QString& name, Id<Process::Port> c, QObject* parent)
871 ✔
685
    : Inlet{name, std::move(c), parent}
871 !
686
{
871 ✔
687
}
871 ✔
688

689
MidiInlet::MidiInlet(DataStream::Deserializer& vis, QObject* parent)
397 ✔
690
    : Inlet{vis, parent}
397 ✔
691
{
397 ✔
692
  vis.writeTo(*this);
397 !
693
}
397 ✔
694
MidiInlet::MidiInlet(JSONObject::Deserializer& vis, QObject* parent)
186 ✔
695
    : Inlet{vis, parent}
186 ✔
696
{
186 ✔
697
  vis.writeTo(*this);
186 !
698
}
186 ✔
699
MidiInlet::MidiInlet(DataStream::Deserializer&& vis, QObject* parent)
×
700
    : Inlet{vis, parent}
×
701
{
×
702
  vis.writeTo(*this);
×
703
}
×
704
MidiInlet::MidiInlet(JSONObject::Deserializer&& vis, QObject* parent)
×
705
    : Inlet{vis, parent}
×
706
{
×
707
  vis.writeTo(*this);
×
708
}
×
709

710
MidiOutlet::~MidiOutlet() { }
2,574 ✔
711

712
MidiOutlet::MidiOutlet(const QString& name, Id<Process::Port> c, QObject* parent)
852 ✔
713
    : Outlet{name, std::move(c), parent}
852 !
714
{
852 ✔
715
}
852 ✔
716

717
MidiOutlet::MidiOutlet(DataStream::Deserializer& vis, QObject* parent)
349 ✔
718
    : Outlet{vis, parent}
349 ✔
719
{
349 ✔
720
  vis.writeTo(*this);
349 !
721
}
349 ✔
722
MidiOutlet::MidiOutlet(JSONObject::Deserializer& vis, QObject* parent)
87 ✔
723
    : Outlet{vis, parent}
87 ✔
724
{
87 ✔
725
  vis.writeTo(*this);
87 !
726
}
87 ✔
727
MidiOutlet::MidiOutlet(DataStream::Deserializer&& vis, QObject* parent)
×
728
    : Outlet{vis, parent}
×
729
{
×
730
  vis.writeTo(*this);
×
731
}
×
732
MidiOutlet::MidiOutlet(JSONObject::Deserializer&& vis, QObject* parent)
×
733
    : Outlet{vis, parent}
×
734
{
×
735
  vis.writeTo(*this);
×
736
}
×
737

738
ControlOutlet::ControlOutlet(const QString& qname, Id<Process::Port> c, QObject* parent)
168 ✔
739
    : Outlet{qname, std::move(c), parent}
168 !
740
{
168 ✔
741
}
168 ✔
742

743
ControlOutlet::~ControlOutlet() { }
308 ✔
744

745
ControlOutlet::ControlOutlet(DataStream::Deserializer& vis, QObject* parent)
30 ✔
746
    : Outlet{vis, parent}
15 ✔
747
{
15 ✔
748
  vis.writeTo(*this);
15 !
749
}
15 ✔
750
ControlOutlet::ControlOutlet(JSONObject::Deserializer& vis, QObject* parent)
36 ✔
751
    : Outlet{vis, parent}
18 ✔
752
{
18 ✔
753
  vis.writeTo(*this);
18 !
754
}
18 ✔
755
ControlOutlet::ControlOutlet(DataStream::Deserializer&& vis, QObject* parent)
×
756
    : Outlet{vis, parent}
×
757
{
×
758
  vis.writeTo(*this);
×
759
}
×
760
ControlOutlet::ControlOutlet(JSONObject::Deserializer&& vis, QObject* parent)
×
761
    : Outlet{vis, parent}
×
762
{
×
763
  vis.writeTo(*this);
×
764
}
×
765

766
QByteArray ControlOutlet::saveData() const noexcept
7 ✔
767
{
768
  return Port::saveData();
7 ✔
769
}
770

771
void ControlOutlet::loadData(const QByteArray& arr, PortLoadDataFlags flags) noexcept
7 ✔
772
{
773
  Port::loadData(arr, flags);
7 ✔
774
}
7 ✔
775

776
ValueInlet::~ValueInlet() { }
4,161 ✔
777

778
ValueInlet::ValueInlet(const QString& name, Id<Process::Port> c, QObject* parent)
1,521 ✔
779
    : Inlet{name, std::move(c), parent}
1,521 !
780
{
1,521 ✔
781
}
1,521 ✔
782

783
ValueInlet::ValueInlet(DataStream::Deserializer& vis, QObject* parent)
273 ✔
784
    : Inlet{vis, parent}
273 ✔
785
{
273 ✔
786
  vis.writeTo(*this);
273 !
787
}
273 ✔
788
ValueInlet::ValueInlet(JSONObject::Deserializer& vis, QObject* parent)
288 ✔
789
    : Inlet{vis, parent}
288 ✔
790
{
288 ✔
791
  vis.writeTo(*this);
288 !
792
}
288 ✔
793
ValueInlet::ValueInlet(DataStream::Deserializer&& vis, QObject* parent)
×
794
    : Inlet{vis, parent}
×
795
{
×
796
  vis.writeTo(*this);
×
797
}
×
798
ValueInlet::ValueInlet(JSONObject::Deserializer&& vis, QObject* parent)
×
799
    : Inlet{vis, parent}
×
800
{
×
801
  vis.writeTo(*this);
×
802
}
×
803

804
QByteArray ValueInlet::saveData() const noexcept
214 ✔
805
{
806
  QByteArray arr;
214 ✔
807
  {
808
    QDataStream p{&arr, QIODevice::WriteOnly};
214 !
809
    DataStreamInput ip{p};
214 ✔
810
    ip << m_cables << m_address;
214 !
811
    savePublication(ip);
214 !
812
    ip << false;
214 !
813
    // Boolean indicates that we don't have a value. Otherwise if we change from ValueInlet to
814
    // ControlInlet in e.g. a JS script, then the ControlInlet tries to reload the value and crashes.
815
  }
214 ✔
816
  return arr;
214 ✔
817
}
214 ✔
818

819
void ValueInlet::loadData(const QByteArray& arr, PortLoadDataFlags flags) noexcept
91 ✔
820
{
821
  QDataStream p{arr};
91 !
822
  DataStreamOutput op{p};
91 ✔
823
  op >> m_cables >> m_address;
91 !
824
  loadPublication(op);
91 !
825
}
91 ✔
826
ValueOutlet::~ValueOutlet() { }
14,328 ✔
827

828
ValueOutlet::ValueOutlet(const QString& name, Id<Process::Port> c, QObject* parent)
5,890 ✔
829
    : Outlet{name, std::move(c), parent}
5,890 !
830
{
5,890 ✔
831
}
5,890 ✔
832

833
ValueOutlet::ValueOutlet(DataStream::Deserializer& vis, QObject* parent)
1,090 ✔
834
    : Outlet{vis, parent}
1,090 ✔
835
{
1,090 ✔
836
  vis.writeTo(*this);
1,090 !
837
}
1,090 ✔
838
ValueOutlet::ValueOutlet(JSONObject::Deserializer& vis, QObject* parent)
842 ✔
839
    : Outlet{vis, parent}
842 ✔
840
{
842 ✔
841
  vis.writeTo(*this);
842 !
842
}
842 ✔
843
ValueOutlet::ValueOutlet(DataStream::Deserializer&& vis, QObject* parent)
×
844
    : Outlet{vis, parent}
×
845
{
×
846
  vis.writeTo(*this);
×
847
}
×
848
ValueOutlet::ValueOutlet(JSONObject::Deserializer&& vis, QObject* parent)
×
849
    : Outlet{vis, parent}
×
850
{
×
851
  vis.writeTo(*this);
×
852
}
×
853

854
PortFactory::~PortFactory() { }
866,655 ✔
855

856
Dataflow::PortItem* PortFactory::makePortItem(
×
857
    Inlet& port, const Process::Context& ctx, QGraphicsItem* parent, QObject* context)
858
{
859
  return new Dataflow::PortItem{port, ctx, parent};
×
860
}
×
861

862
Dataflow::PortItem* PortFactory::makePortItem(
×
863
    Outlet& port, const Process::Context& ctx, QGraphicsItem* parent, QObject* context)
864
{
865
  return new Dataflow::PortItem{port, ctx, parent};
×
866
}
×
867

868
void PortFactory::setupInletInspector(
254 ✔
869
    const Inlet& port, const score::DocumentContext& ctx, QWidget* parent,
870
    Inspector::Layout& lay, QObject* context)
871
{
872
  PortWidgetSetup::setupAlone(port, ctx, lay, parent);
254 ✔
873
}
254 ✔
874

875
void PortFactory::setupOutletInspector(
1,063 ✔
876
    const Outlet& port, const score::DocumentContext& ctx, QWidget* parent,
877
    Inspector::Layout& lay, QObject* context)
878
{
879
  PortWidgetSetup::setupAlone(port, ctx, lay, parent);
1,063 ✔
880
}
1,063 ✔
881

882
PortItemLayout PortFactory::defaultLayout() const noexcept
116 ✔
883
{
884
  return PortItemLayout{
696 ✔
885
      .port = QPointF{0., 4.}, .label = QPointF{20., 2.}, .control = QPointF{18., 15.}};
348 ✔
886
}
887

888
QGraphicsItem* PortFactory::makeControlItem(
9 ✔
889
    ControlInlet& port, const score::DocumentContext& ctx, QGraphicsItem* parent,
890
    QObject* context)
891
{
892
  auto& dom = port.domain().get();
9 ✔
893
  if(bool(dom))
9 !
894
  {
895
    auto min = dom.convert_min<float>();
9 ✔
896
    auto max = dom.convert_max<float>();
9 ✔
897
    struct
898
    {
899
      float min, max, init;
900
      float getMin() const { return min; }
18 ✔
901
      float getMax() const { return max; }
18 ✔
902
      float getInit() const { return init; }
9 ✔
903
    } info{min, max, ossia::convert<float>(port.init())};
9 ✔
904
    return WidgetFactory::FloatSlider::make_item(info, port, ctx, nullptr, context);
9 !
905
  }
906
  else
907
  {
908
    struct SliderInfo
909
    {
910
      static float getMin() { return 0.; }
×
911
      static float getMax() { return 1.; }
×
912
      static float getInit() { return 0.; }
×
913
    };
914
    return WidgetFactory::FloatSlider::make_item(
×
915
        SliderInfo{}, port, ctx, nullptr, context);
×
916
  }
917
}
9 ✔
918

919
QGraphicsItem* PortFactory::makeControlItem(
4 ✔
920
    ControlOutlet& port, const score::DocumentContext& ctx, QGraphicsItem* parent,
921
    QObject* context)
922
{
923
  auto& dom = port.domain().get();
4 ✔
924
  if(bool(dom))
4 !
925
  {
926
    auto min = dom.convert_min<float>();
×
927
    auto max = dom.convert_max<float>();
×
928
    struct
929
    {
930
      float min, max;
931
      float getMin() const { return min; }
×
932
      float getMax() const { return max; }
×
933
      float getInit() const { return min; }
×
934
    } info{min, max};
×
935
    return WidgetFactory::FloatSlider::make_item(info, port, ctx, parent, context);
×
936
  }
937
  else
938
  {
939
    struct SliderInfo
940
    {
941
      static float getMin() { return 0.; }
8 ✔
942
      static float getMax() { return 1.; }
8 ✔
943
      static float getInit() { return 0.; }
4 ✔
944
    };
945
    return WidgetFactory::FloatSlider::make_item(
4 !
946
        SliderInfo{}, port, ctx, parent, context);
4 ✔
947
  }
948
}
4 ✔
949

950
static QGraphicsItem* makeEnumCombo(
77 ✔
951
    Process::Enum& port, const score::DocumentContext& ctx, QObject* context)
952
{
953
  QStringList names;
77 ✔
954
  for(const auto& v : port.getValues())
444 !
955
    names.push_back(v);
367 !
956
  auto sl = new score::QGraphicsCombo{names, nullptr};
77 !
957
  WidgetFactory::initWidgetProperties(port, *sl);
77 !
958

959
  auto set_index = [&port, sl](const ossia::value& v) {
176 ✔
960
    if(const int idx = port.indexOfValue(v); idx >= 0)
99 !
961
      sl->setValue(idx);
99 ✔
962
  };
99 ✔
963
  set_index(port.value());
77 !
964

965
  QObject::connect(sl, &score::QGraphicsCombo::sliderMoved, context, [&port, sl, &ctx] {
77 !
966
    sl->moving = true;
×
967
    if(auto v = port.valueAtIndex(sl->value()); v.valid())
×
968
      ctx.dispatcher.submit<Process::SetControlValue>(port, std::move(v));
×
969
  });
×
970
  QObject::connect(sl, &score::QGraphicsCombo::sliderReleased, context, [sl, &ctx] {
77 !
971
    ctx.dispatcher.commit();
×
972
    sl->moving = false;
×
973
  });
×
974
  QObject::connect(&port, &Process::Enum::valueChanged, sl, [sl, set_index](const ossia::value& v) {
99 !
975
    if(!sl->moving)
22 !
976
      set_index(v);
22 ✔
977
  });
22 ✔
978
  return sl;
77 !
979
}
77 ✔
980

981
//! A sound file shown small: its name as a button, as for any file, rather
982
//! than its waveform
983
static bool isCompactSoundFile(
52,737 ✔
984
    const Process::Port& port, const Process::ControlPresentation& presentation)
985
{
986
  return presentation.widget == Process::ControlPresentation::Widget::Default
102,896 ✔
987
         && presentation.size == score::ControlSize::Small
52,737 ✔
988
         && qobject_cast<const Process::AudioFileChooser*>(&port);
50,159 ✔
989
}
990

991
//! The item layout of the widget the presentation asks for, when the port
992
//! supports that widget.
993
static std::optional<Process::PortItemLayout> presentationLayout(
26,183 ✔
994
    const Process::Port& port, const Process::ControlPresentation& presentation)
995
{
996
  using Widget = Process::ControlPresentation::Widget;
997
  if(isCompactSoundFile(port, presentation))
26,183 ✔
998
    return WidgetFactory::FileChooser::layout();
40 ✔
999
  switch(presentation.widget)
26,143 ✔
1000
  {
1001
    case Widget::Knob:
1002
      if(qobject_cast<const Process::FloatSlider*>(&port)
614 ✔
1003
         || qobject_cast<const Process::LogFloatSlider*>(&port))
614 ✔
1004
        return Process::DefaultControlLayouts::knob();
391 ✔
1005
      break;
223 ✔
1006
    case Widget::Combo:
1007
      if(qobject_cast<const Process::Enum*>(&port))
437 ✔
1008
        return Process::DefaultControlLayouts::combo();
77 ✔
1009
      break;
360 ✔
1010
    case Widget::None:
1011
      // The port, its label beside it, nothing under them
1012
      return Process::PortItemLayout{.port = QPointF{0., 1.}, .label = QPointF{12., 0.}};
32 ✔
1013
    default:
1014
      break;
25,084 ✔
1015
  }
1016
  return std::nullopt;
25,667 ✔
1017
}
26,183 ✔
1018

1019
//! Widget override requested by the presentation, or null if unsupported.
1020
//! Sets the matching item layout.
1021
static QGraphicsItem* makePresentationWidget(
26,048 ✔
1022
    Process::ControlInlet& port, const Process::Context& ctx, QObject* context,
1023
    const Process::ControlPresentation& presentation, Process::PortItemLayout& layout)
1024
{
1025
  const auto widgetLayout = presentationLayout(port, presentation);
26,048 ✔
1026
  if(!widgetLayout)
26,048 ✔
1027
    return nullptr;
25,538 ✔
1028
  layout = *widgetLayout;
510 ✔
1029
  if(presentation.widget == Process::ControlPresentation::Widget::None)
510 ✔
1030
    return new score::EmptyItem{nullptr};
4 !
1031
  if(isCompactSoundFile(port, presentation))
506 ✔
1032
  {
1033
    auto& f = static_cast<Process::AudioFileChooser&>(port);
40 ✔
1034
    return WidgetFactory::FileChooser::make_item(f, f, ctx, nullptr, context);
40 !
1035
  }
1036
  if(auto s = qobject_cast<Process::FloatSlider*>(&port))
466 ✔
1037
    return WidgetFactory::FloatKnob::make_item(*s, *s, ctx, nullptr, context);
385 !
1038
  if(auto s = qobject_cast<Process::LogFloatSlider*>(&port))
81 ✔
1039
    return WidgetFactory::LogFloatKnob::make_item(*s, *s, ctx, nullptr, context);
4 !
1040
  if(auto e = qobject_cast<Process::Enum*>(&port))
77 !
1041
    return makeEnumCombo(*e, ctx, context);
77 ✔
1042
  return nullptr;
×
1043
}
26,048 ✔
1044

1045
static auto makeFullItemImpl(
26,209 ✔
1046
    const Process::Port& portModel, Process::PortItemLayout layout,
1047
    QGraphicsItem& port, QGraphicsItem& control, auto& item,
1048
    const Process::ControlPresentation& presentation,
1049
    score::SimpleTextItem* lab = nullptr)
1050
{
1051
  using namespace score;
1052

1053
  if(!presentation.isDefault())
26,209 ✔
1054
  {
1055
    score::setControlSize(control, presentation.size);
2,658 ✔
1056
    score::setValueOnHover(control, presentation.valueOnHover);
2,658 ✔
1057
    if(!presentation.labelVisible)
2,658 ✔
1058
    {
1059
      // Takes the label's row
1060
      const qreal lift = std::max(0., layout.control.y() - layout.label.y());
173 ✔
1061
      layout.control.ry() -= lift;
173 ✔
1062
      layout.labelVisible = false;
173 ✔
1063
    }
173 ✔
1064
  }
2,658 ✔
1065

1066
  // Port
1067
  port.setParentItem(&item);
26,209 !
1068
  port.setPos(layout.port);
26,209 ✔
1069
  port.setZValue(3);
26,209 ✔
1070

1071
  // Control
1072
  control.setParentItem(&item);
26,209 !
1073
  control.setPos(layout.control);
26,209 ✔
1074
  control.setZValue(2);
26,209 ✔
1075
  // The help panel shows the description of whatever is hovered: the port,
1076
  // its label or its control
1077
  control.setToolTip(portModel.description());
26,209 ✔
1078

1079
  // Text
1080
  if(layout.labelVisible)
26,209 ✔
1081
  {
1082
    if(!lab)
26,036 ✔
1083
      lab = Dataflow::makePortLabel(portModel, &item);
25,905 !
1084
    lab->setVisible(true);
26,036 ✔
1085
    // A label kept from an earlier presentation may hold its custom text.
1086
    lab->setText(presentation.label ? *presentation.label : Process::displayName(portModel));
26,036 !
1087
    lab->setToolTip(portModel.description());
26,036 ✔
1088
    lab->setPos(layout.label);
26,036 ✔
1089
    auto widg_r = control.boundingRect();
26,036 ✔
1090
    auto lab_r = lab->boundingRect();
26,036 ✔
1091
    auto lab_w = lab_r.width();
26,036 ✔
1092
    auto widg_w = widg_r.width();
26,036 ✔
1093

1094
    // In a layout aligned left: at the control's left edge, as its value
1095
    const bool left
26,036 ✔
1096
        = layout.labelAlignment == Qt::AlignCenter && (presentation.alignment & Qt::AlignLeft);
26,036 ✔
1097
    score::setValueAlignment(control, left ? Qt::AlignLeft : Qt::AlignHCenter);
26,036 ✔
1098
    if(left)
26,036 ✔
1099
    {
1100
      lab->setX(control.pos().x());
1,205 ✔
1101
    }
1,205 ✔
1102
    else if(lab_w < widg_w && layout.labelAlignment == Qt::AlignCenter)
24,831 ✔
1103
    {
1104
      lab->setX(control.pos().x() + (widg_w - lab_w) / 2.);
11,236 ✔
1105
    }
11,236 ✔
1106
    else if(layout.labelAlignment == Qt::AlignLeft)
13,595 !
1107
    {
1108
      lab->setX(control.pos().x());
×
1109
    }
×
1110
    else
1111
    {
1112
      if(layout.controlAlignment & Qt::AlignRight)
13,595 !
1113
      {
1114
        // Control outlets
1115
        lab->setPos(0, layout.label.y());
×
1116

1117
        port.setPos(lab_w - 5., port.pos().y());
×
1118
        control.setPos(port.x() - widg_w, control.pos().y());
×
1119
      }
×
1120
    }
1121
  }
26,036 ✔
1122
  else if(lab)
173 !
1123
  {
1124
    lab->setVisible(false);
×
1125
  }
×
1126

1127
  const bool moved = !presentation.labelVisible
52,245 ✔
1128
                     || presentation.size != score::ControlSize::Normal;
26,209 ✔
1129
  if(!presentation.labelVisible && !(layout.controlAlignment & Qt::AlignRight))
26,209 ✔
1130
  {
1131
    // In the label's row: stay clear of the port
1132
    const qreal port_right = port.x() + port.boundingRect().right() + 1.;
173 ✔
1133
    if(control.x() < port_right)
173 !
1134
      control.setX(port_right);
173 ✔
1135
  }
173 ✔
1136
  if(moved && !(layout.controlAlignment & Qt::AlignRight))
26,209 ✔
1137
  {
1138
    // Resized or unlabelled: port level with the widget
1139
    const qreal ph = port.boundingRect().height();
1,436 ✔
1140
    port.setY(control.y() + (control.boundingRect().height() - ph) / 2.);
1,436 ✔
1141
  }
1,436 ✔
1142

1143
  item.fitChildrenRect();
26,209 ✔
1144
  return lab;
26,209 ✔
1145
}
×
1146

1147
static auto makeLabelItemImpl(
7,612 ✔
1148
    const Process::Port& portModel, const Process::PortItemLayout& layout,
1149
    QGraphicsItem& port, auto& item)
1150
{
1151
  score::SimpleTextItem* lab{};
7,612 ✔
1152
  using namespace score;
1153

1154
  // Port
1155
  port.setParentItem(&item);
7,612 !
1156
  port.setPos(layout.port);
7,612 ✔
1157
  port.setZValue(3);
7,612 ✔
1158

1159
  // Text
1160
  if(layout.labelVisible)
7,612 !
1161
  {
1162
    lab = Dataflow::makePortLabel(portModel, &item);
7,612 !
1163
    lab->setToolTip(portModel.description());
7,612 ✔
1164
    lab->setPos(layout.label);
7,612 ✔
1165
    if(layout.labelAlignment == Qt::AlignLeft)
7,612 ✔
1166
    {
1167
      lab->setPos(QPointF{layout.port.x() + 12., 3.5});
3,383 ✔
1168
    }
3,383 ✔
1169
    else
1170
    {
1171
      lab->setPos(0, 3.5);
4,229 ✔
1172
      port.setPos(lab->boundingRect().width() + 2., port.y());
4,229 ✔
1173
      //lab->setPos(QPointF{layout.port.x() - lab->boundingRect().width(), 5.});
1174
    }
1175
  }
7,612 ✔
1176
  item.fitChildrenRect();
7,612 ✔
1177
  return lab;
7,612 ✔
1178
}
1179

1180
Process::ControlLayout PortFactory::makeFullItem(
26,048 ✔
1181
    ControlInlet& portModel, const Process::Context& ctx, QGraphicsItem* parent,
1182
    QObject* context, const ControlPresentation& presentation)
1183
{
1184
  Process::ControlLayout ret;
26,048 ✔
1185
  using namespace score;
1186
#if defined(SCORE_DEBUG_CONTROL_RECTS)
1187
  auto item = new score::GraphicsLayout{parent};
1188
  item->setBrush(score::Skin::instance().Light.main);
1189
#else
1190
  auto item = new score::EmptyRectItem{parent};
26,048 !
1191
#endif
1192
  ret.container = item;
26,048 !
1193

1194
  auto layout = defaultLayout();
26,048 ✔
1195
  ret.port_item = makePortItem(portModel, ctx, ret.container, context);
26,048 ✔
1196
  SCORE_SOFT_ASSERT(ret.port_item);
26,048 !
1197

1198
  if(ret.port_item)
26,048 !
1199
  {
1200
    ret.control = makePresentationWidget(portModel, ctx, context, presentation, layout);
26,048 ✔
1201
    if(ret.control)
26,048 ✔
1202
      ret.control->setParentItem(ret.container);
510 ✔
1203
    else
1204
      ret.control = makeControlItem(portModel, ctx, ret.container, context);
25,538 ✔
1205
    SCORE_SOFT_ASSERT(ret.control);
26,048 !
1206

1207
    if(ret.control)
26,048 !
1208
    {
1209
      // A small sound file is another widget, of its own size
1210
      auto shown = presentation;
26,048 ✔
1211
      if(isCompactSoundFile(portModel, presentation))
26,048 !
1212
        shown.size = score::ControlSize::Normal;
40 ✔
1213
      ret.label
26,048 ✔
1214
          = makeFullItemImpl(portModel, layout, *ret.port_item, *ret.control, *item, shown);
26,048 !
1215
    }
26,048 ✔
1216
  }
26,048 ✔
1217

1218
  return ret;
26,048 ✔
1219
}
×
1220

1221
Process::ControlLayout PortFactory::makeFullItem(
30 ✔
1222
    ControlOutlet& portModel, const Process::Context& ctx, QGraphicsItem* parent,
1223
    QObject* context, const ControlPresentation& presentation)
1224
{
1225
  Process::ControlLayout ret;
30 ✔
1226
  using namespace score;
1227
#if defined(SCORE_DEBUG_CONTROL_RECTS)
1228
  auto item = new score::GraphicsLayout{parent};
1229
  item->setBrush(score::Skin::instance().Light.main);
1230
#else
1231
  auto item = new score::EmptyRectItem{parent};
30 !
1232
#endif
1233
  ret.container = item;
30 !
1234

1235
  auto layout = defaultLayout();
30 ✔
1236
  ret.port_item = makePortItem(portModel, ctx, item, context);
30 !
1237
  SCORE_SOFT_ASSERT(ret.port_item);
30 !
1238

1239
  if(ret.port_item)
30 !
1240
  {
1241
    // An outlet's widget shows its value: the one presentation that applies is
1242
    // none at all
1243
    if(presentation.widget == Process::ControlPresentation::Widget::None)
30 ✔
1244
    {
1245
      layout = *presentationLayout(portModel, presentation);
4 ✔
1246
      ret.control = new score::EmptyItem{item};
4 !
1247
    }
4 ✔
1248
    else
1249
    {
1250
      ret.control = makeControlItem(portModel, ctx, item, context);
26 !
1251
    }
1252
    SCORE_SOFT_ASSERT(ret.control);
30 !
1253

1254
    if(ret.control)
30 !
1255
    {
1256
      ret.label
30 ✔
1257
          = makeFullItemImpl(
60 ✔
1258
              portModel, layout, *ret.port_item, *ret.control, *item, presentation);
30 ✔
1259
    }
30 ✔
1260
  }
30 ✔
1261
  return ret;
30 ✔
1262
}
×
1263

1264
void PortFactory::layoutFullItem(
131 ✔
1265
    ControlLayout& item, const Process::Port& port,
1266
    const ControlPresentation& presentation) const
1267
{
1268
  if(!item.container || !item.port_item || !item.control)
131 !
1269
    return;
×
1270

1271
  const auto layout = presentationLayout(port, presentation).value_or(defaultLayout());
131 ✔
1272

1273
#if defined(SCORE_DEBUG_CONTROL_RECTS)
1274
  auto& container = static_cast<score::GraphicsLayout&>(*item.container);
1275
#else
1276
  auto& container = static_cast<score::EmptyRectItem&>(*item.container);
131 ✔
1277
#endif
1278
  item.label = makeFullItemImpl(
131 ✔
1279
      port, layout, *item.port_item, *item.control, container, presentation, item.label);
131 ✔
1280
}
131 ✔
1281

1282
static constexpr auto defaultInletLabelLayout = Process::PortItemLayout{
1283
    .port = QPointF{0., 3.5},
1284
    .label = QPointF{5., 0.},
1285
    .control = QPointF{0., 0.},
1286
    .labelAlignment = Qt::AlignLeft};
1287
static constexpr auto defaultOutletLabelLayout = Process::PortItemLayout{
1288
    .port = QPointF{0., 3.5},
1289
    .label = QPointF{5., 0.},
1290
    .control = QPointF{0., 0.},
1291
    .labelAlignment = Qt::AlignRight};
1292
;
1293
Process::ControlLayout PortFactory::makeLabelItem(
3,383 ✔
1294
    Inlet& portModel, const Process::Context& ctx, QGraphicsItem* parent,
1295
    QObject* context)
1296
{
1297
  Process::ControlLayout ret;
3,383 ✔
1298

1299
  using namespace score;
1300
#if defined(SCORE_DEBUG_CONTROL_RECTS)
1301
  auto item = new score::GraphicsLayout{parent};
1302
  item->setBrush(score::Skin::instance().Light.main);
1303
#else
1304
  auto item = new score::EmptyRectItem{parent};
3,383 !
1305
#endif
1306
  ret.container = item;
3,383 !
1307

1308
  ret.port_item = makePortItem(portModel, ctx, ret.container, context);
3,383 ✔
1309
  SCORE_SOFT_ASSERT(ret.port_item);
3,383 !
1310

1311
  if(ret.port_item)
3,383 !
1312
  {
1313
    ret.label
3,383 ✔
1314
        = makeLabelItemImpl(portModel, defaultInletLabelLayout, *ret.port_item, *item);
6,766 ✔
1315
  }
3,383 ✔
1316

1317
  return ret;
3,383 ✔
1318
}
×
1319

1320
Process::ControlLayout PortFactory::makeLabelItem(
4,229 ✔
1321
    Outlet& portModel, const Process::Context& ctx, QGraphicsItem* parent,
1322
    QObject* context)
1323
{
1324
  Process::ControlLayout ret;
4,229 ✔
1325
  using namespace score;
1326
#if defined(SCORE_DEBUG_CONTROL_RECTS)
1327
  auto item = new score::GraphicsLayout{parent};
1328
  item->setBrush(score::Skin::instance().Light.main);
1329
#else
1330
  auto item = new score::EmptyRectItem{parent};
4,229 !
1331
#endif
1332
  ret.container = item;
4,229 !
1333

1334
  ret.port_item = makePortItem(portModel, ctx, item, context);
4,229 !
1335
  SCORE_SOFT_ASSERT(ret.port_item);
4,229 !
1336

1337
  if(ret.port_item)
4,229 !
1338
  {
1339
    ret.label
4,229 ✔
1340
        = makeLabelItemImpl(portModel, defaultOutletLabelLayout, *ret.port_item, *item);
8,458 ✔
1341
  }
4,229 ✔
1342
  return ret;
4,229 ✔
1343
}
×
1344

1345
Port* PortFactoryList::loadMissing(const VisitorVariant& vis, QObject* parent) const
129 ✔
1346
{
1347
  return nullptr;
129 ✔
1348
}
1349

1350
PortFactoryList::~PortFactoryList() { }
9,854 ✔
1351

1352
std::unique_ptr<Inlet> load_inlet(DataStreamWriter& wr, QObject* parent)
1,838 ✔
1353
{
1354
  auto& il = wr.components.interfaces<Process::PortFactoryList>();
1,838 ✔
1355
  return std::unique_ptr<Process::Inlet>(
1,838 ✔
1356
      (Process::Inlet*)deserialize_interface(il, wr, parent));
1,838 ✔
1357
}
1358

1359
std::unique_ptr<Inlet> load_inlet(JSONWriter& wr, QObject* parent)
3,186 ✔
1360
{
1361
  auto& il = wr.components.interfaces<Process::PortFactoryList>();
3,186 ✔
1362
  return std::unique_ptr<Process::Inlet>(
3,186 ✔
1363
      (Process::Inlet*)deserialize_interface(il, wr, parent));
3,186 ✔
1364
}
1365

1366
std::unique_ptr<Outlet> load_outlet(DataStreamWriter& wr, QObject* parent)
148 ✔
1367
{
1368
  auto& il = wr.components.interfaces<Process::PortFactoryList>();
148 ✔
1369
  return std::unique_ptr<Process::Outlet>(
148 ✔
1370
      (Process::Outlet*)deserialize_interface(il, wr, parent));
148 ✔
1371
}
1372

1373
std::unique_ptr<Outlet> load_outlet(JSONWriter& wr, QObject* parent)
256 ✔
1374
{
1375
  auto& il = wr.components.interfaces<Process::PortFactoryList>();
256 ✔
1376
  return std::unique_ptr<Process::Outlet>(
256 ✔
1377
      (Process::Outlet*)deserialize_interface(il, wr, parent));
256 ✔
1378
}
1379

1380
static auto copy_port(Port&& src, Port& dst)
×
1381
{
1382
  dst.displayHandledExplicitly = src.displayHandledExplicitly;
×
1383
  dst.singleCable = src.singleCable;
×
1384
  dst.setName(src.name());
×
1385
  dst.setAddress(src.address());
×
1386
  dst.setExposed(src.exposed());
×
1387
  dst.setScriptable(src.scriptable());
×
1388
  dst.setDescription(src.description());
×
1389
  dst.takeCables(std::move(src));
×
1390
}
×
1391

1392
template <typename T, typename W>
1393
auto load_port_t(W& wr, QObject* parent)
5,401 ✔
1394
{
1395
  auto out = [&] {
10,802 ✔
1396
    if constexpr(std::is_base_of_v<Inlet, T>)
1397
      return load_inlet(wr, parent).release();
5,003 ✔
1398
    else if constexpr(std::is_base_of_v<Outlet, T>)
1399
      return load_outlet(wr, parent).release();
398 ✔
1400
    else
1401
      return nullptr;
1402
  }();
1403

1404
  if(auto p = dynamic_cast<T*>(out))
5,401 !
1405
  {
1406
    return std::unique_ptr<T>(static_cast<T*>(out));
5,401 ✔
1407
  }
1408
  else if(out)
×
1409
  {
1410
    // Pre 2.0
1411
    auto new_p = std::make_unique<T>("Port", out->id(), parent);
×
1412
    copy_port(std::move(*out), *new_p);
×
1413
    delete out;
×
1414
    return new_p;
×
1415
  }
×
1416
  else
1417
  {
1418
    // This works with a specific id because it is only for pre 1.0 saves
1419
    return std::make_unique<T>("Port", Id<Process::Port>(0), parent);
×
1420
  }
1421
}
5,401 ✔
1422

1423
std::unique_ptr<ValueInlet> load_value_inlet(DataStreamWriter& wr, QObject* parent)
5 ✔
1424
{
1425
  return load_port_t<ValueInlet>(wr, parent);
5 ✔
1426
}
1427

1428
std::unique_ptr<ValueInlet> load_value_inlet(JSONWriter& wr, QObject* parent)
5 ✔
1429
{
1430
  return load_port_t<ValueInlet>(wr, parent);
5 ✔
1431
}
1432

1433
std::unique_ptr<ValueOutlet> load_value_outlet(DataStreamWriter& wr, QObject* parent)
32 ✔
1434
{
1435
  return load_port_t<ValueOutlet>(wr, parent);
32 ✔
1436
}
1437

1438
std::unique_ptr<ValueOutlet> load_value_outlet(JSONWriter& wr, QObject* parent)
57 ✔
1439
{
1440
  return load_port_t<ValueOutlet>(wr, parent);
57 ✔
1441
}
1442

1443
std::unique_ptr<ControlInlet> load_control_inlet(DataStreamWriter& wr, QObject* parent)
1,736 ✔
1444
{
1445
  return load_port_t<ControlInlet>(wr, parent);
1,736 ✔
1446
}
1447

1448
std::unique_ptr<ControlInlet> load_control_inlet(JSONWriter& wr, QObject* parent)
3,001 ✔
1449
{
1450
  return load_port_t<ControlInlet>(wr, parent);
3,001 ✔
1451
}
1452

1453
std::unique_ptr<ControlOutlet> load_control_outlet(DataStreamWriter& wr, QObject* parent)
×
1454
{
1455
  return load_port_t<ControlOutlet>(wr, parent);
×
1456
}
1457

1458
std::unique_ptr<ControlOutlet> load_control_outlet(JSONWriter& wr, QObject* parent)
×
1459
{
1460
  return load_port_t<ControlOutlet>(wr, parent);
×
1461
}
1462

1463
std::unique_ptr<AudioInlet> load_audio_inlet(DataStreamWriter& wr, QObject* parent)
85 ✔
1464
{
1465
  return load_port_t<AudioInlet>(wr, parent);
85 ✔
1466
}
1467

1468
std::unique_ptr<AudioInlet> load_audio_inlet(JSONWriter& wr, QObject* parent)
171 ✔
1469
{
1470
  return load_port_t<AudioInlet>(wr, parent);
171 ✔
1471
}
1472

1473
std::unique_ptr<AudioOutlet> load_audio_outlet(DataStreamWriter& wr, QObject* parent)
100 ✔
1474
{
1475
  return load_port_t<AudioOutlet>(wr, parent);
100 ✔
1476
}
1477

1478
std::unique_ptr<AudioOutlet> load_audio_outlet(JSONWriter& wr, QObject* parent)
182 ✔
1479
{
1480
  return load_port_t<AudioOutlet>(wr, parent);
182 ✔
1481
}
1482

1483
std::unique_ptr<MidiInlet> load_midi_inlet(DataStreamWriter& wr, QObject* parent)
×
1484
{
1485
  return load_port_t<MidiInlet>(wr, parent);
×
1486
}
1487

1488
std::unique_ptr<MidiInlet> load_midi_inlet(JSONWriter& wr, QObject* parent)
×
1489
{
1490
  return load_port_t<MidiInlet>(wr, parent);
×
1491
}
1492

1493
std::unique_ptr<MidiOutlet> load_midi_outlet(DataStreamWriter& wr, QObject* parent)
12 ✔
1494
{
1495
  return load_port_t<MidiOutlet>(wr, parent);
12 ✔
1496
}
1497

1498
std::unique_ptr<MidiOutlet> load_midi_outlet(JSONWriter& wr, QObject* parent)
15 ✔
1499
{
1500
  return load_port_t<MidiOutlet>(wr, parent);
15 ✔
1501
}
1502

1503
QString
1504
displayNameForPort(const Process::Port& outlet, const score::DocumentContext& doc)
656 ✔
1505
{
1506
  // Try to look for a cable
1507
  if(const auto& cables = outlet.cables(); !cables.empty())
656 ✔
1508
  {
1509
    if(Process::Cable* cbl = cables.front().try_find(doc))
54 ✔
1510
      if(Process::Port* inlet = cbl->sink().try_find(doc))
52 !
1511
      {
1512
        QString name = inlet->name();
52 ✔
1513
        auto inlet_parent = inlet->parent();
52 !
1514
        auto process = qobject_cast<Process::ProcessModel*>(inlet_parent);
52 !
1515
        if(!process && qobject_cast<Process::Port*>(inlet_parent))
52 !
1516
          process = qobject_cast<Process::ProcessModel*>(inlet_parent->parent());
×
1517

1518
        // A process's pretty name can name the port its outlet is cabled to
1519
        // (automations do), so cables forming a cycle -- e.g. an automation
1520
        // feeding itself after a remove that kept the links -- would recurse
1521
        // forever: name each process once along the chain.
1522
        static thread_local ossia::small_vector<const Process::ProcessModel*, 8>
52 ✔
1523
            visiting;
3 ✔
1524
        if(process && !ossia::contains(visiting, process))
52 !
1525
        {
1526
          visiting.push_back(process);
52 !
1527
          struct pop
1528
          {
1529
            ~pop() { visiting.pop_back(); }
52 ✔
1530
          } guard;
1531
          name += " (" + process->prettyName() + ")";
52 !
1532
        }
52 ✔
1533
        return name;
52 ✔
1534
      }
52 ✔
1535
  }
2 ✔
1536

1537
  // If no cable, use the address instead
1538
  auto res = outlet.address().toString_unsafe();
604 ✔
1539
  if(!res.isEmpty())
604 !
1540
    return res;
604 ✔
1541
  return {};
×
1542
}
656 ✔
1543
}
1544

1545
template <>
1546
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::Port& p)
47,567 ✔
1547
{
1548
  insertDelimiter();
47,567 ✔
1549
  m_stream << p.displayHandledExplicitly << p.m_name << p.m_exposed << p.m_description
47,567 ✔
1550
           << p.m_address << p.m_scriptable;
47,567 ✔
1551
  insertDelimiter();
47,567 ✔
1552
}
47,567 ✔
1553
template <>
1554
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::Port& p)
21,959 ✔
1555
{
1556
  checkDelimiter();
21,959 ✔
1557
  m_stream >> p.displayHandledExplicitly >> p.m_name >> p.m_exposed >> p.m_description
21,959 ✔
1558
      >> p.m_address >> p.m_scriptable;
21,959 ✔
1559
  checkDelimiter();
21,959 ✔
1560
}
21,959 ✔
1561

1562
template <>
1563
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::Port& p)
29,295 ✔
1564
{
1565
  obj["Hidden"] = (bool)p.displayHandledExplicitly;
29,295 ✔
1566
  if(!p.m_name.isEmpty())
29,295 ✔
1567
    obj["Custom"] = p.m_name;
29,283 ✔
1568
  if(!p.m_exposed.isEmpty())
29,295 ✔
1569
    obj["Exposed"] = p.m_exposed;
29,283 ✔
1570
  if(!p.m_description.isEmpty())
29,295 ✔
1571
    obj["Description"] = p.m_description;
3,884 ✔
1572
  if(p.m_scriptable)
29,295 ✔
1573
    obj["Scriptable"] = true;
7 ✔
1574
  if(!(p.m_address.address.path.isEmpty() && p.m_address.address.device.isEmpty()
58,558 !
1575
       && p.m_address.qualifiers.get() == ossia::destination_qualifiers{}))
29,264 !
1576
    obj["Address"] = p.m_address;
34 ✔
1577
}
29,295 ✔
1578
template <>
1579
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::Port& p)
22,203 ✔
1580
{
1581
  p.displayHandledExplicitly = obj["Hidden"].toBool();
22,203 ✔
1582
  if(auto it = obj.tryGet("Custom"))
22,203 ✔
1583
    p.m_name = it->toString();
22,194 ✔
1584
  if(auto it = obj.tryGet("Exposed"))
22,203 ✔
1585
    p.m_exposed = it->toString();
22,194 ✔
1586
  if(auto it = obj.tryGet("Description"))
22,203 ✔
1587
    p.m_description = it->toString();
3,011 ✔
1588
  if(auto it = obj.tryGet("Scriptable"))
22,203 ✔
1589
    p.m_scriptable = it->toBool();
7 ✔
1590
  if(auto it = obj.tryGet("Address"))
22,203 ✔
1591
    p.m_address <<= *it;
38 ✔
1592
}
22,203 ✔
1593

1594
template <>
1595
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::Inlet& p)
39,488 ✔
1596
{
1597
  read((Process::Port&)p);
39,488 ✔
1598
}
39,488 ✔
1599
template <>
1600
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::Inlet& p)
19,528 ✔
1601
{
1602
}
19,528 ✔
1603

1604
template <>
1605
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::Inlet& p)
25,812 ✔
1606
{
1607
  read((Process::Port&)p);
25,812 ✔
1608
}
25,812 ✔
1609
template <>
1610
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::Inlet& p)
19,658 ✔
1611
{
1612
}
19,658 ✔
1613

1614
template <>
1615
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::AudioInlet& p)
5,494 ✔
1616
{
1617
  // read((Process::Outlet&)p);
1618
}
5,494 ✔
1619
template <>
1620
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::AudioInlet& p)
871 ✔
1621
{
1622
}
871 ✔
1623

1624
template <>
1625
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::AudioInlet& p)
1,532 ✔
1626
{
1627
  // read((Process::Outlet&)p);
1628
}
1,532 ✔
1629
template <>
1630
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::AudioInlet& p)
1,366 ✔
1631
{
1632
}
1,366 ✔
1633

1634
template <>
1635
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::MidiInlet& p)
475 ✔
1636
{
1637
  // read((Process::Outlet&)p);
1638
}
475 ✔
1639
template <>
1640
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::MidiInlet& p)
397 ✔
1641
{
1642
}
397 ✔
1643

1644
template <>
1645
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::MidiInlet& p)
228 ✔
1646
{
1647
  // read((Process::Outlet&)p);
1648
}
228 ✔
1649
template <>
1650
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::MidiInlet& p)
186 ✔
1651
{
1652
}
186 ✔
1653

1654
template <>
1655
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::ControlInlet& p)
32,208 ✔
1656
{
1657
  // read((Process::Inlet&)p);
1658
  readFrom(p.m_value);
32,208 ✔
1659
  readFrom(p.m_init);
32,208 ✔
1660
  readFrom(p.m_domain);
32,208 ✔
1661
}
32,208 ✔
1662
template <>
1663
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::ControlInlet& p)
17,743 ✔
1664
{
1665
  writeTo(p.m_value);
17,743 ✔
1666
  writeTo(p.m_init);
17,743 ✔
1667
  writeTo(p.m_domain);
17,743 ✔
1668
}
17,743 ✔
1669

1670
template <>
1671
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::ControlInlet& p)
22,862 ✔
1672
{
1673
  // read((Process::Inlet&)p);
1674
  obj[strings.Value] = p.m_value;
22,862 ✔
1675
  obj[strings.Init] = p.m_init;
22,862 ✔
1676
  obj[strings.Domain] = p.m_domain;
22,862 ✔
1677
}
22,862 ✔
1678

1679
template <>
1680
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::ControlInlet& p)
17,565 ✔
1681
{
1682
  p.m_value <<= obj[strings.Value];
17,565 ✔
1683
  if(auto v = obj.tryGet(strings.Init))
17,565 ✔
1684
    p.m_init <<= *v;
17,564 ✔
1685
  p.m_domain <<= obj[strings.Domain];
17,565 ✔
1686
}
17,565 ✔
1687

1688
template <>
1689
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::Outlet& p)
8,077 ✔
1690
{
1691
  read((Process::Port&)p);
8,077 ✔
1692
}
8,077 ✔
1693
template <>
1694
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::Outlet& p)
2,431 ✔
1695
{
1696
}
2,431 ✔
1697

1698
template <>
1699
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::Outlet& p)
3,479 ✔
1700
{
1701
  read((Process::Port&)p);
3,479 ✔
1702
}
3,479 ✔
1703
template <>
1704
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::Outlet& p)
2,545 ✔
1705
{
1706
}
2,545 ✔
1707

1708
template <>
1709
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::AudioOutlet& p)
5,465 ✔
1710
{
1711
  // read((Process::Outlet&)p);
1712
  m_stream << *p.gainInlet << *p.panInlet << p.m_gain
5,465 ✔
1713
           << static_cast<const ossia::small_vector<double, 2>&>(p.m_pan)
5,465 ✔
1714
           << p.m_propagate << p.m_upmixMode << p.m_upmixChannels;
5,465 ✔
1715
}
5,465 ✔
1716
template <>
1717
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::AudioOutlet& p)
844 ✔
1718
{
1719
  p.gainInlet = Process::load_control_inlet(*this, &p);
844 ✔
1720
  p.panInlet = Process::load_control_inlet(*this, &p);
844 ✔
1721
  m_stream >> p.m_gain >> static_cast<ossia::small_vector<double, 2>&>(p.m_pan)
844 ✔
1722
      >> p.m_propagate;
844 ✔
1723
  // Data saved before the upmix existed ends here.
1724
  if(!atDelimiterOrEnd())
844 !
1725
    m_stream >> p.m_upmixMode >> p.m_upmixChannels;
844 ✔
1726
}
844 ✔
1727

1728
template <>
1729
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::AudioOutlet& p)
1,598 ✔
1730
{
1731
  // read((Process::Outlet&)p);
1732
  obj["GainInlet"] = *p.gainInlet;
1,598 ✔
1733
  obj["PanInlet"] = *p.panInlet;
1,598 ✔
1734

1735
  obj["Gain"] = p.m_gain;
1,598 ✔
1736
  obj["Pan"] = static_cast<const ossia::small_vector<double, 2>&>(p.m_pan);
1,598 ✔
1737
  obj["Propagate"] = p.m_propagate;
1,598 ✔
1738
  if(p.m_upmixMode != 0)
1,598 ✔
1739
  {
1740
    obj["Upmix"] = p.m_upmixMode;
1 ✔
1741
    obj["UpmixChannels"] = p.m_upmixChannels;
1 ✔
1742
  }
1 ✔
1743
}
1,598 ✔
1744
template <>
1745
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::AudioOutlet& p)
1,454 ✔
1746
{
1747
  if(auto it = obj.tryGet("GainInlet"))
1,454 !
1748
  {
1749
    JSONWriter writer{*it};
1,454 ✔
1750
    p.gainInlet = Process::load_control_inlet(writer, &p);
1,454 ✔
1751
  }
1,454 ✔
1752
  else
1753
  {
1754
    p.gainInlet
×
1755
        = std::make_unique<Process::ControlInlet>("Gain", Id<Process::Port>{0}, &p);
×
1756
  }
1757

1758
  if(auto it = obj.tryGet("PanInlet"))
1,454 !
1759
  {
1760
    JSONWriter writer{*it};
1,454 ✔
1761
    p.panInlet = Process::load_control_inlet(writer, &p);
1,454 ✔
1762
  }
1,454 ✔
1763
  else
1764
  {
1765
    p.panInlet
×
1766
        = std::make_unique<Process::ControlInlet>("Pan", Id<Process::Port>{1}, &p);
×
1767
  }
1768

1769
  p.m_gain = obj["Gain"].toDouble();
1,454 ✔
1770
  static_cast<ossia::small_vector<double, 2>&>(p.m_pan) <<= obj["Pan"];
1,454 ✔
1771
  p.m_propagate = obj["Propagate"].toBool();
1,454 ✔
1772
  if(auto it = obj.tryGet("Upmix"))
1,454 ✔
1773
    p.m_upmixMode = it->toInt();
1 ✔
1774
  if(auto it = obj.tryGet("UpmixChannels"))
1,454 ✔
1775
    p.m_upmixChannels = it->toInt();
1 ✔
1776
}
1,454 ✔
1777

1778
template <>
1779
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::MidiOutlet& p)
398 ✔
1780
{
1781
  // read((Process::Outlet&)p);
1782
}
398 ✔
1783
template <>
1784
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::MidiOutlet& p)
349 ✔
1785
{
1786
}
349 ✔
1787

1788
template <>
1789
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::MidiOutlet& p)
120 ✔
1790
{
1791
  // read((Process::Outlet&)p);
1792
}
120 ✔
1793
template <>
1794
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::MidiOutlet& p)
87 ✔
1795
{
1796
}
87 ✔
1797

1798
template <>
1799
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::ControlOutlet& p)
29 ✔
1800
{
1801
  // read((Process::Outlet&)p);
1802
  readFrom(p.m_value);
29 ✔
1803
  readFrom(p.m_domain);
29 ✔
1804
}
29 ✔
1805
template <>
1806
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::ControlOutlet& p)
15 ✔
1807
{
1808
  writeTo(p.m_value);
15 ✔
1809
  writeTo(p.m_domain);
15 ✔
1810
}
15 ✔
1811

1812
template <>
1813
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::ControlOutlet& p)
27 ✔
1814
{
1815
  // read((Process::Outlet&)p);
1816
  obj[strings.Value] = p.m_value;
27 ✔
1817
  obj[strings.Domain] = p.m_domain;
27 ✔
1818
}
27 ✔
1819
template <>
1820
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::ControlOutlet& p)
18 ✔
1821
{
1822
  p.m_value <<= obj[strings.Value];
18 ✔
1823
  p.m_domain <<= obj[strings.Domain];
18 ✔
1824
}
18 ✔
1825

1826
template <>
1827
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::ValueInlet& p)
548 ✔
1828
{
1829
  // read((Process::Outlet&)p);
1830
}
548 ✔
1831
template <>
1832
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::ValueInlet& p)
273 ✔
1833
{
1834
}
273 ✔
1835

1836
template <>
1837
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::ValueInlet& p)
520 ✔
1838
{
1839
  // read((Process::Outlet&)p);
1840
}
520 ✔
1841
template <>
1842
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::ValueInlet& p)
288 ✔
1843
{
1844
}
288 ✔
1845

1846
template <>
1847
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::ValueOutlet& p)
1,813 ✔
1848
{
1849
  // read((Process::Outlet&)p);
1850
}
1,813 ✔
1851
template <>
1852
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::ValueOutlet& p)
1,090 ✔
1853
{
1854
}
1,090 ✔
1855

1856
template <>
1857
SCORE_LIB_PROCESS_EXPORT void JSONReader::read(const Process::ValueOutlet& p)
1,427 ✔
1858
{
1859
  // read((Process::Outlet&)p);
1860
}
1,427 ✔
1861
template <>
1862
SCORE_LIB_PROCESS_EXPORT void JSONWriter::write(Process::ValueOutlet& p)
842 ✔
1863
{
1864
}
842 ✔
1865

1866
template <>
1867
SCORE_LIB_PROCESS_EXPORT void DataStreamReader::read(const Process::pan_weight& p)
68 ✔
1868
{
1869
  this->m_stream << static_cast<const ossia::small_vector<double, 2>&>(p);
68 ✔
1870
  // read((Process::Outlet&)p);
1871
}
68 ✔
1872
template <>
1873
SCORE_LIB_PROCESS_EXPORT void DataStreamWriter::write(Process::pan_weight& p)
62 ✔
1874
{
1875
  this->m_stream >> static_cast<ossia::small_vector<double, 2>&>(p);
62 ✔
1876
}
62 ✔
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