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

Function osc_load_handler

src/CardinalCommon.cpp:378–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378static int osc_load_handler(const char*, const char* types, lo_arg** argv, int argc, const lo_message m, void* const self)
379{
380 d_debug("osc_load_handler()");
381 DISTRHO_SAFE_ASSERT_RETURN(argc == 1, 0);
382 DISTRHO_SAFE_ASSERT_RETURN(types != nullptr && types[0] == 'b', 0);
383
384 const int32_t size = argv[0]->blob.size;
385 DISTRHO_SAFE_ASSERT_RETURN(size > 4, 0);
386
387 const uint8_t* const blob = (uint8_t*)(&argv[0]->blob.data);
388 DISTRHO_SAFE_ASSERT_RETURN(blob != nullptr, 0);
389
390 bool ok = false;
391
392 if (CardinalBasePlugin* const plugin = static_cast<Initializer*>(self)->remotePluginInstance)
393 {
394 CardinalPluginContext* const context = plugin->context;
395 std::vector<uint8_t> data(size);
396 std::memcpy(data.data(), blob, size);
397
398 #ifdef CARDINAL_INIT_OSC_THREAD
399 rack::contextSet(context);
400 #endif
401
402 rack::system::removeRecursively(context->patch->autosavePath);
403 rack::system::createDirectories(context->patch->autosavePath);
404 try {
405 rack::system::unarchiveToDirectory(data, context->patch->autosavePath);
406 context->patch->loadAutosave();
407 ok = true;
408 }
409 catch (rack::Exception& e) {
410 WARN("%s", e.what());
411 }
412
413 #ifdef CARDINAL_INIT_OSC_THREAD
414 rack::contextSet(nullptr);
415 #endif
416 }
417
418 const lo_address source = lo_message_get_source(m);
419 const lo_server server = static_cast<Initializer*>(self)->oscServer;
420 lo_send_from(source, server, LO_TT_IMMEDIATE, "/resp", "ss", "load", ok ? "ok" : "fail");
421 return 0;
422}
423
424static int osc_param_handler(const char*, const char* types, lo_arg** argv, int argc, const lo_message m, void* const self)
425{

Callers

nothing calls this directly

Calls 2

contextSetFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected