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

ossia / score / 30213925900

26 Jul 2026 06:03PM UTC coverage: 15.298% (-0.01%) from 15.311%
30213925900

push

github

jcelerier
3rdparty: bump libossia for the network-context poll fix

Brings in ossia/libossia#913: SDL joystick init no longer requires haptic
support (which the Emscripten SDL2 port does not have), and
network_context::poll() restarts the io_context, without which the
WebAssembly polling path stops after its first tick.

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

30400 of 198713 relevant lines covered (15.3%)

997.67 hits per line

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

0.0
/src/plugins/score-plugin-js/JS/Qml/DeviceEnumerator.cpp
1
#include "DeviceEnumerator.hpp"
2

3
#include <Device/Protocol/ProtocolFactoryInterface.hpp>
4
#include <Device/Protocol/ProtocolList.hpp>
5

6
#include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
7

8
#include <score/application/GUIApplicationContext.hpp>
9

10
#include <ossia-qt/js_utilities.hpp>
11

12
#include <QtQml>
13

14
#include <wobjectimpl.h>
15
W_OBJECT_IMPL(JS::GlobalDeviceEnumerator)
×
16
W_OBJECT_IMPL(JS::DeviceIdentifier)
×
17
W_OBJECT_IMPL(JS::DeviceListener)
×
18
namespace JS
19
{
20
/**
21
  var e = Score.enumerateDevices();
22
  e.enumerate = true;
23
  console.log(e.devices);
24
 */
25

26
GlobalDeviceEnumerator::GlobalDeviceEnumerator() { }
×
27

28
void GlobalDeviceEnumerator::setDeviceType(const QString& uid)
×
29
{
30
  if(uid.length() != 36)
×
31
  {
32
    qDebug("Invalid UUID");
×
33
    return;
×
34
  }
35

36
  // Convert the textual UUID in a strongly typed UUID
37
  try
38
  {
39

40
    auto uuid = uid.toUtf8();
×
41
    auto score_uid = score::uuids::string_generator::compute(uuid.begin(), uuid.end());
×
42
    if(score_uid.is_nil())
×
43
      return;
×
44
    this->m_deviceType = UuidKey<Device::ProtocolFactory>{score_uid};
×
45
  }
×
46
  catch(...)
47
  {
48
    qDebug("Error while parsing device type");
×
49
    return;
50
  }
×
51
  reprocess();
×
52
}
×
53

54
GlobalDeviceEnumerator::~GlobalDeviceEnumerator()
×
55
{
×
56
  m_enumerate = false;
×
57
  reprocess();
×
58
}
×
59

60
void GlobalDeviceEnumerator::setContext(const score::DocumentContext* doc)
×
61
{
62
  this->doc = doc;
×
63
  reprocess();
×
64
}
×
65

66
QQmlListProperty<DeviceIdentifier> GlobalDeviceEnumerator::devices()
×
67
{
68
  using CountFunction = QQmlListProperty<DeviceIdentifier>::CountFunction;
69
  using AtFunction = QQmlListProperty<DeviceIdentifier>::AtFunction;
70

71
  CountFunction count = +[](QQmlListProperty<DeviceIdentifier>* d) -> qsizetype {
×
72
    return ((GlobalDeviceEnumerator*)d->object)->m_raw_list.size();
×
73
  };
74
  AtFunction at = +[](QQmlListProperty<DeviceIdentifier>* d,
×
75
                      qsizetype index) -> DeviceIdentifier* {
76
    auto self = (GlobalDeviceEnumerator*)d->object;
×
77
    if(index >= 0 && index < std::ssize(self->m_raw_list))
×
78
      return self->m_raw_list[index];
×
79
    else
80
      return nullptr;
×
81
  };
×
82

83
  return QQmlListProperty<DeviceIdentifier>(this, nullptr, count, at);
×
84
}
85

86
void GlobalDeviceEnumerator::setEnumerate(bool b)
×
87
{
88
  if(m_enumerate == b)
×
89
    return;
×
90

91
  m_enumerate = b;
×
92
  enumerateChanged(b);
×
93

94
  QMetaObject::invokeMethod(this, &GlobalDeviceEnumerator::reprocess);
×
95
}
×
96

97
void GlobalDeviceEnumerator::reprocess()
×
98
{
99
  for(auto& [k, v] : this->m_current_enums)
×
100
  {
101
    for(auto& [ename, e] : v)
×
102
      delete e;
×
103
  }
104
  this->m_current_enums.clear();
×
105
  this->m_known_devices.clear();
×
106
  for(auto d : m_raw_list)
×
107
    delete d;
×
108
  m_raw_list.clear();
×
109

110
  if(!this->doc)
×
111
  {
112
    doc = score::GUIAppContext().currentDocument();
×
113
    if(!doc)
×
114
      return;
×
115
  }
×
116
  if(!this->m_enumerate)
×
117
    return;
×
118

119
  auto& doc = *this->doc;
×
120
  for(auto& protocol : doc.app.interfaces<Device::ProtocolFactoryList>())
×
121
  {
122
    if(m_deviceType != Device::ProtocolFactory::ConcreteKey{})
×
123
      if(m_deviceType != protocol.concreteKey())
×
124
        continue;
×
125

126
    auto enums = protocol.getEnumerators(doc);
×
127
    m_current_enums[&protocol] = enums;
×
128
    for(auto& [category, enumerator] : enums)
×
129
    {
130
      auto on_deviceAdded
131
          = [this, category = category, proto = &protocol](
×
132
                const QString& name, const Device::DeviceSettings& devs) {
133
        this->deviceAdded(proto, category, name, devs);
×
134
        this->m_known_devices[proto].emplace_back(category, name, devs);
×
135
        m_raw_list.push_back(new DeviceIdentifier{category, name, devs, proto});
×
136
      };
×
137
      connect(
×
138
          enumerator, &Device::DeviceEnumerator::deviceAdded, this, on_deviceAdded,
×
139
          Qt::QueuedConnection);
140
      connect(
×
141
          enumerator, &Device::DeviceEnumerator::deviceRemoved, this,
×
142
          [this, category = category, proto = &protocol](const QString& name) {
×
143
        this->deviceRemoved(proto, name);
×
144
        {
145
          auto& vec = this->m_known_devices[proto];
×
146
          auto it = ossia::find_key(vec, category, name);
×
147
          if(it != vec.end())
×
148
            vec.erase(it);
×
149
        }
150
        {
151
          auto it = ossia::find_if(this->m_raw_list, [&](auto& di) {
×
152
            return di->protocol == proto && di->name == name;
×
153
          });
154
          if(it != this->m_raw_list.end())
×
155
          {
156
            delete *it;
×
157
            this->m_raw_list.erase(it);
×
158
          }
×
159
        }
160
      }, Qt::QueuedConnection);
×
161

162
      enumerator->enumerate(on_deviceAdded);
×
163
    }
×
164
  }
×
165
}
×
166

167
DeviceListener::DeviceListener()
×
168
{
×
169
  auto doc = score::GUIAppContext().currentDocument();
×
170
  if(!doc)
×
171
    return;
×
172
  ctx = doc;
×
173
}
×
174

175
void DeviceListener::init()
×
176
{
177
  auto& plug = ctx->plugin<Explorer::DeviceDocumentPlugin>();
×
178
  auto& list = plug.list();
×
179
  for(auto& dev : list.devices())
×
180
  {
181
    on_deviceAdded(*dev);
×
182
  }
183

184
  connect(
×
185
      &list, &Device::DeviceList::deviceAdded, this,
×
186
      [this](Device::DeviceInterface* dev) { on_deviceAdded(*dev); });
×
187
  connect(
×
188
      &list, &Device::DeviceList::deviceRemoved, this,
×
189
      [](Device::DeviceInterface* dev) { });
×
190
}
×
191

192
QString addressFromParameter(const ossia::net::parameter_base& p)
×
193
{
194
  auto& dev = p.get_node().get_device();
×
195
  auto nm = QString::fromStdString(dev.get_name());
×
196
  auto str = QString::fromStdString(p.get_node().osc_address());
×
197
  return nm + ":" + str;
×
198
}
×
199

200
void DeviceListener::on_deviceAdded(Device::DeviceInterface& dev)
×
201
{
202
  auto ossia_dev = dev.getDevice();
×
203
  if(!ossia_dev)
×
204
  {
205
    return;
×
206
  }
207

208
  if(!this->m_name.isEmpty())
×
209
    if(ossia_dev->get_name() != this->m_name.toStdString())
×
210
      return;
×
211

212
  ossia_dev->on_node_created.connect<&DeviceListener::on_nodeCreated>(*this);
×
213
  ossia_dev->on_parameter_created.connect<&DeviceListener::on_parameterCreated>(*this);
×
214
}
×
215

216
void DeviceListener::on_nodeCreated(const ossia::net::node_base& n)
×
217
{
218
  if(auto param = n.get_parameter())
×
219
  {
220
    on_parameterCreated(*param);
×
221
  }
×
222
}
×
223

224
void DeviceListener::on_parameterCreated(const ossia::net::parameter_base& p)
×
225
{
226
  auto addr = addressFromParameter(p);
×
227
  parameterCreated(addr);
×
228
  const_cast<ossia::net::parameter_base&>(p).add_callback(
×
229
      [this, addr](const ossia::value& v) {
×
230
    auto vv = v.apply(ossia::qt::ossia_to_qvariant{});
×
231
    message(addr, vv);
×
232
  });
×
233
}
×
234

235
DeviceListener::~DeviceListener() { }
×
236

237
void DeviceListener::setDeviceName(const QString& b)
×
238
{
239
  if(b == m_name)
×
240
    return;
×
241
  m_name = b;
×
242
  deviceNameChanged(m_name);
×
243
}
×
244

245
void DeviceListener::setDeviceType(const QString& b)
×
246
{
247
  if(b == m_uuid)
×
248
    return;
×
249
  m_uuid = b;
×
250
  deviceTypeChanged(m_uuid);
×
251
}
×
252
void DeviceListener::setListen(bool b)
×
253
{
254
  if(b == m_listen)
×
255
    return;
×
256
  m_listen = b;
×
257
  listenChanged(m_listen);
×
258

259
  init();
×
260
}
×
261
}
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