2 #include <Device/Loading/JamomaDeviceLoader.hpp>
3 #include <Device/Loading/ScoreDeviceLoader.hpp>
4 #include <Device/Loading/TouchOSCDeviceLoader.hpp>
5 #include <Device/Protocol/ProtocolList.hpp>
7 #include <Explorer/Commands/Add/LoadDevice.hpp>
8 #include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
9 #include <Explorer/Explorer/Widgets/DeviceEditDialog.hpp>
11 #include <Library/LibraryInterface.hpp>
12 #include <Protocols/Mapper/MapperDevice.hpp>
14 #include <score/command/Dispatchers/CommandDispatcher.hpp>
15 #include <score/document/DocumentContext.hpp>
17 #include <score/serialization/MapSerialization.hpp>
18 #include <score/widgets/MessageBox.hpp>
20 #include <ossia-qt/js_utilities.hpp>
23 #include <QMainWindow>
24 #if __has_include(<QQmlEngine>)
25 #include <QQmlComponent>
27 #include <QQmlProperty>
29 #if defined(OSSIA_PROTOCOL_OSC)
30 #include <Protocols/OSC/OSCProtocolFactory.hpp>
32 #if defined(OSSIA_PROTOCOL_OSCQUERY)
33 #include <Protocols/Minuit/MinuitProtocolFactory.hpp>
35 #if defined(OSSIA_PROTOCOL_MINUIT)
36 #include <Protocols/OSCQuery/OSCQueryProtocolFactory.hpp>
38 #if defined(OSSIA_PROTOCOL_HTTP)
39 #include <Protocols/HTTP/HTTPProtocolFactory.hpp>
40 #include <Protocols/HTTP/HTTPSpecificSettings.hpp>
42 #include <ossia-qt/http/http_protocol.hpp>
44 #if defined(OSSIA_PROTOCOL_WEBSOCKETS)
45 #include <Protocols/WS/WSProtocolFactory.hpp>
46 #include <Protocols/WS/WSSpecificSettings.hpp>
48 #include <ossia-qt/websocket-generic-client/ws_generic_client_protocol.hpp>
50 #if defined(OSSIA_PROTOCOL_SERIAL)
51 #include <Protocols/Serial/SerialProtocolFactory.hpp>
52 #include <Protocols/Serial/SerialSpecificSettings.hpp>
54 #include <ossia-qt/serial/serial_protocol.hpp>
60 SCORE_CONCRETE(
"8d4c06e2-851b-4d5f-82f2-68056a50c370")
62 QSet<QString> acceptedFiles()
const noexcept
override
64 return {
"touchosc",
"json",
"xml",
"device"};
70 bool ok = (path.endsWith(
".touchosc") && Device::loadDeviceFromTouchOSC(path, n))
71 || (path.endsWith(
".json") && Device::loadDeviceFromScoreJSON(path, n))
73 || (path.endsWith(
".device") && Device::loadDeviceFromScoreJSON(path, n));
77 auto& devplug = ctx.plugin<Explorer::DeviceDocumentPlugin>();
78 auto& model = devplug.explorer();
81 if(set.name.isEmpty())
82 set.name = QFileInfo(path).completeBaseName();
84 if(set.protocol.impl().is_nil())
85 set.protocol = Protocols::OSCProtocolFactory::static_concreteKey();
87 model.checkAndLoadDevice(std::move(n));
92 #if __has_include(<QQmlEngine>)
95 SCORE_CONCRETE(
"fee42cea-ff1a-48ef-a0da-922773081779")
97 QSet<QString> acceptedFiles() const noexcept
override {
return {
"qml"}; }
102 if(!f.open(QIODevice::ReadOnly))
104 auto content = f.readAll();
108 c.setData(content, QUrl());
110 std::unique_ptr<QObject> obj{c.create()};
116 set.name = QFileInfo(f).baseName();
118 if(
dynamic_cast<Protocols::Mapper*
>(obj.get()))
120 set.protocol = Protocols::MapperProtocolFactory::static_concreteKey();
121 set.deviceSpecificSettings
122 = QVariant::fromValue(Protocols::MapperSpecificSettings{content});
124 #if defined(OSSIA_PROTOCOL_SERIAL)
125 else if(
dynamic_cast<ossia::net::Serial*
>(obj.get()))
127 set.protocol = Protocols::SerialProtocolFactory::static_concreteKey();
128 set.deviceSpecificSettings
132 #if defined(OSSIA_PROTOCOL_HTTP)
133 else if(
dynamic_cast<ossia::net::HTTP*
>(obj.get()))
135 set.protocol = Protocols::HTTPProtocolFactory::static_concreteKey();
136 set.deviceSpecificSettings
140 #if defined(OSSIA_PROTOCOL_WEBSOCKETS)
141 else if(
dynamic_cast<ossia::net::WS*
>(obj.get()))
143 set.protocol = Protocols::WSProtocolFactory::static_concreteKey();
145 QQmlProperty(obj.get(),
"host").read().toString(), content});
152 auto& devplug = ctx.plugin<Explorer::DeviceDocumentPlugin>();
153 auto& model = devplug.explorer();
155 model.checkAndLoadDevice(set);
Serialization mechanism for ossia::any.
Definition: LibraryInterface.hpp:22
Definition: ProtocolLibrary.hpp:59
bool loadDeviceFromXML(const QString &filePath, Device::Node &node)
loadDeviceFromJamomaJSON Will load a device in a Jamoma-format XML file into the node.
Definition: JamomaDeviceLoader.cpp:248
Definition: DeviceSettings.hpp:20
Definition: HTTPSpecificSettings.hpp:9
Definition: SerialSpecificSettings.hpp:13
Definition: WSSpecificSettings.hpp:9
Definition: DocumentContext.hpp:18