From a2da4e86a3d4d4d4128f29b2d5b891390f2db2ff Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 26 Jan 2022 01:05:00 +0000 Subject: [PATCH] AudioFile: correctly position UI elements, add save/load filepath --- plugins/Cardinal/src/AudioFile.cpp | 67 ++++++++++++++++------------- plugins/Cardinal/src/TextEditor.cpp | 3 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/plugins/Cardinal/src/AudioFile.cpp b/plugins/Cardinal/src/AudioFile.cpp index 8497fab..1100f98 100644 --- a/plugins/Cardinal/src/AudioFile.cpp +++ b/plugins/Cardinal/src/AudioFile.cpp @@ -213,25 +213,36 @@ struct CarlaInternalPluginModule : Module, Thread { return 0; } -// json_t* dataToJson() override -// { -// if (fCarlaPluginHandle == nullptr) -// return nullptr; -// -// char* const state = fCarlaPluginDescriptor->get_state(fCarlaPluginHandle); -// return json_string(state); -// } -// -// void dataFromJson(json_t* const rootJ) override -// { -// if (fCarlaPluginHandle == nullptr) -// return; -// -// const char* const state = json_string_value(rootJ); -// DISTRHO_SAFE_ASSERT_RETURN(state != nullptr,); -// -// fCarlaPluginDescriptor->set_state(fCarlaPluginHandle, state); -// } + json_t* dataToJson() override + { + json_t* const rootJ = json_object(); + DISTRHO_SAFE_ASSERT_RETURN(rootJ != nullptr, nullptr); + + json_object_set_new(rootJ, "filepath", json_string(currentFile.c_str())); + return rootJ; + } + + void dataFromJson(json_t* const rootJ) override + { + if (json_t* const filepathJ = json_object_get(rootJ, "filepath")) + { + const char* const filepath = json_string_value(filepathJ); + + if (filepath[0] != '\0') + { + currentFile = filepath; + fileChanged = true; + + if (fCarlaPluginHandle != nullptr) + fCarlaPluginDescriptor->set_custom_data(fCarlaPluginHandle, "file", filepath); + + return; + } + } + + currentFile.clear(); + fileChanged = true; + } void process(const ProcessArgs&) override { @@ -450,8 +461,6 @@ struct AudioFileListWidget : ImGuiWidget { }; struct AudioFileWidget : ModuleWidget { - static constexpr const float startX_In = 14.0f; - static constexpr const float startX_Out = 96.0f; static constexpr const float padding = 29.0f; CarlaInternalPluginModule* const module; @@ -471,19 +480,17 @@ struct AudioFileWidget : ModuleWidget { addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addOutput(createOutput(Vec(box.size.x - RACK_GRID_WIDTH * 5/2, - RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding * 2), - module, 0)); + addOutput(createOutput(Vec(box.size.x - RACK_GRID_WIDTH * 5/2 - padding, + RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding), module, 0)); addOutput(createOutput(Vec(box.size.x - RACK_GRID_WIDTH * 5/2, - RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding * 1), - module, 1)); + RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding), module, 1)); if (m != nullptr) { AudioFileListWidget* const listw = new AudioFileListWidget(m); listw->box.pos.x = 0; - listw->box.pos.y = 36; + listw->box.pos.y = 71.0f; listw->box.size.x = box.size.x; listw->box.size.y = box.size.y / 2 - 20; addChild(listw); @@ -495,7 +502,7 @@ struct AudioFileWidget : ModuleWidget { if (layer != 1) return ModuleWidget::drawLayer(args, layer); - const Rect audioPreviewPos = Rect(8, box.size.y - 80 - 80, box.size.x - 16, 80); + const Rect audioPreviewPos = Rect(8, box.size.y - 51 - 80, box.size.x - 16, 80); const float alpha = 1.0f - (0.5f - settings::rackBrightness * 0.5f); char textInfo[0xff]; @@ -553,7 +560,7 @@ struct AudioFileWidget : ModuleWidget { nvgRGB(0x21, 0x22, 0x22))); nvgFill(args.vg); - const Rect audioPreviewPos = Rect(8, box.size.y - 80 - 80, box.size.x - 16, 80); + const Rect audioPreviewPos = Rect(8, box.size.y - 51 - 80, box.size.x - 16, 80); nvgBeginPath(args.vg); nvgRoundedRect(args.vg, @@ -567,7 +574,7 @@ struct AudioFileWidget : ModuleWidget { nvgBeginPath(args.vg); nvgRoundedRect(args.vg, - startX_Out - 4.0f, + 02.0f, RACK_GRID_HEIGHT - padding * CarlaInternalPluginModule::NUM_INPUTS - 2.0f, padding, padding * CarlaInternalPluginModule::NUM_INPUTS, 4); diff --git a/plugins/Cardinal/src/TextEditor.cpp b/plugins/Cardinal/src/TextEditor.cpp index 9119b65..bb9cd1b 100644 --- a/plugins/Cardinal/src/TextEditor.cpp +++ b/plugins/Cardinal/src/TextEditor.cpp @@ -64,11 +64,12 @@ struct TextEditorModule : Module { void dataFromJson(json_t* const rootJ) override { + file.clear(); + // Rack Core Notes compatiblity if (json_t* const textJ = json_object_get(rootJ, "text")) { text = json_string_value(textJ); - file = ""; lang = "None"; width = 16; #ifndef HEADLESS