Skip to content

Commit

Permalink
Preset list functions are now reaper actions
Browse files Browse the repository at this point in the history
Improved code style according to new clangd suggestions
Updated WDL
Added more code for improved window design
Updated reaper_plugin_functions.h to 6.09
Added FilterPreset compare function to show equal preset in LivePresetEditController.cpp if possible
Now selecting a saved FilterPreset in LivePresetEditController.cpp when it is equal to the one saved in the preset
Added function to remove a filter in settings dialoge
  • Loading branch information
Burtan committed May 7, 2020
1 parent a886e8c commit 3e57ef9
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 75 deletions.
64 changes: 63 additions & 1 deletion src/main/cpp/LivePresetsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ LPE::LPE(REAPER_PLUGIN_HINSTANCE hInstance, HWND mainHwnd) : mMainHwnd(mainHwnd)
std::bind(&LPE::toggleMutedTracksVisibility, this)
));

mActions.add(new HotkeyCommand(
"LPE_ADDPRESET",
"LPE - Creates a new preset",
std::bind(&LPE::createPreset, this)
));

mActions.add(new HotkeyCommand(
"LPE_UPDATEPRESET",
"LPE - Updates the selected preset",
std::bind(&LPE::updatePreset, this)
));

mActions.add(new HotkeyCommand(
"LPE_EDITPRESET",
"LPE - Edits the selected preset",
std::bind(&LPE::editPreset, this)
));

mActions.add(new HotkeyCommand(
"LPE_REMOVEORESET",
"LPE - Removes the selected presets",
std::bind(&LPE::removePresets, this)
));

mActions.add(new HotkeyCommand(
"LPE_SHOWSETTINGS",
"LPE - Shows/Hides the settings menu",
std::bind(&LPE::showSettings, this)
));

