Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow device specific presets #273

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions fxsound/Source/GUI/FxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ FxController::FxController() : message_window_(L"FxSoundHotkeys", (WNDPROC) even
free_plan_ = settings_.getBool("free_plan");
hide_help_tooltips_ = settings_.getBool("hide_help_tooltips");
hide_notifications_ = settings_.getBool("hide_notifications");

device_specific_preset_ = settings_.getBool("device_specific_preset");

String loaded_settings_string = settings_.getString("device_preset_map_");

auto parsed_device_preset_map = JSON::parse(loaded_settings_string);
String ad = JSON::toString(parsed_device_preset_map);

device_preset_map_ = parsed_device_preset_map.getDynamicObject()
? DynamicObject(*parsed_device_preset_map.getDynamicObject()->clone().get())
: DynamicObject();


output_device_id_ = settings_.getString("output_device_id");
output_device_name_ = settings_.getString("output_device_name");
max_user_presets_ = settings_.getInt("max_user_presets");
Expand Down Expand Up @@ -319,6 +332,24 @@ void FxController::init(FxMainWindow* main_window, FxSystemTrayView* system_tray
initPresets();

auto preset_name = settings_.getString("preset");

bool device_specific_preset = settings_.getBool("device_specific_preset");
if (device_specific_preset)
{
String loaded_settings_string = settings_.getString("device_preset_map_");

auto parsed_device_preset_map = JSON::fromString(settings_.getString("device_preset_map_"));

device_preset_map_ = parsed_device_preset_map.getDynamicObject() != nullptr
? DynamicObject(*parsed_device_preset_map.getDynamicObject()->clone().get())
: DynamicObject();

if (device_preset_map_.hasProperty(output_device_id_))
{
preset_name = device_preset_map_.getProperty(output_device_id_);
}
}

if (!authenticated_)
{
preset_name = "General";
Expand Down Expand Up @@ -540,6 +571,8 @@ bool FxController::setPreset(int selected_preset)

auto preset = model.getPreset(selected_preset);

setDevicePreset(selected_device_id_, preset.name);

if (model.isPresetModified() && selected_preset != model.getSelectedPreset())
{
if (authenticated_ && !FxConfirmationMessage::showMessage(TRANS("Changes to your preset are not saved.\r\nDo you want to ignore the changes?")))
Expand Down Expand Up @@ -650,6 +683,9 @@ void FxController::setOutput(int output, bool notify)
FxModel::getModel().pushMessage(TRANS("Output: ") + output_device_name_);
}

selected_device_id_ = selected_sound_device.pwszID.c_str();
loadDevicePreset(selected_sound_device.pwszID.c_str());

FxModel::getModel().setSelectedOutput(output, selected_sound_device, notify);
}

Expand Down Expand Up @@ -1119,6 +1155,29 @@ void FxController::setSelectedOutput(String id, String name)
}
}


void FxController::loadDevicePreset(String device_id)
{
if (!isDeviceSpecificPreset())
return;

String saved_preset = getDevicePreset(device_id);

Array<FxModel::Preset> presets = FxModel::getModel().getPresets();

int saved_preset_index = -1;
for (auto i = 0; i < presets.size(); i++)
{
if (saved_preset.equalsIgnoreCase(presets[i].name))
{
saved_preset_index = i;
}
}

if (saved_preset_index >= 0)
setPreset(saved_preset_index);
}

float FxController::getEffectValue(FxEffects::EffectType effect)
{
return dfx_dsp_.getEffectValue(static_cast<DfxDsp::Effect>(effect));
Expand Down Expand Up @@ -1530,6 +1589,35 @@ void FxController::setNotificationsHidden(bool status)
hide_notifications_ = status;
settings_.setBool("hide_notifications", true);
}
bool FxController::isDeviceSpecificPreset()
{
return device_specific_preset_;
}

