Skip to content

Commit

Permalink
Format code base
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR committed Oct 10, 2023
1 parent f0d2a81 commit 337fe25
Show file tree
Hide file tree
Showing 19 changed files with 2,360 additions and 1,800 deletions.
30 changes: 16 additions & 14 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* License: GNU General Public License version 2.0
*/

#include "config.h"

#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include "config.h"
#include <string>

#include "resource.h"
#include "translation.h"

Expand All @@ -21,7 +23,7 @@ namespace settings {
#define BoolSetting(name, displayName, default) bool name = default;
#include "settings.h"
#undef BoolSetting
}
} // namespace settings

void loadConfig() {
// GetExtState returns an empty string (not NULL) if the key doesn't exist.
Expand All @@ -42,9 +44,8 @@ void config_onOk(HWND dialog) {
#undef BoolSetting
}

INT_PTR CALLBACK config_dialogProc(HWND dialog, UINT msg, WPARAM wParam,
LPARAM lParam
) {
INT_PTR CALLBACK config_dialogProc(
HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
Expand All @@ -69,8 +70,7 @@ void cmdConfig(Command* command) {
translateDialog(dialog);
int id = ID_CONFIG_DLG;
#define BoolSetting(name, displayName, default) \
CheckDlgButton(dialog, ++id, \
settings::name ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(dialog, ++id, settings::name ? BST_CHECKED : BST_UNCHECKED);
#include "settings.h"
#undef BoolSetting
ShowWindow(dialog, SW_SHOWNORMAL);
Expand All @@ -85,6 +85,7 @@ struct ToggleCommand {
string settingName;
string settingDisp;
};

map<int, ToggleCommand> toggleCommands;

bool handleSettingCommand(int command) {
Expand All @@ -95,11 +96,11 @@ bool handleSettingCommand(int command) {
isHandlingCommand = true;
ToggleCommand& tc = it->second;
*tc.setting = !*tc.setting;
SetExtState(CONFIG_SECTION, tc.settingName.c_str(), *tc.setting ? "1" : "0",
true);
SetExtState(
CONFIG_SECTION, tc.settingName.c_str(), *tc.setting ? "1" : "0", true);
ostringstream s;
s << (*tc.setting ? translate("enabled") : translate("disabled")) <<
" " << tc.settingDisp;
s << (*tc.setting ? translate("enabled") : translate("disabled")) << " "
<< tc.settingDisp;
outputMessage(s);
isHandlingCommand = false;
return true;
Expand All @@ -126,8 +127,9 @@ void registerSettingCommands() {
gaccel.accel.cmd = cmd; \
tc.settingDisp = translate(displayName); \
/* Strip the '&' character indicating the access key. */ \
tc.settingDisp.erase(remove(tc.settingDisp.begin(), tc.settingDisp.end(), \
'&'), tc.settingDisp.end()); \
tc.settingDisp.erase( \
remove(tc.settingDisp.begin(), tc.settingDisp.end(), '&'), \
tc.settingDisp.end()); \
s.str(""); \
s << translate("OSARA: Toggle") << " " << tc.settingDisp; \
tc.desc = s.str(); \
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace settings {
#define BoolSetting(name, displayName, default) extern bool name;
#include "settings.h"
#undef BoolSetting
}
} // namespace settings

const char CONFIG_SECTION[] = "osara";

Expand Down
48 changes: 26 additions & 22 deletions src/controlSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* License: GNU General Public License version 2.0
*/

#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <WDL/db2val.h>

#include <cstdint>
#include "osara.h"
#include <iomanip>
#include <map>
#include <sstream>
#include <string>

#include "config.h"
#include "paramsUi.h"
#include "midiEditorCommands.h"
#include "osara.h"
#include "paramsUi.h"
#include "translation.h"

using namespace std;
Expand All @@ -39,7 +41,7 @@ const uint8_t TC_UNARMED = 1 << 5;
template<uint8_t enableFlag, uint8_t disableFlag>
class TrackCacheState {
public:
TrackCacheState(uint8_t& value): value(value) {}
TrackCacheState(uint8_t& value) : value(value) {}

// Check if a supplied new state has changed from the cached state.
bool hasChanged(bool isEnabled) {
Expand All @@ -64,9 +66,10 @@ class TrackCacheState {
uint8_t& value;
};

/*** A control surface to obtain certain info that can only be retrieved that way.
/*** A control surface to obtain certain info that can only be retrieved that
* way.
*/
class Surface: public IReaperControlSurface {
class Surface : public IReaperControlSurface {
public:
virtual const char* GetTypeString() override {
return "OSARA";
Expand Down Expand Up @@ -146,8 +149,8 @@ class Surface: public IReaperControlSurface {
return;
}
auto cache = this->cachedTrackState<TC_MUTED, TC_UNMUTED>(track);
if (!isParamsDialogOpen && !this->wasCausedByCommand() &&
cache.hasChanged(mute)) {
if (!isParamsDialogOpen && !this->wasCausedByCommand()
&& cache.hasChanged(mute)) {
ostringstream s;
this->reportTrackIfDifferent(track, s);
s << (mute ? translate("muted") : translate("unmuted"));
Expand All @@ -166,8 +169,8 @@ class Surface: public IReaperControlSurface {
return;
}
auto cache = this->cachedTrackState<TC_SOLOED, TC_UNSOLOED>(track);
if (!isParamsDialogOpen && !this->wasCausedByCommand() &&
cache.hasChanged(solo)) {
if (!isParamsDialogOpen && !this->wasCausedByCommand()
&& cache.hasChanged(solo)) {
ostringstream s;
this->reportTrackIfDifferent(track, s);
s << (solo ? translate("soloed") : translate("unsoloed"));
Expand All @@ -181,8 +184,8 @@ class Surface: public IReaperControlSurface {
return;
}
auto cache = this->cachedTrackState<TC_ARMED, TC_UNARMED>(track);
if (!isParamsDialogOpen && !this->wasCausedByCommand() &&
cache.hasChanged(arm)) {
if (!isParamsDialogOpen && !this->wasCausedByCommand()
&& cache.hasChanged(arm)) {
ostringstream s;
this->reportTrackIfDifferent(track, s);
s << (arm ? translate("armed") : translate("unarmed"));
Expand All @@ -199,8 +202,7 @@ class Surface: public IReaperControlSurface {
// REAPER calls this a *lot*, even if the track was already selected; e.g.
// for mute, arm, solo, etc. Ignore this if we were already told about
// this track being selected.
track == lastSelectedTrack
) {
track == lastSelectedTrack) {
return;
}
// Cache the track even if we're handling a command because that command
Expand All @@ -214,7 +216,8 @@ class Surface: public IReaperControlSurface {
postGoToTrack(0, track);
}

virtual int Extended(int call, void* parm1, void* parm2, void* parm3) override {
virtual int Extended(
int call, void* parm1, void* parm2, void* parm3) override {
if (call == CSURF_EXT_SETFXPARAM) {
if (!this->shouldHandleParamChange()) {
return 0; // Unsupported.
Expand Down Expand Up @@ -243,8 +246,8 @@ class Surface: public IReaperControlSurface {
s << chunk << " ";
}
this->lastParam = param;
TrackFX_FormatParamValueNormalized(track, fx, param, normVal, chunk,
sizeof(chunk));
TrackFX_FormatParamValueNormalized(
track, fx, param, normVal, chunk, sizeof(chunk));
if (chunk[0]) {
s << chunk;
} else {
Expand Down Expand Up @@ -276,14 +279,15 @@ class Surface: public IReaperControlSurface {
// Only handle param changes if the last change was 100ms or more ago.
return now - prevChangeTime >= 100;
}

DWORD lastParamChangeTime = 0;

bool reportTrackIfDifferent(MediaTrack* track, ostringstream& output) {
bool different = track != this->lastChangedTrack;
if (different) {
this->lastChangedTrack = track;
int trackNum = (int)(size_t)GetSetMediaTrackInfo(track, "IP_TRACKNUMBER",
nullptr);
int trackNum =
(int)(size_t)GetSetMediaTrackInfo(track, "IP_TRACKNUMBER", nullptr);
if (trackNum <= 0) {
output << translate("master");
} else {
Expand Down
Loading

0 comments on commit 337fe25

Please sign in to comment.