diff --git a/MidiKraft-librarian b/MidiKraft-librarian index 1bc467e6..bd05c6ec 160000 --- a/MidiKraft-librarian +++ b/MidiKraft-librarian @@ -1 +1 @@ -Subproject commit 1bc467e628720b228bd2d68fb45daa6028eaca07 +Subproject commit bd05c6ec4b901906590a4e52b5ecfbbca97001bb diff --git a/The-Orm/CMakeLists.txt b/The-Orm/CMakeLists.txt index ae6e9616..e35d5c37 100644 --- a/The-Orm/CMakeLists.txt +++ b/The-Orm/CMakeLists.txt @@ -40,6 +40,7 @@ set(SOURCES AutoThumbnailingDialog.cpp AutoThumbnailingDialog.h BCR2000_Component.cpp BCR2000_Component.h CurrentPatchDisplay.cpp CurrentPatchDisplay.h + ExportDialog.cpp ExportDialog.h ImportFromSynthDialog.cpp ImportFromSynthDialog.h KeyboardMacroView.cpp KeyboardMacroView.h MacroConfig.cpp MacroConfig.h diff --git a/The-Orm/ExportDialog.cpp b/The-Orm/ExportDialog.cpp new file mode 100644 index 00000000..c3b319ea --- /dev/null +++ b/The-Orm/ExportDialog.cpp @@ -0,0 +1,73 @@ +#include "ExportDialog.h" + +static std::function sCallback_; + +ExportDialog::ExportDialog() +{ + // Properties to edit... + props_.push_back(std::make_shared(TypedNamedValue("Sysex format", "Export options", midikraft::Librarian::PROGRAM_DUMPS, + { {midikraft::Librarian::PROGRAM_DUMPS, "Sysex format individual program dumps"}, { midikraft::Librarian::EDIT_BUFFER_DUMPS, "Sysex format individual edit buffer dumps" } }))); + props_.push_back(std::make_shared(TypedNamedValue("File format", "Export options", midikraft::Librarian::MANY_FILES, + { {midikraft::Librarian::MANY_FILES, "Each patch separately into a file"}, { midikraft::Librarian::ZIPPED_FILES, "Each patch separately into a file, but all zipped up" }, + { midikraft::Librarian::ONE_FILE, "One sysex file with all messages" }, { midikraft::Librarian::MID_FILE, "One MIDI file (SMF) to play from a player or DAW" } }))); + + parameters_.setProperties(props_); + addAndMakeVisible(parameters_); + + ok_.onClick = [this]() { sWindow_->exitModalState(true); }; + ok_.setButtonText("Export"); + addAndMakeVisible(ok_); + + cancel_.onClick = [this]() { sWindow_->exitModalState(false); }; + cancel_.setButtonText("Cancel"); + addAndMakeVisible(cancel_); + + // Finally we need a default size + setBounds(0, 0, 540, 200); +} + +void ExportDialog::resized() +{ + auto area = getLocalBounds(); + auto buttonRow = area.removeFromBottom(40).withSizeKeepingCentre(220, 40); + ok_.setBounds(buttonRow.removeFromLeft(100).reduced(4)); + cancel_.setBounds(buttonRow.removeFromLeft(100).reduced(4)); + parameters_.setBounds(area.reduced(8)); +} + +midikraft::Librarian::ExportParameters ExportDialog::getResult() +{ + // Query the property editors + return { props_.valueByName("Sysex format").getValue(), props_.valueByName("File format").getValue() }; +} + +static void dialogClosed(int modalResult, ExportDialog* dialog) +{ + if (modalResult == 1 && dialog != nullptr) { // (must check that dialog isn't null in case it was deleted..) + sCallback_(dialog->getResult()); + } +} + +void ExportDialog::showExportDialog(Component *centeredAround, std::function callback) +{ + if (!sExportDialog_) { + sExportDialog_ = std::make_unique(); + } + sCallback_ = callback; + + DialogWindow::LaunchOptions launcher; + launcher.content.set(sExportDialog_.get(), false); + launcher.componentToCentreAround = centeredAround; + launcher.dialogTitle = "Export patches"; + launcher.useNativeTitleBar = false; + launcher.dialogBackgroundColour = Colours::black; + sWindow_ = launcher.launchAsync(); + ModalComponentManager::getInstance()->attachCallback(sWindow_, ModalCallbackFunction::forComponent(dialogClosed, sExportDialog_.get())); + +} + +std::unique_ptr ExportDialog::sExportDialog_; + +juce::DialogWindow * ExportDialog::sWindow_; + + diff --git a/The-Orm/ExportDialog.h b/The-Orm/ExportDialog.h new file mode 100644 index 00000000..4f4f1608 --- /dev/null +++ b/The-Orm/ExportDialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include "JuceHeader.h" + +#include "PropertyEditor.h" +#include "Librarian.h" + +class ExportDialog : public Component { +public: + ExportDialog(); + + virtual void resized() override; + + midikraft::Librarian::ExportParameters getResult(); + + static void showExportDialog(Component *centeredAround, std::function callback); + +private: + static std::unique_ptr sExportDialog_; + static DialogWindow *sWindow_; + + PropertyEditor parameters_; + TypedNamedValueSet props_; + TextButton ok_; + TextButton cancel_; + +}; + + diff --git a/The-Orm/PatchView.cpp b/The-Orm/PatchView.cpp index 3effe00a..58e8e8b4 100644 --- a/The-Orm/PatchView.cpp +++ b/The-Orm/PatchView.cpp @@ -25,6 +25,7 @@ #include "PatchInterchangeFormat.h" #include "Settings.h" #include "ReceiveManualDumpWindow.h" +#include "ExportDialog.h" const char *kAllPatchesFilter = "All patches"; const char *kAllDataTypesFilter = "All types"; @@ -81,7 +82,7 @@ PatchView::PatchView(midikraft::PatchDatabase &database, std::vector patches) { - librarian_.saveSysexPatchesToDisk(patches); + ExportDialog::showExportDialog(this, [this, patches](midikraft::Librarian::ExportParameters params) { + librarian_.saveSysexPatchesToDisk(params, patches); + }); }); } }