void FxController::setDeviceSpecificPreset(bool status)
{
device_specific_preset_ = status;
settings_.setBool("device_specific_preset", true);
}

String FxController::getDevicePreset(const String& device_id)
{
return device_preset_map_.getProperty(device_id);
}

void FxController::setDevicePreset(const String& device_id, const String& preset_id)
{
if (device_id == "")
return;
device_preset_map_.setProperty(device_id, preset_id);
settings_.setString("device_preset_map", JSON::toString(device_preset_map_.clone().get()));
}

void FxController::removeDevicePreset(const String& device_id)
{
device_preset_map_.removeProperty(device_id);
settings_.setString("device_preset_map", JSON::toString(device_preset_map_.clone().get()));
}

String FxController::getLanguage() const
{
Expand Down
11 changes: 11 additions & 0 deletions fxsound/Source/GUI/FxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class FxController : public Timer, private AudioPassthruCallback
bool isNotificationsHidden();
void setNotificationsHidden(bool status);

bool isDeviceSpecificPreset();
void setDeviceSpecificPreset(bool status);

String getDevicePreset(const String& device_id);
void setDevicePreset(const String& device_id, const String& preset_id);
void removeDevicePreset(const String& device_id);

String getLanguage() const;
void setLanguage(String language_code);
String getLanguageName(String language_code) const;
Expand Down Expand Up @@ -179,6 +186,7 @@ class FxController : public Timer, private AudioPassthruCallback
void selectOutput();
void updateOutputs(std::vector<SoundDevice>& sound_devices);
void setSelectedOutput(String id, String name);
void loadDevicePreset(String device_id);

void registerHotkeys();
void unregisterHotkeys();
Expand All @@ -202,7 +210,10 @@ class FxController : public Timer, private AudioPassthruCallback
bool free_plan_;
bool output_changed_;
bool playback_device_available_;
bool device_specific_preset_;
DynamicObject device_preset_map_;
String output_device_id_;
String selected_device_id_; // represents fxview selection
String output_device_name_;
StringArray output_ids_;
std::vector<SoundDevice> output_devices_;
Expand Down
5 changes: 5 additions & 0 deletions fxsound/Source/GUI/FxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ FxModel::Preset FxModel::getPreset(int preset) const
return {};
}

Array<FxModel::Preset> FxModel::getPresets() const
{
return presets_;
}

