Skip to content

Commit

Permalink
[sendMode] Make the sendMode persisted across sessions, and synth spe…
Browse files Browse the repository at this point in the history
…cific!
  • Loading branch information
christofmuc committed Aug 15, 2024
1 parent b5f70a5 commit bf9cba3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
30 changes: 25 additions & 5 deletions The-Orm/PatchButtonPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ PatchButtonPanel::PatchButtonPanel(std::function<void(midikraft::PatchHolder &)>
patchButtons_ = std::make_unique<PatchButtonGrid<PatchHolderButton>>(gridWidth_, gridHeight_, [this](int index) { buttonClicked(index, true); });
addAndMakeVisible(patchButtons_.get());

buttonSendMode_.setTextWhenNoChoicesAvailable("<default mode>");
buttonSendMode_.setTextWhenNoChoicesAvailable("<none selected>");
buttonSendMode_.onChange = [this]() {
// Value changed, update property
auto selectedText = buttonSendMode_.getItemText(buttonSendMode_.getSelectedItemIndex());
Data::instance().getEphemeralPropertyAsValue(EPROPERTY_BUTTON_SEND_MODE).setValue(selectedText);
auto currentSynth = UIModel::currentSynthNameOrMultiOrEmpty();
if (!currentSynth.empty()) {
auto oldValue = UIModel::getSynthSpecificPropertyAsValue(currentSynth, PROPERTY_COMBOBOX_SENDMODE, "automatic");
oldValue = selectedText;
}
};
Data::ensureEphemeralPropertyExists(EPROPERTY_BUTTON_SEND_MODE, "auto");
addAndMakeVisible(buttonSendMode_);

buttonSendModeLabel_.setText("send mode", NotificationType::dontSendNotification);
addAndMakeVisible(buttonSendModeLabel_);
//buttonSendModeLabel_.attachToComponent(&buttonSendMode_, true);

addAndMakeVisible(pageUp_);
pageUp_.setButtonText(">");
Expand Down Expand Up @@ -375,7 +377,6 @@ void PatchButtonPanel::setButtonSendModes(std::vector<std::string> const& modes)
for (auto const& mode : modes) {
buttonSendMode_.addItem(mode, index++);
}
buttonSendMode_.setSelectedItemIndex(0);
}

void PatchButtonPanel::pageUp(bool selectNext) {
Expand Down Expand Up @@ -415,6 +416,25 @@ void PatchButtonPanel::changeListenerCallback(ChangeBroadcaster* source)
}
else if (source == &UIModel::instance()->currentSynth_ || source == &UIModel::instance()->multiMode_) {
refreshGridSize();
if (UIModel::instance()->multiMode_.multiSynthMode()) {
buttonSendModeLabel_.setVisible(false);
buttonSendMode_.setVisible(false);
}
else {
buttonSendModeLabel_.setVisible(true);
buttonSendMode_.setVisible(true);
std::string synthName = UIModel::currentSynthNameOrMultiOrEmpty();
if (!synthName.empty()) {
UIModel::ensureSynthSpecificPropertyExists(synthName, PROPERTY_COMBOBOX_SENDMODE, "automatic");
auto value = UIModel::instance()->getSynthSpecificPropertyAsValue(synthName, PROPERTY_COMBOBOX_SENDMODE, "automatic").getValue();
for (int i = 0; i < buttonSendMode_.getNumItems(); i++) {
if (buttonSendMode_.getItemText(i) == value.toString()) {
buttonSendMode_.setSelectedItemIndex(i);
break;
}
}
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions The-Orm/PatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ void PatchView::selectPatch(midikraft::PatchHolder &patch, bool alsoSendToSynth)
if (alsoSendToSynth) {
auto midiLocation = midikraft::Capability::hasCapability<midikraft::MidiLocationCapability>(patch.smartSynth());
if (isSynthConnected(patch.smartSynth())) {
Data::ensureEphemeralPropertyExists(EPROPERTY_BUTTON_SEND_MODE, "auto");
auto synthSpecificSendMode = Data::getEphemeralProperty(EPROPERTY_BUTTON_SEND_MODE);
UIModel::ensureSynthSpecificPropertyExists(patch.smartSynth()->getName(), PROPERTY_COMBOBOX_SENDMODE, "automatic");
auto synthSpecificSendMode = UIModel::instance()->getSynthSpecificPropertyAsValue(patch.smartSynth()->getName(), PROPERTY_COMBOBOX_SENDMODE, "automatic").getValue();

auto alreadyInSynth = patchIsInSynth(patch);
if (synthSpecificSendMode == "program change") {
Expand Down
11 changes: 11 additions & 0 deletions The-Orm/UIModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ bool CurrentMultiMode::multiSynthMode() const
return multiSynthMode_;
}

std::string UIModel::currentSynthNameOrMultiOrEmpty() {
// Get the name of the current Synth, or "multiMode" if activated, or empty if no synth
if (UIModel::instance()->multiMode_.multiSynthMode()) {
return "MultiSynth";
}
if (auto newCurrentSynth = UIModel::instance()->currentSynth()) {
return newCurrentSynth->getName();
}
return "";
}

ValueTree UIModel::ensureSynthSpecificPropertyExists(std::string const& synthName, juce::Identifier const& property, var const& defaultValue) {

auto synths = Data::instance().get().getOrCreateChildWithName(PROPERTY_SYNTH_LIST, nullptr);
Expand Down
3 changes: 2 additions & 1 deletion The-Orm/UIModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

juce::Identifier const PROPERTY_SYNTH_LIST {"SynthList"};
juce::Identifier const PROPERTY_BUTTON_INFO_TYPE {"ButtonInfoType"};
juce::Identifier const PROPERTY_COMBOBOX_SENDMODE {"SynthSendMode"};
juce::Identifier const PROPERTY_WINDOW_LIST {"Windows"};
juce::Identifier const PROPERTY_WINDOW_OPENNESS {"Open"};
juce::Identifier const PROPERTY_WINDOW_SIZE {"Size"};

// The EphemeralData is not stored on disk, but needs to be cleared via the UIModel clear method when the database changes.
juce::Identifier const EPROPERTY_LIBRARY_PATCH_LIST {"LibraryPatchList"};
juce::Identifier const EPROPERTY_BUTTON_SEND_MODE {"PatchButtonSendMode"};


juce::Identifier const EPROPERTY_MIDI_LOG_LEVEL{ "MIDILog" };
Expand Down Expand Up @@ -132,6 +132,7 @@ class UIModel {
ChangeBroadcaster categoriesChanged; // Listen to this to get notified of category list changes
ChangeBroadcaster databaseChanged; // Listen to this when you need to know a new database was opened

static std::string currentSynthNameOrMultiOrEmpty(); // Get the name of the current Synth, or "multiMode" if activated, or empty if no synth
static ValueTree ensureSynthSpecificPropertyExists(std::string const& synthName, juce::Identifier const& property, var const& defaultValue);
static Value getSynthSpecificPropertyAsValue(std::string const& synthName, juce::Identifier const& property, var const& defaultValue);

Expand Down

0 comments on commit bf9cba3

Please sign in to comment.