33 if(!f.open(QIODevice::ReadOnly))
38 auto [_, desc] = isf::parser::parse_isf_header(score::readFileAsString(f));
39 if(desc.credits.starts_with(
"Automatically converted from "))
40 desc.credits = desc.credits.substr(strlen(
"Automatically converted from "));
41 else if(desc.credits.starts_with(
"by "))
42 desc.credits = desc.credits.substr(strlen(
"by "));
43 if(!desc.credits.empty())
44 base.author = QString::fromStdString(desc.credits);
45 if(!desc.description.empty())
46 base.description = QString::fromStdString(desc.description);
47 for(
auto& cat : desc.categories)
48 base.tags.push_back(QString::fromStdString(cat));
58 static void setupISFModelPorts(
59 T& self,
const isf::descriptor& desc,
60 const ossia::flat_map<QString, ossia::value>& previous_values)
80 const ossia::flat_map<QString, ossia::value>& previous_values;
81 const isf::input& input;
91 auto nm = QString::fromStdString(input.name);
95 self.m_inlets.push_back(port);
96 if(
auto it = previous_values.find(nm);
97 it != previous_values.end()
98 && it->second.get_type() == ossia::val_type::FLOAT)
99 port->setValue(it->second);
101 self.controlAdded(port->id());
107 auto nm = QString::fromStdString(input.name);
110 if(v.values.empty() && v.min && v.max)
115 if(
auto it = previous_values.find(nm);
116 it != previous_values.end()
117 && it->second.get_type() == port->value().get_type())
118 port->setValue(it->second);
120 self.m_inlets.push_back(port);
121 self.controlAdded(port->id());
126 std::vector<std::pair<QString, ossia::value>> alternatives;
127 if(v.labels.size() == v.values.size())
129 for(std::size_t value_idx = 0; value_idx < v.values.size(); value_idx++)
131 auto& val = v.values[value_idx];
132 if(
auto int_ptr = ossia::get_if<int64_t>(&val))
134 alternatives.emplace_back(
135 QString::fromStdString(v.labels[value_idx]), int(*int_ptr));
137 else if(
auto dbl_ptr = ossia::get_if<double>(&val))
139 alternatives.emplace_back(
140 QString::fromStdString(v.labels[value_idx]), int(*dbl_ptr));
144 alternatives.emplace_back(
145 QString::fromStdString(v.labels[value_idx]), int(value_idx));
151 for(std::size_t value_idx = 0; value_idx < v.values.size(); value_idx++)
153 auto& val = v.values[value_idx];
154 if(
auto int_ptr = ossia::get_if<int64_t>(&val))
156 alternatives.emplace_back(QString::number(*int_ptr), int(*int_ptr));
158 else if(
auto dbl_ptr = ossia::get_if<double>(&val))
160 alternatives.emplace_back(QString::number(*dbl_ptr), int(*dbl_ptr));
162 else if(
auto str_ptr = ossia::get_if<std::string>(&val))
164 alternatives.emplace_back(
165 QString::fromStdString(*str_ptr), int(value_idx));
170 if(alternatives.empty())
172 alternatives.emplace_back(
"0", 0);
173 alternatives.emplace_back(
"1", 1);
174 alternatives.emplace_back(
"2", 2);
181 const std::size_t def_idx
182 = std::min<std::size_t>(v.def, alternatives.size() - 1);
183 const ossia::value& init_value = alternatives[def_idx].second;
188 if(
auto it = previous_values.find(nm);
189 it != previous_values.end()
190 && it->second.get_type() == port->value().get_type())
191 port->setValue(it->second);
193 self.m_inlets.push_back(port);
194 self.controlAdded(port->id());
200 auto nm = QString::fromStdString(input.name);
203 self.m_inlets.push_back(port);
204 self.controlAdded(port->id());
210 auto nm = QString::fromStdString(input.name);
213 if(
auto it = previous_values.find(nm);
214 it != previous_values.end()
215 && it->second.get_type() == port->value().get_type())
216 port->setValue(it->second);
218 self.m_inlets.push_back(port);
219 self.controlAdded(port->id());
225 auto nm = QString::fromStdString(input.name);
226 ossia::vec2f min{-100., -100.};
227 ossia::vec2f max{100., 100.};
228 ossia::vec2f init{0.0, 0.0};
230 std::copy_n(v.def->begin(), 2, init.begin());
232 std::copy_n(v.min->begin(), 2, min.begin());
234 std::copy_n(v.max->begin(), 2, max.begin());
238 auto& ctx = score::IDocument::documentContext(self);
239 auto& device_plug = ctx.template plugin<Explorer::DeviceDocumentPlugin>();
241 QString firstWindowDeviceName;
242 for(
auto dev : list.devices())
244 if(
auto win = qobject_cast<WindowDevice*>(dev))
246 firstWindowDeviceName = win->name();
251 if(!firstWindowDeviceName.isEmpty())
253 if(nm.contains(
"iMouse"))
257 else if(nm.contains(
"mouse", Qt::CaseInsensitive))
263 if(
auto it = previous_values.find(nm);
264 it != previous_values.end()
265 && it->second.get_type() == port->value().get_type())
266 port->setValue(it->second);
268 self.m_inlets.push_back(port);
269 self.controlAdded(port->id());
275 auto nm = QString::fromStdString(input.name);
276 ossia::vec3f min{-100., -100., -100.};
277 ossia::vec3f max{100., 100., 100.};
278 ossia::vec3f init{0., 0., 0.};
280 std::copy_n(v.def->begin(), 3, init.begin());
282 std::copy_n(v.min->begin(), 3, min.begin());
284 std::copy_n(v.max->begin(), 3, max.begin());
288 if(
auto it = previous_values.find(nm);
289 it != previous_values.end()
290 && it->second.get_type() == port->value().get_type())
291 port->setValue(it->second);
293 self.m_inlets.push_back(port);
294 self.controlAdded(port->id());
300 auto nm = QString::fromStdString(input.name);
301 ossia::vec4f init{0.5, 0.5, 0.5, 1.};
304 std::copy_n(v.def->begin(), 4, init.begin());
309 if(
auto it = previous_values.find(nm);
310 it != previous_values.end()
311 && it->second.get_type() == port->value().get_type())
312 port->setValue(it->second);
314 self.m_inlets.push_back(port);
315 self.controlAdded(port->id());
320 auto port =
new Gfx::TextureInlet(
323 self.m_inlets.push_back(port);
328 auto port =
new Gfx::TextureInlet(
331 self.m_inlets.push_back(port);
338 self.m_inlets.push_back(port);
345 self.m_inlets.push_back(port);
352 self.m_inlets.push_back(port);
364 if(v.access ==
"read_only")
370 auto port =
new Gfx::TextureInlet(
372 self.m_inlets.push_back(port);
378 auto outport =
new Gfx::TextureOutlet(
381 self.m_outlets.push_back(outport);
388 && v.layout.back().type.find(
"[]") != std::string::npos)
392 QString::fromStdString(input.name) +
" size",
394 self.m_inlets.push_back(size_inl);
395 self.controlAdded(size_inl->id());
407 auto port =
new Gfx::TextureInlet(
409 self.m_inlets.push_back(port);
417 auto port =
new Gfx::TextureInlet(
419 self.m_inlets.push_back(port);
429 if(v.access ==
"read_only")
431 auto port =
new Gfx::TextureInlet(
433 self.m_inlets.push_back(port);
436 auto outport =
new Gfx::TextureOutlet(
439 self.m_outlets.push_back(outport);
442 Process::Inlet* operator()(
const geometry_input& v) {
return nullptr; }
448 static constexpr int storage_outlet_base = 20000;
449 int outlet_id = storage_outlet_base;
451 for(
const isf::input& input : desc.inputs)
453 ossia::visit(input_vis{previous_values, input, i, self, outlet_id}, input.data);
464 std::stable_partition(
465 self.m_outlets.begin(), self.m_outlets.end(),
466 [](
Process::Outlet* o) { return o->id().val() >= storage_outlet_base; });
472 if(!desc.outputs.empty())
474 for(
auto it = self.m_outlets.begin(); it != self.m_outlets.end();)
476 if((*it)->id().val() < storage_outlet_base)
479 it = self.m_outlets.erase(it);
488 for(
const auto& out : desc.outputs)
490 self.m_outlets.push_back(
new Gfx::TextureOutlet{
491 QString::fromStdString(out.name),