@@ -114,10 +114,15 @@ Process::ScriptChangeResult Model::setProgram(const ShaderSource& f)
114
114
if (const auto & [processed, error] = ProgramCache::instance ().get (api, version, f);
115
115
bool (processed))
116
116
{
117
+ ossia::flat_map<QString, ossia::value> previous_values;
118
+ for (auto inl : m_inlets)
119
+ if (auto control = qobject_cast<Process::ControlInlet*>(inl))
120
+ previous_values.emplace (control->name (), control->value ());
121
+
117
122
auto inls = score::clearAndDeleteLater (m_inlets);
118
123
m_processedProgram = *processed;
119
124
120
- setupIsf (m_processedProgram.descriptor );
125
+ setupIsf (m_processedProgram.descriptor , previous_values );
121
126
return {.valid = true , .inlets = std::move (inls)};
122
127
}
123
128
return {};
@@ -165,7 +170,9 @@ QString Model::prettyName() const noexcept
165
170
return tr (" GFX Filter" );
166
171
}
167
172
168
- void Model::setupIsf (const isf::descriptor& desc)
173
+ void Model::setupIsf (
174
+ const isf::descriptor& desc,
175
+ const ossia::flat_map<QString, ossia::value>& previous_values)
169
176
{
170
177
/*
171
178
{
@@ -184,23 +191,30 @@ void Model::setupIsf(const isf::descriptor& desc)
184
191
using namespace isf ;
185
192
struct input_vis
186
193
{
194
+ const ossia::flat_map<QString, ossia::value>& previous_values;
187
195
const isf::input& input;
188
196
const int i;
189
197
Model& self;
190
198
191
199
Process::Inlet* operator ()(const float_input& v)
192
200
{
201
+ auto nm = QString::fromStdString (input.name );
193
202
auto port = new Process::FloatSlider (
194
203
v.min , v.max , v.def , QString::fromStdString (input.name ), Id<Process::Port>(i),
195
204
&self);
196
205
197
206
self.m_inlets .push_back (port);
207
+ if (auto it = previous_values.find (nm);
208
+ it != previous_values.end () && it->second .get_type () == ossia::val_type::FLOAT)
209
+ port->setValue (it->second );
210
+
198
211
self.controlAdded (port->id ());
199
212
return port;
200
213
}
201
214
202
215
Process::Inlet* operator ()(const long_input& v)
203
216
{
217
+ auto nm = QString::fromStdString (input.name );
204
218
std::vector<std::pair<QString, ossia::value>> alternatives;
205
219
std::size_t value_idx = 0 ;
206
220
for (; value_idx < v.values .size () && value_idx < v.labels .size (); value_idx++)
@@ -217,8 +231,12 @@ void Model::setupIsf(const isf::descriptor& desc)
217
231
}
218
232
219
233
auto port = new Process::ComboBox (
220
- std::move (alternatives), (int )v.def , QString::fromStdString (input.name ),
221
- Id<Process::Port>(i), &self);
234
+ std::move (alternatives), (int )v.def , nm, Id<Process::Port>(i), &self);
235
+
236
+ if (auto it = previous_values.find (nm);
237
+ it != previous_values.end ()
238
+ && it->second .get_type () == port->value ().get_type ())
239
+ port->setValue (it->second );
222
240
223
241
self.m_inlets .push_back (port);
224
242
self.controlAdded (port->id ());
@@ -227,24 +245,30 @@ void Model::setupIsf(const isf::descriptor& desc)
227
245
228
246
Process::Inlet* operator ()(const event_input& v)
229
247
{
230
- auto port = new Process::Button (
231
- QString::fromStdString (input. name ) , Id<Process::Port>(i), &self);
248
+ auto nm = QString::fromStdString (input. name );
249
+ auto port = new Process::Button (nm , Id<Process::Port>(i), &self);
232
250
233
251
self.m_inlets .push_back (port);
234
252
self.controlAdded (port->id ());
235
253
return port;
236
254
}
237
255
Process::Inlet* operator ()(const bool_input& v)
238
256
{
239
- auto port = new Process::Toggle (
240
- v.def , QString::fromStdString (input.name ), Id<Process::Port>(i), &self);
257
+ auto nm = QString::fromStdString (input.name );
258
+ auto port = new Process::Toggle (v.def , nm, Id<Process::Port>(i), &self);
259
+
260
+ if (auto it = previous_values.find (nm);
261
+ it != previous_values.end ()
262
+ && it->second .get_type () == port->value ().get_type ())
263
+ port->setValue (it->second );
241
264
242
265
self.m_inlets .push_back (port);
243
266
self.controlAdded (port->id ());
244
267
return port;
245
268
}
246
269
Process::Inlet* operator ()(const point2d_input& v)
247
270
{
271
+ auto nm = QString::fromStdString (input.name );
248
272
ossia::vec2f min{0 ., 0 .};
249
273
ossia::vec2f max{1 ., 1 .};
250
274
ossia::vec2f init{0.5 , 0.5 };
@@ -254,13 +278,13 @@ void Model::setupIsf(const isf::descriptor& desc)
254
278
std::copy_n (v.min ->begin (), 2 , min.begin ());
255
279
if (v.max )
256
280
std::copy_n (v.max ->begin (), 2 , max.begin ());
257
- auto port = new Process::XYSpinboxes{min,
258
- max,
259
- init,
260
- false ,
261
- QString::fromStdString (input. name ),
262
- Id<Process::Port>(i),
263
- &self} ;
281
+ auto port = new Process::XYSpinboxes{
282
+ min, max, init, false , nm, Id<Process::Port>(i), &self};
283
+
284
+ if ( auto it = previous_values. find (nm);
285
+ it != previous_values. end ()
286
+ && it-> second . get_type () == port-> value (). get_type ())
287
+ port-> setValue (it-> second ) ;
264
288
265
289
self.m_inlets .push_back (port);
266
290
self.controlAdded (port->id ());
@@ -269,7 +293,23 @@ void Model::setupIsf(const isf::descriptor& desc)
269
293
270
294
Process::Inlet* operator ()(const point3d_input& v)
271
295
{
272
- auto port = new Process::ControlInlet{Id<Process::Port>(i), &self};
296
+ auto nm = QString::fromStdString (input.name );
297
+ ossia::vec3f min{0 ., 0 ., 0 .};
298
+ ossia::vec3f max{1 ., 1 ., 1 .};
299
+ ossia::vec3f init{0.5 , 0.5 , 0.5 };
300
+ if (v.def )
301
+ std::copy_n (v.def ->begin (), 3 , init.begin ());
302
+ if (v.min )
303
+ std::copy_n (v.min ->begin (), 3 , min.begin ());
304
+ if (v.max )
305
+ std::copy_n (v.max ->begin (), 3 , max.begin ());
306
+ auto port
307
+ = new Process::XYZSpinboxes{min, max, init, nm, Id<Process::Port>(i), &self};
308
+
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 );
273
313
274
314
self.m_inlets .push_back (port);
275
315
self.controlAdded (port->id ());
@@ -278,6 +318,7 @@ void Model::setupIsf(const isf::descriptor& desc)
278
318
279
319
Process::Inlet* operator ()(const color_input& v)
280
320
{
321
+ auto nm = QString::fromStdString (input.name );
281
322
ossia::vec4f init{0.5 , 0.5 , 0.5 , 1 .};
282
323
if (v.def )
283
324
{
@@ -286,6 +327,11 @@ void Model::setupIsf(const isf::descriptor& desc)
286
327
auto port = new Process::HSVSlider (
287
328
init, QString::fromStdString (input.name ), Id<Process::Port>(i), &self);
288
329
330
+ if (auto it = previous_values.find (nm);
331
+ it != previous_values.end ()
332
+ && it->second .get_type () == port->value ().get_type ())
333
+ port->setValue (it->second );
334
+
289
335
self.m_inlets .push_back (port);
290
336
self.controlAdded (port->id ());
291
337
return port;
@@ -312,7 +358,7 @@ void Model::setupIsf(const isf::descriptor& desc)
312
358
313
359
for (const isf::input& input : desc.inputs )
314
360
{
315
- ossia::visit (input_vis{input, i, *this }, input.data );
361
+ ossia::visit (input_vis{previous_values, input, i, *this }, input.data );
316
362
i++;
317
363
}
318
364
0 commit comments