-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of directly writing to a syx file, open a new ExportDialog wi…
…th a choice of export options regarding file type and dump type.
- Loading branch information
1 parent
9defb5a
commit 427df3f
Showing
5 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
|
||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters