MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / loadModelFromStream

Method loadModelFromStream

plugins/Cardinal/src/AIDA-X.cpp:371–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369 }
370
371 void loadModelFromStream(std::istream& jsonStream)
372 {
373#ifndef QUICK_BUILD_TESTING
374 int input_size;
375 int input_skip;
376 float input_gain;
377 float output_gain;
378 nlohmann::json model_json;
379
380 jsonStream >> model_json;
381
382 /* Understand which model type to load */
383 input_size = model_json["in_shape"].back().get<int>();
384 if (input_size > MAX_INPUT_SIZE) {
385 throw std::invalid_argument("Value for input_size not supported");
386 }
387
388 if (model_json["in_skip"].is_number()) {
389 input_skip = model_json["in_skip"].get<int>();
390 if (input_skip > 1)
391 throw std::invalid_argument("Values for in_skip > 1 are not supported");
392 }
393 else {
394 input_skip = 0;
395 }
396
397 if (model_json["in_gain"].is_number()) {
398 input_gain = DB_CO(model_json["in_gain"].get<float>());
399 }
400 else {
401 input_gain = 1.0f;
402 }
403
404 if (model_json["out_gain"].is_number()) {
405 output_gain = DB_CO(model_json["out_gain"].get<float>());
406 }
407 else {
408 output_gain = 1.0f;
409 }
410
411 std::unique_ptr<DynamicModel> newmodel = std::make_unique<DynamicModel>();
412
413 if (! custom_model_creator(model_json, newmodel->variant))
414 throw std::runtime_error("Unable to identify a known model architecture!");
415
416 std::visit (
417 [&model_json] (auto&& custom_model)
418 {
419 using ModelType = std::decay_t<decltype (custom_model)>;
420 if constexpr (! std::is_same_v<ModelType, NullModel>)
421 {
422 custom_model.parseJson (model_json, true);
423 custom_model.reset();
424 }
425 },
426 newmodel->variant);
427
428 // save extra info

Callers

nothing calls this directly

Calls 7

DB_COFunction · 0.85
custom_model_creatorFunction · 0.85
applyModelOfflineFunction · 0.85
backMethod · 0.80
resetMethod · 0.45
getMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected