AudioFile: correctly position UI elements, add save/load filepath

This commit is contained in:
falkTX 2022-01-26 01:05:00 +00:00
parent 3c9a597f7f
commit a2da4e86a3
2 changed files with 39 additions and 31 deletions

View file

@ -213,25 +213,36 @@ struct CarlaInternalPluginModule : Module, Thread {
return 0; return 0;
} }
// json_t* dataToJson() override json_t* dataToJson() override
// { {
// if (fCarlaPluginHandle == nullptr) json_t* const rootJ = json_object();
// return nullptr; DISTRHO_SAFE_ASSERT_RETURN(rootJ != nullptr, nullptr);
//
// char* const state = fCarlaPluginDescriptor->get_state(fCarlaPluginHandle); json_object_set_new(rootJ, "filepath", json_string(currentFile.c_str()));
// return json_string(state); return rootJ;
// } }
//
// void dataFromJson(json_t* const rootJ) override void dataFromJson(json_t* const rootJ) override
// { {
// if (fCarlaPluginHandle == nullptr) if (json_t* const filepathJ = json_object_get(rootJ, "filepath"))
// return; {
// const char* const filepath = json_string_value(filepathJ);
// const char* const state = json_string_value(rootJ);
// DISTRHO_SAFE_ASSERT_RETURN(state != nullptr,); if (filepath[0] != '\0')
// {
// fCarlaPluginDescriptor->set_state(fCarlaPluginHandle, state); currentFile = filepath;
// } fileChanged = true;
if (fCarlaPluginHandle != nullptr)
fCarlaPluginDescriptor->set_custom_data(fCarlaPluginHandle, "file", filepath);
return;
}
}
currentFile.clear();
fileChanged = true;
}
void process(const ProcessArgs&) override void process(const ProcessArgs&) override
{ {
@ -450,8 +461,6 @@ struct AudioFileListWidget : ImGuiWidget {
}; };
struct AudioFileWidget : ModuleWidget { 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; static constexpr const float padding = 29.0f;
CarlaInternalPluginModule* const module; CarlaInternalPluginModule* const module;
@ -471,19 +480,17 @@ struct AudioFileWidget : ModuleWidget {
addChild(createWidget<ScrewBlack>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); addChild(createWidget<ScrewBlack>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); addChild(createWidget<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addOutput(createOutput<PJ301MPort>(Vec(box.size.x - RACK_GRID_WIDTH * 5/2, addOutput(createOutput<PJ301MPort>(Vec(box.size.x - RACK_GRID_WIDTH * 5/2 - padding,
RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding * 2), RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding), module, 0));
module, 0));
addOutput(createOutput<PJ301MPort>(Vec(box.size.x - RACK_GRID_WIDTH * 5/2, addOutput(createOutput<PJ301MPort>(Vec(box.size.x - RACK_GRID_WIDTH * 5/2,
RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding * 1), RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding), module, 1));
module, 1));
if (m != nullptr) if (m != nullptr)
{ {
AudioFileListWidget* const listw = new AudioFileListWidget(m); AudioFileListWidget* const listw = new AudioFileListWidget(m);
listw->box.pos.x = 0; 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.x = box.size.x;
listw->box.size.y = box.size.y / 2 - 20; listw->box.size.y = box.size.y / 2 - 20;
addChild(listw); addChild(listw);
@ -495,7 +502,7 @@ struct AudioFileWidget : ModuleWidget {
if (layer != 1) if (layer != 1)
return ModuleWidget::drawLayer(args, layer); 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); const float alpha = 1.0f - (0.5f - settings::rackBrightness * 0.5f);
char textInfo[0xff]; char textInfo[0xff];
@ -553,7 +560,7 @@ struct AudioFileWidget : ModuleWidget {
nvgRGB(0x21, 0x22, 0x22))); nvgRGB(0x21, 0x22, 0x22)));
nvgFill(args.vg); 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); nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, nvgRoundedRect(args.vg,
@ -567,7 +574,7 @@ struct AudioFileWidget : ModuleWidget {
nvgBeginPath(args.vg); nvgBeginPath(args.vg);
nvgRoundedRect(args.vg, nvgRoundedRect(args.vg,
startX_Out - 4.0f, 02.0f,
RACK_GRID_HEIGHT - padding * CarlaInternalPluginModule::NUM_INPUTS - 2.0f, RACK_GRID_HEIGHT - padding * CarlaInternalPluginModule::NUM_INPUTS - 2.0f,
padding, padding,
padding * CarlaInternalPluginModule::NUM_INPUTS, 4); padding * CarlaInternalPluginModule::NUM_INPUTS, 4);

View file

@ -64,11 +64,12 @@ struct TextEditorModule : Module {
void dataFromJson(json_t* const rootJ) override void dataFromJson(json_t* const rootJ) override
{ {
file.clear();
// Rack Core Notes compatiblity // Rack Core Notes compatiblity
if (json_t* const textJ = json_object_get(rootJ, "text")) if (json_t* const textJ = json_object_get(rootJ, "text"))
{ {
text = json_string_value(textJ); text = json_string_value(textJ);
file = "";
lang = "None"; lang = "None";
width = 16; width = 16;
#ifndef HEADLESS #ifndef HEADLESS