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

Add a .clang-format file #940

Draft
wants to merge 3 commits into
base: master
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
100 changes: 100 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# OSARA: Open Source Accessibility for the REAPER Application
# .clang-format
# Author: James Teh <[email protected]>
# Copyright 2023 Leonard de Ruijter
# License: GNU General Public License version 2.0

# Style based on Microsofts' C++ style conventions.
BasedOnStyle: Microsoft
# Offset for access modifiers (public, protected, private).
AccessModifierOffset: 0
# Align code after an open bracket with block indentation.
AlignAfterOpenBracket: BlockIndent
# Do not align consecutive assignments.
AlignConsecutiveAssignments: None
# Do not align consecutive bit fields.
AlignConsecutiveBitFields: None
# Do not align consecutive declarations.
AlignConsecutiveDeclarations: None
# Do not align consecutive macros.
AlignConsecutiveMacros: None
# Do not align escaped newlines.
AlignEscapedNewlines: DontAlign
# Do not align operands in expressions.
AlignOperands: DontAlign
# Do not align trailing comments.
AlignTrailingComments: Never
# Do not allow short blocks (e.g., if statements without braces) on a single line.
AllowShortBlocksOnASingleLine: Never
# Do not allow short case labels in switch statements on a single line.
AllowShortCaseLabelsOnASingleLine: false
# Do not allow short enums on a single line.
AllowShortEnumsOnASingleLine: false
# Only allow empty functions on a single line.
AllowShortFunctionsOnASingleLine: Empty
# Do not allow short if statements on a single line.
AllowShortIfStatementsOnASingleLine: Never
# Do not allow short loops on a single line.
AllowShortLoopsOnASingleLine: false
# Add a space after the colon in bit fields.
BitFieldColonSpacing: After
# Don't break before binary operators.
BreakBeforeBinaryOperators: None
# Keep template declaration lines together with concept.
BreakBeforeConceptDeclarations: Never
# Attach opening braces to the same line as the statement or declaration it belongs to.
BreakBeforeBraces: Attach
# Ternary operators will be placed after line breaks.
BreakBeforeTernaryOperators: true
# Don't break string literals if they are too long.
BreakStringLiterals: false
# Indentation width for constructor initializers.
ConstructorInitializerIndentWidth: 2
# Indentation width for continuation lines.
ContinuationIndentWidth: 4
# Format braced lists as best suited for C++11 braced lists.
Cpp11BracedListStyle: true
# Use a fixed alignment for all pointers.
DerivePointerAlignment: false
# Do not indent case blocks in switch statements.
IndentCaseBlocks: false
# Indent case labels in switch statements.
IndentCaseLabels: true
# Standard indentation width.
IndentWidth: 2
# Do not indent if a function definition or declaration is wrapped after the type.
IndentWrappedFunctionNames: false
# Insert a newline at end of file if missing.
InsertNewlineAtEOF: true
# Maximum number of consecutive empty lines to keep.
MaxEmptyLinesToKeep: 2
# Do not indent namespaces.
NamespaceIndentation: None
# Penalty for indentation using spaces rather than tabs.
PenaltyIndentedWhitespace: 1
# Pointer alignment (Left or Right).
PointerAlignment: Left
# Separate definition blocks (Always, Never, or Leave).
SeparateDefinitionBlocks: Always
# Use one space before trailing comments, as more spaces can be replaced by tabs somehow.
SpacesBeforeTrailingComments: 1
# Do not add a space after a C-style cast.
SpaceAfterCStyleCast: false
# Do not add a space after the template keyword.
SpaceAfterTemplateKeyword: false
# Sort includes (CaseSensitive, CaseInsensitive, or Never).
SortIncludes: Never
# C++ standard to be followed (e.g., c++98, c++11, c++14, c++17, c++20).
Standard: c++20
# Interpreted macros as complete statements.
StatementMacros: [
"BoolSetting"
]
# Add a space before opening parentheses in control statements.
SpaceBeforeParens: ControlStatements
# Do not add a space before square brackets.
SpaceBeforeSquareBrackets: false
# Width of a tab character.
TabWidth: 2
# Use tabs for line continuation and indentation, and spaces for alignment. Note that we should not align.
UseTab: Always
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gitattributes text
.gitignore text
.clang-format text
*.cpp text
*.h text
*.bat eol=crlf
Expand Down
24 changes: 9 additions & 15 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace settings {
#define BoolSetting(name, sectionId, 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 @@ -43,9 +43,7 @@ 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 @@ -65,13 +63,11 @@ INT_PTR CALLBACK config_dialogProc(HWND dialog, UINT msg, WPARAM wParam,
}

void cmdConfig(Command* command) {
HWND dialog = CreateDialog(pluginHInstance, MAKEINTRESOURCE(ID_CONFIG_DLG),
GetForegroundWindow(), config_dialogProc);
HWND dialog = CreateDialog(pluginHInstance, MAKEINTRESOURCE(ID_CONFIG_DLG), GetForegroundWindow(), config_dialogProc);
translateDialog(dialog);
int id = ID_CONFIG_DLG;
#define BoolSetting(name, sectionId, 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 @@ -86,6 +82,7 @@ struct ToggleCommand {
string settingName;
string settingDisp;
};

map<int, ToggleCommand> toggleCommands;

bool handleSettingCommand(int command) {
Expand All @@ -96,11 +93,9 @@ 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 @@ -123,8 +118,7 @@ void registerSettingCommands() {
string idStr = s.str(); \
tc.settingDisp = translate_ctxt("OSARA Configuration", 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 All @@ -136,7 +130,7 @@ void registerSettingCommands() {
gaccel.accel.cmd = cmd; \
gaccel.desc = tc.desc.c_str(); \
plugin_register("gaccel", &gaccel); \
} else { \
} else { \
custom_action_register_t action; \
action.uniqueSectionId = sectionId; \
action.idStr = idStr.c_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, sectionId, displayName, default) extern bool name;
#include "settings.h"
#undef BoolSetting
}
} // namespace settings

const char CONFIG_SECTION[] = "osara";

Expand Down
40 changes: 17 additions & 23 deletions src/controlSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ const uint8_t TC_ARMED = 1 << 4;
const uint8_t TC_UNARMED = 1 << 5;

// Make it easier to manipulate these cached states.
template<uint8_t enableFlag, uint8_t disableFlag>
class TrackCacheState {
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 @@ -66,7 +65,7 @@ class TrackCacheState {

/*** 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 +145,7 @@ 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 +164,7 @@ 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 +178,7 @@ 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 @@ -196,11 +192,10 @@ class Surface: public IReaperControlSurface {

virtual void SetSurfaceSelected(MediaTrack* track, bool selected) override {
if (!selected || !settings::reportSurfaceChanges ||
// 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
) {
// 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) {
return;
}
// Cache the track even if we're handling a command because that command
Expand Down Expand Up @@ -243,8 +238,7 @@ 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 All @@ -267,10 +261,10 @@ class Surface: public IReaperControlSurface {
private:
bool wasCausedByCommand() {
return isHandlingCommand ||
// Sometimes, REAPER updates control surfaces after a command rather than
// during. If the last command OSARA handled was <= 50 ms ago, we assume
// this update was caused by that command.
GetTickCount() - lastCommandTime <= 50;
// Sometimes, REAPER updates control surfaces after a command rather than
// during. If the last command OSARA handled was <= 50 ms ago, we assume
// this update was caused by that command.
GetTickCount() - lastCommandTime <= 50;
}

// Used for parameters we don't cache such as volume, pan and FX parameters.
Expand All @@ -285,14 +279,14 @@ 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