using namespace std::placeholders;
mActions.add(new ActionCommand(
"LPE_SELECTPRESET",
Expand Down Expand Up @@ -219,6 +249,38 @@ void LPE::onMenuClicked(const char* menustr, HMENU menu, int flag) {
}
}

/**
* Creates a new preset
*/
void LPE::createPreset() {
mController.createPreset();
}

/**
* Updates the selected preset
*/
void LPE::updatePreset() {
mController.updateSelectedPreset();
}

/**
* Edits the selected preset
*/
void LPE::editPreset() {
mController.editSelectedPreset();
}

/**
* Removes the selected preset
*/
void LPE::removePresets() {
mController.removeSelectedPresets();
}

void LPE::showSettings() {
mController.showSettings();
}

/*
* Recall a preset by its GUID which is encoded in all 4 variables
*/
Expand Down Expand Up @@ -320,7 +382,7 @@ bool LPE::recallState(ProjectStateContext* ctx, bool) {
while (!ctx->GetLine(buf, sizeof(buf)) && !lp.parse(buf)) {

// objects start with <OBJECTNAME
auto token = lp.gettoken_str(0);
const auto *token = lp.gettoken_str(0);
if (strcmp(token, "<LIVEPRESETSMODEL") == 0) {
mModel = LivePresetsModel(ctx);
}
Expand Down
20 changes: 16 additions & 4 deletions src/main/cpp/controller/LivePresetEditController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ void LivePresetEditController::onInitDlg() {
mCombo = std::make_unique<ComboBox>(GetDlgItem(mHwnd, IDC_COMBO));
auto comboAdapter = std::make_unique<FilterPresetsComboAdapter>(FilterPreset_GetNames(g_lpe->mModel.mFilterPresets));
mCombo->setAdapter(std::move(comboAdapter));

int index = 0;
for (auto *af : g_lpe->mModel.mFilterPresets) {
auto *bf = mPreset->extractFilterPreset();
if (FilterPreset_IsEqual(af, bf)) {
SendMessage(mCombo->mHwnd, CB_SETCURSEL, index, 0);
}
index++;
}
}

LRESULT WINAPI LivePresetEditController::wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
Expand All @@ -89,7 +98,7 @@ LRESULT WINAPI LivePresetEditController::wndProc(HWND hwnd, UINT uMsg, WPARAM wP
msg.wParam = wParam;
msg.lParam = lParam;

if (auto handled = tree->onKey(&msg, lParam & 24)) {
if (auto handled = tree->onKey(&msg, (int) lParam & 24)) {
return handled;
}
}
Expand Down Expand Up @@ -144,15 +153,15 @@ void LivePresetEditController::onCommand(WPARAM wparam, LPARAM lparam) {
break;
case IDC_RECALL: {
if (mPreset->mRecallCmdId != 0) {
auto section = SectionFromUniqueID(0);
auto *section = SectionFromUniqueID(0);
DoActionShortcutDialog(mHwnd, section, mPreset->mRecallCmdId, 0);
}
}
case IDC_SETTINGS:
showFilterSettings();
break;
case IDC_ADD: {
auto filter = mPreset->extractFilterPreset();
auto *filter = mPreset->extractFilterPreset();
std::string name = "New preset";
auto dlg = ConfirmationController("Save filter...", &name);
if (dlg.show()) {
Expand Down Expand Up @@ -241,4 +250,7 @@ void LivePresetEditController::showFilterSettings() {
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN, r.left, r.bottom, 0, mHwnd, nullptr);
}


void LivePresetEditController::getMinMaxInfo(LPMINMAXINFO info) {
info->ptMinTrackSize.x = 1400;
info->ptMinTrackSize.y = 1200;
}
48 changes: 32 additions & 16 deletions src/main/cpp/controller/LivePresetsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void LivePresetsController::onInitDlg() {
mList->addListViewEventListener([this](NMLISTVIEW* event) -> void {
switch (event->hdr.code) {
case NM_DBLCLK: {
const auto preset = mList->getAdapter()->getItem(event->iItem);
auto *const preset = mList->getAdapter()->getItem(event->iItem);
recallLivePreset(preset);
break;
}
Expand All @@ -75,18 +75,20 @@ void LivePresetsController::recallLivePreset(LivePreset* preset) {
/**
* Opens the edit dialog and creates the preset when the result is not cancelled
*/
void LivePresetsController::createPreset() {
auto preset = g_lpe->mModel.getCurrentSettingsAsPreset();
if (auto filter = FilterPreset_GetFilterByName(g_lpe->mModel.mFilterPresets, &g_lpe->mModel.mDefaultFilterPreset)) {
void LivePresetsController::createPreset() const {
auto *preset = g_lpe->mModel.getCurrentSettingsAsPreset();
if (auto *filter = FilterPreset_GetFilterByName(g_lpe->mModel.mFilterPresets, &g_lpe->mModel.mDefaultFilterPreset)) {
preset->applyFilterPreset(filter);
}

//keep track of the recallCmdId to remove it if the created preset is removed
auto tempCmdId = preset->mRecallCmdId;
auto editedPreset = editPreset(preset);
auto *editedPreset = editPreset(preset);

if (editedPreset != nullptr) {
g_lpe->mModel.addPreset(editedPreset, false);
if (!mList)
return;
mList->invalidate();
int index = mList->getAdapter()->getIndex(editedPreset);
mList->selectIndex(index);
Expand All @@ -100,21 +102,27 @@ void LivePresetsController::createPreset() {
*/
LivePreset* LivePresetsController::editPreset(LivePreset* preset) {
auto dlg = LivePresetEditController(preset);
auto result = (LivePreset*) dlg.show();
auto *result = (LivePreset*) dlg.show();
return result;
}

void LivePresetsController::updateSelectedPreset() {
void LivePresetsController::updateSelectedPreset() const {
if (!mList)
return;

auto indices = mList->getSelectedIndices();
if (indices.size() != 1)
return;

auto preset = mList->getAdapter()->getItem(indices.front());
auto *preset = mList->getAdapter()->getItem(indices.front());
preset->saveCurrentState(true);
Undo_OnStateChangeEx2(nullptr, "Update LivePreset", UNDO_STATE_MISCCFG, -1);
}

void LivePresetsController::removeSelectedPresets() {
void LivePresetsController::removeSelectedPresets() const {
if (!mList)
return;

std::vector<LivePreset*> presets;
for (auto index : mList->getSelectedIndices()) {
presets.push_back(mList->getAdapter()->getItem(index));
Expand All @@ -127,19 +135,22 @@ void LivePresetsController::removeSelectedPresets() {
* Creates a copy of the currently selected preset and opens the edit dialog for it. When the dialog is confirmed
* The copy is saved in place of the original one
*/
void LivePresetsController::editSelectedPreset() {
void LivePresetsController::editSelectedPreset() const {
if (!mList)
return;

auto indices = mList->getSelectedIndices();
if (indices.size() != 1)
return;

auto preset = mList->getAdapter()->getItem(indices.front());
auto *preset = mList->getAdapter()->getItem(indices.front());

WDL_FastString str;
preset->persist(str);
auto ctx = StringProjectStateContext(str);
auto presetToEdit = new LivePreset((ProjectStateContext*) &ctx, preset->mRecallCmdId);
auto *presetToEdit = new LivePreset((ProjectStateContext*) &ctx, preset->mRecallCmdId);

auto editedPreset = editPreset(presetToEdit);
auto *editedPreset = editPreset(presetToEdit);

if (editedPreset != nullptr) {
g_lpe->mModel.replacePreset(preset, editedPreset);
Expand Down Expand Up @@ -178,7 +189,7 @@ void LivePresetsController::onContextMenu(HMENU menu) {
InsertMenuItem(menu, 0, true, &mii);

int index = 0;
for (auto filter : filters) {
for (auto *filter : filters) {
mii = MENUITEMINFO();

mii.fMask |= MIIM_TYPE | MIIM_ID | MIIM_DATA;
Expand All @@ -197,7 +208,7 @@ void LivePresetsController::onContextMenu(HMENU menu) {
}
}

void LivePresetsController::applyFilterToSelectedTracks(int filterIndex) {
void LivePresetsController::applyFilterToSelectedTracks(int filterIndex) const {
for (auto index : mList->getSelectedIndices()) {
mList->getAdapter()->getItem(index)->applyFilterPreset(g_lpe->mModel.mFilterPresets[filterIndex]);
}
Expand Down Expand Up @@ -268,10 +279,15 @@ void LivePresetsController::onClose() {
mList->onDestroy();
}

void LivePresetsController::reset() {
void LivePresetsController::reset() const {
if (mList) {
auto adapter = std::make_unique<LivePresetsListAdapter>(&g_lpe->mModel.mPresets);
mList->setAdapter(std::move(adapter));
mList->invalidate();
}
}

void LivePresetsController::getMinMaxInfo(LPMINMAXINFO info) {
info->ptMinTrackSize.x = 1284;
info->ptMinTrackSize.y = 625;
}
16 changes: 13 additions & 3 deletions src/main/cpp/controller/SettingsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void SettingsController::onInitDlg() {
auto comboAdapter = std::make_unique<FilterPresetsComboAdapter>(filterNames);
mCombo->setAdapter(std::move(comboAdapter));
int index = 0;
for (auto filter : filterNames) {
for (auto *filter : filterNames) {
if (*filter == g_lpe->mModel.mDefaultFilterPreset) {
SendMessage(mCombo->mHwnd, CB_SETCURSEL, 0, index);
}
Expand All @@ -80,16 +80,26 @@ void SettingsController::onCommand(WPARAM wParam, LPARAM lparam) {
switch (wParam) {
case IDC_RECALL: {
auto cmdId = NamedCommandLookup("_LPE_SELECTPRESET");
auto section = SectionFromUniqueID(0);
auto *section = SectionFromUniqueID(0);
DoActionShortcutDialog(mHwnd, section, cmdId, 0);
break;
}
case IDC_TOGGLETRACKVISIBILITY: {
auto cmdId = NamedCommandLookup("_LPE_TOGGLEMUTEDVISIBILITY");
auto section = SectionFromUniqueID(0);
auto *section = SectionFromUniqueID(0);
DoActionShortcutDialog(mHwnd, section, cmdId, 0);
break;
}
case IDC_REMOVE: {
int index = SendMessage(mCombo->mHwnd, CB_GETCURSEL, 0, 0);
if (index == CB_ERR)
break;
g_lpe->mModel.mFilterPresets.erase(g_lpe->mModel.mFilterPresets.begin() + index);
SendMessage(mCombo->mHwnd, CB_SETCURSEL, -1, 0);
mCombo->getAdapter()->mItems = FilterPreset_GetNames(g_lpe->mModel.mFilterPresets);
mCombo->invalidate();
break;
}
case IDC_SAVE:
close();
break;
Expand Down
Loading

0 comments on commit 3e57ef9

Please sign in to comment.