bool FxModel::isPresetModified() const
{
return preset_modified_;
Expand Down
1 change: 1 addition & 0 deletions fxsound/Source/GUI/FxModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FxModel final
int getPresetCount() const;
int getUserPresetCount() const;
Preset getPreset(int preset) const;
Array<Preset> getPresets() const;
bool isPresetModified() const;
void setPresetModified(bool preset_modified);
bool isPresetNameValid(const String& preset_name);
Expand Down
13 changes: 13 additions & 0 deletions fxsound/Source/GUI/FxSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ FxSettingsDialog::GeneralSettingsPane::GeneralSettingsPane() :
launch_toggle_(TRANS("Launch on system startup")),
hide_help_tips_toggle_(TRANS("Hide help tips for audio controls")),
hide_notifications_toggle_(TRANS("Hide notifications")),
device_specific_preset_toggle_(TRANS("Enable device specific preset")),
hotkeys_toggle_(TRANS("Disable keyboard shortcuts")),
reset_presets_button_(TRANS("Reset presets to factory defaults"))
{
Expand Down Expand Up @@ -227,6 +228,10 @@ FxSettingsDialog::GeneralSettingsPane::GeneralSettingsPane() :
hide_notifications_toggle_.setColour(ToggleButton::ColourIds::tickColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
hide_notifications_toggle_.setColour(ToggleButton::ColourIds::textColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
hide_notifications_toggle_.setWantsKeyboardFocus(true);
device_specific_preset_toggle_.setMouseCursor(MouseCursor::PointingHandCursor);
device_specific_preset_toggle_.setColour(ToggleButton::ColourIds::tickColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
device_specific_preset_toggle_.setColour(ToggleButton::ColourIds::textColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
device_specific_preset_toggle_.setWantsKeyboardFocus(true);
hotkeys_toggle_.setMouseCursor(MouseCursor::PointingHandCursor);
hotkeys_toggle_.setColour(ToggleButton::ColourIds::tickColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
hotkeys_toggle_.setColour(ToggleButton::ColourIds::textColourId, getLookAndFeel().findColour(TextButton::textColourOnId));
Expand Down Expand Up @@ -268,6 +273,9 @@ FxSettingsDialog::GeneralSettingsPane::GeneralSettingsPane() :
hide_notifications_toggle_.setToggleState(FxController::getInstance().isNotificationsHidden(), NotificationType::dontSendNotification);
hide_notifications_toggle_.onClick = [this]() { FxController::getInstance().setNotificationsHidden(hide_notifications_toggle_.getToggleState()); };

device_specific_preset_toggle_.setToggleState(FxController::getInstance().isDeviceSpecificPreset(), NotificationType::dontSendNotification);
device_specific_preset_toggle_.onClick = [this]() { FxController::getInstance().setDeviceSpecificPreset(device_specific_preset_toggle_.getToggleState()); };

reset_presets_button_.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
reset_presets_button_.setEnabled(FxModel::getModel().getUserPresetCount() > 0);
reset_presets_button_.setMouseCursor(MouseCursor::PointingHandCursor);
Expand All @@ -286,6 +294,7 @@ FxSettingsDialog::GeneralSettingsPane::GeneralSettingsPane() :
addAndMakeVisible(&preferred_endpoint_);
addAndMakeVisible(&hide_help_tips_toggle_);
addAndMakeVisible(&hide_notifications_toggle_);
addAndMakeVisible(&device_specific_preset_toggle_);
addAndMakeVisible(&hotkeys_toggle_);
addAndMakeVisible(&reset_presets_button_);
addAndMakeVisible(&language_switch_);
Expand Down Expand Up @@ -325,6 +334,9 @@ void FxSettingsDialog::GeneralSettingsPane::resized()
hide_notifications_toggle_.setBounds(X_MARGIN, y, getWidth() - X_MARGIN, TOGGLE_BUTTON_HEIGHT);

y = hide_notifications_toggle_.getBottom() + 10;
device_specific_preset_toggle_.setBounds(X_MARGIN, y, getWidth() - X_MARGIN, TOGGLE_BUTTON_HEIGHT);

y = device_specific_preset_toggle_.getBottom() + 10;
hotkeys_toggle_.setBounds(X_MARGIN, y, getWidth()-X_MARGIN, TOGGLE_BUTTON_HEIGHT);

y = hotkeys_toggle_.getBottom() + 5;
Expand Down Expand Up @@ -354,6 +366,7 @@ void FxSettingsDialog::GeneralSettingsPane::setText()
launch_toggle_.setButtonText(TRANS("Launch on system startup"));
hide_help_tips_toggle_.setButtonText(TRANS("Hide help tips for audio controls"));
hide_notifications_toggle_.setButtonText(TRANS("Hide notifications"));
device_specific_preset_toggle_.setButtonText(TRANS("Enable device specific preset"));

hotkeys_toggle_.setButtonText(TRANS("Disable keyboard shortcuts"));
reset_presets_button_.setButtonText(TRANS("Reset presets to factory defaults"));
Expand Down
1 change: 1 addition & 0 deletions fxsound/Source/GUI/FxSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class FxSettingsDialog : public FxWindow
ToggleButton launch_toggle_;
ToggleButton hide_help_tips_toggle_;
ToggleButton hide_notifications_toggle_;
ToggleButton device_specific_preset_toggle_;
ToggleButton hotkeys_toggle_;
TextButton reset_presets_button_;
OwnedArray<FxHotkeyLabel> hotkey_labels_;
Expand Down