Skip to content

Commit

Permalink
Instead of directly writing to a syx file, open a new ExportDialog wi…
Browse files Browse the repository at this point in the history
…th a choice of export options regarding file type and dump type.
  • Loading branch information
christofmuc committed Jan 22, 2021
1 parent 9defb5a commit 427df3f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MidiKraft-librarian
1 change: 1 addition & 0 deletions The-Orm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions The-Orm/ExportDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "ExportDialog.h"

static std::function<void(midikraft::Librarian::ExportParameters)> sCallback_;

ExportDialog::ExportDialog()
{
// Properties to edit...
props_.push_back(std::make_shared<TypedNamedValue>(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>(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<void(midikraft::Librarian::ExportParameters)> callback)
{
if (!sExportDialog_) {
sExportDialog_ = std::make_unique<ExportDialog>();
}
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> ExportDialog::sExportDialog_;

juce::DialogWindow * ExportDialog::sWindow_;


29 changes: 29 additions & 0 deletions The-Orm/ExportDialog.h
Original file line number Diff line number Diff line change
@@ -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<void(midikraft::Librarian::ExportParameters)> callback);

private:
static std::unique_ptr<ExportDialog> sExportDialog_;
static DialogWindow *sWindow_;

PropertyEditor parameters_;
TypedNamedValueSet props_;
TextButton ok_;
TextButton cancel_;

};


7 changes: 5 additions & 2 deletions The-Orm/PatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -81,7 +82,7 @@ PatchView::PatchView(midikraft::PatchDatabase &database, std::vector<midikraft::
} } },
{ "exportSysex", { "Export into sysex files", [this]() {
exportPatches();
}}},
}}},
{ "exportPIF", { "Export into PIF", [this]() {
createPatchInterchangeFile();
} } },
Expand Down Expand Up @@ -547,7 +548,9 @@ void PatchView::exportPatches()
// If at least one synth is selected, build and run the query. Never run a query against all synths from this code
if (!advancedFilters_.synthFilters_.selectedCategories().empty()) {
loadPage(0, -1, [this](std::vector<midikraft::PatchHolder> patches) {
librarian_.saveSysexPatchesToDisk(patches);
ExportDialog::showExportDialog(this, [this, patches](midikraft::Librarian::ExportParameters params) {
librarian_.saveSysexPatchesToDisk(params, patches);
});
});
}
}
Expand Down

0 comments on commit 427df3f

Please sign in to comment.