From 4038f8a8aede7981dea70bf7e7677b8d25bf13e4 Mon Sep 17 00:00:00 2001 From: Powei Lin Date: Wed, 25 Dec 2024 15:58:53 -0500 Subject: [PATCH 01/12] action --- .clang-format | 280 +++++++++++ .github/workflows/test.yml | 6 +- include/component/knob.hh | 48 +- include/component/switch.hh | 42 +- include/core/app.hh | 100 ++-- include/core/cv.hh | 45 +- include/core/interface.hh | 109 ++--- include/core/parameter.hh | 102 ++-- include/core/plugin.hh | 28 +- include/core/plugin_selector.hh | 16 +- include/core/timeline.hh | 120 ++--- include/core/track.hh | 53 +- include/core/util.hh | 34 +- include/plugin/chorus.hh | 44 +- include/plugin/compressor.hh | 43 +- include/plugin/delay.hh | 41 +- include/plugin/four_osc.hh | 39 +- src/core/app.cc | 303 ++++++------ src/core/interface.cc | 140 +++--- src/core/plugin.cc | 29 +- src/core/plugin_selector.cc | 133 +++-- src/core/timeline.cc | 829 +++++++++++++++----------------- src/core/track.cc | 279 +++++------ src/core/util.cc | 134 +++--- src/main.cc | 102 ++-- src/plugin/chorus.cc | 162 +++---- src/plugin/compressor.cc | 163 +++---- src/plugin/delay.cc | 135 +++--- src/plugin/four_osc.cc | 107 ++--- 29 files changed, 1822 insertions(+), 1844 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7403b0f --- /dev/null +++ b/.clang-format @@ -0,0 +1,280 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: NextLine +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a19265..7cd7f42 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,11 @@ jobs: run: | sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update - sudo apt-get install -y tree ccache gcc-11 g++-11 freeglut3-dev g++ libasound2-dev libcurl4-openssl-dev libfreetype6-dev libjack-jackd2-dev libx11-dev libxcomposite-dev libxcursor-dev libxinerama-dev libxrandr-dev mesa-common-dev ladspa-sdk webkit2gtk-4.0 libgtk-3-dev xvfb ninja-build libwebkit2gtk-4.1-dev + sudo apt-get install -y tree ccache gcc-11 g++-11 freeglut3-dev g++ libasound2-dev libcurl4-openssl-dev libfreetype6-dev libjack-jackd2-dev libx11-dev libxcomposite-dev libxcursor-dev libxinerama-dev libxrandr-dev mesa-common-dev ladspa-sdk webkit2gtk-4.0 libgtk-3-dev xvfb ninja-build libwebkit2gtk-4.1-dev clang-format + + - name: Check format + run: | + clang-format --dry-run --Werror src/**/*.cc include/**/*.hh - name: Set reusable strings # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. diff --git a/include/component/knob.hh b/include/component/knob.hh index b5515e2..4c4e5e4 100644 --- a/include/component/knob.hh +++ b/include/component/knob.hh @@ -1,38 +1,32 @@ #pragma once -#include "core/util.hh" -#include "core/parameter.hh" #include "core/cv.hh" +#include "core/parameter.hh" +#include "core/util.hh" namespace box { template -struct Knob -{ - Parameter param_; - uint8_t x_, y_, radius_; - Color color_; - std::string name_; +struct Knob { + Parameter param_; + uint8_t x_, y_, radius_; + Color color_; + std::string name_; - Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, std::string name = "") - : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} - {} + Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, + std::string name = "") + : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} {} - virtual void Render(Interface &interface) - { - auto angle = param_.GetNorm() * 360; - auto x = static_cast(x_); - auto y = static_cast(y_); - DrawCircleSector(Vector2{x, y}, radius_, 0.f, angle, 360, color_); + virtual void Render(Interface& interface) { + auto angle = param_.GetNorm() * 360; + auto x = static_cast(x_); + auto y = static_cast(y_); + DrawCircleSector(Vector2{x, y}, radius_, 0.f, angle, 360, color_); - const int font_size = 10; - int width = MeasureText(name_.c_str(), font_size); - DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, WHITE); - } - virtual void HandleEvent(const Event& event) - { - - } + const int font_size = 10; + int width = MeasureText(name_.c_str(), font_size); + DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, WHITE); + } + virtual void HandleEvent(const Event& event) {} }; -} // namespace box - +} // namespace box diff --git a/include/component/switch.hh b/include/component/switch.hh index e343a24..eec8ab9 100644 --- a/include/component/switch.hh +++ b/include/component/switch.hh @@ -1,35 +1,29 @@ #pragma once -#include "core/util.hh" #include "core/parameter.hh" +#include "core/util.hh" // instead of using cv.hh, we directly use juce::CachedValue -namespace box -{ - -struct Switch -{ - juce::CachedValue &value_; - uint8_t x_, y_; - Color color_; - std::string name_; +namespace box { - Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, std::string name) - : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} - {} +struct Switch { + juce::CachedValue &value_; + uint8_t x_, y_; + Color color_; + std::string name_; - virtual void Render(Interface &interface) - { - Color text_color = value_ ? color_ : WHITE; - const int font_size = 10; - int width = MeasureText(name_.c_str(), font_size); - DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, text_color); - } + Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, + std::string name) + : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} {} - virtual void HandleEvent(const Event& event) - { + virtual void Render(Interface &interface) { + Color text_color = value_ ? color_ : WHITE; + const int font_size = 10; + int width = MeasureText(name_.c_str(), font_size); + DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, text_color); + } - } + virtual void HandleEvent(const Event &event) {} }; -} // namespace box +} // namespace box diff --git a/include/core/app.hh b/include/core/app.hh index cfe9d53..a2c4770 100644 --- a/include/core/app.hh +++ b/include/core/app.hh @@ -1,59 +1,59 @@ #pragma once -#include "core/util.hh" -#include "core/track.hh" #include "core/plugin_selector.hh" #include "core/timeline.hh" +#include "core/track.hh" +#include "core/util.hh" namespace box { struct App { - enum class ScreenState { - Timeline, - Track, - PluginSelector, - }; - - enum class Mode { - Normal, - Insert, - }; - - ScreenState screen_state_ = ScreenState::Timeline; - Mode mode_ = Mode::Normal; - int key_offset_ = 0; - std::map active_notes_; - - te::Engine &engine_ ; - te::Edit &edit_ ; - - std::vector> tracks_; - juce::Array base_tracks_; - - PluginSelector plugin_sel_; - Timeline timeline_; - - const std::vector colors_ = { - Color{0x29, 0x73, 0x55, 0xff}, - Color{0x1e, 0x4d, 0x3f, 0xff}, - Color{0xdd, 0xe6, 0x63, 0xff}, - Color{0x7d, 0x54, 0x39, 0xff}, - }; - - // functions - App(te::Engine &engine, te::Edit &edit); - void Render(Interface& interface); - void HandleEvent(const Event& event); - - Track &CurrTrack(); - size_t GetCurrTrack(); - void SetCurrTrack(size_t track_index); - void AddTrack(); - void ChangeArmMidi(size_t new_index); - -private: - size_t current_track_; - void ArmMidi(size_t index); - void UnarmMidi(size_t index); + enum class ScreenState { + Timeline, + Track, + PluginSelector, + }; + + enum class Mode { + Normal, + Insert, + }; + + ScreenState screen_state_ = ScreenState::Timeline; + Mode mode_ = Mode::Normal; + int key_offset_ = 0; + std::map active_notes_; + + te::Engine &engine_; + te::Edit &edit_; + + std::vector> tracks_; + juce::Array base_tracks_; + + PluginSelector plugin_sel_; + Timeline timeline_; + + const std::vector colors_ = { + Color{0x29, 0x73, 0x55, 0xff}, + Color{0x1e, 0x4d, 0x3f, 0xff}, + Color{0xdd, 0xe6, 0x63, 0xff}, + Color{0x7d, 0x54, 0x39, 0xff}, + }; + + // functions + App(te::Engine &engine, te::Edit &edit); + void Render(Interface &interface); + void HandleEvent(const Event &event); + + Track &CurrTrack(); + size_t GetCurrTrack(); + void SetCurrTrack(size_t track_index); + void AddTrack(); + void ChangeArmMidi(size_t new_index); + + private: + size_t current_track_; + void ArmMidi(size_t index); + void UnarmMidi(size_t index); }; -} // namespace box +} // namespace box diff --git a/include/core/cv.hh b/include/core/cv.hh index 43a84e6..6f2bafb 100644 --- a/include/core/cv.hh +++ b/include/core/cv.hh @@ -1,36 +1,31 @@ #pragma once -#include "core/util.hh" #include +#include "core/util.hh" + template struct CV { - juce::CachedValue &value_; - T min_, max_; + juce::CachedValue &value_; + T min_, max_; - // TODO add default value? - CV(juce::CachedValue &cv, T min, T max) - : value_{cv}, min_{min}, max_{max} - { - assert(min <= max); - } + // TODO add default value? + CV(juce::CachedValue &cv, T min, T max) + : value_{cv}, min_{min}, max_{max} { + assert(min <= max); + } - void SetValue(T new_value) - { - value_ = std::clamp(new_value, min_, max_); - } + void SetValue(T new_value) { value_ = std::clamp(new_value, min_, max_); } - void SetNorm(T norm) - { - norm = std::clamp(norm, static_cast(0), static_cast(1)); - const auto range = max_ - min_; - value_ = range * norm; - } + void SetNorm(T norm) { + norm = std::clamp(norm, static_cast(0), static_cast(1)); + const auto range = max_ - min_; + value_ = range * norm; + } - T GetValue() const { return value_.get(); } - T GetNorm() const - { - const auto range = max_ - min_; - return value_ / range; - } + T GetValue() const { return value_.get(); } + T GetNorm() const { + const auto range = max_ - min_; + return value_ / range; + } }; diff --git a/include/core/interface.hh b/include/core/interface.hh index 0998161..611e010 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -1,80 +1,47 @@ #pragma once #include + #include "core/util.hh" namespace box { class Interface { -public: - static const int WIDTH = 128; - static const int HEIGHT = 128; - constexpr static DeviceType DISPLAY_TYPE = DeviceType::Emulator; - constexpr static DeviceType INPUT_TYPE = DeviceType::Emulator; - - Interface(); - ~Interface(); - - void PreRender(); - void PostRender(); - - bool PollEvent(Event& event); - bool ShouldClose() const; - -private: - RenderTexture2D target_; - std::map keys_ = { - {KEY_ZERO, false}, - {KEY_ONE, false}, - {KEY_TWO, false}, - {KEY_THREE, false}, - {KEY_FOUR, false}, - {KEY_FIVE, false}, - {KEY_SIX, false}, - {KEY_SEVEN, false}, - {KEY_EIGHT, false}, - {KEY_NINE, false}, - {KEY_A, false}, - {KEY_B, false}, - {KEY_C, false}, - {KEY_D, false}, - {KEY_E, false}, - {KEY_F, false}, - {KEY_G, false}, - {KEY_H, false}, - {KEY_I, false}, - {KEY_J, false}, - {KEY_K, false}, - {KEY_L, false}, - {KEY_M, false}, - {KEY_N, false}, - {KEY_O, false}, - {KEY_P, false}, - {KEY_Q, false}, - {KEY_R, false}, - {KEY_S, false}, - {KEY_T, false}, - {KEY_U, false}, - {KEY_V, false}, - {KEY_W, false}, - {KEY_X, false}, - {KEY_Y, false}, - {KEY_Z, false}, - {KEY_SPACE, false}, - {KEY_ESCAPE, false}, - {KEY_ENTER, false}, - {KEY_TAB, false}, - {KEY_BACKSPACE, false}, - {KEY_COMMA, false}, - {KEY_PERIOD, false}, - {KEY_DELETE, false}, - {KEY_MINUS, false}, - {KEY_EQUAL, false}, - {KEY_RIGHT, false}, - {KEY_LEFT, false}, - {KEY_DOWN, false}, - {KEY_UP, false}, - }; - + public: + static const int WIDTH = 128; + static const int HEIGHT = 128; + constexpr static DeviceType DISPLAY_TYPE = DeviceType::Emulator; + constexpr static DeviceType INPUT_TYPE = DeviceType::Emulator; + + Interface(); + ~Interface(); + + void PreRender(); + void PostRender(); + + bool PollEvent(Event& event); + bool ShouldClose() const; + + private: + RenderTexture2D target_; + std::map keys_ = { + {KEY_ZERO, false}, {KEY_ONE, false}, {KEY_TWO, false}, + {KEY_THREE, false}, {KEY_FOUR, false}, {KEY_FIVE, false}, + {KEY_SIX, false}, {KEY_SEVEN, false}, {KEY_EIGHT, false}, + {KEY_NINE, false}, {KEY_A, false}, {KEY_B, false}, + {KEY_C, false}, {KEY_D, false}, {KEY_E, false}, + {KEY_F, false}, {KEY_G, false}, {KEY_H, false}, + {KEY_I, false}, {KEY_J, false}, {KEY_K, false}, + {KEY_L, false}, {KEY_M, false}, {KEY_N, false}, + {KEY_O, false}, {KEY_P, false}, {KEY_Q, false}, + {KEY_R, false}, {KEY_S, false}, {KEY_T, false}, + {KEY_U, false}, {KEY_V, false}, {KEY_W, false}, + {KEY_X, false}, {KEY_Y, false}, {KEY_Z, false}, + {KEY_SPACE, false}, {KEY_ESCAPE, false}, {KEY_ENTER, false}, + {KEY_TAB, false}, {KEY_BACKSPACE, false}, {KEY_COMMA, false}, + {KEY_PERIOD, false}, {KEY_DELETE, false}, {KEY_MINUS, false}, + {KEY_EQUAL, false}, {KEY_RIGHT, false}, {KEY_LEFT, false}, + {KEY_DOWN, false}, {KEY_UP, false}, + }; }; -} // namespace box +} // namespace box diff --git a/include/core/parameter.hh b/include/core/parameter.hh index d723a37..8c91d58 100644 --- a/include/core/parameter.hh +++ b/include/core/parameter.hh @@ -1,9 +1,10 @@ #pragma once #include -#include "core/util.hh" -#include "core/interface.hh" + #include "core/cv.hh" +#include "core/interface.hh" +#include "core/util.hh" namespace box { @@ -11,69 +12,50 @@ using AP = te::AutomatableParameter; template class Parameter { - std::variant, AP*> param_; -public: - Parameter(CV cv) - : param_{cv} - {} + std::variant, AP *> param_; + + public: + Parameter(CV cv) : param_{cv} {} - Parameter(AP *p) - : param_{p} - {} + Parameter(AP *p) : param_{p} {} - void SetValue(T new_value) - { - if (std::holds_alternative>(param_)) - { - auto v = std::get>(param_); - v.SetValue(new_value); - } - else if (std::holds_alternative(param_)) - { - auto v = std::get(param_); - v->setParameter(new_value, juce::NotificationType::dontSendNotification); - } + void SetValue(T new_value) { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + v.SetValue(new_value); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + v->setParameter(new_value, juce::NotificationType::dontSendNotification); } - void SetNorm(T new_value) - { - if (std::holds_alternative>(param_)) - { - auto v = std::get>(param_); - v.SetNorm(new_value); - } - else if (std::holds_alternative(param_)) - { - auto v = std::get(param_); - v->setNormalisedParameter(new_value, juce::NotificationType::dontSendNotification); - } + } + void SetNorm(T new_value) { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + v.SetNorm(new_value); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + v->setNormalisedParameter(new_value, + juce::NotificationType::dontSendNotification); } - T GetValue() const - { - if (std::holds_alternative>(param_)) - { - auto v = std::get>(param_); - return v.GetValue(); - } - else if (std::holds_alternative(param_)) - { - auto v = std::get(param_); - return v->getCurrentValue(); - } + } + T GetValue() const { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + return v.GetValue(); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + return v->getCurrentValue(); } - T GetNorm() const - { - if (std::holds_alternative>(param_)) - { - auto v = std::get>(param_); - return v.GetNorm(); - } - else if (std::holds_alternative(param_)) - { - auto v = std::get(param_); - return v->getCurrentNormalisedValue(); - } + } + T GetNorm() const { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + return v.GetNorm(); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + return v->getCurrentNormalisedValue(); } + } }; - -} // namespace box +} // namespace box diff --git a/include/core/plugin.hh b/include/core/plugin.hh index eb0c29f..4ed8049 100644 --- a/include/core/plugin.hh +++ b/include/core/plugin.hh @@ -1,26 +1,24 @@ #pragma once -#include "core/util.hh" #include "core/interface.hh" +#include "core/util.hh" namespace box { - struct Plugin { - te::Plugin *const plugin_; + te::Plugin *const plugin_; -public: - Plugin(te::Plugin *p); - virtual ~Plugin(); + public: + Plugin(te::Plugin *p); + virtual ~Plugin(); - void EnsureTextureLoaded() const; - te::Plugin *const GetPlugin() const; + void EnsureTextureLoaded() const; + te::Plugin *const GetPlugin() const; - virtual Texture2D &GetIcon() const = 0; - virtual const char *GetIconPath() const = 0; - virtual const char *GetName() const = 0; - virtual void Render(Interface &interface) = 0; - virtual void HandleEvent(const Event &event) = 0; + virtual Texture2D &GetIcon() const = 0; + virtual const char *GetIconPath() const = 0; + virtual const char *GetName() const = 0; + virtual void Render(Interface &interface) = 0; + virtual void HandleEvent(const Event &event) = 0; }; - -} // namespace box +} // namespace box diff --git a/include/core/plugin_selector.hh b/include/core/plugin_selector.hh index 1557125..20ecd99 100644 --- a/include/core/plugin_selector.hh +++ b/include/core/plugin_selector.hh @@ -1,17 +1,17 @@ #pragma once -#include "core/util.hh" #include "core/interface.hh" +#include "core/util.hh" namespace box { struct PluginSelector { - PluginSelector(); - void Render(Interface &interface); - void HandleEvent(const Event &event); - void Select(const std::string &name); + PluginSelector(); + void Render(Interface &interface); + void HandleEvent(const Event &event); + void Select(const std::string &name); - static const std::vector PLUGIN_NAMES; - size_t current_index_ = 0; + static const std::vector PLUGIN_NAMES; + size_t current_index_ = 0; }; -} // namespace box +} // namespace box diff --git a/include/core/timeline.hh b/include/core/timeline.hh index 9f51546..21a1bcf 100644 --- a/include/core/timeline.hh +++ b/include/core/timeline.hh @@ -1,69 +1,69 @@ #pragma once -#include "util.hh" #include "interface.hh" +#include "util.hh" namespace box { struct Timeline { - - enum class ScreenState { - Overview, - }; - - enum class PlayheadMode { - Detached, - Locked, - }; - - struct BeatWindow { - float start; - float len; - float LeftEdge() const {return start;} - float RightEdge() const {return start + len;} - }; - - struct BeatFrame { - float center; - float radius; - float LeftEdge() const {return center - radius;} - float RightEdge() const {return center + radius;} - float Width() const {return radius * 2;} - BeatFrame(float c, float &r): center{c}, radius{r} {} - }; - - struct Position { - float secs; - float beats; - }; - - float bar_width_ = 4.0; // Assuming a 4/4 time signature by default TODO update with time signature changes - float step_size_ = 4.0; // Move cursor by 4 beat (1 bar) - float radius_ = 8.0; - BeatWindow cursor_ = {0.0, bar_width_}; - BeatFrame frame_ = {0.0, radius_}; - - ScreenState screen_state_ = ScreenState::Overview; - PlayheadMode playhead_mode_ = PlayheadMode::Detached; - size_t scroll_offset_ = 0; - - static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; - static constexpr const char *METRONOME_PATH_R = "assets/metronome_r.png"; - static constexpr const char *METRONOME_PATH_OFF = "assets/metronome_off.png"; - Texture2D metronome_l_; - Texture2D metronome_r_; - Texture2D metronome_off_; - - Timeline(); - ~Timeline(); - - void FocusCursor(); - - void Render(Interface& interface); - void HandleEvent(const Event& event); -private: - void print_timeline(); + enum class ScreenState { + Overview, + }; + + enum class PlayheadMode { + Detached, + Locked, + }; + + struct BeatWindow { + float start; + float len; + float LeftEdge() const { return start; } + float RightEdge() const { return start + len; } + }; + + struct BeatFrame { + float center; + float radius; + float LeftEdge() const { return center - radius; } + float RightEdge() const { return center + radius; } + float Width() const { return radius * 2; } + BeatFrame(float c, float &r) : center{c}, radius{r} {} + }; + + struct Position { + float secs; + float beats; + }; + + float bar_width_ = 4.0; // Assuming a 4/4 time signature by default TODO + // update with time signature changes + float step_size_ = 4.0; // Move cursor by 4 beat (1 bar) + float radius_ = 8.0; + BeatWindow cursor_ = {0.0, bar_width_}; + BeatFrame frame_ = {0.0, radius_}; + + ScreenState screen_state_ = ScreenState::Overview; + PlayheadMode playhead_mode_ = PlayheadMode::Detached; + size_t scroll_offset_ = 0; + + static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; + static constexpr const char *METRONOME_PATH_R = "assets/metronome_r.png"; + static constexpr const char *METRONOME_PATH_OFF = "assets/metronome_off.png"; + Texture2D metronome_l_; + Texture2D metronome_r_; + Texture2D metronome_off_; + + Timeline(); + ~Timeline(); + + void FocusCursor(); + + void Render(Interface &interface); + void HandleEvent(const Event &event); + + private: + void print_timeline(); }; -} // namespace box - +} // namespace box diff --git a/include/core/track.hh b/include/core/track.hh index 4449dda..5a736ec 100644 --- a/include/core/track.hh +++ b/include/core/track.hh @@ -2,38 +2,37 @@ #include #include -#include "core/util.hh" + #include "core/interface.hh" #include "core/plugin.hh" +#include "core/util.hh" namespace box { class Track { - enum class ScreenState { - Overview, - Plugin, - }; -public: - static constexpr int MAX_PLUGINS = 8; - static constexpr int GRID_SIZE = 4; - std::vector> plugins_; - int active_plugin_ = -1; - te::AudioTrack &base_; - ScreenState screen_state_ = ScreenState::Overview; - - - - Track(te::AudioTrack &base); - ~Track(); - - void AddPlugin(std::unique_ptr plugin); - void SetActivePlugin(int index); - int GetActivePlugin(); - void RemoveActivePlugin(); - - void HandleEvent(const Event& event); - void Render(Interface& Interface); - + enum class ScreenState { + Overview, + Plugin, + }; + + public: + static constexpr int MAX_PLUGINS = 8; + static constexpr int GRID_SIZE = 4; + std::vector> plugins_; + int active_plugin_ = -1; + te::AudioTrack& base_; + ScreenState screen_state_ = ScreenState::Overview; + + Track(te::AudioTrack& base); + ~Track(); + + void AddPlugin(std::unique_ptr plugin); + void SetActivePlugin(int index); + int GetActivePlugin(); + void RemoveActivePlugin(); + + void HandleEvent(const Event& event); + void Render(Interface& Interface); }; -} // namespace box +} // namespace box diff --git a/include/core/util.hh b/include/core/util.hh index bdcb829..e7c50d3 100644 --- a/include/core/util.hh +++ b/include/core/util.hh @@ -1,12 +1,13 @@ #pragma once +#include + #include -#include #include +#include #include #include "raylib.h" -#include namespace te = tracktion; @@ -43,33 +44,30 @@ std::string format_cursor_pos(size_t track_pos, float cursor_pos); size_t clamp_decrement(size_t x); size_t clamp_increment(size_t x, size_t max); -enum class LogLevel {Off, Debug, Warn, Err}; -LogLevel string_to_loglevel(const std::string& s); +enum class LogLevel { Off, Debug, Warn, Err }; +LogLevel string_to_loglevel(const std::string &s); std::string loglevel_to_string(LogLevel l); LogLevel get_loglevel(); const LogLevel LOGLEVEL = get_loglevel(); -void LOG_MSG(const std::string& msg, LogLevel l = LogLevel::Debug); -template +void LOG_MSG(const std::string &msg, LogLevel l = LogLevel::Debug); +template void log_var(const std::string &var_name, const T &var_value) { - LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); + LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); } #define LOG_VAR(var) log_var(#var, var) -enum class DeviceType { - Emulator, - Hardware -}; +enum class DeviceType { Emulator, Hardware }; enum class EventType { - KeyPress, - KeyRelease, - PotDown, - PotUp, + KeyPress, + KeyRelease, + PotDown, + PotUp, }; struct Event { - EventType type; - int value; + EventType type; + int value; }; const std::unordered_map KEY_TO_MIDI = { @@ -90,4 +88,4 @@ const std::unordered_map KEY_TO_MIDI = { {KEY_L, 74} // D5 }; -} // namespace box +} // namespace box diff --git a/include/plugin/chorus.hh b/include/plugin/chorus.hh index 32c5646..4fd71bd 100644 --- a/include/plugin/chorus.hh +++ b/include/plugin/chorus.hh @@ -1,34 +1,30 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" - -namespace box -{ - -struct Chorus : public Plugin -{ - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "chrs"; +namespace box { - te::ChorusPlugin *base_plugin_; - Knob knob_depth_; - Knob knob_width_; - Knob knob_speed_; - Knob knob_mix_; +struct Chorus : public Plugin { + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "chrs"; -public: + te::ChorusPlugin *base_plugin_; + Knob knob_depth_; + Knob knob_width_; + Knob knob_speed_; + Knob knob_mix_; - Chorus(te::Plugin *p); - ~Chorus() override; + public: + Chorus(te::Plugin *p); + ~Chorus() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/include/plugin/compressor.hh b/include/plugin/compressor.hh index 4761953..fe3e775 100644 --- a/include/plugin/compressor.hh +++ b/include/plugin/compressor.hh @@ -1,33 +1,30 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" - -namespace box -{ -struct Compressor : public Plugin -{ - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "cmpr"; +namespace box { - te::CompressorPlugin *base_plugin_; - Knob knob_threshold_; - Knob knob_ratio_; - Knob knob_attack_; - Knob knob_release_; +struct Compressor : public Plugin { + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "cmpr"; -public: + te::CompressorPlugin *base_plugin_; + Knob knob_threshold_; + Knob knob_ratio_; + Knob knob_attack_; + Knob knob_release_; - Compressor(te::Plugin *p); - ~Compressor() override; + public: + Compressor(te::Plugin *p); + ~Compressor() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} +} // namespace box diff --git a/include/plugin/delay.hh b/include/plugin/delay.hh index 8d8c995..bfaa57c 100644 --- a/include/plugin/delay.hh +++ b/include/plugin/delay.hh @@ -1,32 +1,29 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" - -namespace box -{ -struct Delay : public Plugin -{ - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "dlay"; +namespace box { - te::DelayPlugin *base_plugin_; - Knob knob_feedback_; - Knob knob_mix_; - Knob knob_length_; +struct Delay : public Plugin { + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "dlay"; -public: + te::DelayPlugin *base_plugin_; + Knob knob_feedback_; + Knob knob_mix_; + Knob knob_length_; - Delay(te::Plugin *p); - ~Delay() override; + public: + Delay(te::Plugin *p); + ~Delay() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/include/plugin/four_osc.hh b/include/plugin/four_osc.hh index fd8d8be..0a5780c 100644 --- a/include/plugin/four_osc.hh +++ b/include/plugin/four_osc.hh @@ -1,30 +1,27 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" namespace box { - struct FourOsc : public Plugin { - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/four_16x16.png"; - static constexpr const char *name_ = "4osc"; - - te::FourOscPlugin *base_plugin_; - Knob knob_master_level_; - -public: - - FourOsc(te::Plugin *p); - ~FourOsc() override; - - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/four_16x16.png"; + static constexpr const char *name_ = "4osc"; + + te::FourOscPlugin *base_plugin_; + Knob knob_master_level_; + + public: + FourOsc(te::Plugin *p); + ~FourOsc() override; + + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; - -} // namespace box +} // namespace box diff --git a/src/core/app.cc b/src/core/app.cc index bc05664..4d6dc43 100644 --- a/src/core/app.cc +++ b/src/core/app.cc @@ -1,208 +1,175 @@ #include "core/app.hh" + #include namespace box { -static void assert_tracks(const std::vector> &tracks, size_t index, const std::string &name) -{ - if (tracks.size() == 0 || index >= tracks.size()) - { - throw std::runtime_error{"App::" + name + "(): index [" + std::to_string(index) + - "] out of range: [0, " + std::to_string(tracks.size()) + "]"}; - } +static void assert_tracks(const std::vector> &tracks, + size_t index, const std::string &name) { + if (tracks.size() == 0 || index >= tracks.size()) { + throw std::runtime_error{"App::" + name + "(): index [" + + std::to_string(index) + "] out of range: [0, " + + std::to_string(tracks.size()) + "]"}; + } } -void print_tracks(App a) -{ - for (auto &t : a.tracks_) - { - // std::cout << "Wave Input Device: " << t->track_.getWaveInputDevice() << std::endl; - // WaveInputDevice& getWaveInputDevice() const noexcept { jassert (waveInputDevice); return *waveInputDevice; } - // MidiInputDevice& getMidiInputDevice() const noexcept { jassert (midiInputDevice); return *midiInputDevice; } - } +void print_tracks(App a) { + for (auto &t : a.tracks_) { + // std::cout << "Wave Input Device: " << t->track_.getWaveInputDevice() << + // std::endl; WaveInputDevice& getWaveInputDevice() const noexcept { + // jassert (waveInputDevice); return *waveInputDevice; } MidiInputDevice& + // getMidiInputDevice() const noexcept { jassert (midiInputDevice); + // return *midiInputDevice; } + } } -App:: App(te::Engine &engine, te::Edit &edit): - engine_{engine}, - edit_{edit}, - current_track_{0}, - base_tracks_{te::getAudioTracks(edit)} -{ - AddTrack(); // ensure there's always at least 1 - LOG_VAR(tracks_.size()); - ArmMidi(current_track_); // turn on midi for it +App::App(te::Engine &engine, te::Edit &edit) + : engine_{engine}, + edit_{edit}, + current_track_{0}, + base_tracks_{te::getAudioTracks(edit)} { + AddTrack(); // ensure there's always at least 1 + LOG_VAR(tracks_.size()); + ArmMidi(current_track_); // turn on midi for it } -void App:: AddTrack() -{ - tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); +void App::AddTrack() { + tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); } -Track &App:: CurrTrack() -{ - return *tracks_[current_track_]; -} +Track &App::CurrTrack() { return *tracks_[current_track_]; } -size_t App:: GetCurrTrack() -{ - return current_track_; -} -void App:: SetCurrTrack(size_t track_index) -{ - size_t old = current_track_; - if (track_index >= 0 && track_index < MAX_TRACKS) - { - current_track_ = track_index; - } - else - { - throw std::runtime_error{"SetCurrTrack() out of range: "}; - } +size_t App::GetCurrTrack() { return current_track_; } +void App::SetCurrTrack(size_t track_index) { + size_t old = current_track_; + if (track_index >= 0 && track_index < MAX_TRACKS) { + current_track_ = track_index; + } else { + throw std::runtime_error{"SetCurrTrack() out of range: "}; + } - UnarmMidi(old); - ArmMidi(current_track_); + UnarmMidi(old); + ArmMidi(current_track_); } -void App:: ArmMidi(size_t index) -{ - assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) - { - auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) - { - auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) - { - [[ maybe_unused ]] auto res = instance->setTarget (t->itemID, true, &edit_.getUndoManager(), 0); - instance->setRecordingEnabled (t->itemID, true); - } - } +void App::ArmMidi(size_t index) { + assert(0 <= index && index < tracks_.size()); + for (auto instance : edit_.getAllInputDevices()) { + auto device_type = instance->getInputDevice().getDeviceType(); + if (device_type == te::InputDevice::physicalMidiDevice || + device_type == te::InputDevice::virtualMidiDevice) { + auto t = te::getAudioTracks(edit_)[index]; + if (t != nullptr) { + [[maybe_unused]] auto res = + instance->setTarget(t->itemID, true, &edit_.getUndoManager(), 0); + instance->setRecordingEnabled(t->itemID, true); + } } + } } -void App:: UnarmMidi(size_t index) -{ - assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) - { - auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) - { - auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) - { - instance->removeTarget(t->itemID, &edit_.getUndoManager()); - } - } +void App::UnarmMidi(size_t index) { + assert(0 <= index && index < tracks_.size()); + for (auto instance : edit_.getAllInputDevices()) { + auto device_type = instance->getInputDevice().getDeviceType(); + if (device_type == te::InputDevice::physicalMidiDevice || + device_type == te::InputDevice::virtualMidiDevice) { + auto t = te::getAudioTracks(edit_)[index]; + if (t != nullptr) { + instance->removeTarget(t->itemID, &edit_.getUndoManager()); + } } + } } -void App:: Render(Interface& interface) -{ - assert_tracks(tracks_, current_track_, "render"); +void App::Render(Interface &interface) { + assert_tracks(tracks_, current_track_, "render"); - // TODO this is for debugging fps - // std::string text = std::to_string(GetFPS()); - // DrawText(text.c_str(), 115, 0, 10, WHITE); + // TODO this is for debugging fps + // std::string text = std::to_string(GetFPS()); + // DrawText(text.c_str(), 115, 0, 10, WHITE); - switch (screen_state_) - { + switch (screen_state_) { case ScreenState::Timeline: - timeline_.Render(interface); - break; + timeline_.Render(interface); + break; case ScreenState::Track: - tracks_[current_track_]->Render(interface); - break; + tracks_[current_track_]->Render(interface); + break; case ScreenState::PluginSelector: - plugin_sel_.Render(interface); - break; - } + plugin_sel_.Render(interface); + break; + } + + if (mode_ == Mode::Insert) { + DrawRectangleLines(0, 0, 128, 127, PURPLE); // -1 so bottom row shows + } + if (edit_.getTransport().isRecording()) { + DrawRectangleLines(1, 1, 126, 125, RED); // -1 so bottom row shows + } +} - if (mode_ == Mode::Insert) - { - DrawRectangleLines(0, 0, 128, 127, PURPLE); // -1 so bottom row shows +void App::HandleEvent(const Event &event) { + assert_tracks(tracks_, current_track_, "handleEvent"); + if (event.type == EventType::KeyPress && event.value == KEY_I) { + if (mode_ == Mode::Normal) { + mode_ = Mode::Insert; + } else if (mode_ == Mode::Insert) { + mode_ = Mode::Normal; } - if (edit_.getTransport().isRecording()) - { - DrawRectangleLines(1, 1, 126, 125, RED); // -1 so bottom row shows - } -} + } + + if (mode_ == Mode::Insert) { + switch (event.type) { + case EventType::KeyPress: + LOG_VAR(event.value); + if (event.value == KEY_UP) { + APP->key_offset_ += 1; + break; + } + if (event.value == KEY_DOWN) { + APP->key_offset_ -= 1; + break; + } -void App:: HandleEvent(const Event& event) -{ - assert_tracks(tracks_, current_track_, "handleEvent"); - if (event.type == EventType::KeyPress && event.value == KEY_I) - { - if (mode_ == Mode::Normal) - { - mode_ = Mode::Insert; - } - else if (mode_ == Mode::Insert) - { - mode_ = Mode::Normal; + if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && + active_notes_.find(event.value) == active_notes_.end()) { + int note = (12 * key_offset_) + KEY_TO_MIDI.at(event.value); + + active_notes_[event.value] = note; + auto message = juce::MidiMessage::noteOn(1, note, 1.0f); + te::MidiInputDevice *dev = + engine_.getDeviceManager().getDefaultMidiInDevice(); + dev->keyboardState.noteOn(1, note, 1.0); } - } + break; + case EventType::KeyRelease: - if (mode_ == Mode::Insert) - { - switch (event.type) - { - case EventType::KeyPress: - LOG_VAR(event.value); - if (event.value == KEY_UP) - { - APP->key_offset_ += 1; - break; - } - if (event.value == KEY_DOWN) - { - APP->key_offset_ -= 1; - break; - } - - if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() - && active_notes_.find(event.value) == active_notes_.end()) - { - int note = (12 * key_offset_) + KEY_TO_MIDI.at(event.value); - - active_notes_[event.value] = note; - auto message = juce::MidiMessage::noteOn(1, note, 1.0f); - te::MidiInputDevice* dev = engine_.getDeviceManager().getDefaultMidiInDevice(); - dev->keyboardState.noteOn(1, note, 1.0); - } - break; - case EventType::KeyRelease: - - if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() - && active_notes_.find(event.value) != active_notes_.end()) - { - int note = active_notes_[event.value]; - - active_notes_.erase(event.value); - auto message = juce::MidiMessage::noteOff(1, note); - te::MidiInputDevice* dev = engine_.getDeviceManager().getDefaultMidiInDevice(); - dev->keyboardState.noteOff(1, note, 1.0); - } - break; + if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && + active_notes_.find(event.value) != active_notes_.end()) { + int note = active_notes_[event.value]; + + active_notes_.erase(event.value); + auto message = juce::MidiMessage::noteOff(1, note); + te::MidiInputDevice *dev = + engine_.getDeviceManager().getDefaultMidiInDevice(); + dev->keyboardState.noteOff(1, note, 1.0); } - return; + break; } + return; + } - switch (screen_state_) - { + switch (screen_state_) { case ScreenState::Timeline: - timeline_.HandleEvent(event); - break; + timeline_.HandleEvent(event); + break; case ScreenState::Track: - tracks_[current_track_]->HandleEvent(event); - break; + tracks_[current_track_]->HandleEvent(event); + break; case ScreenState::PluginSelector: - plugin_sel_.HandleEvent(event); - break; - } - + plugin_sel_.HandleEvent(event); + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/interface.cc b/src/core/interface.cc index 23d2c4f..dbb4344 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -1,102 +1,84 @@ #include "core/interface.hh" -#include + #include +#include namespace box { -Interface:: Interface() -{ - SetConfigFlags(FLAG_WINDOW_RESIZABLE); - InitWindow(512, 512, "raylib - Rescalable 128x128 render"); - target_ = LoadRenderTexture(WIDTH, HEIGHT); - SetTargetFPS(60); - SetExitKey(0); // esc doesn't close program +Interface::Interface() { + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(512, 512, "raylib - Rescalable 128x128 render"); + target_ = LoadRenderTexture(WIDTH, HEIGHT); + SetTargetFPS(60); + SetExitKey(0); // esc doesn't close program - if constexpr (INPUT_TYPE == DeviceType::Hardware) - { - // Initialize microcontroller input handling (e.g., serial interface) - } + if constexpr (INPUT_TYPE == DeviceType::Hardware) { + // Initialize microcontroller input handling (e.g., serial interface) + } } -Interface:: ~Interface() -{ - if (DISPLAY_TYPE == DeviceType::Emulator) - { - UnloadRenderTexture(target_); - CloseWindow(); - } +Interface::~Interface() { + if (DISPLAY_TYPE == DeviceType::Emulator) { + UnloadRenderTexture(target_); + CloseWindow(); + } } -void Interface:: PreRender() -{ - BeginTextureMode(target_); // matches PostRender - ClearBackground(BLACK); +void Interface::PreRender() { + BeginTextureMode(target_); // matches PostRender + ClearBackground(BLACK); } -void Interface:: PostRender() -{ - if (DISPLAY_TYPE == DeviceType::Emulator) - { +void Interface::PostRender() { + if (DISPLAY_TYPE == DeviceType::Emulator) { + int screen_width = GetScreenWidth(); + int screen_height = GetScreenHeight(); - int screen_width = GetScreenWidth(); - int screen_height = GetScreenHeight(); + int square_len = std::min(screen_width, screen_height); + int pos_x = (screen_width - square_len) / 2; + int pos_y = (screen_height - square_len) / 2; - int square_len = std::min(screen_width, screen_height); - int pos_x = (screen_width - square_len) / 2; - int pos_y = (screen_height - square_len) / 2; - - EndTextureMode(); // matches PreRender - BeginDrawing(); - DrawTexturePro( - target_.texture, - Rectangle{0, 0, float(target_.texture.width), float(-target_.texture.height)}, - Rectangle{float(pos_x), float(pos_y), float(square_len), float(square_len)}, - Vector2{0, 0}, - 0.0f, - WHITE - ); - EndDrawing(); + EndTextureMode(); // matches PreRender + BeginDrawing(); + DrawTexturePro(target_.texture, + Rectangle{0, 0, float(target_.texture.width), + float(-target_.texture.height)}, + Rectangle{float(pos_x), float(pos_y), float(square_len), + float(square_len)}, + Vector2{0, 0}, 0.0f, WHITE); + EndDrawing(); // hardware rendering - } - else if (DISPLAY_TYPE == DeviceType::Hardware) - { - Image image = LoadImageFromTexture(target_.texture); - Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) - } + } else if (DISPLAY_TYPE == DeviceType::Hardware) { + Image image = LoadImageFromTexture(target_.texture); + Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) + } } // this code has really bad performance. keys often get stuck, // but for the purpose of being an emulator this is fine. -bool Interface:: PollEvent(Event& event) -{ - for (auto &[key, is_pressed] : keys_) { - if (IsKeyDown(key)) - { - if (is_pressed == false) - { - is_pressed = !is_pressed; - event.type = EventType::KeyPress; - event.value = key; - return true; - } - } - if (IsKeyUp(key)) { - if (is_pressed == true) - { - is_pressed = !is_pressed; - event.type = EventType::KeyRelease; - event.value = key; - return true; - } - } +bool Interface::PollEvent(Event& event) { + for (auto& [key, is_pressed] : keys_) { + if (IsKeyDown(key)) { + if (is_pressed == false) { + is_pressed = !is_pressed; + event.type = EventType::KeyPress; + event.value = key; + return true; + } } - - return false; -} + if (IsKeyUp(key)) { + if (is_pressed == true) { + is_pressed = !is_pressed; + event.type = EventType::KeyRelease; + event.value = key; + return true; + } + } + } -bool Interface::ShouldClose() const -{ - return WindowShouldClose(); + return false; } -} // namespace box +bool Interface::ShouldClose() const { return WindowShouldClose(); } + +} // namespace box diff --git a/src/core/plugin.cc b/src/core/plugin.cc index 84d6fa0..157c29b 100644 --- a/src/core/plugin.cc +++ b/src/core/plugin.cc @@ -2,27 +2,18 @@ namespace box { -Plugin:: Plugin(te::Plugin *p) -: plugin_{p} -{} +Plugin::Plugin(te::Plugin *p) : plugin_{p} {} -Plugin:: ~Plugin() -{ - plugin_->deleteFromParent(); -} +Plugin::~Plugin() { plugin_->deleteFromParent(); } -void Plugin:: EnsureTextureLoaded() const -{ - if (GetIcon().id == 0) { - Image icon = LoadImage(GetIconPath()); - GetIcon() = LoadTextureFromImage(icon); - UnloadImage(icon); - } +void Plugin::EnsureTextureLoaded() const { + if (GetIcon().id == 0) { + Image icon = LoadImage(GetIconPath()); + GetIcon() = LoadTextureFromImage(icon); + UnloadImage(icon); + } } -te::Plugin *const Plugin:: GetPlugin() const -{ - return plugin_; -} +te::Plugin *const Plugin::GetPlugin() const { return plugin_; } -} +} // namespace box diff --git a/src/core/plugin_selector.cc b/src/core/plugin_selector.cc index 1d7390a..ea4e80c 100644 --- a/src/core/plugin_selector.cc +++ b/src/core/plugin_selector.cc @@ -1,99 +1,84 @@ #include "core/plugin_selector.hh" -#include "core/app.hh" +#include "core/app.hh" #include "plugin/chorus.hh" -#include "plugin/four_osc.hh" #include "plugin/compressor.hh" #include "plugin/delay.hh" +#include "plugin/four_osc.hh" namespace box { -const std::vector PluginSelector:: PLUGIN_NAMES = { - te::FourOscPlugin::xmlTypeName, - te::ChorusPlugin::xmlTypeName, - te::CompressorPlugin::xmlTypeName, - te::DelayPlugin::xmlTypeName, - te::EqualiserPlugin::xmlTypeName, - te::PhaserPlugin::xmlTypeName, +const std::vector PluginSelector::PLUGIN_NAMES = { + te::FourOscPlugin::xmlTypeName, te::ChorusPlugin::xmlTypeName, + te::CompressorPlugin::xmlTypeName, te::DelayPlugin::xmlTypeName, + te::EqualiserPlugin::xmlTypeName, te::PhaserPlugin::xmlTypeName, te::ReverbPlugin::xmlTypeName, }; -void assert_index(std::vector v, size_t curr) -{ - if (curr >= v.size()) throw std::runtime_error{"PluginSelector index out of range: " + std::to_string(curr)}; +void assert_index(std::vector v, size_t curr) { + if (curr >= v.size()) + throw std::runtime_error{"PluginSelector index out of range: " + + std::to_string(curr)}; } -PluginSelector:: PluginSelector() -{ +PluginSelector::PluginSelector() {} -} - -void PluginSelector:: Render(Interface &interface) -{ - for (size_t i = 0; i < interface.HEIGHT / 8; i++) - { - if (i >= PLUGIN_NAMES.size()) break; - auto name = PLUGIN_NAMES[i]; - float x = 0; - float y = 16 * i; - float width = 128; - float height = 15; - Color color = RED; - if (current_index_ == i) - { - color = BLUE; - } - DrawRectangleRec(Rectangle{x, y, width, height}, DARKGRAY); - DrawText(name.c_str(), x, y, 5, color); +void PluginSelector::Render(Interface &interface) { + for (size_t i = 0; i < interface.HEIGHT / 8; i++) { + if (i >= PLUGIN_NAMES.size()) break; + auto name = PLUGIN_NAMES[i]; + float x = 0; + float y = 16 * i; + float width = 128; + float height = 15; + Color color = RED; + if (current_index_ == i) { + color = BLUE; } + DrawRectangleRec(Rectangle{x, y, width, height}, DARKGRAY); + DrawText(name.c_str(), x, y, 5, color); + } } -void PluginSelector:: HandleEvent(const Event &event) -{ - switch(event.type) - { +void PluginSelector::HandleEvent(const Event &event) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) - { + switch (event.value) { case KEY_ESCAPE: - APP->screen_state_ = App::ScreenState::Track; - break; + APP->screen_state_ = App::ScreenState::Track; + break; case KEY_K: - current_index_ = clamp_decrement(current_index_); - break; + current_index_ = clamp_decrement(current_index_); + break; case KEY_J: - current_index_ = std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); - break; - case KEY_ENTER: - // TODO proper back button? - APP->screen_state_ = App::ScreenState::Track; - const auto &name = PLUGIN_NAMES[current_index_]; + current_index_ = + std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); + break; + case KEY_ENTER: + // TODO proper back button? + APP->screen_state_ = App::ScreenState::Track; + const auto &name = PLUGIN_NAMES[current_index_]; - std::unique_ptr p; - auto base = APP->edit_.getPluginCache().createNewPlugin(name.c_str(), {}).get(); - // TODO use cast? - if (name == te::ChorusPlugin::xmlTypeName) - { - p = std::make_unique(base); - } - else if (name == te::FourOscPlugin::xmlTypeName) - { - p = std::make_unique(base); - } - else if (name == te::CompressorPlugin::xmlTypeName) - { - p = std::make_unique(base); - } - else if (name == te::DelayPlugin::xmlTypeName) - { - p = std::make_unique(base); - } + std::unique_ptr p; + auto base = APP->edit_.getPluginCache() + .createNewPlugin(name.c_str(), {}) + .get(); + // TODO use cast? + if (name == te::ChorusPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::FourOscPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::CompressorPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::DelayPlugin::xmlTypeName) { + p = std::make_unique(base); + } - APP->CurrTrack().AddPlugin(std::move(p)); - break; - } - break; - } + APP->CurrTrack().AddPlugin(std::move(p)); + break; + } + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/timeline.cc b/src/core/timeline.cc index ba0c8f2..1e834a6 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -1,225 +1,214 @@ #include "core/timeline.hh" + #include "core/app.hh" namespace box { -Timeline:: Timeline() -{ - { - Image tmp_l = LoadImage(METRONOME_PATH_L); - metronome_l_ = LoadTextureFromImage(tmp_l); - UnloadImage(tmp_l); - Image tmp_r = LoadImage(METRONOME_PATH_R); - metronome_r_ = LoadTextureFromImage(tmp_r); - UnloadImage(tmp_r); - Image tmp_off = LoadImage(METRONOME_PATH_OFF); - metronome_off_ = LoadTextureFromImage(tmp_off); - UnloadImage(tmp_off); - } +Timeline::Timeline() { + { + Image tmp_l = LoadImage(METRONOME_PATH_L); + metronome_l_ = LoadTextureFromImage(tmp_l); + UnloadImage(tmp_l); + Image tmp_r = LoadImage(METRONOME_PATH_R); + metronome_r_ = LoadTextureFromImage(tmp_r); + UnloadImage(tmp_r); + Image tmp_off = LoadImage(METRONOME_PATH_OFF); + metronome_off_ = LoadTextureFromImage(tmp_off); + UnloadImage(tmp_off); + } } -Timeline:: ~Timeline() -{ - UnloadTexture(metronome_l_); - UnloadTexture(metronome_r_); - UnloadTexture(metronome_off_); +Timeline::~Timeline() { + UnloadTexture(metronome_l_); + UnloadTexture(metronome_r_); + UnloadTexture(metronome_off_); } -void Timeline:: Render(Interface &interface) -{ - /* - terminology: - - row = the relative index of a track. - - so the top rectangle is always row 0, no matter what track it is - - track - - the actual "track" - */ - assert(is_close(frame_.radius, radius_)); - - const size_t num_rows = std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); - const size_t curr_row = APP->GetCurrTrack() - scroll_offset_; - - const te::TransportControl &transport = APP->edit_.getTransport(); - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - - const Position curr_pos = { - static_cast(APP->edit_.getTransport().getPosition().inSeconds()), - static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; - - BeatFrame screen{curr_pos.beats, radius_}; - - if (playhead_mode_ == PlayheadMode::Detached) - { - screen = frame_; +void Timeline::Render(Interface &interface) { + /* + terminology: + - row = the relative index of a track. + - so the top rectangle is always row 0, no matter what track it is + - track + - the actual "track" + */ + assert(is_close(frame_.radius, radius_)); + + const size_t num_rows = + std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); + const size_t curr_row = APP->GetCurrTrack() - scroll_offset_; + + const te::TransportControl &transport = APP->edit_.getTransport(); + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + + const Position curr_pos = { + static_cast(APP->edit_.getTransport().getPosition().inSeconds()), + static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; + + BeatFrame screen{curr_pos.beats, radius_}; + + if (playhead_mode_ == PlayheadMode::Detached) { + screen = frame_; + } + + assert(is_close(screen.radius, radius_)); + + // draw track outlines + for (size_t i = 0; i < num_rows; i++) { + float x = 0; + float y = (ROW_HEIGHT * i) + HEADER_HEIGHT; + DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, DARKGRAY); + } + + // render pos + { + auto text = format_time(curr_pos.secs); + + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), (SCREEN_HALF - text_size.x / 2), + (HEADER_HEIGHT / 2 - text_size.y / 2), HEADER_FONT_SIZE, WHITE); + } + + // render metronome + { + if (APP->edit_.clickTrackEnabled == true) { + const int beat = static_cast(curr_pos.beats); + if (beat % 2 == 0) { + DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + } else { + DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + } + } else { + DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } - - assert(is_close(screen.radius, radius_)); - - // draw track outlines - for (size_t i = 0; i < num_rows; i++) - { - float x = 0; - float y = (ROW_HEIGHT * i) + HEADER_HEIGHT; - DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, DARKGRAY); + } + + // render key offset + { + DrawRectangle(SCREEN_EIGHTH, 0, ICON_WIDTH, ICON_HEIGHT, YELLOW); + auto text = format_key_offset(APP->key_offset_); + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), SCREEN_EIGHTH + SCREEN_EIGHTH / 2 - text_size.x / 2, + HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, BLACK); + } + + // render cursor position + { + auto text = format_cursor_pos(APP->GetCurrTrack(), cursor_.LeftEdge()); + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x / 2, + HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, WHITE); + } + + // render bar lines + { + float first_bar_start = + std::floor(screen.LeftEdge() / bar_width_) * bar_width_; + + for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); + bar_start += bar_width_) { + float bar_position_pct = (bar_start - screen.LeftEdge()) / screen.Width(); + int x = static_cast(bar_position_pct * SCREEN_WIDTH); + DrawLine(x, HEADER_HEIGHT, x, HEADER_HEIGHT + (ROW_HEIGHT * num_rows), + DARKGRAY); } - - // render pos - { - auto text = format_time(curr_pos.secs); - - Vector2 text_size = MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), (SCREEN_HALF - text_size.x/2), (HEADER_HEIGHT/2 - text_size.y/2), HEADER_FONT_SIZE, WHITE); + } + + // render current live clip (if recording) + if (transport.isRecording()) { + const float start_time = + tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); + if (screen.LeftEdge() < start_time) { + float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); + float left_px = (left_pct * SCREEN_WIDTH); + DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, + (SCREEN_HALF - left_px), ROW_HEIGHT, RED); + } else { + DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, + (SCREEN_HALF - 0), ROW_HEIGHT, + RED); // 64 - 0 means full half bar } - - // render metronome - { - if (APP->edit_.clickTrackEnabled == true) - { - const int beat = static_cast(curr_pos.beats); - if (beat % 2 == 0) - { - DrawTexture(metronome_l_, SCREEN_EIGHTH/2 - ICON_RADIUS, HEADER_HEIGHT/2 - ICON_RADIUS, WHITE); - } - else - { - DrawTexture(metronome_r_, SCREEN_EIGHTH/2 - ICON_RADIUS, HEADER_HEIGHT/2 - ICON_RADIUS, WHITE); - } - } - else + } + + // render clips + { + for (size_t i = 0; i < num_rows; i++) { + const size_t track_idx = i + scroll_offset_; + const auto &t = APP->tracks_[track_idx]; + for (const auto &c : t->base_.getClips()) { + const te::ClipPosition c_pos = c->getPosition(); + te::BeatRange t_br = te::toBeats(c_pos.time, tempo); + BeatWindow clip = {static_cast(t_br.getStart().inBeats()), + static_cast(t_br.getLength().inBeats())}; + + // Determine overlap with visible range + const float visible_start = + std::max(screen.LeftEdge(), clip.LeftEdge()); + const float visible_end = + std::min(screen.RightEdge(), clip.RightEdge()); + + if (visible_start < visible_end) // Clip is visible { - DrawTexture(metronome_off_, SCREEN_EIGHTH/2 - ICON_RADIUS, HEADER_HEIGHT/2 - ICON_RADIUS, WHITE); - } - } - - // render key offset - { - DrawRectangle(SCREEN_EIGHTH, 0, ICON_WIDTH, ICON_HEIGHT, YELLOW); - auto text = format_key_offset(APP->key_offset_); - Vector2 text_size = MeasureTextEx( - GetFontDefault(), - text.c_str(), - HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText( - text.c_str(), - SCREEN_EIGHTH + SCREEN_EIGHTH/2 - text_size.x/2, - HEADER_HEIGHT/2 - text_size.y/2, - HEADER_FONT_SIZE, - BLACK); - } - - // render cursor position - { - auto text = format_cursor_pos(APP->GetCurrTrack(), cursor_.LeftEdge()); - Vector2 text_size = MeasureTextEx( - GetFontDefault(), - text.c_str(), - HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText( - text.c_str(), - SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x/2, - HEADER_HEIGHT/2 - text_size.y/2, - HEADER_FONT_SIZE, - WHITE); - } - - // render bar lines - { - float first_bar_start = std::floor(screen.LeftEdge() / bar_width_) * bar_width_; - - for (float bar_start = first_bar_start; - bar_start < screen.RightEdge(); - bar_start += bar_width_) - { - float bar_position_pct = (bar_start - screen.LeftEdge()) / screen.Width(); - int x = static_cast(bar_position_pct * SCREEN_WIDTH); - DrawLine(x, HEADER_HEIGHT, x, HEADER_HEIGHT + (ROW_HEIGHT * num_rows), DARKGRAY); - } - } - - // render current live clip (if recording) - if (transport.isRecording()) - { - const float start_time = tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); - if (screen.LeftEdge() < start_time) - { - float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); - float left_px = (left_pct * SCREEN_WIDTH); - DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - left_px), ROW_HEIGHT, RED); - } - else { - DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - 0), ROW_HEIGHT, RED); // 64 - 0 means full half bar - } - } - - // render clips - { - for (size_t i = 0; i < num_rows; i++) - { - const size_t track_idx = i + scroll_offset_; - const auto &t = APP->tracks_[track_idx]; - for (const auto &c : t->base_.getClips()) - { - const te::ClipPosition c_pos = c->getPosition(); - te::BeatRange t_br = te::toBeats(c_pos.time, tempo); - BeatWindow clip = { - static_cast(t_br.getStart().inBeats()), - static_cast(t_br.getLength().inBeats())}; - - // Determine overlap with visible range - const float visible_start = std::max(screen.LeftEdge(), clip.LeftEdge()); - const float visible_end = std::min(screen.RightEdge(), clip.RightEdge()); - - if (visible_start < visible_end) // Clip is visible - { - float start_pct = (visible_start - screen.LeftEdge()) / screen.Width(); - float end_pct = (visible_end - screen.LeftEdge()) / screen.Width(); - - const int left_px = static_cast(start_pct * SCREEN_WIDTH); - const int right_px = static_cast(end_pct * SCREEN_WIDTH); - int clip_width = right_px - left_px; - - DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, ROW_HEIGHT, GREEN); - DrawRectangleLines(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, ROW_HEIGHT, LIGHTGRAY); - } - } + float start_pct = + (visible_start - screen.LeftEdge()) / screen.Width(); + float end_pct = (visible_end - screen.LeftEdge()) / screen.Width(); + + const int left_px = static_cast(start_pct * SCREEN_WIDTH); + const int right_px = static_cast(end_pct * SCREEN_WIDTH); + int clip_width = right_px - left_px; + + DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, + ROW_HEIGHT, GREEN); + DrawRectangleLines(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, + clip_width, ROW_HEIGHT, LIGHTGRAY); } + } } - - // render active track - assert(curr_row < num_rows); - { - float x = 0; - float y = (ROW_HEIGHT * curr_row) + HEADER_HEIGHT; - DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, RED); - } - - - // render cursor - if (!transport.isRecording() && !transport.isPlaying()) - { - const float left_pct = (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); - const float right_pct = (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); - - const int left_px = static_cast(left_pct * SCREEN_WIDTH); - const int right_px = static_cast(right_pct * SCREEN_WIDTH); - const int width = right_px - left_px; - - DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, width, ROW_HEIGHT, ORANGE); - } - - // render playhead - { - if (screen.LeftEdge() < curr_pos.beats && - curr_pos.beats < screen.RightEdge()) - { - const float left_pct = (curr_pos.beats - screen.LeftEdge()) / screen.Width(); - const int left_px = static_cast(left_pct * SCREEN_WIDTH); - // -1 so that you can see the tick - DrawLine(left_px, HEADER_HEIGHT - 1, left_px, SCREEN_HEIGHT, WHITE); - } + } + + // render active track + assert(curr_row < num_rows); + { + float x = 0; + float y = (ROW_HEIGHT * curr_row) + HEADER_HEIGHT; + DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, RED); + } + + // render cursor + if (!transport.isRecording() && !transport.isPlaying()) { + const float left_pct = + (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); + const float right_pct = + (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); + + const int left_px = static_cast(left_pct * SCREEN_WIDTH); + const int right_px = static_cast(right_pct * SCREEN_WIDTH); + const int width = right_px - left_px; + + DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, width, + ROW_HEIGHT, ORANGE); + } + + // render playhead + { + if (screen.LeftEdge() < curr_pos.beats && + curr_pos.beats < screen.RightEdge()) { + const float left_pct = + (curr_pos.beats - screen.LeftEdge()) / screen.Width(); + const int left_px = static_cast(left_pct * SCREEN_WIDTH); + // -1 so that you can see the tick + DrawLine(left_px, HEADER_HEIGHT - 1, left_px, SCREEN_HEIGHT, WHITE); } + } } // TODO update? @@ -243,253 +232,235 @@ void Timeline:: Render(Interface &interface) // return false; // } -void Timeline:: print_timeline() -{ - std::cout << std::endl; - const auto &track = APP->CurrTrack().base_; - std::cout << "name: " << track.getName() << std::endl; - std::cout << "isMuted: " << track.isMuted(false) << std::endl; - std::cout << "isSolo: " << track.isSolo(false) << std::endl; - - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - const te::TransportControl &transport = APP->edit_.getTransport(); - const te::TimePosition &curr_time_pos = transport.getPosition(); - const te::BeatPosition &curr_beat_pos = te::toBeats(te::EditTime{transport.getPosition()}, tempo); - const te::TimeSigSetting &time_sig = tempo.getTimeSigAt(curr_time_pos); - - std::cout << "TIME curr position: " << curr_time_pos.inSeconds() << std::endl; - std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() << std::endl; - std::cout << "bpm: " << tempo.getBpmAt(curr_time_pos) << std::endl; - std::cout << "time signature: " << time_sig.getStringTimeSig() << std::endl; - std::cout << "time signature numerator: " << time_sig.numerator << std::endl; - std::cout << "time signature denominator: " << time_sig.denominator << std::endl; - - const auto clips = track.getClips(); - std::cout << "num clips: " << clips.size() << std::endl; - for (auto c : clips) - { - std::cout << "\t"<< "name: " << c->getName() << std::endl; - std::cout << "\t\t"<< "isMidi: " << c->isMidi() << std::endl; - const te::ClipPosition pos = c->getPosition(); - auto edit_range = te::EditTimeRange{pos.time}; - te::TimeRange time_range = te::toTime(edit_range, APP->edit_.tempoSequence); - te::BeatRange beat_range = te::toBeats(edit_range, APP->edit_.tempoSequence); - std::cout << "\t\t" << "TIME start: " << time_range.getStart().inSeconds() << std::endl; - std::cout << "\t\t" << "TIME end: " << time_range.getEnd().inSeconds() << std::endl; - std::cout << "\t\t" << "TIME length: " << pos.getLength().inSeconds() << std::endl; - std::cout << "\t\t" << "BEATS start: " << beat_range.getStart().inBeats() << std::endl; - std::cout << "\t\t" << "BEATS end: " << beat_range.getEnd().inBeats() << std::endl; - std::cout << "\t\t" << "BEATS length: " << beat_range.getLength().inBeats() << std::endl; - } +void Timeline::print_timeline() { + std::cout << std::endl; + const auto &track = APP->CurrTrack().base_; + std::cout << "name: " << track.getName() << std::endl; + std::cout << "isMuted: " << track.isMuted(false) << std::endl; + std::cout << "isSolo: " << track.isSolo(false) << std::endl; + + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + const te::TransportControl &transport = APP->edit_.getTransport(); + const te::TimePosition &curr_time_pos = transport.getPosition(); + const te::BeatPosition &curr_beat_pos = + te::toBeats(te::EditTime{transport.getPosition()}, tempo); + const te::TimeSigSetting &time_sig = tempo.getTimeSigAt(curr_time_pos); + + std::cout << "TIME curr position: " << curr_time_pos.inSeconds() << std::endl; + std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() << std::endl; + std::cout << "bpm: " << tempo.getBpmAt(curr_time_pos) << std::endl; + std::cout << "time signature: " << time_sig.getStringTimeSig() << std::endl; + std::cout << "time signature numerator: " << time_sig.numerator << std::endl; + std::cout << "time signature denominator: " << time_sig.denominator + << std::endl; + + const auto clips = track.getClips(); + std::cout << "num clips: " << clips.size() << std::endl; + for (auto c : clips) { + std::cout << "\t" << "name: " << c->getName() << std::endl; + std::cout << "\t\t" << "isMidi: " << c->isMidi() << std::endl; + const te::ClipPosition pos = c->getPosition(); + auto edit_range = te::EditTimeRange{pos.time}; + te::TimeRange time_range = te::toTime(edit_range, APP->edit_.tempoSequence); + te::BeatRange beat_range = + te::toBeats(edit_range, APP->edit_.tempoSequence); + std::cout << "\t\t" << "TIME start: " << time_range.getStart().inSeconds() + << std::endl; + std::cout << "\t\t" << "TIME end: " << time_range.getEnd().inSeconds() + << std::endl; + std::cout << "\t\t" << "TIME length: " << pos.getLength().inSeconds() + << std::endl; + std::cout << "\t\t" << "BEATS start: " << beat_range.getStart().inBeats() + << std::endl; + std::cout << "\t\t" << "BEATS end: " << beat_range.getEnd().inBeats() + << std::endl; + std::cout << "\t\t" << "BEATS length: " << beat_range.getLength().inBeats() + << std::endl; + } } -void Timeline:: FocusCursor() -{ - assert(cursor_.len < frame_.Width()); - if (cursor_.LeftEdge() < frame_.LeftEdge()) - { - const float diff = frame_.LeftEdge() - cursor_.LeftEdge(); - frame_.center -= diff; - } - else if (cursor_.RightEdge() > frame_.RightEdge()) - { - const float diff = cursor_.RightEdge() - frame_.RightEdge(); - frame_.center += diff; - } +void Timeline::FocusCursor() { + assert(cursor_.len < frame_.Width()); + if (cursor_.LeftEdge() < frame_.LeftEdge()) { + const float diff = frame_.LeftEdge() - cursor_.LeftEdge(); + frame_.center -= diff; + } else if (cursor_.RightEdge() > frame_.RightEdge()) { + const float diff = cursor_.RightEdge() - frame_.RightEdge(); + frame_.center += diff; + } } -void Timeline:: HandleEvent(const Event &event) -{ - switch (screen_state_) - { +void Timeline::HandleEvent(const Event &event) { + switch (screen_state_) { case ScreenState::Overview: - switch (event.type) - { + switch (event.type) { case EventType::KeyPress: - switch (event.value) - { + switch (event.value) { case KEY_ENTER: - APP->screen_state_ = App::ScreenState::Track; - break; + APP->screen_state_ = App::ScreenState::Track; + break; case KEY_H: - cursor_.start -= step_size_; - LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge()); - FocusCursor(); - break; + cursor_.start -= step_size_; + LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge()); + FocusCursor(); + break; case KEY_L: - cursor_.start += step_size_; - LOG_VAR(cursor_.RightEdge() > frame_.RightEdge()); - FocusCursor(); - break; + cursor_.start += step_size_; + LOG_VAR(cursor_.RightEdge() > frame_.RightEdge()); + FocusCursor(); + break; case KEY_J: - if (!APP->edit_.getTransport().isRecording()) - { - APP->SetCurrTrack( - clamp_increment(APP->GetCurrTrack(), APP->tracks_.size())); - if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) - { - scroll_offset_ = clamp_increment(scroll_offset_, APP->tracks_.size()); - } + if (!APP->edit_.getTransport().isRecording()) { + APP->SetCurrTrack( + clamp_increment(APP->GetCurrTrack(), APP->tracks_.size())); + if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) { + scroll_offset_ = + clamp_increment(scroll_offset_, APP->tracks_.size()); } - break; + } + break; case KEY_K: - if (!APP->edit_.getTransport().isRecording()) - { - APP->SetCurrTrack(clamp_decrement(APP->GetCurrTrack())); - if (APP->GetCurrTrack() < scroll_offset_) - { - scroll_offset_ = clamp_decrement(scroll_offset_); - } + if (!APP->edit_.getTransport().isRecording()) { + APP->SetCurrTrack(clamp_decrement(APP->GetCurrTrack())); + if (APP->GetCurrTrack() < scroll_offset_) { + scroll_offset_ = clamp_decrement(scroll_offset_); } - break; + } + break; case KEY_UP: - scroll_offset_ = clamp_decrement(scroll_offset_); - break; + scroll_offset_ = clamp_decrement(scroll_offset_); + break; case KEY_DOWN: - scroll_offset_ = clamp_increment(scroll_offset_, APP->tracks_.size()); - break; - case KEY_O: // add track - if (APP->tracks_.size() < MAX_TRACKS) - { - APP->AddTrack(); - } - break; - case KEY_W: - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.RightEdge())); - - te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) - { - LOG_MSG("KEY_W found NONE"); - } - else - { - if (auto clip = dynamic_cast(item)) - { - cursor_.start = clip->getStartBeat().inBeats(); - FocusCursor(); - } - } + scroll_offset_ = + clamp_increment(scroll_offset_, APP->tracks_.size()); + break; + case KEY_O: // add track + if (APP->tracks_.size() < MAX_TRACKS) { + APP->AddTrack(); + } + break; + case KEY_W: { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + auto pos = tempo.toTime( + te::BeatPosition::fromBeats(cursor_.RightEdge())); + + te::TrackItem *item = + APP->CurrTrack().base_.getNextTrackItemAt(pos); + if (item == nullptr) { + LOG_MSG("KEY_W found NONE"); + } else { + if (auto clip = dynamic_cast(item)) { + cursor_.start = clip->getStartBeat().inBeats(); + FocusCursor(); } - break; - case KEY_D: - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); - - te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) - { - LOG_MSG("KEY_D found NONE"); - } - else - { - LOG_MSG("deleting item of type:"); - LOG_MSG(te::TrackItem::typeToString(item->type)); - if (auto clip = dynamic_cast(item)) - { - clip->removeFromParent(); - } - } + } + } break; + case KEY_D: { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + auto pos = + tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); + + te::TrackItem *item = + APP->CurrTrack().base_.getNextTrackItemAt(pos); + if (item == nullptr) { + LOG_MSG("KEY_D found NONE"); + } else { + LOG_MSG("deleting item of type:"); + LOG_MSG(te::TrackItem::typeToString(item->type)); + if (auto clip = dynamic_cast(item)) { + clip->removeFromParent(); } - break; + } + } break; case KEY_P: - print_timeline(); - LOG_VAR(frame_.center); - break; + print_timeline(); + LOG_VAR(frame_.center); + break; case KEY_C: - // toggle metronome - APP->edit_.clickTrackEnabled = !APP->edit_.clickTrackEnabled; - break; - case KEY_R: - { - auto &transport = APP->edit_.getTransport(); - LOG_VAR(transport.getPosition().inSeconds()); - LOG_VAR(transport.isRecording()); - if (transport.isRecording()) - { - transport.stop(false, false); // TODO should this discard? - te::EditFileOperations (APP->edit_).save(true, true, false); - playhead_mode_ = PlayheadMode::Detached; - - { - const float curr_pos = APP->edit_.tempoSequence.toBeats(transport.getPosition()).inBeats(); - cursor_.start = std::floor(curr_pos/bar_width_) * bar_width_; - frame_.center = curr_pos; - } - assert_multiple(cursor_.start, bar_width_); - } - else - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime(te::BeatPosition::fromBeats(cursor_.LeftEdge()))); - transport.record(false); - playhead_mode_ = PlayheadMode::Locked; - } - } - break; - case KEY_T: - { - auto &transport = APP->edit_.getTransport(); - if (transport.isPlaying()) - { - transport.stop(false, false); // TODO should this discard? - playhead_mode_ = PlayheadMode::Detached; - - { - const float curr_pos = APP->edit_.tempoSequence.toBeats(transport.getPosition()).inBeats(); - cursor_.start = std::floor(curr_pos/bar_width_) * bar_width_; - frame_.center = curr_pos; - } - assert_multiple(cursor_.start, bar_width_); - } - else - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime(te::BeatPosition::fromBeats(cursor_.LeftEdge()))); - transport.play(false); - playhead_mode_ = PlayheadMode::Locked; - } - } - break; - case KEY_S: - { - LOG_MSG("move to origin"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds(0.f)); - cursor_.start = 0; - frame_.center = 0; - } - break; - case KEY_COMMA: + // toggle metronome + APP->edit_.clickTrackEnabled = !APP->edit_.clickTrackEnabled; + break; + case KEY_R: { + auto &transport = APP->edit_.getTransport(); + LOG_VAR(transport.getPosition().inSeconds()); + LOG_VAR(transport.isRecording()); + if (transport.isRecording()) { + transport.stop(false, false); // TODO should this discard? + te::EditFileOperations(APP->edit_).save(true, true, false); + playhead_mode_ = PlayheadMode::Detached; + { - LOG_MSG("move left"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds(transport.getPosition().inSeconds() - 2.f)); + const float curr_pos = + APP->edit_.tempoSequence.toBeats(transport.getPosition()) + .inBeats(); + cursor_.start = + std::floor(curr_pos / bar_width_) * bar_width_; + frame_.center = curr_pos; } - break; - case KEY_PERIOD: + assert_multiple(cursor_.start, bar_width_); + } else { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + transport.setPosition(tempo.toTime( + te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.record(false); + playhead_mode_ = PlayheadMode::Locked; + } + } break; + case KEY_T: { + auto &transport = APP->edit_.getTransport(); + if (transport.isPlaying()) { + transport.stop(false, false); // TODO should this discard? + playhead_mode_ = PlayheadMode::Detached; + { - LOG_MSG("move right"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds(transport.getPosition().inSeconds() + 2.f)); + const float curr_pos = + APP->edit_.tempoSequence.toBeats(transport.getPosition()) + .inBeats(); + cursor_.start = + std::floor(curr_pos / bar_width_) * bar_width_; + frame_.center = curr_pos; } - break; + assert_multiple(cursor_.start, bar_width_); + } else { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + transport.setPosition(tempo.toTime( + te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.play(false); + playhead_mode_ = PlayheadMode::Locked; + } + } break; + case KEY_S: { + LOG_MSG("move to origin"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds(0.f)); + cursor_.start = 0; + frame_.center = 0; + } break; + case KEY_COMMA: { + LOG_MSG("move left"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds( + transport.getPosition().inSeconds() - 2.f)); + } break; + case KEY_PERIOD: { + LOG_MSG("move right"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds( + transport.getPosition().inSeconds() + 2.f)); + } break; case KEY_MINUS: - radius_ *= 2; - frame_.radius *= 2; // TODO centralize this - break; + radius_ *= 2; + frame_.radius *= 2; // TODO centralize this + break; case KEY_EQUAL: - radius_ /= 2; - frame_.radius /= 2; // TODO centralize this - break; - } - break; - } - break; - } + radius_ /= 2; + frame_.radius /= 2; // TODO centralize this + break; + } + break; + } + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/track.cc b/src/core/track.cc index c52b628..004d5ba 100644 --- a/src/core/track.cc +++ b/src/core/track.cc @@ -1,181 +1,168 @@ #include "core/track.hh" -#include "core/util.hh" -#include "core/app.hh" + #include +#include "core/app.hh" +#include "core/util.hh" + namespace box { -static void assert_plugins(const std::vector> &plugins, int index, std::string function_name) -{ - if (index >= plugins.size()) - { - throw std::runtime_error{"Track::" + function_name + " => index ["+ std::to_string(index) + "] out of range: [0, " + std::to_string(plugins.size()) + "]"}; - } +static void assert_plugins(const std::vector>& plugins, + int index, std::string function_name) { + if (index >= plugins.size()) { + throw std::runtime_error{"Track::" + function_name + " => index [" + + std::to_string(index) + "] out of range: [0, " + + std::to_string(plugins.size()) + "]"}; + } } -Track:: Track(te::AudioTrack &base): base_{base} -{ -} +Track::Track(te::AudioTrack& base) : base_{base} {} -Track:: ~Track() -{ -} +Track::~Track() {} -void Track:: AddPlugin(std::unique_ptr plugin) -{ - if (active_plugin_ == -1) active_plugin_ = 0; // TODO better way to handle this - int index = plugins_.size(); - base_.pluginList.insertPlugin(plugin->GetPlugin(), index, nullptr); - plugins_.push_back(std::move(plugin)); +void Track::AddPlugin(std::unique_ptr plugin) { + if (active_plugin_ == -1) + active_plugin_ = 0; // TODO better way to handle this + int index = plugins_.size(); + base_.pluginList.insertPlugin(plugin->GetPlugin(), index, nullptr); + plugins_.push_back(std::move(plugin)); } -void Track:: RemoveActivePlugin() -{ - if (plugins_.size() == 0) - { - LOG_MSG("tried to remove plugin from empty track", LogLevel::Warn); - return; - } - if (active_plugin_ == -1) - { - LOG_MSG("tried to remove active_plugin == -1", LogLevel::Warn); - return; - } - plugins_.erase(plugins_.begin() + active_plugin_); - // TODO check for underflow messing up min - active_plugin_ = std::min(active_plugin_, static_cast(plugins_.size()) - 1); +void Track::RemoveActivePlugin() { + if (plugins_.size() == 0) { + LOG_MSG("tried to remove plugin from empty track", LogLevel::Warn); + return; + } + if (active_plugin_ == -1) { + LOG_MSG("tried to remove active_plugin == -1", LogLevel::Warn); + return; + } + plugins_.erase(plugins_.begin() + active_plugin_); + // TODO check for underflow messing up min + active_plugin_ = + std::min(active_plugin_, static_cast(plugins_.size()) - 1); } -void Track:: SetActivePlugin(int index) -{ - active_plugin_ = index; -} +void Track::SetActivePlugin(int index) { active_plugin_ = index; } -int Track:: GetActivePlugin() -{ - return active_plugin_; -} +int Track::GetActivePlugin() { return active_plugin_; } -int clamp_index(int i, int len) -{ - int range = len ; - int val = i % range; - if (val < 0) val += range; - return val; +int clamp_index(int i, int len) { + int range = len; + int val = i % range; + if (val < 0) val += range; + return val; } -void Track:: HandleEvent(const Event& event) -{ - switch (screen_state_) - { +void Track::HandleEvent(const Event& event) { + switch (screen_state_) { case ScreenState::Overview: - switch (APP->mode_) - { + switch (APP->mode_) { case App::Mode::Normal: - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) - { + switch (event.value) { case KEY_ESCAPE: - APP->screen_state_ = App::ScreenState::Timeline; - break; + APP->screen_state_ = App::ScreenState::Timeline; + break; case KEY_A: - APP->screen_state_ = App::ScreenState::PluginSelector; - break; + APP->screen_state_ = App::ScreenState::PluginSelector; + break; case KEY_X: - RemoveActivePlugin(); - break; - case KEY_P: - { - auto l = base_.pluginList.getPlugins(); - for (auto p : l) - { - std::cout << p->getName() << ", "; - } - std::cout << std::endl; - } - break; + RemoveActivePlugin(); + break; + case KEY_P: { + auto l = base_.pluginList.getPlugins(); + for (auto p : l) { + std::cout << p->getName() << ", "; + } + std::cout << std::endl; + } break; // TODO KEY_J and KEY_K move up and down case KEY_H: - LOG_MSG("left"); - active_plugin_ = clamp_index(active_plugin_ - 1, plugins_.size()); - LOG_VAR(active_plugin_); - break; + LOG_MSG("left"); + active_plugin_ = + clamp_index(active_plugin_ - 1, plugins_.size()); + LOG_VAR(active_plugin_); + break; case KEY_L: - LOG_MSG("right"); - active_plugin_ = clamp_index(active_plugin_ + 1, plugins_.size()); - LOG_VAR(active_plugin_); - break; + LOG_MSG("right"); + active_plugin_ = + clamp_index(active_plugin_ + 1, plugins_.size()); + LOG_VAR(active_plugin_); + break; case KEY_ENTER: - // TODO sketchy - if (active_plugin_ != -1) screen_state_ = ScreenState::Plugin; - break; - } - break; - } - break; + // TODO sketchy + if (active_plugin_ != -1) screen_state_ = ScreenState::Plugin; + break; + } + break; + } + break; case App::Mode::Insert: - break; - } - break; + break; + } + break; case ScreenState::Plugin: - if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) - { - screen_state_ = ScreenState::Overview; - return; - } - switch (APP->mode_) - { + if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) { + screen_state_ = ScreenState::Overview; + return; + } + switch (APP->mode_) { case App::Mode::Normal: - plugins_[active_plugin_]->HandleEvent(event); - break; + plugins_[active_plugin_]->HandleEvent(event); + break; case App::Mode::Insert: - break; - } - break; - } + break; + } + break; + } } -void Track:: Render(Interface& interface) -{ - switch (screen_state_) - { - case ScreenState::Overview: - // draw grid - for (int i = 1; i < GRID_SIZE; i++) - { - float pos = static_cast(i); - DrawLineV(Vector2{0, pos * 32}, Vector2{128, pos * 32}, WHITE); - DrawLineV(Vector2{pos * 32, 0}, Vector2{pos * 32, 128}, WHITE); - } - - for (int i = 0; i < plugins_.size(); i++) - { - auto x = static_cast((i % 4) * 32 + 16); - auto y = static_cast((i / 4) * 32 + 64 + 16); - DrawTexture(plugins_[i]->GetIcon(), x - 8, y - 8, WHITE); - - constexpr int font_size = 10; - int width = MeasureText(plugins_[i]->GetName(), font_size); - DrawText(plugins_[i]->GetName(), (x - width/2), y + 6, font_size, WHITE); - - if (i == active_plugin_) - { - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, 5.0f, GREEN); - } - } - for (int i = plugins_.size(); i < MAX_PLUGINS; i++) - { - auto x = static_cast((i % 4) * 32 + 16); - auto y = static_cast((i / 4) * 32 + 64 + 16); - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, 1.0f, RED); - DrawTextPro(GetFontDefault(), "none", Vector2{x, y}, Vector2{11, -4,}, 0.0f, 10.0f, 1.0f, WHITE); - } - break; - case ScreenState::Plugin: - plugins_[active_plugin_]->Render(interface); - break; - } +void Track::Render(Interface& interface) { + switch (screen_state_) { + case ScreenState::Overview: + // draw grid + for (int i = 1; i < GRID_SIZE; i++) { + float pos = static_cast(i); + DrawLineV(Vector2{0, pos * 32}, Vector2{128, pos * 32}, WHITE); + DrawLineV(Vector2{pos * 32, 0}, Vector2{pos * 32, 128}, WHITE); + } + + for (int i = 0; i < plugins_.size(); i++) { + auto x = static_cast((i % 4) * 32 + 16); + auto y = static_cast((i / 4) * 32 + 64 + 16); + DrawTexture(plugins_[i]->GetIcon(), x - 8, y - 8, WHITE); + + constexpr int font_size = 10; + int width = MeasureText(plugins_[i]->GetName(), font_size); + DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, + WHITE); + + if (i == active_plugin_) { + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, + static_cast(i / 4) * 32 + 64 + 16}, + 5.0f, GREEN); + } + } + for (int i = plugins_.size(); i < MAX_PLUGINS; i++) { + auto x = static_cast((i % 4) * 32 + 16); + auto y = static_cast((i / 4) * 32 + 64 + 16); + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, + static_cast(i / 4) * 32 + 64 + 16}, + 1.0f, RED); + DrawTextPro(GetFontDefault(), "none", Vector2{x, y}, + Vector2{ + 11, + -4, + }, + 0.0f, 10.0f, 1.0f, WHITE); + } + break; + case ScreenState::Plugin: + plugins_[active_plugin_]->Render(interface); + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/util.cc b/src/core/util.cc index 295f0ac..04fda33 100644 --- a/src/core/util.cc +++ b/src/core/util.cc @@ -4,100 +4,92 @@ namespace box { App* APP = nullptr; // Define the global APP variable -void assert_multiple(float a, float b) -{ - const float epsilon = 1e-6; // Small tolerance for floating-point precision - assert(std::fabs(std::fmod(a, b)) < epsilon && "a is not a multiple of b"); +void assert_multiple(float a, float b) { + const float epsilon = 1e-6; // Small tolerance for floating-point precision + assert(std::fabs(std::fmod(a, b)) < epsilon && "a is not a multiple of b"); } -bool is_close(float a, float b) -{ - return std::abs(a - b) < 1e-6; -} +bool is_close(float a, float b) { return std::abs(a - b) < 1e-6; } std::string format_time(float time) { - int minutes = static_cast(time) / 60; - int seconds = static_cast(time) % 60; - int decimal = static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places + int minutes = static_cast(time) / 60; + int seconds = static_cast(time) % 60; + int decimal = + static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places - std::ostringstream oss; - oss << std::setw(2) << std::setfill('0') << minutes << "." - << std::setw(2) << std::setfill('0') << seconds << "." - << std::setw(2) << std::setfill('0') << decimal; + std::ostringstream oss; + oss << std::setw(2) << std::setfill('0') << minutes << "." << std::setw(2) + << std::setfill('0') << seconds << "." << std::setw(2) + << std::setfill('0') << decimal; - return oss.str(); + return oss.str(); } std::string format_key_offset(int key_offset) { - if (key_offset > 0) - return "+" + std::to_string(key_offset); - else - return std::to_string(key_offset); + if (key_offset > 0) + return "+" + std::to_string(key_offset); + else + return std::to_string(key_offset); } -std::string format_cursor_pos(size_t track_pos, float cursor_pos) -{ - std::ostringstream oss; - oss << std::setw(1) << track_pos << ":" - << std::setw(3) << std::setfill('0') << cursor_pos; - return oss.str(); +std::string format_cursor_pos(size_t track_pos, float cursor_pos) { + std::ostringstream oss; + oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') + << cursor_pos; + return oss.str(); } -size_t clamp_decrement(size_t x) -{ - if (x == 0) return 0; - else return x - 1; +size_t clamp_decrement(size_t x) { + if (x == 0) + return 0; + else + return x - 1; } -size_t clamp_increment(size_t x, size_t max) -{ - return std::min(x + 1, clamp_decrement(max)); +size_t clamp_increment(size_t x, size_t max) { + return std::min(x + 1, clamp_decrement(max)); } -LogLevel string_to_loglevel(const std::string& s) -{ - if (s == "OFF") return LogLevel::Off; - if (s == "DEBUG") return LogLevel::Debug; - if (s == "WARN") return LogLevel::Warn; - if (s == "ERR") return LogLevel::Err; - throw std::runtime_error{"string_to_loglevel(" + s + ") not found"}; +LogLevel string_to_loglevel(const std::string& s) { + if (s == "OFF") return LogLevel::Off; + if (s == "DEBUG") return LogLevel::Debug; + if (s == "WARN") return LogLevel::Warn; + if (s == "ERR") return LogLevel::Err; + throw std::runtime_error{"string_to_loglevel(" + s + ") not found"}; } -std::string loglevel_to_string(LogLevel l) -{ - if (l == LogLevel::Off) return "OFF"; - if (l == LogLevel::Debug) return "DEBUG"; - if (l == LogLevel::Warn) return "WARN"; - if (l == LogLevel::Err) return "ERR"; - throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + ") not found"}; +std::string loglevel_to_string(LogLevel l) { + if (l == LogLevel::Off) return "OFF"; + if (l == LogLevel::Debug) return "DEBUG"; + if (l == LogLevel::Warn) return "WARN"; + if (l == LogLevel::Err) return "ERR"; + throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + + ") not found"}; } // get loglevel from env -LogLevel get_loglevel() -{ - const char* env = std::getenv("BOX_LOG"); - if (env) - { - return string_to_loglevel(env); - } - return LogLevel::Off; // default +LogLevel get_loglevel() { + const char* env = std::getenv("BOX_LOG"); + if (env) { + return string_to_loglevel(env); + } + return LogLevel::Off; // default } -void LOG_MSG(const std::string& msg, LogLevel l) -{ - static LogLevel curr = get_loglevel(); - - if (l < curr) - { - return; - } - // get time - std::time_t now = std::time(nullptr); - char buf[20]; - std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); - - // print - std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg << std::endl; +void LOG_MSG(const std::string& msg, LogLevel l) { + static LogLevel curr = get_loglevel(); + + if (l < curr) { + return; + } + // get time + std::time_t now = std::time(nullptr); + char buf[20]; + std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); + + // print + std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg + << std::endl; } -} // namespace box +} // namespace box diff --git a/src/main.cc b/src/main.cc index 78cf8d1..3a26bea 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,75 +1,61 @@ -#include #include +#include -#include "core/util.hh" -#include "core/interface.hh" #include "core/app.hh" - +#include "core/interface.hh" +#include "core/util.hh" #include "raylib.h" +int main() { + const juce::ScopedJuceInitialiser_GUI initialiser; // need this + SetTargetFPS(60); -int main() -{ - const juce::ScopedJuceInitialiser_GUI initialiser; // need this - SetTargetFPS(60); - - te::Engine engine{"Tracktion Hello World"}; - std::filesystem::path curr_path = std::filesystem::current_path(); - juce::File my_file {juce::String{curr_path.string() + "/tmp.box"}}; + te::Engine engine{"Tracktion Hello World"}; + std::filesystem::path curr_path = std::filesystem::current_path(); + juce::File my_file{juce::String{curr_path.string() + "/tmp.box"}}; - std::unique_ptr my_edit = createEmptyEdit(engine, my_file); - te::Edit &edit = *my_edit; - edit.ensureNumberOfAudioTracks(8); - edit.getTransport().ensureContextAllocated(); - box::Interface interface{}; + std::unique_ptr my_edit = createEmptyEdit(engine, my_file); + te::Edit &edit = *my_edit; + edit.ensureNumberOfAudioTracks(8); + edit.getTransport().ensureContextAllocated(); + box::Interface interface{}; - box::App app(engine, edit); - box::APP = &app; + box::App app(engine, edit); + box::APP = &app; - try + try { + // arm { - // arm - { - auto& dm = engine.getDeviceManager(); - - for (int i = 0; i < dm.getNumWaveInDevices(); i++) - { - if (auto wip = dm.getWaveInDevice(i)) - { - wip->setStereoPair(false); - // wip->setEndToEnd(true); // TODO update ? - wip->setEnabled(true); - } - else if (auto mip = dm.getMidiInDevice(i)) - { - // mip->setEndToEndEnabled(true); // TODO update ? - mip->setEnabled(true); - } - } + auto &dm = engine.getDeviceManager(); + + for (int i = 0; i < dm.getNumWaveInDevices(); i++) { + if (auto wip = dm.getWaveInDevice(i)) { + wip->setStereoPair(false); + // wip->setEndToEnd(true); // TODO update ? + wip->setEnabled(true); + } else if (auto mip = dm.getMidiInDevice(i)) { + // mip->setEndToEndEnabled(true); // TODO update ? + mip->setEnabled(true); } + } + } - while (!interface.ShouldClose()) - { - // poll and handle events - box::Event event; - if (interface.PollEvent(event)) - { - app.HandleEvent(event); - } + while (!interface.ShouldClose()) { + // poll and handle events + box::Event event; + if (interface.PollEvent(event)) { + app.HandleEvent(event); + } - interface.PreRender(); + interface.PreRender(); - // do rendering - { - app.Render(interface); - } + // do rendering + { app.Render(interface); } - interface.PostRender(); - } - } - catch (std::exception &e) - { - std::cerr << e.what() << std::endl; + interface.PostRender(); } - return 0; + } catch (std::exception &e) { + std::cerr << e.what() << std::endl; + } + return 0; } diff --git a/src/plugin/chorus.cc b/src/plugin/chorus.cc index 3b0b518..7530d36 100644 --- a/src/plugin/chorus.cc +++ b/src/plugin/chorus.cc @@ -1,4 +1,5 @@ #include "plugin/chorus.hh" + #include "core/cv.hh" namespace box { @@ -6,115 +7,92 @@ namespace box { Texture2D Chorus::icon_; // Define the static member Chorus::Chorus(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, - knob_depth_{ - Parameter{CV{base_plugin_->depthMs, 0.0, 10.0}}, - 32, // x - 22, // y - 16, // radius - GREEN, - "depth" - }, - knob_width_{ - Parameter{CV{base_plugin_->width, 0.0, 1.0}}, - 96, // x - 22, // y - 16, // radius - RED, - "width" - }, - knob_speed_{ - Parameter{CV{base_plugin_->speedHz, 0.0, 10.0}}, - 32, // x - 86, // y - 16, // radius - BLUE, - "speed" - }, - knob_mix_{ - Parameter{CV{base_plugin_->mixProportion, 0.0, 1.0}}, - 96, // x - 86, // y - 16, // radius - YELLOW, - "mix" - } -{ - EnsureTextureLoaded(); + : Plugin(p), + base_plugin_{static_cast(p)}, + knob_depth_{Parameter{CV{base_plugin_->depthMs, 0.0, 10.0}}, + 32, // x + 22, // y + 16, // radius + GREEN, + "depth"}, + knob_width_{Parameter{CV{base_plugin_->width, 0.0, 1.0}}, + 96, // x + 22, // y + 16, // radius + RED, + "width"}, + knob_speed_{Parameter{CV{base_plugin_->speedHz, 0.0, 10.0}}, + 32, // x + 86, // y + 16, // radius + BLUE, + "speed"}, + knob_mix_{ + Parameter{CV{base_plugin_->mixProportion, 0.0, 1.0}}, + 96, // x + 86, // y + 16, // radius + YELLOW, + "mix"} { + EnsureTextureLoaded(); } -Chorus:: ~Chorus() -{ - UnloadTexture(icon_); -} +Chorus::~Chorus() { UnloadTexture(icon_); } -Texture2D &Chorus:: GetIcon() const -{ - return icon_; -} +Texture2D &Chorus::GetIcon() const { return icon_; } -const char *Chorus::GetIconPath() const -{ - return icon_path_; -} +const char *Chorus::GetIconPath() const { return icon_path_; } -const char *Chorus::GetName() const -{ - return name_; -} +const char *Chorus::GetName() const { return name_; } -void Chorus::Render(Interface &interface) -{ - knob_depth_.Render(interface); - knob_width_.Render(interface); - knob_speed_.Render(interface); - knob_mix_.Render(interface); +void Chorus::Render(Interface &interface) { + knob_depth_.Render(interface); + knob_width_.Render(interface); + knob_speed_.Render(interface); + knob_mix_.Render(interface); } -void Chorus::HandleEvent(const Event &event) -{ - switch (event.type) - { +void Chorus::HandleEvent(const Event &event) { + switch (event.type) { case EventType::KeyPress: - switch(event.value) - { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() - 0.125); + break; case KEY_TWO: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() + 0.125); + break; case KEY_SEVEN: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); + break; case KEY_EIGHT: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/compressor.cc b/src/plugin/compressor.cc index 24a8123..2e9e364 100644 --- a/src/plugin/compressor.cc +++ b/src/plugin/compressor.cc @@ -1,4 +1,5 @@ #include "plugin/compressor.hh" + #include "core/cv.hh" namespace box { @@ -6,115 +7,93 @@ namespace box { Texture2D Compressor::icon_; // Define the static member Compressor::Compressor(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, - knob_threshold_{ - Parameter{base_plugin_->thresholdGain.parameter}, - 32, // x - 22, // y - 16, // radius - GREEN, - "threshold" - }, - knob_ratio_{ - Parameter{base_plugin_->ratio.parameter}, - 96, // x - 22, // y - 16, // radius - RED, - "ratio" - }, - knob_attack_{ - Parameter{base_plugin_->attackMs.parameter}, - 32, // x - 86, // y - 16, // radius - BLUE, - "attack" - }, - knob_release_{ - Parameter{base_plugin_->releaseMs.parameter}, - 96, // x - 86, // y - 16, // radius - YELLOW, - "release" - } -{ - EnsureTextureLoaded(); + : Plugin(p), + base_plugin_{static_cast(p)}, + knob_threshold_{Parameter{base_plugin_->thresholdGain.parameter}, + 32, // x + 22, // y + 16, // radius + GREEN, + "threshold"}, + knob_ratio_{Parameter{base_plugin_->ratio.parameter}, + 96, // x + 22, // y + 16, // radius + RED, + "ratio"}, + knob_attack_{Parameter{base_plugin_->attackMs.parameter}, + 32, // x + 86, // y + 16, // radius + BLUE, + "attack"}, + knob_release_{Parameter{base_plugin_->releaseMs.parameter}, + 96, // x + 86, // y + 16, // radius + YELLOW, + "release"} { + EnsureTextureLoaded(); } -Compressor:: ~Compressor() -{ - UnloadTexture(icon_); -} +Compressor::~Compressor() { UnloadTexture(icon_); } -Texture2D &Compressor:: GetIcon() const -{ - return icon_; -} +Texture2D &Compressor::GetIcon() const { return icon_; } -const char *Compressor:: GetIconPath() const -{ - return icon_path_; -} +const char *Compressor::GetIconPath() const { return icon_path_; } -const char *Compressor::GetName() const -{ - return name_; -} +const char *Compressor::GetName() const { return name_; } -void Compressor::Render(Interface &interface) -{ - knob_threshold_.Render(interface); - knob_ratio_.Render(interface); - knob_attack_.Render(interface); - knob_release_.Render(interface); +void Compressor::Render(Interface &interface) { + knob_threshold_.Render(interface); + knob_ratio_.Render(interface); + knob_attack_.Render(interface); + knob_release_.Render(interface); } -void Compressor::HandleEvent(const Event &event) -{ - switch (event.type) - { +void Compressor::HandleEvent(const Event &event) { + switch (event.type) { case EventType::KeyPress: - switch(event.value) - { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_threshold_.param_.GetNorm()); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - + 0.125); + break; case KEY_TWO: - LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_threshold_.param_.GetNorm()); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_ratio_.param_.GetNorm()); - knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_ratio_.param_.GetNorm()); + knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_ratio_.param_.GetNorm()); - knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_ratio_.param_.GetNorm()); + knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_attack_.param_.GetNorm()); - knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_attack_.param_.GetNorm()); + knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_attack_.param_.GetNorm()); - knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_attack_.param_.GetNorm()); + knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() + 0.125); + break; case KEY_SEVEN: - LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_release_.param_.GetNorm()); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - 0.125); + break; case KEY_EIGHT: - LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_release_.param_.GetNorm()); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/delay.cc b/src/plugin/delay.cc index e0500b5..63c1e0b 100644 --- a/src/plugin/delay.cc +++ b/src/plugin/delay.cc @@ -1,4 +1,5 @@ #include "plugin/delay.hh" + #include "core/cv.hh" namespace box { @@ -6,98 +7,78 @@ namespace box { Texture2D Delay::icon_; // Define the static member Delay::Delay(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, - knob_feedback_{ - Parameter{base_plugin_->feedbackDb}, - 32, // x - 22, // y - 16, // radius - GREEN, - "feedback" - }, - knob_mix_{ - Parameter{base_plugin_->mixProportion}, - 96, // x - 22, // y - 16, // radius - RED, - "mix" - }, - knob_length_{ - Parameter{CV{base_plugin_->lengthMs, 0, 10}}, - 32, // x - 86, // y - 16, // radius - BLUE, - "speed" - } -{ - EnsureTextureLoaded(); + : Plugin(p), + base_plugin_{static_cast(p)}, + knob_feedback_{Parameter{base_plugin_->feedbackDb}, + 32, // x + 22, // y + 16, // radius + GREEN, + "feedback"}, + knob_mix_{Parameter{base_plugin_->mixProportion}, + 96, // x + 22, // y + 16, // radius + RED, + "mix"}, + knob_length_{Parameter{CV{base_plugin_->lengthMs, 0, 10}}, + 32, // x + 86, // y + 16, // radius + BLUE, + "speed"} { + EnsureTextureLoaded(); } -Delay:: ~Delay() -{ - UnloadTexture(icon_); -} +Delay::~Delay() { UnloadTexture(icon_); } -Texture2D &Delay:: GetIcon() const -{ - return icon_; -} +Texture2D &Delay::GetIcon() const { return icon_; } -const char *Delay:: GetIconPath() const -{ - return icon_path_; -} +const char *Delay::GetIconPath() const { return icon_path_; } -const char *Delay::GetName() const -{ - return name_; -} +const char *Delay::GetName() const { return name_; } -void Delay::Render(Interface &interface) -{ - knob_feedback_.Render(interface); - knob_mix_.Render(interface); - knob_length_.Render(interface); +void Delay::Render(Interface &interface) { + knob_feedback_.Render(interface); + knob_mix_.Render(interface); + knob_length_.Render(interface); } -void Delay::HandleEvent(const Event &event) -{ - switch (event.type) - { +void Delay::HandleEvent(const Event &event) { + switch (event.type) { case EventType::KeyPress: - switch(event.value) - { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_feedback_.param_.GetNorm()); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - + 0.125); + break; case KEY_TWO: - LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_feedback_.param_.GetNorm()); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_mix_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_mix_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_mix_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_mix_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_length_.param_.GetNorm()); - knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_length_.param_.GetNorm()); + knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_length_.param_.GetNorm()); - knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_length_.param_.GetNorm()); + knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/four_osc.cc b/src/plugin/four_osc.cc index d992893..4be9256 100644 --- a/src/plugin/four_osc.cc +++ b/src/plugin/four_osc.cc @@ -4,82 +4,63 @@ namespace box { Texture2D FourOsc::icon_; // Define the static member -FourOsc:: FourOsc(te::Plugin *p): - Plugin(p), base_plugin_{static_cast(p)}, - // knob_master_level_{32, 64, 16, {255,0,0}, base_plugin_->masterLevelValue, base_plugin_->masterLevel} +FourOsc::FourOsc(te::Plugin *p) + : Plugin(p), + base_plugin_{static_cast(p)}, + // knob_master_level_{32, 64, 16, {255,0,0}, + // base_plugin_->masterLevelValue, base_plugin_->masterLevel} - knob_master_level_{ - Parameter(base_plugin_->masterLevel), - 32, // x - 22, // y - 16, // radius - GREEN, - "volume" - } -{ - EnsureTextureLoaded(); - // TODO for testing effects - for (int i = 0; i < base_plugin_->oscParams.size(); i++) - { - base_plugin_->oscParams[i]->waveShapeValue.setValue(2, nullptr); - } + knob_master_level_{Parameter(base_plugin_->masterLevel), + 32, // x + 22, // y + 16, // radius + GREEN, + "volume"} { + EnsureTextureLoaded(); + // TODO for testing effects + for (int i = 0; i < base_plugin_->oscParams.size(); i++) { + base_plugin_->oscParams[i]->waveShapeValue.setValue(2, nullptr); + } } -FourOsc:: ~FourOsc() -{ - UnloadTexture(icon_); -} +FourOsc::~FourOsc() { UnloadTexture(icon_); } -Texture2D &FourOsc:: GetIcon() const -{ - return icon_; -} +Texture2D &FourOsc::GetIcon() const { return icon_; } -const char *FourOsc:: GetIconPath() const -{ - return icon_path_; -} +const char *FourOsc::GetIconPath() const { return icon_path_; } -const char *FourOsc::GetName() const -{ - return name_; -} +const char *FourOsc::GetName() const { return name_; } -void FourOsc:: Render(Interface &interface) -{ - for (int y = 0; y < Interface::HEIGHT; ++y) - { - for (int x = 0; x < Interface::WIDTH; ++x) - { - if (x % 2 == 0 && y % 2 == 0) - { - DrawPixel(x, y, RED); - } - } +void FourOsc::Render(Interface &interface) { + for (int y = 0; y < Interface::HEIGHT; ++y) { + for (int x = 0; x < Interface::WIDTH; ++x) { + if (x % 2 == 0 && y % 2 == 0) { + DrawPixel(x, y, RED); + } } - knob_master_level_.Render(interface); + } + knob_master_level_.Render(interface); } -void FourOsc:: HandleEvent(const Event &event) -{ - switch (event.type) - { +void FourOsc::HandleEvent(const Event &event) { + switch (event.type) { case EventType::KeyPress: - switch(event.value) - { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm(knob_master_level_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_master_level_.param_.GetNorm()); + knob_master_level_.param_.SetNorm( + knob_master_level_.param_.GetNorm() - 0.125); + break; case KEY_TWO: - LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm(knob_master_level_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_master_level_.param_.GetNorm()); + knob_master_level_.param_.SetNorm( + knob_master_level_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box From eb4be38adce94452d7357f891c80b1b7b8223a3a Mon Sep 17 00:00:00 2001 From: Powei Lin Date: Wed, 25 Dec 2024 16:07:33 -0500 Subject: [PATCH 02/12] test action --- print.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.sh b/print.sh index 5621651..0496a60 100755 --- a/print.sh +++ b/print.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash # # Define the directory where you want to search recursively # DIRECTORY="." From 3413098a9fcee7b1bb5ecd7941061271891589c9 Mon Sep 17 00:00:00 2001 From: Powei Lin Date: Wed, 25 Dec 2024 16:13:24 -0500 Subject: [PATCH 03/12] use clang-format 11 --- .clang-format | 156 ++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 127 deletions(-) diff --git a/.clang-format b/.clang-format index 7403b0f..70da6ad 100644 --- a/.clang-format +++ b/.clang-format @@ -3,76 +3,40 @@ Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCaseColons: false +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left AlignOperands: Align -AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 +AlignTrailingComments: true AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never +AllowShortEnumsOnASingleLine: true AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes -AttributeMacros: - - __capability BinPackArguments: true BinPackParameters: true -BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false AfterControlStatement: Never AfterEnum: false - AfterExternBlock: false AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false AfterStruct: false AfterUnion: false + AfterExternBlock: false BeforeCatch: false BeforeElse: false BeforeLambdaBody: false @@ -81,81 +45,58 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakArrays: true BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach -BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon +BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true +DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE IncludeBlocks: Regroup IncludeCategories: - Regex: '^' Priority: 2 SortPriority: 0 - CaseSensitive: false - Regex: '^<.*\.h>' Priority: 1 SortPriority: 0 - CaseSensitive: false - Regex: '^<.*' Priority: 2 SortPriority: 0 - CaseSensitive: false - Regex: '.*' Priority: 3 SortPriority: 0 - CaseSensitive: false IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false IndentCaseLabels: true -IndentExternBlock: AfterExternBlock +IndentCaseBlocks: false IndentGotoLabels: true IndentPPDirectives: None -IndentRequiresClause: true +IndentExternBlock: AfterExternBlock IndentWidth: 2 IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigits: 0 - Decimal: 0 - DecimalMinDigits: 0 - Hex: 0 - HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false -KeepEmptyLinesAtEOF: false -LambdaBodyIndentation: Signature -LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -165,21 +106,15 @@ ObjCBlockIndentWidth: 2 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true -PackConstructorInitializers: NextLine PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left -PPIndentWidth: -1 -QualifierAlignment: Leave RawStringFormats: - Language: Cpp Delimiters: @@ -208,73 +143,40 @@ RawStringFormats: - ParseTextProtoOrDie - ParseTestProto - ParsePartialTestProto - CanonicalDelimiter: pb + CanonicalDelimiter: '' BasedOnStyle: google -ReferenceAlignment: Pointer ReflowComments: true -RemoveBracesLLVM: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric +SortIncludes: true +SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: Never +SpacesInAngles: false +SpacesInConditionalStatement: false SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false Standard: Auto -StatementAttributeLikeMacros: - - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 8 +UseCRLF: false UseTab: Never -VerilogBreakBetweenInstancePorts: true WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE ... From 2dcf5fcf448cb427fefc019a896b1a7b474d91c9 Mon Sep 17 00:00:00 2001 From: Powei Lin Date: Wed, 25 Dec 2024 16:15:32 -0500 Subject: [PATCH 04/12] format again --- print.sh | 2 +- src/core/timeline.cc | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/print.sh b/print.sh index 0496a60..5621651 100755 --- a/print.sh +++ b/print.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash # # Define the directory where you want to search recursively # DIRECTORY="." diff --git a/src/core/timeline.cc b/src/core/timeline.cc index 1e834a6..2421e1b 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -257,24 +257,29 @@ void Timeline::print_timeline() { const auto clips = track.getClips(); std::cout << "num clips: " << clips.size() << std::endl; for (auto c : clips) { - std::cout << "\t" << "name: " << c->getName() << std::endl; - std::cout << "\t\t" << "isMidi: " << c->isMidi() << std::endl; + std::cout << "\t" + << "name: " << c->getName() << std::endl; + std::cout << "\t\t" + << "isMidi: " << c->isMidi() << std::endl; const te::ClipPosition pos = c->getPosition(); auto edit_range = te::EditTimeRange{pos.time}; te::TimeRange time_range = te::toTime(edit_range, APP->edit_.tempoSequence); te::BeatRange beat_range = te::toBeats(edit_range, APP->edit_.tempoSequence); - std::cout << "\t\t" << "TIME start: " << time_range.getStart().inSeconds() + std::cout << "\t\t" + << "TIME start: " << time_range.getStart().inSeconds() << std::endl; - std::cout << "\t\t" << "TIME end: " << time_range.getEnd().inSeconds() + std::cout << "\t\t" + << "TIME end: " << time_range.getEnd().inSeconds() << std::endl; + std::cout << "\t\t" + << "TIME length: " << pos.getLength().inSeconds() << std::endl; + std::cout << "\t\t" + << "BEATS start: " << beat_range.getStart().inBeats() << std::endl; - std::cout << "\t\t" << "TIME length: " << pos.getLength().inSeconds() - << std::endl; - std::cout << "\t\t" << "BEATS start: " << beat_range.getStart().inBeats() - << std::endl; - std::cout << "\t\t" << "BEATS end: " << beat_range.getEnd().inBeats() - << std::endl; - std::cout << "\t\t" << "BEATS length: " << beat_range.getLength().inBeats() + std::cout << "\t\t" + << "BEATS end: " << beat_range.getEnd().inBeats() << std::endl; + std::cout << "\t\t" + << "BEATS length: " << beat_range.getLength().inBeats() << std::endl; } } From 11facd15fd29205562686ddb961dfe2e295cce6c Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Tue, 31 Dec 2024 21:15:27 -0500 Subject: [PATCH 05/12] simplify .clang-format and use 4 indent --- .clang-format | 183 +------------------------------------------------- 1 file changed, 2 insertions(+), 181 deletions(-) diff --git a/.clang-format b/.clang-format index 70da6ad..49c9b6d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,182 +1,3 @@ --- -Language: Cpp -# BasedOnStyle: Google -AccessModifierOffset: -1 -AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveBitFields: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Left -AlignOperands: Align -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: true -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DeriveLineEnding: true -DerivePointerAlignment: true -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^' - Priority: 2 - SortPriority: 0 - - Regex: '^<.*\.h>' - Priority: 1 - SortPriority: 0 - - Regex: '^<.*' - Priority: 2 - SortPriority: 0 - - Regex: '.*' - Priority: 3 - SortPriority: 0 -IncludeIsMainRegex: '([-_](test|unittest))?$' -IncludeIsMainSourceRegex: '' -IndentCaseLabels: true -IndentCaseBlocks: false -IndentGotoLabels: true -IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertTrailingCommas: None -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Never -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -RawStringFormats: - - Language: Cpp - Delimiters: - - cc - - CC - - cpp - - Cpp - - CPP - - 'c++' - - 'C++' - CanonicalDelimiter: '' - BasedOnStyle: google - - Language: TextProto - Delimiters: - - pb - - PB - - proto - - PROTO - EnclosingFunctions: - - EqualsProto - - EquivToProto - - PARSE_PARTIAL_TEXT_PROTO - - PARSE_TEST_PROTO - - PARSE_TEXT_PROTO - - ParseTextOrDie - - ParseTextProtoOrDie - - ParseTestProto - - ParsePartialTestProto - CanonicalDelimiter: '' - BasedOnStyle: google -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -Standard: Auto -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseCRLF: false -UseTab: Never -WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - - BOOST_PP_STRINGIZE -... - +BasedOnStyle: Google +IndentWidth: 4 From 17df0d5788222eb963dfe6535ac0ab12dd9ef780 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:08:57 -0500 Subject: [PATCH 06/12] use LLVM format --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 49c9b6d..4fbc004 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,3 @@ --- -BasedOnStyle: Google +BasedOnStyle: LLVM IndentWidth: 4 From 2b1084478ff78ee6529acc6273994dcea3fee400 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:09:10 -0500 Subject: [PATCH 07/12] autoformat --- include/component/knob.hh | 40 +- include/component/switch.hh | 30 +- include/core/app.hh | 96 ++-- include/core/cv.hh | 39 +- include/core/interface.hh | 74 +-- include/core/parameter.hh | 86 ++-- include/core/plugin.hh | 24 +- include/core/plugin_selector.hh | 14 +- include/core/timeline.hh | 97 ++-- include/core/track.hh | 48 +- include/core/util.hh | 46 +- include/plugin/chorus.hh | 34 +- include/plugin/compressor.hh | 34 +- include/plugin/delay.hh | 32 +- include/plugin/four_osc.hh | 28 +- src/core/app.cc | 244 +++++----- src/core/interface.cc | 108 ++--- src/core/plugin.cc | 12 +- src/core/plugin_selector.cc | 97 ++-- src/core/timeline.cc | 783 ++++++++++++++++---------------- src/core/track.cc | 236 +++++----- src/core/util.cc | 118 ++--- src/main.cc | 92 ++-- src/plugin/chorus.cc | 101 ++-- src/plugin/compressor.cc | 107 ++--- src/plugin/delay.cc | 85 ++-- src/plugin/four_osc.cc | 65 ++- 27 files changed, 1398 insertions(+), 1372 deletions(-) diff --git a/include/component/knob.hh b/include/component/knob.hh index 4c4e5e4..5eaf07d 100644 --- a/include/component/knob.hh +++ b/include/component/knob.hh @@ -5,28 +5,28 @@ namespace box { -template -struct Knob { - Parameter param_; - uint8_t x_, y_, radius_; - Color color_; - std::string name_; +template struct Knob { + Parameter param_; + uint8_t x_, y_, radius_; + Color color_; + std::string name_; - Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, - std::string name = "") - : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} {} + Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, + std::string name = "") + : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} { + } - virtual void Render(Interface& interface) { - auto angle = param_.GetNorm() * 360; - auto x = static_cast(x_); - auto y = static_cast(y_); - DrawCircleSector(Vector2{x, y}, radius_, 0.f, angle, 360, color_); + virtual void Render(Interface &interface) { + auto angle = param_.GetNorm() * 360; + auto x = static_cast(x_); + auto y = static_cast(y_); + DrawCircleSector(Vector2{x, y}, radius_, 0.f, angle, 360, color_); - const int font_size = 10; - int width = MeasureText(name_.c_str(), font_size); - DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, WHITE); - } - virtual void HandleEvent(const Event& event) {} + const int font_size = 10; + int width = MeasureText(name_.c_str(), font_size); + DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, WHITE); + } + virtual void HandleEvent(const Event &event) {} }; -} // namespace box +} // namespace box diff --git a/include/component/switch.hh b/include/component/switch.hh index eec8ab9..e4d344c 100644 --- a/include/component/switch.hh +++ b/include/component/switch.hh @@ -7,23 +7,23 @@ namespace box { struct Switch { - juce::CachedValue &value_; - uint8_t x_, y_; - Color color_; - std::string name_; + juce::CachedValue &value_; + uint8_t x_, y_; + Color color_; + std::string name_; - Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, - std::string name) - : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} {} + Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, + std::string name) + : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} {} - virtual void Render(Interface &interface) { - Color text_color = value_ ? color_ : WHITE; - const int font_size = 10; - int width = MeasureText(name_.c_str(), font_size); - DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, text_color); - } + virtual void Render(Interface &interface) { + Color text_color = value_ ? color_ : WHITE; + const int font_size = 10; + int width = MeasureText(name_.c_str(), font_size); + DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, text_color); + } - virtual void HandleEvent(const Event &event) {} + virtual void HandleEvent(const Event &event) {} }; -} // namespace box +} // namespace box diff --git a/include/core/app.hh b/include/core/app.hh index a2c4770..68b1365 100644 --- a/include/core/app.hh +++ b/include/core/app.hh @@ -7,53 +7,53 @@ namespace box { struct App { - enum class ScreenState { - Timeline, - Track, - PluginSelector, - }; - - enum class Mode { - Normal, - Insert, - }; - - ScreenState screen_state_ = ScreenState::Timeline; - Mode mode_ = Mode::Normal; - int key_offset_ = 0; - std::map active_notes_; - - te::Engine &engine_; - te::Edit &edit_; - - std::vector> tracks_; - juce::Array base_tracks_; - - PluginSelector plugin_sel_; - Timeline timeline_; - - const std::vector colors_ = { - Color{0x29, 0x73, 0x55, 0xff}, - Color{0x1e, 0x4d, 0x3f, 0xff}, - Color{0xdd, 0xe6, 0x63, 0xff}, - Color{0x7d, 0x54, 0x39, 0xff}, - }; - - // functions - App(te::Engine &engine, te::Edit &edit); - void Render(Interface &interface); - void HandleEvent(const Event &event); - - Track &CurrTrack(); - size_t GetCurrTrack(); - void SetCurrTrack(size_t track_index); - void AddTrack(); - void ChangeArmMidi(size_t new_index); - - private: - size_t current_track_; - void ArmMidi(size_t index); - void UnarmMidi(size_t index); + enum class ScreenState { + Timeline, + Track, + PluginSelector, + }; + + enum class Mode { + Normal, + Insert, + }; + + ScreenState screen_state_ = ScreenState::Timeline; + Mode mode_ = Mode::Normal; + int key_offset_ = 0; + std::map active_notes_; + + te::Engine &engine_; + te::Edit &edit_; + + std::vector> tracks_; + juce::Array base_tracks_; + + PluginSelector plugin_sel_; + Timeline timeline_; + + const std::vector colors_ = { + Color{0x29, 0x73, 0x55, 0xff}, + Color{0x1e, 0x4d, 0x3f, 0xff}, + Color{0xdd, 0xe6, 0x63, 0xff}, + Color{0x7d, 0x54, 0x39, 0xff}, + }; + + // functions + App(te::Engine &engine, te::Edit &edit); + void Render(Interface &interface); + void HandleEvent(const Event &event); + + Track &CurrTrack(); + size_t GetCurrTrack(); + void SetCurrTrack(size_t track_index); + void AddTrack(); + void ChangeArmMidi(size_t new_index); + + private: + size_t current_track_; + void ArmMidi(size_t index); + void UnarmMidi(size_t index); }; -} // namespace box +} // namespace box diff --git a/include/core/cv.hh b/include/core/cv.hh index 6f2bafb..099f851 100644 --- a/include/core/cv.hh +++ b/include/core/cv.hh @@ -4,28 +4,27 @@ #include "core/util.hh" -template -struct CV { - juce::CachedValue &value_; - T min_, max_; +template struct CV { + juce::CachedValue &value_; + T min_, max_; - // TODO add default value? - CV(juce::CachedValue &cv, T min, T max) - : value_{cv}, min_{min}, max_{max} { - assert(min <= max); - } + // TODO add default value? + CV(juce::CachedValue &cv, T min, T max) + : value_{cv}, min_{min}, max_{max} { + assert(min <= max); + } - void SetValue(T new_value) { value_ = std::clamp(new_value, min_, max_); } + void SetValue(T new_value) { value_ = std::clamp(new_value, min_, max_); } - void SetNorm(T norm) { - norm = std::clamp(norm, static_cast(0), static_cast(1)); - const auto range = max_ - min_; - value_ = range * norm; - } + void SetNorm(T norm) { + norm = std::clamp(norm, static_cast(0), static_cast(1)); + const auto range = max_ - min_; + value_ = range * norm; + } - T GetValue() const { return value_.get(); } - T GetNorm() const { - const auto range = max_ - min_; - return value_ / range; - } + T GetValue() const { return value_.get(); } + T GetNorm() const { + const auto range = max_ - min_; + return value_ / range; + } }; diff --git a/include/core/interface.hh b/include/core/interface.hh index 611e010..2ba933c 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -6,42 +6,42 @@ namespace box { class Interface { - public: - static const int WIDTH = 128; - static const int HEIGHT = 128; - constexpr static DeviceType DISPLAY_TYPE = DeviceType::Emulator; - constexpr static DeviceType INPUT_TYPE = DeviceType::Emulator; - - Interface(); - ~Interface(); - - void PreRender(); - void PostRender(); - - bool PollEvent(Event& event); - bool ShouldClose() const; - - private: - RenderTexture2D target_; - std::map keys_ = { - {KEY_ZERO, false}, {KEY_ONE, false}, {KEY_TWO, false}, - {KEY_THREE, false}, {KEY_FOUR, false}, {KEY_FIVE, false}, - {KEY_SIX, false}, {KEY_SEVEN, false}, {KEY_EIGHT, false}, - {KEY_NINE, false}, {KEY_A, false}, {KEY_B, false}, - {KEY_C, false}, {KEY_D, false}, {KEY_E, false}, - {KEY_F, false}, {KEY_G, false}, {KEY_H, false}, - {KEY_I, false}, {KEY_J, false}, {KEY_K, false}, - {KEY_L, false}, {KEY_M, false}, {KEY_N, false}, - {KEY_O, false}, {KEY_P, false}, {KEY_Q, false}, - {KEY_R, false}, {KEY_S, false}, {KEY_T, false}, - {KEY_U, false}, {KEY_V, false}, {KEY_W, false}, - {KEY_X, false}, {KEY_Y, false}, {KEY_Z, false}, - {KEY_SPACE, false}, {KEY_ESCAPE, false}, {KEY_ENTER, false}, - {KEY_TAB, false}, {KEY_BACKSPACE, false}, {KEY_COMMA, false}, - {KEY_PERIOD, false}, {KEY_DELETE, false}, {KEY_MINUS, false}, - {KEY_EQUAL, false}, {KEY_RIGHT, false}, {KEY_LEFT, false}, - {KEY_DOWN, false}, {KEY_UP, false}, - }; + public: + static const int WIDTH = 128; + static const int HEIGHT = 128; + constexpr static DeviceType DISPLAY_TYPE = DeviceType::Emulator; + constexpr static DeviceType INPUT_TYPE = DeviceType::Emulator; + + Interface(); + ~Interface(); + + void PreRender(); + void PostRender(); + + bool PollEvent(Event &event); + bool ShouldClose() const; + + private: + RenderTexture2D target_; + std::map keys_ = { + {KEY_ZERO, false}, {KEY_ONE, false}, {KEY_TWO, false}, + {KEY_THREE, false}, {KEY_FOUR, false}, {KEY_FIVE, false}, + {KEY_SIX, false}, {KEY_SEVEN, false}, {KEY_EIGHT, false}, + {KEY_NINE, false}, {KEY_A, false}, {KEY_B, false}, + {KEY_C, false}, {KEY_D, false}, {KEY_E, false}, + {KEY_F, false}, {KEY_G, false}, {KEY_H, false}, + {KEY_I, false}, {KEY_J, false}, {KEY_K, false}, + {KEY_L, false}, {KEY_M, false}, {KEY_N, false}, + {KEY_O, false}, {KEY_P, false}, {KEY_Q, false}, + {KEY_R, false}, {KEY_S, false}, {KEY_T, false}, + {KEY_U, false}, {KEY_V, false}, {KEY_W, false}, + {KEY_X, false}, {KEY_Y, false}, {KEY_Z, false}, + {KEY_SPACE, false}, {KEY_ESCAPE, false}, {KEY_ENTER, false}, + {KEY_TAB, false}, {KEY_BACKSPACE, false}, {KEY_COMMA, false}, + {KEY_PERIOD, false}, {KEY_DELETE, false}, {KEY_MINUS, false}, + {KEY_EQUAL, false}, {KEY_RIGHT, false}, {KEY_LEFT, false}, + {KEY_DOWN, false}, {KEY_UP, false}, + }; }; -} // namespace box +} // namespace box diff --git a/include/core/parameter.hh b/include/core/parameter.hh index 8c91d58..6841f2a 100644 --- a/include/core/parameter.hh +++ b/include/core/parameter.hh @@ -10,52 +10,52 @@ namespace box { using AP = te::AutomatableParameter; -template -class Parameter { - std::variant, AP *> param_; - - public: - Parameter(CV cv) : param_{cv} {} - - Parameter(AP *p) : param_{p} {} - - void SetValue(T new_value) { - if (std::holds_alternative>(param_)) { - auto v = std::get>(param_); - v.SetValue(new_value); - } else if (std::holds_alternative(param_)) { - auto v = std::get(param_); - v->setParameter(new_value, juce::NotificationType::dontSendNotification); +template class Parameter { + std::variant, AP *> param_; + + public: + Parameter(CV cv) : param_{cv} {} + + Parameter(AP *p) : param_{p} {} + + void SetValue(T new_value) { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + v.SetValue(new_value); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + v->setParameter(new_value, + juce::NotificationType::dontSendNotification); + } } - } - void SetNorm(T new_value) { - if (std::holds_alternative>(param_)) { - auto v = std::get>(param_); - v.SetNorm(new_value); - } else if (std::holds_alternative(param_)) { - auto v = std::get(param_); - v->setNormalisedParameter(new_value, - juce::NotificationType::dontSendNotification); + void SetNorm(T new_value) { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + v.SetNorm(new_value); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + v->setNormalisedParameter( + new_value, juce::NotificationType::dontSendNotification); + } } - } - T GetValue() const { - if (std::holds_alternative>(param_)) { - auto v = std::get>(param_); - return v.GetValue(); - } else if (std::holds_alternative(param_)) { - auto v = std::get(param_); - return v->getCurrentValue(); + T GetValue() const { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + return v.GetValue(); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + return v->getCurrentValue(); + } } - } - T GetNorm() const { - if (std::holds_alternative>(param_)) { - auto v = std::get>(param_); - return v.GetNorm(); - } else if (std::holds_alternative(param_)) { - auto v = std::get(param_); - return v->getCurrentNormalisedValue(); + T GetNorm() const { + if (std::holds_alternative>(param_)) { + auto v = std::get>(param_); + return v.GetNorm(); + } else if (std::holds_alternative(param_)) { + auto v = std::get(param_); + return v->getCurrentNormalisedValue(); + } } - } }; -} // namespace box +} // namespace box diff --git a/include/core/plugin.hh b/include/core/plugin.hh index 4ed8049..6edd573 100644 --- a/include/core/plugin.hh +++ b/include/core/plugin.hh @@ -5,20 +5,20 @@ namespace box { struct Plugin { - te::Plugin *const plugin_; + te::Plugin *const plugin_; - public: - Plugin(te::Plugin *p); - virtual ~Plugin(); + public: + Plugin(te::Plugin *p); + virtual ~Plugin(); - void EnsureTextureLoaded() const; - te::Plugin *const GetPlugin() const; + void EnsureTextureLoaded() const; + te::Plugin *const GetPlugin() const; - virtual Texture2D &GetIcon() const = 0; - virtual const char *GetIconPath() const = 0; - virtual const char *GetName() const = 0; - virtual void Render(Interface &interface) = 0; - virtual void HandleEvent(const Event &event) = 0; + virtual Texture2D &GetIcon() const = 0; + virtual const char *GetIconPath() const = 0; + virtual const char *GetName() const = 0; + virtual void Render(Interface &interface) = 0; + virtual void HandleEvent(const Event &event) = 0; }; -} // namespace box +} // namespace box diff --git a/include/core/plugin_selector.hh b/include/core/plugin_selector.hh index 20ecd99..2701b11 100644 --- a/include/core/plugin_selector.hh +++ b/include/core/plugin_selector.hh @@ -5,13 +5,13 @@ namespace box { struct PluginSelector { - PluginSelector(); - void Render(Interface &interface); - void HandleEvent(const Event &event); - void Select(const std::string &name); + PluginSelector(); + void Render(Interface &interface); + void HandleEvent(const Event &event); + void Select(const std::string &name); - static const std::vector PLUGIN_NAMES; - size_t current_index_ = 0; + static const std::vector PLUGIN_NAMES; + size_t current_index_ = 0; }; -} // namespace box +} // namespace box diff --git a/include/core/timeline.hh b/include/core/timeline.hh index 21a1bcf..aed8922 100644 --- a/include/core/timeline.hh +++ b/include/core/timeline.hh @@ -6,64 +6,65 @@ namespace box { struct Timeline { - enum class ScreenState { - Overview, - }; + enum class ScreenState { + Overview, + }; - enum class PlayheadMode { - Detached, - Locked, - }; + enum class PlayheadMode { + Detached, + Locked, + }; - struct BeatWindow { - float start; - float len; - float LeftEdge() const { return start; } - float RightEdge() const { return start + len; } - }; + struct BeatWindow { + float start; + float len; + float LeftEdge() const { return start; } + float RightEdge() const { return start + len; } + }; - struct BeatFrame { - float center; - float radius; - float LeftEdge() const { return center - radius; } - float RightEdge() const { return center + radius; } - float Width() const { return radius * 2; } - BeatFrame(float c, float &r) : center{c}, radius{r} {} - }; + struct BeatFrame { + float center; + float radius; + float LeftEdge() const { return center - radius; } + float RightEdge() const { return center + radius; } + float Width() const { return radius * 2; } + BeatFrame(float c, float &r) : center{c}, radius{r} {} + }; - struct Position { - float secs; - float beats; - }; + struct Position { + float secs; + float beats; + }; - float bar_width_ = 4.0; // Assuming a 4/4 time signature by default TODO - // update with time signature changes - float step_size_ = 4.0; // Move cursor by 4 beat (1 bar) - float radius_ = 8.0; - BeatWindow cursor_ = {0.0, bar_width_}; - BeatFrame frame_ = {0.0, radius_}; + float bar_width_ = 4.0; // Assuming a 4/4 time signature by default TODO + // update with time signature changes + float step_size_ = 4.0; // Move cursor by 4 beat (1 bar) + float radius_ = 8.0; + BeatWindow cursor_ = {0.0, bar_width_}; + BeatFrame frame_ = {0.0, radius_}; - ScreenState screen_state_ = ScreenState::Overview; - PlayheadMode playhead_mode_ = PlayheadMode::Detached; - size_t scroll_offset_ = 0; + ScreenState screen_state_ = ScreenState::Overview; + PlayheadMode playhead_mode_ = PlayheadMode::Detached; + size_t scroll_offset_ = 0; - static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; - static constexpr const char *METRONOME_PATH_R = "assets/metronome_r.png"; - static constexpr const char *METRONOME_PATH_OFF = "assets/metronome_off.png"; - Texture2D metronome_l_; - Texture2D metronome_r_; - Texture2D metronome_off_; + static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; + static constexpr const char *METRONOME_PATH_R = "assets/metronome_r.png"; + static constexpr const char *METRONOME_PATH_OFF = + "assets/metronome_off.png"; + Texture2D metronome_l_; + Texture2D metronome_r_; + Texture2D metronome_off_; - Timeline(); - ~Timeline(); + Timeline(); + ~Timeline(); - void FocusCursor(); + void FocusCursor(); - void Render(Interface &interface); - void HandleEvent(const Event &event); + void Render(Interface &interface); + void HandleEvent(const Event &event); - private: - void print_timeline(); + private: + void print_timeline(); }; -} // namespace box +} // namespace box diff --git a/include/core/track.hh b/include/core/track.hh index 5a736ec..c127b99 100644 --- a/include/core/track.hh +++ b/include/core/track.hh @@ -10,29 +10,29 @@ namespace box { class Track { - enum class ScreenState { - Overview, - Plugin, - }; - - public: - static constexpr int MAX_PLUGINS = 8; - static constexpr int GRID_SIZE = 4; - std::vector> plugins_; - int active_plugin_ = -1; - te::AudioTrack& base_; - ScreenState screen_state_ = ScreenState::Overview; - - Track(te::AudioTrack& base); - ~Track(); - - void AddPlugin(std::unique_ptr plugin); - void SetActivePlugin(int index); - int GetActivePlugin(); - void RemoveActivePlugin(); - - void HandleEvent(const Event& event); - void Render(Interface& Interface); + enum class ScreenState { + Overview, + Plugin, + }; + + public: + static constexpr int MAX_PLUGINS = 8; + static constexpr int GRID_SIZE = 4; + std::vector> plugins_; + int active_plugin_ = -1; + te::AudioTrack &base_; + ScreenState screen_state_ = ScreenState::Overview; + + Track(te::AudioTrack &base); + ~Track(); + + void AddPlugin(std::unique_ptr plugin); + void SetActivePlugin(int index); + int GetActivePlugin(); + void RemoveActivePlugin(); + + void HandleEvent(const Event &event); + void Render(Interface &Interface); }; -} // namespace box +} // namespace box diff --git a/include/core/util.hh b/include/core/util.hh index e7c50d3..9f0a941 100644 --- a/include/core/util.hh +++ b/include/core/util.hh @@ -52,40 +52,40 @@ const LogLevel LOGLEVEL = get_loglevel(); void LOG_MSG(const std::string &msg, LogLevel l = LogLevel::Debug); template void log_var(const std::string &var_name, const T &var_value) { - LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); + LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); } #define LOG_VAR(var) log_var(#var, var) enum class DeviceType { Emulator, Hardware }; enum class EventType { - KeyPress, - KeyRelease, - PotDown, - PotUp, + KeyPress, + KeyRelease, + PotDown, + PotUp, }; struct Event { - EventType type; - int value; + EventType type; + int value; }; const std::unordered_map KEY_TO_MIDI = { - {KEY_A, 60}, // C4 - {KEY_W, 61}, // C#4 - {KEY_S, 62}, // D4 - {KEY_E, 63}, // D#4 - {KEY_D, 64}, // E4 - {KEY_F, 65}, // F4 - {KEY_T, 66}, // F#4 - {KEY_G, 67}, // G4 - {KEY_Y, 68}, // G#4 - {KEY_H, 69}, // A4 - {KEY_U, 70}, // A#4 - {KEY_J, 71}, // B4 - {KEY_K, 72}, // C5 - {KEY_O, 73}, // C#5 - {KEY_L, 74} // D5 + {KEY_A, 60}, // C4 + {KEY_W, 61}, // C#4 + {KEY_S, 62}, // D4 + {KEY_E, 63}, // D#4 + {KEY_D, 64}, // E4 + {KEY_F, 65}, // F4 + {KEY_T, 66}, // F#4 + {KEY_G, 67}, // G4 + {KEY_Y, 68}, // G#4 + {KEY_H, 69}, // A4 + {KEY_U, 70}, // A#4 + {KEY_J, 71}, // B4 + {KEY_K, 72}, // C5 + {KEY_O, 73}, // C#5 + {KEY_L, 74} // D5 }; -} // namespace box +} // namespace box diff --git a/include/plugin/chorus.hh b/include/plugin/chorus.hh index 4fd71bd..a3551ef 100644 --- a/include/plugin/chorus.hh +++ b/include/plugin/chorus.hh @@ -6,25 +6,25 @@ namespace box { struct Chorus : public Plugin { - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "chrs"; + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "chrs"; - te::ChorusPlugin *base_plugin_; - Knob knob_depth_; - Knob knob_width_; - Knob knob_speed_; - Knob knob_mix_; + te::ChorusPlugin *base_plugin_; + Knob knob_depth_; + Knob knob_width_; + Knob knob_speed_; + Knob knob_mix_; - public: - Chorus(te::Plugin *p); - ~Chorus() override; + public: + Chorus(te::Plugin *p); + ~Chorus() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event &event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/include/plugin/compressor.hh b/include/plugin/compressor.hh index fe3e775..28e1dd2 100644 --- a/include/plugin/compressor.hh +++ b/include/plugin/compressor.hh @@ -6,25 +6,25 @@ namespace box { struct Compressor : public Plugin { - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "cmpr"; + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "cmpr"; - te::CompressorPlugin *base_plugin_; - Knob knob_threshold_; - Knob knob_ratio_; - Knob knob_attack_; - Knob knob_release_; + te::CompressorPlugin *base_plugin_; + Knob knob_threshold_; + Knob knob_ratio_; + Knob knob_attack_; + Knob knob_release_; - public: - Compressor(te::Plugin *p); - ~Compressor() override; + public: + Compressor(te::Plugin *p); + ~Compressor() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event &event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/include/plugin/delay.hh b/include/plugin/delay.hh index bfaa57c..7bac72b 100644 --- a/include/plugin/delay.hh +++ b/include/plugin/delay.hh @@ -6,24 +6,24 @@ namespace box { struct Delay : public Plugin { - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/star_16x16.png"; - static constexpr const char *name_ = "dlay"; + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/star_16x16.png"; + static constexpr const char *name_ = "dlay"; - te::DelayPlugin *base_plugin_; - Knob knob_feedback_; - Knob knob_mix_; - Knob knob_length_; + te::DelayPlugin *base_plugin_; + Knob knob_feedback_; + Knob knob_mix_; + Knob knob_length_; - public: - Delay(te::Plugin *p); - ~Delay() override; + public: + Delay(te::Plugin *p); + ~Delay() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event &event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/include/plugin/four_osc.hh b/include/plugin/four_osc.hh index 0a5780c..8b8bca8 100644 --- a/include/plugin/four_osc.hh +++ b/include/plugin/four_osc.hh @@ -6,22 +6,22 @@ namespace box { struct FourOsc : public Plugin { - static Texture2D icon_; - static constexpr const char *icon_path_ = "assets/four_16x16.png"; - static constexpr const char *name_ = "4osc"; + static Texture2D icon_; + static constexpr const char *icon_path_ = "assets/four_16x16.png"; + static constexpr const char *name_ = "4osc"; - te::FourOscPlugin *base_plugin_; - Knob knob_master_level_; + te::FourOscPlugin *base_plugin_; + Knob knob_master_level_; - public: - FourOsc(te::Plugin *p); - ~FourOsc() override; + public: + FourOsc(te::Plugin *p); + ~FourOsc() override; - Texture2D &GetIcon() const override; - const char *GetIconPath() const override; - const char *GetName() const override; - void Render(Interface &interface) override; - void HandleEvent(const Event &event) override; + Texture2D &GetIcon() const override; + const char *GetIconPath() const override; + const char *GetName() const override; + void Render(Interface &interface) override; + void HandleEvent(const Event &event) override; }; -} // namespace box +} // namespace box diff --git a/src/core/app.cc b/src/core/app.cc index 4d6dc43..199c7ea 100644 --- a/src/core/app.cc +++ b/src/core/app.cc @@ -6,170 +6,168 @@ namespace box { static void assert_tracks(const std::vector> &tracks, size_t index, const std::string &name) { - if (tracks.size() == 0 || index >= tracks.size()) { - throw std::runtime_error{"App::" + name + "(): index [" + - std::to_string(index) + "] out of range: [0, " + - std::to_string(tracks.size()) + "]"}; - } + if (tracks.size() == 0 || index >= tracks.size()) { + throw std::runtime_error{ + "App::" + name + "(): index [" + std::to_string(index) + + "] out of range: [0, " + std::to_string(tracks.size()) + "]"}; + } } void print_tracks(App a) { - for (auto &t : a.tracks_) { - // std::cout << "Wave Input Device: " << t->track_.getWaveInputDevice() << - // std::endl; WaveInputDevice& getWaveInputDevice() const noexcept { - // jassert (waveInputDevice); return *waveInputDevice; } MidiInputDevice& - // getMidiInputDevice() const noexcept { jassert (midiInputDevice); - // return *midiInputDevice; } - } + for (auto &t : a.tracks_) { + // std::cout << "Wave Input Device: " << t->track_.getWaveInputDevice() + // << std::endl; WaveInputDevice& getWaveInputDevice() const noexcept { + // jassert (waveInputDevice); return *waveInputDevice; } + // MidiInputDevice& getMidiInputDevice() const noexcept { jassert + // (midiInputDevice); return *midiInputDevice; } + } } App::App(te::Engine &engine, te::Edit &edit) - : engine_{engine}, - edit_{edit}, - current_track_{0}, + : engine_{engine}, edit_{edit}, current_track_{0}, base_tracks_{te::getAudioTracks(edit)} { - AddTrack(); // ensure there's always at least 1 - LOG_VAR(tracks_.size()); - ArmMidi(current_track_); // turn on midi for it + AddTrack(); // ensure there's always at least 1 + LOG_VAR(tracks_.size()); + ArmMidi(current_track_); // turn on midi for it } void App::AddTrack() { - tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); + tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); } Track &App::CurrTrack() { return *tracks_[current_track_]; } size_t App::GetCurrTrack() { return current_track_; } void App::SetCurrTrack(size_t track_index) { - size_t old = current_track_; - if (track_index >= 0 && track_index < MAX_TRACKS) { - current_track_ = track_index; - } else { - throw std::runtime_error{"SetCurrTrack() out of range: "}; - } - - UnarmMidi(old); - ArmMidi(current_track_); + size_t old = current_track_; + if (track_index >= 0 && track_index < MAX_TRACKS) { + current_track_ = track_index; + } else { + throw std::runtime_error{"SetCurrTrack() out of range: "}; + } + + UnarmMidi(old); + ArmMidi(current_track_); } void App::ArmMidi(size_t index) { - assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) { - auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) { - auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) { - [[maybe_unused]] auto res = - instance->setTarget(t->itemID, true, &edit_.getUndoManager(), 0); - instance->setRecordingEnabled(t->itemID, true); - } + assert(0 <= index && index < tracks_.size()); + for (auto instance : edit_.getAllInputDevices()) { + auto device_type = instance->getInputDevice().getDeviceType(); + if (device_type == te::InputDevice::physicalMidiDevice || + device_type == te::InputDevice::virtualMidiDevice) { + auto t = te::getAudioTracks(edit_)[index]; + if (t != nullptr) { + [[maybe_unused]] auto res = instance->setTarget( + t->itemID, true, &edit_.getUndoManager(), 0); + instance->setRecordingEnabled(t->itemID, true); + } + } } - } } void App::UnarmMidi(size_t index) { - assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) { - auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) { - auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) { - instance->removeTarget(t->itemID, &edit_.getUndoManager()); - } + assert(0 <= index && index < tracks_.size()); + for (auto instance : edit_.getAllInputDevices()) { + auto device_type = instance->getInputDevice().getDeviceType(); + if (device_type == te::InputDevice::physicalMidiDevice || + device_type == te::InputDevice::virtualMidiDevice) { + auto t = te::getAudioTracks(edit_)[index]; + if (t != nullptr) { + instance->removeTarget(t->itemID, &edit_.getUndoManager()); + } + } } - } } void App::Render(Interface &interface) { - assert_tracks(tracks_, current_track_, "render"); + assert_tracks(tracks_, current_track_, "render"); - // TODO this is for debugging fps - // std::string text = std::to_string(GetFPS()); - // DrawText(text.c_str(), 115, 0, 10, WHITE); + // TODO this is for debugging fps + // std::string text = std::to_string(GetFPS()); + // DrawText(text.c_str(), 115, 0, 10, WHITE); - switch (screen_state_) { + switch (screen_state_) { case ScreenState::Timeline: - timeline_.Render(interface); - break; + timeline_.Render(interface); + break; case ScreenState::Track: - tracks_[current_track_]->Render(interface); - break; + tracks_[current_track_]->Render(interface); + break; case ScreenState::PluginSelector: - plugin_sel_.Render(interface); - break; - } - - if (mode_ == Mode::Insert) { - DrawRectangleLines(0, 0, 128, 127, PURPLE); // -1 so bottom row shows - } - if (edit_.getTransport().isRecording()) { - DrawRectangleLines(1, 1, 126, 125, RED); // -1 so bottom row shows - } -} - -void App::HandleEvent(const Event &event) { - assert_tracks(tracks_, current_track_, "handleEvent"); - if (event.type == EventType::KeyPress && event.value == KEY_I) { - if (mode_ == Mode::Normal) { - mode_ = Mode::Insert; - } else if (mode_ == Mode::Insert) { - mode_ = Mode::Normal; + plugin_sel_.Render(interface); + break; } - } - - if (mode_ == Mode::Insert) { - switch (event.type) { - case EventType::KeyPress: - LOG_VAR(event.value); - if (event.value == KEY_UP) { - APP->key_offset_ += 1; - break; - } - if (event.value == KEY_DOWN) { - APP->key_offset_ -= 1; - break; - } - if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && - active_notes_.find(event.value) == active_notes_.end()) { - int note = (12 * key_offset_) + KEY_TO_MIDI.at(event.value); + if (mode_ == Mode::Insert) { + DrawRectangleLines(0, 0, 128, 127, PURPLE); // -1 so bottom row shows + } + if (edit_.getTransport().isRecording()) { + DrawRectangleLines(1, 1, 126, 125, RED); // -1 so bottom row shows + } +} - active_notes_[event.value] = note; - auto message = juce::MidiMessage::noteOn(1, note, 1.0f); - te::MidiInputDevice *dev = - engine_.getDeviceManager().getDefaultMidiInDevice(); - dev->keyboardState.noteOn(1, note, 1.0); +void App::HandleEvent(const Event &event) { + assert_tracks(tracks_, current_track_, "handleEvent"); + if (event.type == EventType::KeyPress && event.value == KEY_I) { + if (mode_ == Mode::Normal) { + mode_ = Mode::Insert; + } else if (mode_ == Mode::Insert) { + mode_ = Mode::Normal; } - break; - case EventType::KeyRelease: - - if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && - active_notes_.find(event.value) != active_notes_.end()) { - int note = active_notes_[event.value]; + } - active_notes_.erase(event.value); - auto message = juce::MidiMessage::noteOff(1, note); - te::MidiInputDevice *dev = - engine_.getDeviceManager().getDefaultMidiInDevice(); - dev->keyboardState.noteOff(1, note, 1.0); + if (mode_ == Mode::Insert) { + switch (event.type) { + case EventType::KeyPress: + LOG_VAR(event.value); + if (event.value == KEY_UP) { + APP->key_offset_ += 1; + break; + } + if (event.value == KEY_DOWN) { + APP->key_offset_ -= 1; + break; + } + + if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && + active_notes_.find(event.value) == active_notes_.end()) { + int note = (12 * key_offset_) + KEY_TO_MIDI.at(event.value); + + active_notes_[event.value] = note; + auto message = juce::MidiMessage::noteOn(1, note, 1.0f); + te::MidiInputDevice *dev = + engine_.getDeviceManager().getDefaultMidiInDevice(); + dev->keyboardState.noteOn(1, note, 1.0); + } + break; + case EventType::KeyRelease: + + if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && + active_notes_.find(event.value) != active_notes_.end()) { + int note = active_notes_[event.value]; + + active_notes_.erase(event.value); + auto message = juce::MidiMessage::noteOff(1, note); + te::MidiInputDevice *dev = + engine_.getDeviceManager().getDefaultMidiInDevice(); + dev->keyboardState.noteOff(1, note, 1.0); + } + break; } - break; + return; } - return; - } - switch (screen_state_) { + switch (screen_state_) { case ScreenState::Timeline: - timeline_.HandleEvent(event); - break; + timeline_.HandleEvent(event); + break; case ScreenState::Track: - tracks_[current_track_]->HandleEvent(event); - break; + tracks_[current_track_]->HandleEvent(event); + break; case ScreenState::PluginSelector: - plugin_sel_.HandleEvent(event); - break; - } + plugin_sel_.HandleEvent(event); + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/interface.cc b/src/core/interface.cc index dbb4344..4d55815 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -6,79 +6,79 @@ namespace box { Interface::Interface() { - SetConfigFlags(FLAG_WINDOW_RESIZABLE); - InitWindow(512, 512, "raylib - Rescalable 128x128 render"); - target_ = LoadRenderTexture(WIDTH, HEIGHT); - SetTargetFPS(60); - SetExitKey(0); // esc doesn't close program + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(512, 512, "raylib - Rescalable 128x128 render"); + target_ = LoadRenderTexture(WIDTH, HEIGHT); + SetTargetFPS(60); + SetExitKey(0); // esc doesn't close program - if constexpr (INPUT_TYPE == DeviceType::Hardware) { - // Initialize microcontroller input handling (e.g., serial interface) - } + if constexpr (INPUT_TYPE == DeviceType::Hardware) { + // Initialize microcontroller input handling (e.g., serial interface) + } } Interface::~Interface() { - if (DISPLAY_TYPE == DeviceType::Emulator) { - UnloadRenderTexture(target_); - CloseWindow(); - } + if (DISPLAY_TYPE == DeviceType::Emulator) { + UnloadRenderTexture(target_); + CloseWindow(); + } } void Interface::PreRender() { - BeginTextureMode(target_); // matches PostRender - ClearBackground(BLACK); + BeginTextureMode(target_); // matches PostRender + ClearBackground(BLACK); } void Interface::PostRender() { - if (DISPLAY_TYPE == DeviceType::Emulator) { - int screen_width = GetScreenWidth(); - int screen_height = GetScreenHeight(); + if (DISPLAY_TYPE == DeviceType::Emulator) { + int screen_width = GetScreenWidth(); + int screen_height = GetScreenHeight(); - int square_len = std::min(screen_width, screen_height); - int pos_x = (screen_width - square_len) / 2; - int pos_y = (screen_height - square_len) / 2; + int square_len = std::min(screen_width, screen_height); + int pos_x = (screen_width - square_len) / 2; + int pos_y = (screen_height - square_len) / 2; - EndTextureMode(); // matches PreRender - BeginDrawing(); - DrawTexturePro(target_.texture, - Rectangle{0, 0, float(target_.texture.width), - float(-target_.texture.height)}, - Rectangle{float(pos_x), float(pos_y), float(square_len), - float(square_len)}, - Vector2{0, 0}, 0.0f, WHITE); - EndDrawing(); - // hardware rendering - } else if (DISPLAY_TYPE == DeviceType::Hardware) { - Image image = LoadImageFromTexture(target_.texture); - Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) - } + EndTextureMode(); // matches PreRender + BeginDrawing(); + DrawTexturePro(target_.texture, + Rectangle{0, 0, float(target_.texture.width), + float(-target_.texture.height)}, + Rectangle{float(pos_x), float(pos_y), float(square_len), + float(square_len)}, + Vector2{0, 0}, 0.0f, WHITE); + EndDrawing(); + // hardware rendering + } else if (DISPLAY_TYPE == DeviceType::Hardware) { + Image image = LoadImageFromTexture(target_.texture); + Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) + } } // this code has really bad performance. keys often get stuck, // but for the purpose of being an emulator this is fine. -bool Interface::PollEvent(Event& event) { - for (auto& [key, is_pressed] : keys_) { - if (IsKeyDown(key)) { - if (is_pressed == false) { - is_pressed = !is_pressed; - event.type = EventType::KeyPress; - event.value = key; - return true; - } - } - if (IsKeyUp(key)) { - if (is_pressed == true) { - is_pressed = !is_pressed; - event.type = EventType::KeyRelease; - event.value = key; - return true; - } +bool Interface::PollEvent(Event &event) { + for (auto &[key, is_pressed] : keys_) { + if (IsKeyDown(key)) { + if (is_pressed == false) { + is_pressed = !is_pressed; + event.type = EventType::KeyPress; + event.value = key; + return true; + } + } + if (IsKeyUp(key)) { + if (is_pressed == true) { + is_pressed = !is_pressed; + event.type = EventType::KeyRelease; + event.value = key; + return true; + } + } } - } - return false; + return false; } bool Interface::ShouldClose() const { return WindowShouldClose(); } -} // namespace box +} // namespace box diff --git a/src/core/plugin.cc b/src/core/plugin.cc index 157c29b..c247652 100644 --- a/src/core/plugin.cc +++ b/src/core/plugin.cc @@ -7,13 +7,13 @@ Plugin::Plugin(te::Plugin *p) : plugin_{p} {} Plugin::~Plugin() { plugin_->deleteFromParent(); } void Plugin::EnsureTextureLoaded() const { - if (GetIcon().id == 0) { - Image icon = LoadImage(GetIconPath()); - GetIcon() = LoadTextureFromImage(icon); - UnloadImage(icon); - } + if (GetIcon().id == 0) { + Image icon = LoadImage(GetIconPath()); + GetIcon() = LoadTextureFromImage(icon); + UnloadImage(icon); + } } te::Plugin *const Plugin::GetPlugin() const { return plugin_; } -} // namespace box +} // namespace box diff --git a/src/core/plugin_selector.cc b/src/core/plugin_selector.cc index ea4e80c..0bd9a68 100644 --- a/src/core/plugin_selector.cc +++ b/src/core/plugin_selector.cc @@ -16,69 +16,70 @@ const std::vector PluginSelector::PLUGIN_NAMES = { }; void assert_index(std::vector v, size_t curr) { - if (curr >= v.size()) - throw std::runtime_error{"PluginSelector index out of range: " + - std::to_string(curr)}; + if (curr >= v.size()) + throw std::runtime_error{"PluginSelector index out of range: " + + std::to_string(curr)}; } PluginSelector::PluginSelector() {} void PluginSelector::Render(Interface &interface) { - for (size_t i = 0; i < interface.HEIGHT / 8; i++) { - if (i >= PLUGIN_NAMES.size()) break; - auto name = PLUGIN_NAMES[i]; - float x = 0; - float y = 16 * i; - float width = 128; - float height = 15; - Color color = RED; - if (current_index_ == i) { - color = BLUE; + for (size_t i = 0; i < interface.HEIGHT / 8; i++) { + if (i >= PLUGIN_NAMES.size()) + break; + auto name = PLUGIN_NAMES[i]; + float x = 0; + float y = 16 * i; + float width = 128; + float height = 15; + Color color = RED; + if (current_index_ == i) { + color = BLUE; + } + DrawRectangleRec(Rectangle{x, y, width, height}, DARKGRAY); + DrawText(name.c_str(), x, y, 5, color); } - DrawRectangleRec(Rectangle{x, y, width, height}, DARKGRAY); - DrawText(name.c_str(), x, y, 5, color); - } } void PluginSelector::HandleEvent(const Event &event) { - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ESCAPE: - APP->screen_state_ = App::ScreenState::Track; - break; + APP->screen_state_ = App::ScreenState::Track; + break; case KEY_K: - current_index_ = clamp_decrement(current_index_); - break; + current_index_ = clamp_decrement(current_index_); + break; case KEY_J: - current_index_ = - std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); - break; + current_index_ = + std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); + break; case KEY_ENTER: - // TODO proper back button? - APP->screen_state_ = App::ScreenState::Track; - const auto &name = PLUGIN_NAMES[current_index_]; + // TODO proper back button? + APP->screen_state_ = App::ScreenState::Track; + const auto &name = PLUGIN_NAMES[current_index_]; - std::unique_ptr p; - auto base = APP->edit_.getPluginCache() - .createNewPlugin(name.c_str(), {}) - .get(); - // TODO use cast? - if (name == te::ChorusPlugin::xmlTypeName) { - p = std::make_unique(base); - } else if (name == te::FourOscPlugin::xmlTypeName) { - p = std::make_unique(base); - } else if (name == te::CompressorPlugin::xmlTypeName) { - p = std::make_unique(base); - } else if (name == te::DelayPlugin::xmlTypeName) { - p = std::make_unique(base); - } + std::unique_ptr p; + auto base = APP->edit_.getPluginCache() + .createNewPlugin(name.c_str(), {}) + .get(); + // TODO use cast? + if (name == te::ChorusPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::FourOscPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::CompressorPlugin::xmlTypeName) { + p = std::make_unique(base); + } else if (name == te::DelayPlugin::xmlTypeName) { + p = std::make_unique(base); + } - APP->CurrTrack().AddPlugin(std::move(p)); - break; - } - break; - } + APP->CurrTrack().AddPlugin(std::move(p)); + break; + } + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/timeline.cc b/src/core/timeline.cc index 2421e1b..ac594e5 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -5,210 +5,218 @@ namespace box { Timeline::Timeline() { - { - Image tmp_l = LoadImage(METRONOME_PATH_L); - metronome_l_ = LoadTextureFromImage(tmp_l); - UnloadImage(tmp_l); - Image tmp_r = LoadImage(METRONOME_PATH_R); - metronome_r_ = LoadTextureFromImage(tmp_r); - UnloadImage(tmp_r); - Image tmp_off = LoadImage(METRONOME_PATH_OFF); - metronome_off_ = LoadTextureFromImage(tmp_off); - UnloadImage(tmp_off); - } + { + Image tmp_l = LoadImage(METRONOME_PATH_L); + metronome_l_ = LoadTextureFromImage(tmp_l); + UnloadImage(tmp_l); + Image tmp_r = LoadImage(METRONOME_PATH_R); + metronome_r_ = LoadTextureFromImage(tmp_r); + UnloadImage(tmp_r); + Image tmp_off = LoadImage(METRONOME_PATH_OFF); + metronome_off_ = LoadTextureFromImage(tmp_off); + UnloadImage(tmp_off); + } } Timeline::~Timeline() { - UnloadTexture(metronome_l_); - UnloadTexture(metronome_r_); - UnloadTexture(metronome_off_); + UnloadTexture(metronome_l_); + UnloadTexture(metronome_r_); + UnloadTexture(metronome_off_); } void Timeline::Render(Interface &interface) { - /* - terminology: - - row = the relative index of a track. - - so the top rectangle is always row 0, no matter what track it is - - track - - the actual "track" - */ - assert(is_close(frame_.radius, radius_)); - - const size_t num_rows = - std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); - const size_t curr_row = APP->GetCurrTrack() - scroll_offset_; - - const te::TransportControl &transport = APP->edit_.getTransport(); - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - - const Position curr_pos = { - static_cast(APP->edit_.getTransport().getPosition().inSeconds()), - static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; - - BeatFrame screen{curr_pos.beats, radius_}; - - if (playhead_mode_ == PlayheadMode::Detached) { - screen = frame_; - } - - assert(is_close(screen.radius, radius_)); - - // draw track outlines - for (size_t i = 0; i < num_rows; i++) { - float x = 0; - float y = (ROW_HEIGHT * i) + HEADER_HEIGHT; - DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, DARKGRAY); - } - - // render pos - { - auto text = format_time(curr_pos.secs); - - Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), (SCREEN_HALF - text_size.x / 2), - (HEADER_HEIGHT / 2 - text_size.y / 2), HEADER_FONT_SIZE, WHITE); - } - - // render metronome - { - if (APP->edit_.clickTrackEnabled == true) { - const int beat = static_cast(curr_pos.beats); - if (beat % 2 == 0) { - DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); - } else { - DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); - } - } else { - DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + /* + terminology: + - row = the relative index of a track. + - so the top rectangle is always row 0, no matter what track it is + - track + - the actual "track" + */ + assert(is_close(frame_.radius, radius_)); + + const size_t num_rows = + std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); + const size_t curr_row = APP->GetCurrTrack() - scroll_offset_; + + const te::TransportControl &transport = APP->edit_.getTransport(); + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + + const Position curr_pos = { + static_cast(APP->edit_.getTransport().getPosition().inSeconds()), + static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; + + BeatFrame screen{curr_pos.beats, radius_}; + + if (playhead_mode_ == PlayheadMode::Detached) { + screen = frame_; } - } - - // render key offset - { - DrawRectangle(SCREEN_EIGHTH, 0, ICON_WIDTH, ICON_HEIGHT, YELLOW); - auto text = format_key_offset(APP->key_offset_); - Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), SCREEN_EIGHTH + SCREEN_EIGHTH / 2 - text_size.x / 2, - HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, BLACK); - } - - // render cursor position - { - auto text = format_cursor_pos(APP->GetCurrTrack(), cursor_.LeftEdge()); - Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x / 2, - HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, WHITE); - } - - // render bar lines - { - float first_bar_start = - std::floor(screen.LeftEdge() / bar_width_) * bar_width_; - - for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); - bar_start += bar_width_) { - float bar_position_pct = (bar_start - screen.LeftEdge()) / screen.Width(); - int x = static_cast(bar_position_pct * SCREEN_WIDTH); - DrawLine(x, HEADER_HEIGHT, x, HEADER_HEIGHT + (ROW_HEIGHT * num_rows), - DARKGRAY); + + assert(is_close(screen.radius, radius_)); + + // draw track outlines + for (size_t i = 0; i < num_rows; i++) { + float x = 0; + float y = (ROW_HEIGHT * i) + HEADER_HEIGHT; + DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, DARKGRAY); } - } - - // render current live clip (if recording) - if (transport.isRecording()) { - const float start_time = - tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); - if (screen.LeftEdge() < start_time) { - float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); - float left_px = (left_pct * SCREEN_WIDTH); - DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, - (SCREEN_HALF - left_px), ROW_HEIGHT, RED); - } else { - DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, - (SCREEN_HALF - 0), ROW_HEIGHT, - RED); // 64 - 0 means full half bar + + // render pos + { + auto text = format_time(curr_pos.secs); + + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), (SCREEN_HALF - text_size.x / 2), + (HEADER_HEIGHT / 2 - text_size.y / 2), HEADER_FONT_SIZE, + WHITE); } - } - // render clips - { - for (size_t i = 0; i < num_rows; i++) { - const size_t track_idx = i + scroll_offset_; - const auto &t = APP->tracks_[track_idx]; - for (const auto &c : t->base_.getClips()) { - const te::ClipPosition c_pos = c->getPosition(); - te::BeatRange t_br = te::toBeats(c_pos.time, tempo); - BeatWindow clip = {static_cast(t_br.getStart().inBeats()), - static_cast(t_br.getLength().inBeats())}; - - // Determine overlap with visible range - const float visible_start = - std::max(screen.LeftEdge(), clip.LeftEdge()); - const float visible_end = - std::min(screen.RightEdge(), clip.RightEdge()); - - if (visible_start < visible_end) // Clip is visible - { - float start_pct = - (visible_start - screen.LeftEdge()) / screen.Width(); - float end_pct = (visible_end - screen.LeftEdge()) / screen.Width(); - - const int left_px = static_cast(start_pct * SCREEN_WIDTH); - const int right_px = static_cast(end_pct * SCREEN_WIDTH); - int clip_width = right_px - left_px; - - DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, - ROW_HEIGHT, GREEN); - DrawRectangleLines(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, - clip_width, ROW_HEIGHT, LIGHTGRAY); + // render metronome + { + if (APP->edit_.clickTrackEnabled == true) { + const int beat = static_cast(curr_pos.beats); + if (beat % 2 == 0) { + DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + } else { + DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + } + } else { + DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, + HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } - } } - } - - // render active track - assert(curr_row < num_rows); - { - float x = 0; - float y = (ROW_HEIGHT * curr_row) + HEADER_HEIGHT; - DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, RED); - } - - // render cursor - if (!transport.isRecording() && !transport.isPlaying()) { - const float left_pct = - (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); - const float right_pct = - (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); - - const int left_px = static_cast(left_pct * SCREEN_WIDTH); - const int right_px = static_cast(right_pct * SCREEN_WIDTH); - const int width = right_px - left_px; - - DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, width, - ROW_HEIGHT, ORANGE); - } - - // render playhead - { - if (screen.LeftEdge() < curr_pos.beats && - curr_pos.beats < screen.RightEdge()) { - const float left_pct = - (curr_pos.beats - screen.LeftEdge()) / screen.Width(); - const int left_px = static_cast(left_pct * SCREEN_WIDTH); - // -1 so that you can see the tick - DrawLine(left_px, HEADER_HEIGHT - 1, left_px, SCREEN_HEIGHT, WHITE); + + // render key offset + { + DrawRectangle(SCREEN_EIGHTH, 0, ICON_WIDTH, ICON_HEIGHT, YELLOW); + auto text = format_key_offset(APP->key_offset_); + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), + SCREEN_EIGHTH + SCREEN_EIGHTH / 2 - text_size.x / 2, + HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, BLACK); + } + + // render cursor position + { + auto text = format_cursor_pos(APP->GetCurrTrack(), cursor_.LeftEdge()); + Vector2 text_size = + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, + HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x / 2, + HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, WHITE); + } + + // render bar lines + { + float first_bar_start = + std::floor(screen.LeftEdge() / bar_width_) * bar_width_; + + for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); + bar_start += bar_width_) { + float bar_position_pct = + (bar_start - screen.LeftEdge()) / screen.Width(); + int x = static_cast(bar_position_pct * SCREEN_WIDTH); + DrawLine(x, HEADER_HEIGHT, x, + HEADER_HEIGHT + (ROW_HEIGHT * num_rows), DARKGRAY); + } + } + + // render current live clip (if recording) + if (transport.isRecording()) { + const float start_time = + tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); + if (screen.LeftEdge() < start_time) { + float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); + float left_px = (left_pct * SCREEN_WIDTH); + DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, + (SCREEN_HALF - left_px), ROW_HEIGHT, RED); + } else { + DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, + (SCREEN_HALF - 0), ROW_HEIGHT, + RED); // 64 - 0 means full half bar + } + } + + // render clips + { + for (size_t i = 0; i < num_rows; i++) { + const size_t track_idx = i + scroll_offset_; + const auto &t = APP->tracks_[track_idx]; + for (const auto &c : t->base_.getClips()) { + const te::ClipPosition c_pos = c->getPosition(); + te::BeatRange t_br = te::toBeats(c_pos.time, tempo); + BeatWindow clip = { + static_cast(t_br.getStart().inBeats()), + static_cast(t_br.getLength().inBeats())}; + + // Determine overlap with visible range + const float visible_start = + std::max(screen.LeftEdge(), clip.LeftEdge()); + const float visible_end = + std::min(screen.RightEdge(), clip.RightEdge()); + + if (visible_start < visible_end) // Clip is visible + { + float start_pct = + (visible_start - screen.LeftEdge()) / screen.Width(); + float end_pct = + (visible_end - screen.LeftEdge()) / screen.Width(); + + const int left_px = + static_cast(start_pct * SCREEN_WIDTH); + const int right_px = + static_cast(end_pct * SCREEN_WIDTH); + int clip_width = right_px - left_px; + + DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, + clip_width, ROW_HEIGHT, GREEN); + DrawRectangleLines(left_px, + (i * ROW_HEIGHT) + HEADER_HEIGHT, + clip_width, ROW_HEIGHT, LIGHTGRAY); + } + } + } + } + + // render active track + assert(curr_row < num_rows); + { + float x = 0; + float y = (ROW_HEIGHT * curr_row) + HEADER_HEIGHT; + DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, RED); + } + + // render cursor + if (!transport.isRecording() && !transport.isPlaying()) { + const float left_pct = + (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); + const float right_pct = + (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); + + const int left_px = static_cast(left_pct * SCREEN_WIDTH); + const int right_px = static_cast(right_pct * SCREEN_WIDTH); + const int width = right_px - left_px; + + DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, + width, ROW_HEIGHT, ORANGE); + } + + // render playhead + { + if (screen.LeftEdge() < curr_pos.beats && + curr_pos.beats < screen.RightEdge()) { + const float left_pct = + (curr_pos.beats - screen.LeftEdge()) / screen.Width(); + const int left_px = static_cast(left_pct * SCREEN_WIDTH); + // -1 so that you can see the tick + DrawLine(left_px, HEADER_HEIGHT - 1, left_px, SCREEN_HEIGHT, WHITE); + } } - } } // TODO update? @@ -233,239 +241,248 @@ void Timeline::Render(Interface &interface) { // } void Timeline::print_timeline() { - std::cout << std::endl; - const auto &track = APP->CurrTrack().base_; - std::cout << "name: " << track.getName() << std::endl; - std::cout << "isMuted: " << track.isMuted(false) << std::endl; - std::cout << "isSolo: " << track.isSolo(false) << std::endl; - - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - const te::TransportControl &transport = APP->edit_.getTransport(); - const te::TimePosition &curr_time_pos = transport.getPosition(); - const te::BeatPosition &curr_beat_pos = - te::toBeats(te::EditTime{transport.getPosition()}, tempo); - const te::TimeSigSetting &time_sig = tempo.getTimeSigAt(curr_time_pos); - - std::cout << "TIME curr position: " << curr_time_pos.inSeconds() << std::endl; - std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() << std::endl; - std::cout << "bpm: " << tempo.getBpmAt(curr_time_pos) << std::endl; - std::cout << "time signature: " << time_sig.getStringTimeSig() << std::endl; - std::cout << "time signature numerator: " << time_sig.numerator << std::endl; - std::cout << "time signature denominator: " << time_sig.denominator - << std::endl; - - const auto clips = track.getClips(); - std::cout << "num clips: " << clips.size() << std::endl; - for (auto c : clips) { - std::cout << "\t" - << "name: " << c->getName() << std::endl; - std::cout << "\t\t" - << "isMidi: " << c->isMidi() << std::endl; - const te::ClipPosition pos = c->getPosition(); - auto edit_range = te::EditTimeRange{pos.time}; - te::TimeRange time_range = te::toTime(edit_range, APP->edit_.tempoSequence); - te::BeatRange beat_range = - te::toBeats(edit_range, APP->edit_.tempoSequence); - std::cout << "\t\t" - << "TIME start: " << time_range.getStart().inSeconds() + std::cout << std::endl; + const auto &track = APP->CurrTrack().base_; + std::cout << "name: " << track.getName() << std::endl; + std::cout << "isMuted: " << track.isMuted(false) << std::endl; + std::cout << "isSolo: " << track.isSolo(false) << std::endl; + + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + const te::TransportControl &transport = APP->edit_.getTransport(); + const te::TimePosition &curr_time_pos = transport.getPosition(); + const te::BeatPosition &curr_beat_pos = + te::toBeats(te::EditTime{transport.getPosition()}, tempo); + const te::TimeSigSetting &time_sig = tempo.getTimeSigAt(curr_time_pos); + + std::cout << "TIME curr position: " << curr_time_pos.inSeconds() + << std::endl; + std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() << std::endl; - std::cout << "\t\t" - << "TIME end: " << time_range.getEnd().inSeconds() << std::endl; - std::cout << "\t\t" - << "TIME length: " << pos.getLength().inSeconds() << std::endl; - std::cout << "\t\t" - << "BEATS start: " << beat_range.getStart().inBeats() + std::cout << "bpm: " << tempo.getBpmAt(curr_time_pos) << std::endl; + std::cout << "time signature: " << time_sig.getStringTimeSig() << std::endl; + std::cout << "time signature numerator: " << time_sig.numerator << std::endl; - std::cout << "\t\t" - << "BEATS end: " << beat_range.getEnd().inBeats() << std::endl; - std::cout << "\t\t" - << "BEATS length: " << beat_range.getLength().inBeats() + std::cout << "time signature denominator: " << time_sig.denominator << std::endl; - } + + const auto clips = track.getClips(); + std::cout << "num clips: " << clips.size() << std::endl; + for (auto c : clips) { + std::cout << "\t" + << "name: " << c->getName() << std::endl; + std::cout << "\t\t" + << "isMidi: " << c->isMidi() << std::endl; + const te::ClipPosition pos = c->getPosition(); + auto edit_range = te::EditTimeRange{pos.time}; + te::TimeRange time_range = + te::toTime(edit_range, APP->edit_.tempoSequence); + te::BeatRange beat_range = + te::toBeats(edit_range, APP->edit_.tempoSequence); + std::cout << "\t\t" + << "TIME start: " << time_range.getStart().inSeconds() + << std::endl; + std::cout << "\t\t" + << "TIME end: " << time_range.getEnd().inSeconds() + << std::endl; + std::cout << "\t\t" + << "TIME length: " << pos.getLength().inSeconds() + << std::endl; + std::cout << "\t\t" + << "BEATS start: " << beat_range.getStart().inBeats() + << std::endl; + std::cout << "\t\t" + << "BEATS end: " << beat_range.getEnd().inBeats() + << std::endl; + std::cout << "\t\t" + << "BEATS length: " << beat_range.getLength().inBeats() + << std::endl; + } } void Timeline::FocusCursor() { - assert(cursor_.len < frame_.Width()); - if (cursor_.LeftEdge() < frame_.LeftEdge()) { - const float diff = frame_.LeftEdge() - cursor_.LeftEdge(); - frame_.center -= diff; - } else if (cursor_.RightEdge() > frame_.RightEdge()) { - const float diff = cursor_.RightEdge() - frame_.RightEdge(); - frame_.center += diff; - } + assert(cursor_.len < frame_.Width()); + if (cursor_.LeftEdge() < frame_.LeftEdge()) { + const float diff = frame_.LeftEdge() - cursor_.LeftEdge(); + frame_.center -= diff; + } else if (cursor_.RightEdge() > frame_.RightEdge()) { + const float diff = cursor_.RightEdge() - frame_.RightEdge(); + frame_.center += diff; + } } void Timeline::HandleEvent(const Event &event) { - switch (screen_state_) { + switch (screen_state_) { case ScreenState::Overview: - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ENTER: - APP->screen_state_ = App::ScreenState::Track; - break; + APP->screen_state_ = App::ScreenState::Track; + break; case KEY_H: - cursor_.start -= step_size_; - LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge()); - FocusCursor(); - break; + cursor_.start -= step_size_; + LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge()); + FocusCursor(); + break; case KEY_L: - cursor_.start += step_size_; - LOG_VAR(cursor_.RightEdge() > frame_.RightEdge()); - FocusCursor(); - break; + cursor_.start += step_size_; + LOG_VAR(cursor_.RightEdge() > frame_.RightEdge()); + FocusCursor(); + break; case KEY_J: - if (!APP->edit_.getTransport().isRecording()) { - APP->SetCurrTrack( - clamp_increment(APP->GetCurrTrack(), APP->tracks_.size())); - if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) { - scroll_offset_ = - clamp_increment(scroll_offset_, APP->tracks_.size()); + if (!APP->edit_.getTransport().isRecording()) { + APP->SetCurrTrack(clamp_increment(APP->GetCurrTrack(), + APP->tracks_.size())); + if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) { + scroll_offset_ = clamp_increment(scroll_offset_, + APP->tracks_.size()); + } } - } - break; + break; case KEY_K: - if (!APP->edit_.getTransport().isRecording()) { - APP->SetCurrTrack(clamp_decrement(APP->GetCurrTrack())); - if (APP->GetCurrTrack() < scroll_offset_) { - scroll_offset_ = clamp_decrement(scroll_offset_); + if (!APP->edit_.getTransport().isRecording()) { + APP->SetCurrTrack(clamp_decrement(APP->GetCurrTrack())); + if (APP->GetCurrTrack() < scroll_offset_) { + scroll_offset_ = clamp_decrement(scroll_offset_); + } } - } - break; + break; case KEY_UP: - scroll_offset_ = clamp_decrement(scroll_offset_); - break; + scroll_offset_ = clamp_decrement(scroll_offset_); + break; case KEY_DOWN: - scroll_offset_ = - clamp_increment(scroll_offset_, APP->tracks_.size()); - break; - case KEY_O: // add track - if (APP->tracks_.size() < MAX_TRACKS) { - APP->AddTrack(); - } - break; + scroll_offset_ = + clamp_increment(scroll_offset_, APP->tracks_.size()); + break; + case KEY_O: // add track + if (APP->tracks_.size() < MAX_TRACKS) { + APP->AddTrack(); + } + break; case KEY_W: { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime( - te::BeatPosition::fromBeats(cursor_.RightEdge())); - - te::TrackItem *item = - APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) { - LOG_MSG("KEY_W found NONE"); - } else { - if (auto clip = dynamic_cast(item)) { - cursor_.start = clip->getStartBeat().inBeats(); - FocusCursor(); + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + auto pos = tempo.toTime( + te::BeatPosition::fromBeats(cursor_.RightEdge())); + + te::TrackItem *item = + APP->CurrTrack().base_.getNextTrackItemAt(pos); + if (item == nullptr) { + LOG_MSG("KEY_W found NONE"); + } else { + if (auto clip = dynamic_cast(item)) { + cursor_.start = clip->getStartBeat().inBeats(); + FocusCursor(); + } } - } } break; case KEY_D: { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = - tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); - - te::TrackItem *item = - APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) { - LOG_MSG("KEY_D found NONE"); - } else { - LOG_MSG("deleting item of type:"); - LOG_MSG(te::TrackItem::typeToString(item->type)); - if (auto clip = dynamic_cast(item)) { - clip->removeFromParent(); + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + auto pos = + tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); + + te::TrackItem *item = + APP->CurrTrack().base_.getNextTrackItemAt(pos); + if (item == nullptr) { + LOG_MSG("KEY_D found NONE"); + } else { + LOG_MSG("deleting item of type:"); + LOG_MSG(te::TrackItem::typeToString(item->type)); + if (auto clip = dynamic_cast(item)) { + clip->removeFromParent(); + } } - } } break; case KEY_P: - print_timeline(); - LOG_VAR(frame_.center); - break; + print_timeline(); + LOG_VAR(frame_.center); + break; case KEY_C: - // toggle metronome - APP->edit_.clickTrackEnabled = !APP->edit_.clickTrackEnabled; - break; + // toggle metronome + APP->edit_.clickTrackEnabled = !APP->edit_.clickTrackEnabled; + break; case KEY_R: { - auto &transport = APP->edit_.getTransport(); - LOG_VAR(transport.getPosition().inSeconds()); - LOG_VAR(transport.isRecording()); - if (transport.isRecording()) { - transport.stop(false, false); // TODO should this discard? - te::EditFileOperations(APP->edit_).save(true, true, false); - playhead_mode_ = PlayheadMode::Detached; - - { - const float curr_pos = - APP->edit_.tempoSequence.toBeats(transport.getPosition()) - .inBeats(); - cursor_.start = - std::floor(curr_pos / bar_width_) * bar_width_; - frame_.center = curr_pos; + auto &transport = APP->edit_.getTransport(); + LOG_VAR(transport.getPosition().inSeconds()); + LOG_VAR(transport.isRecording()); + if (transport.isRecording()) { + transport.stop(false, false); // TODO should this discard? + te::EditFileOperations(APP->edit_).save(true, true, false); + playhead_mode_ = PlayheadMode::Detached; + + { + const float curr_pos = + APP->edit_.tempoSequence + .toBeats(transport.getPosition()) + .inBeats(); + cursor_.start = + std::floor(curr_pos / bar_width_) * bar_width_; + frame_.center = curr_pos; + } + assert_multiple(cursor_.start, bar_width_); + } else { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + transport.setPosition(tempo.toTime( + te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.record(false); + playhead_mode_ = PlayheadMode::Locked; } - assert_multiple(cursor_.start, bar_width_); - } else { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime( - te::BeatPosition::fromBeats(cursor_.LeftEdge()))); - transport.record(false); - playhead_mode_ = PlayheadMode::Locked; - } } break; case KEY_T: { - auto &transport = APP->edit_.getTransport(); - if (transport.isPlaying()) { - transport.stop(false, false); // TODO should this discard? - playhead_mode_ = PlayheadMode::Detached; - - { - const float curr_pos = - APP->edit_.tempoSequence.toBeats(transport.getPosition()) - .inBeats(); - cursor_.start = - std::floor(curr_pos / bar_width_) * bar_width_; - frame_.center = curr_pos; + auto &transport = APP->edit_.getTransport(); + if (transport.isPlaying()) { + transport.stop(false, false); // TODO should this discard? + playhead_mode_ = PlayheadMode::Detached; + + { + const float curr_pos = + APP->edit_.tempoSequence + .toBeats(transport.getPosition()) + .inBeats(); + cursor_.start = + std::floor(curr_pos / bar_width_) * bar_width_; + frame_.center = curr_pos; + } + assert_multiple(cursor_.start, bar_width_); + } else { + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + transport.setPosition(tempo.toTime( + te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.play(false); + playhead_mode_ = PlayheadMode::Locked; } - assert_multiple(cursor_.start, bar_width_); - } else { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime( - te::BeatPosition::fromBeats(cursor_.LeftEdge()))); - transport.play(false); - playhead_mode_ = PlayheadMode::Locked; - } } break; case KEY_S: { - LOG_MSG("move to origin"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds(0.f)); - cursor_.start = 0; - frame_.center = 0; + LOG_MSG("move to origin"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds(0.f)); + cursor_.start = 0; + frame_.center = 0; } break; case KEY_COMMA: { - LOG_MSG("move left"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds( - transport.getPosition().inSeconds() - 2.f)); + LOG_MSG("move left"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds( + transport.getPosition().inSeconds() - 2.f)); } break; case KEY_PERIOD: { - LOG_MSG("move right"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds( - transport.getPosition().inSeconds() + 2.f)); + LOG_MSG("move right"); + auto &transport = APP->edit_.getTransport(); + transport.setPosition(te::TimePosition::fromSeconds( + transport.getPosition().inSeconds() + 2.f)); } break; case KEY_MINUS: - radius_ *= 2; - frame_.radius *= 2; // TODO centralize this - break; + radius_ *= 2; + frame_.radius *= 2; // TODO centralize this + break; case KEY_EQUAL: - radius_ /= 2; - frame_.radius /= 2; // TODO centralize this - break; - } - break; - } - break; - } + radius_ /= 2; + frame_.radius /= 2; // TODO centralize this + break; + } + break; + } + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/track.cc b/src/core/track.cc index 004d5ba..3f009d7 100644 --- a/src/core/track.cc +++ b/src/core/track.cc @@ -7,40 +7,40 @@ namespace box { -static void assert_plugins(const std::vector>& plugins, +static void assert_plugins(const std::vector> &plugins, int index, std::string function_name) { - if (index >= plugins.size()) { - throw std::runtime_error{"Track::" + function_name + " => index [" + - std::to_string(index) + "] out of range: [0, " + - std::to_string(plugins.size()) + "]"}; - } + if (index >= plugins.size()) { + throw std::runtime_error{ + "Track::" + function_name + " => index [" + std::to_string(index) + + "] out of range: [0, " + std::to_string(plugins.size()) + "]"}; + } } -Track::Track(te::AudioTrack& base) : base_{base} {} +Track::Track(te::AudioTrack &base) : base_{base} {} Track::~Track() {} void Track::AddPlugin(std::unique_ptr plugin) { - if (active_plugin_ == -1) - active_plugin_ = 0; // TODO better way to handle this - int index = plugins_.size(); - base_.pluginList.insertPlugin(plugin->GetPlugin(), index, nullptr); - plugins_.push_back(std::move(plugin)); + if (active_plugin_ == -1) + active_plugin_ = 0; // TODO better way to handle this + int index = plugins_.size(); + base_.pluginList.insertPlugin(plugin->GetPlugin(), index, nullptr); + plugins_.push_back(std::move(plugin)); } void Track::RemoveActivePlugin() { - if (plugins_.size() == 0) { - LOG_MSG("tried to remove plugin from empty track", LogLevel::Warn); - return; - } - if (active_plugin_ == -1) { - LOG_MSG("tried to remove active_plugin == -1", LogLevel::Warn); - return; - } - plugins_.erase(plugins_.begin() + active_plugin_); - // TODO check for underflow messing up min - active_plugin_ = - std::min(active_plugin_, static_cast(plugins_.size()) - 1); + if (plugins_.size() == 0) { + LOG_MSG("tried to remove plugin from empty track", LogLevel::Warn); + return; + } + if (active_plugin_ == -1) { + LOG_MSG("tried to remove active_plugin == -1", LogLevel::Warn); + return; + } + plugins_.erase(plugins_.begin() + active_plugin_); + // TODO check for underflow messing up min + active_plugin_ = + std::min(active_plugin_, static_cast(plugins_.size()) - 1); } void Track::SetActivePlugin(int index) { active_plugin_ = index; } @@ -48,121 +48,123 @@ void Track::SetActivePlugin(int index) { active_plugin_ = index; } int Track::GetActivePlugin() { return active_plugin_; } int clamp_index(int i, int len) { - int range = len; - int val = i % range; - if (val < 0) val += range; - return val; + int range = len; + int val = i % range; + if (val < 0) + val += range; + return val; } -void Track::HandleEvent(const Event& event) { - switch (screen_state_) { +void Track::HandleEvent(const Event &event) { + switch (screen_state_) { case ScreenState::Overview: - switch (APP->mode_) { + switch (APP->mode_) { case App::Mode::Normal: - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ESCAPE: - APP->screen_state_ = App::ScreenState::Timeline; - break; + APP->screen_state_ = App::ScreenState::Timeline; + break; case KEY_A: - APP->screen_state_ = App::ScreenState::PluginSelector; - break; + APP->screen_state_ = App::ScreenState::PluginSelector; + break; case KEY_X: - RemoveActivePlugin(); - break; + RemoveActivePlugin(); + break; case KEY_P: { - auto l = base_.pluginList.getPlugins(); - for (auto p : l) { - std::cout << p->getName() << ", "; - } - std::cout << std::endl; + auto l = base_.pluginList.getPlugins(); + for (auto p : l) { + std::cout << p->getName() << ", "; + } + std::cout << std::endl; } break; // TODO KEY_J and KEY_K move up and down case KEY_H: - LOG_MSG("left"); - active_plugin_ = - clamp_index(active_plugin_ - 1, plugins_.size()); - LOG_VAR(active_plugin_); - break; + LOG_MSG("left"); + active_plugin_ = + clamp_index(active_plugin_ - 1, plugins_.size()); + LOG_VAR(active_plugin_); + break; case KEY_L: - LOG_MSG("right"); - active_plugin_ = - clamp_index(active_plugin_ + 1, plugins_.size()); - LOG_VAR(active_plugin_); - break; + LOG_MSG("right"); + active_plugin_ = + clamp_index(active_plugin_ + 1, plugins_.size()); + LOG_VAR(active_plugin_); + break; case KEY_ENTER: - // TODO sketchy - if (active_plugin_ != -1) screen_state_ = ScreenState::Plugin; - break; - } - break; - } - break; + // TODO sketchy + if (active_plugin_ != -1) + screen_state_ = ScreenState::Plugin; + break; + } + break; + } + break; case App::Mode::Insert: - break; - } - break; + break; + } + break; case ScreenState::Plugin: - if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) { - screen_state_ = ScreenState::Overview; - return; - } - switch (APP->mode_) { + if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) { + screen_state_ = ScreenState::Overview; + return; + } + switch (APP->mode_) { case App::Mode::Normal: - plugins_[active_plugin_]->HandleEvent(event); - break; + plugins_[active_plugin_]->HandleEvent(event); + break; case App::Mode::Insert: - break; - } - break; - } + break; + } + break; + } } -void Track::Render(Interface& interface) { - switch (screen_state_) { +void Track::Render(Interface &interface) { + switch (screen_state_) { case ScreenState::Overview: - // draw grid - for (int i = 1; i < GRID_SIZE; i++) { - float pos = static_cast(i); - DrawLineV(Vector2{0, pos * 32}, Vector2{128, pos * 32}, WHITE); - DrawLineV(Vector2{pos * 32, 0}, Vector2{pos * 32, 128}, WHITE); - } - - for (int i = 0; i < plugins_.size(); i++) { - auto x = static_cast((i % 4) * 32 + 16); - auto y = static_cast((i / 4) * 32 + 64 + 16); - DrawTexture(plugins_[i]->GetIcon(), x - 8, y - 8, WHITE); - - constexpr int font_size = 10; - int width = MeasureText(plugins_[i]->GetName(), font_size); - DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, - WHITE); - - if (i == active_plugin_) { - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, - static_cast(i / 4) * 32 + 64 + 16}, - 5.0f, GREEN); + // draw grid + for (int i = 1; i < GRID_SIZE; i++) { + float pos = static_cast(i); + DrawLineV(Vector2{0, pos * 32}, Vector2{128, pos * 32}, WHITE); + DrawLineV(Vector2{pos * 32, 0}, Vector2{pos * 32, 128}, WHITE); + } + + for (int i = 0; i < plugins_.size(); i++) { + auto x = static_cast((i % 4) * 32 + 16); + auto y = static_cast((i / 4) * 32 + 64 + 16); + DrawTexture(plugins_[i]->GetIcon(), x - 8, y - 8, WHITE); + + constexpr int font_size = 10; + int width = MeasureText(plugins_[i]->GetName(), font_size); + DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, + WHITE); + + if (i == active_plugin_) { + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, + static_cast(i / 4) * 32 + 64 + 16}, + 5.0f, GREEN); + } + } + for (int i = plugins_.size(); i < MAX_PLUGINS; i++) { + auto x = static_cast((i % 4) * 32 + 16); + auto y = static_cast((i / 4) * 32 + 64 + 16); + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, + static_cast(i / 4) * 32 + 64 + 16}, + 1.0f, RED); + DrawTextPro(GetFontDefault(), "none", Vector2{x, y}, + Vector2{ + 11, + -4, + }, + 0.0f, 10.0f, 1.0f, WHITE); } - } - for (int i = plugins_.size(); i < MAX_PLUGINS; i++) { - auto x = static_cast((i % 4) * 32 + 16); - auto y = static_cast((i / 4) * 32 + 64 + 16); - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, - static_cast(i / 4) * 32 + 64 + 16}, - 1.0f, RED); - DrawTextPro(GetFontDefault(), "none", Vector2{x, y}, - Vector2{ - 11, - -4, - }, - 0.0f, 10.0f, 1.0f, WHITE); - } - break; + break; case ScreenState::Plugin: - plugins_[active_plugin_]->Render(interface); - break; - } + plugins_[active_plugin_]->Render(interface); + break; + } } -} // namespace box +} // namespace box diff --git a/src/core/util.cc b/src/core/util.cc index 04fda33..e27294f 100644 --- a/src/core/util.cc +++ b/src/core/util.cc @@ -2,94 +2,102 @@ namespace box { -App* APP = nullptr; // Define the global APP variable +App *APP = nullptr; // Define the global APP variable void assert_multiple(float a, float b) { - const float epsilon = 1e-6; // Small tolerance for floating-point precision - assert(std::fabs(std::fmod(a, b)) < epsilon && "a is not a multiple of b"); + const float epsilon = 1e-6; // Small tolerance for floating-point precision + assert(std::fabs(std::fmod(a, b)) < epsilon && "a is not a multiple of b"); } bool is_close(float a, float b) { return std::abs(a - b) < 1e-6; } std::string format_time(float time) { - int minutes = static_cast(time) / 60; - int seconds = static_cast(time) % 60; - int decimal = - static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places + int minutes = static_cast(time) / 60; + int seconds = static_cast(time) % 60; + int decimal = + static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places - std::ostringstream oss; - oss << std::setw(2) << std::setfill('0') << minutes << "." << std::setw(2) - << std::setfill('0') << seconds << "." << std::setw(2) - << std::setfill('0') << decimal; + std::ostringstream oss; + oss << std::setw(2) << std::setfill('0') << minutes << "." << std::setw(2) + << std::setfill('0') << seconds << "." << std::setw(2) + << std::setfill('0') << decimal; - return oss.str(); + return oss.str(); } std::string format_key_offset(int key_offset) { - if (key_offset > 0) - return "+" + std::to_string(key_offset); - else - return std::to_string(key_offset); + if (key_offset > 0) + return "+" + std::to_string(key_offset); + else + return std::to_string(key_offset); } std::string format_cursor_pos(size_t track_pos, float cursor_pos) { - std::ostringstream oss; - oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') - << cursor_pos; - return oss.str(); + std::ostringstream oss; + oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') + << cursor_pos; + return oss.str(); } size_t clamp_decrement(size_t x) { - if (x == 0) - return 0; - else - return x - 1; + if (x == 0) + return 0; + else + return x - 1; } size_t clamp_increment(size_t x, size_t max) { - return std::min(x + 1, clamp_decrement(max)); + return std::min(x + 1, clamp_decrement(max)); } -LogLevel string_to_loglevel(const std::string& s) { - if (s == "OFF") return LogLevel::Off; - if (s == "DEBUG") return LogLevel::Debug; - if (s == "WARN") return LogLevel::Warn; - if (s == "ERR") return LogLevel::Err; - throw std::runtime_error{"string_to_loglevel(" + s + ") not found"}; +LogLevel string_to_loglevel(const std::string &s) { + if (s == "OFF") + return LogLevel::Off; + if (s == "DEBUG") + return LogLevel::Debug; + if (s == "WARN") + return LogLevel::Warn; + if (s == "ERR") + return LogLevel::Err; + throw std::runtime_error{"string_to_loglevel(" + s + ") not found"}; } std::string loglevel_to_string(LogLevel l) { - if (l == LogLevel::Off) return "OFF"; - if (l == LogLevel::Debug) return "DEBUG"; - if (l == LogLevel::Warn) return "WARN"; - if (l == LogLevel::Err) return "ERR"; - throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + - ") not found"}; + if (l == LogLevel::Off) + return "OFF"; + if (l == LogLevel::Debug) + return "DEBUG"; + if (l == LogLevel::Warn) + return "WARN"; + if (l == LogLevel::Err) + return "ERR"; + throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + + ") not found"}; } // get loglevel from env LogLevel get_loglevel() { - const char* env = std::getenv("BOX_LOG"); - if (env) { - return string_to_loglevel(env); - } - return LogLevel::Off; // default + const char *env = std::getenv("BOX_LOG"); + if (env) { + return string_to_loglevel(env); + } + return LogLevel::Off; // default } -void LOG_MSG(const std::string& msg, LogLevel l) { - static LogLevel curr = get_loglevel(); +void LOG_MSG(const std::string &msg, LogLevel l) { + static LogLevel curr = get_loglevel(); - if (l < curr) { - return; - } - // get time - std::time_t now = std::time(nullptr); - char buf[20]; - std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); + if (l < curr) { + return; + } + // get time + std::time_t now = std::time(nullptr); + char buf[20]; + std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); - // print - std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg - << std::endl; + // print + std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg + << std::endl; } -} // namespace box +} // namespace box diff --git a/src/main.cc b/src/main.cc index 3a26bea..83a87a4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,55 +7,57 @@ #include "raylib.h" int main() { - const juce::ScopedJuceInitialiser_GUI initialiser; // need this - SetTargetFPS(60); - - te::Engine engine{"Tracktion Hello World"}; - std::filesystem::path curr_path = std::filesystem::current_path(); - juce::File my_file{juce::String{curr_path.string() + "/tmp.box"}}; - - std::unique_ptr my_edit = createEmptyEdit(engine, my_file); - te::Edit &edit = *my_edit; - edit.ensureNumberOfAudioTracks(8); - edit.getTransport().ensureContextAllocated(); - box::Interface interface{}; - - box::App app(engine, edit); - box::APP = &app; - - try { - // arm - { - auto &dm = engine.getDeviceManager(); - - for (int i = 0; i < dm.getNumWaveInDevices(); i++) { - if (auto wip = dm.getWaveInDevice(i)) { - wip->setStereoPair(false); - // wip->setEndToEnd(true); // TODO update ? - wip->setEnabled(true); - } else if (auto mip = dm.getMidiInDevice(i)) { - // mip->setEndToEndEnabled(true); // TODO update ? - mip->setEnabled(true); + const juce::ScopedJuceInitialiser_GUI initialiser; // need this + SetTargetFPS(60); + + te::Engine engine{"Tracktion Hello World"}; + std::filesystem::path curr_path = std::filesystem::current_path(); + juce::File my_file{juce::String{curr_path.string() + "/tmp.box"}}; + + std::unique_ptr my_edit = createEmptyEdit(engine, my_file); + te::Edit &edit = *my_edit; + edit.ensureNumberOfAudioTracks(8); + edit.getTransport().ensureContextAllocated(); + box::Interface interface{}; + + box::App app(engine, edit); + box::APP = &app; + + try { + // arm + { + auto &dm = engine.getDeviceManager(); + + for (int i = 0; i < dm.getNumWaveInDevices(); i++) { + if (auto wip = dm.getWaveInDevice(i)) { + wip->setStereoPair(false); + // wip->setEndToEnd(true); // TODO update ? + wip->setEnabled(true); + } else if (auto mip = dm.getMidiInDevice(i)) { + // mip->setEndToEndEnabled(true); // TODO update ? + mip->setEnabled(true); + } + } } - } - } - while (!interface.ShouldClose()) { - // poll and handle events - box::Event event; - if (interface.PollEvent(event)) { - app.HandleEvent(event); - } + while (!interface.ShouldClose()) { + // poll and handle events + box::Event event; + if (interface.PollEvent(event)) { + app.HandleEvent(event); + } - interface.PreRender(); + interface.PreRender(); - // do rendering - { app.Render(interface); } + // do rendering + { + app.Render(interface); + } - interface.PostRender(); + interface.PostRender(); + } + } catch (std::exception &e) { + std::cerr << e.what() << std::endl; } - } catch (std::exception &e) { - std::cerr << e.what() << std::endl; - } - return 0; + return 0; } diff --git a/src/plugin/chorus.cc b/src/plugin/chorus.cc index 7530d36..bc99174 100644 --- a/src/plugin/chorus.cc +++ b/src/plugin/chorus.cc @@ -4,37 +4,36 @@ namespace box { -Texture2D Chorus::icon_; // Define the static member +Texture2D Chorus::icon_; // Define the static member Chorus::Chorus(te::Plugin *p) - : Plugin(p), - base_plugin_{static_cast(p)}, + : Plugin(p), base_plugin_{static_cast(p)}, knob_depth_{Parameter{CV{base_plugin_->depthMs, 0.0, 10.0}}, - 32, // x - 22, // y - 16, // radius + 32, // x + 22, // y + 16, // radius GREEN, "depth"}, knob_width_{Parameter{CV{base_plugin_->width, 0.0, 1.0}}, - 96, // x - 22, // y - 16, // radius + 96, // x + 22, // y + 16, // radius RED, "width"}, knob_speed_{Parameter{CV{base_plugin_->speedHz, 0.0, 10.0}}, - 32, // x - 86, // y - 16, // radius + 32, // x + 86, // y + 16, // radius BLUE, "speed"}, knob_mix_{ Parameter{CV{base_plugin_->mixProportion, 0.0, 1.0}}, - 96, // x - 86, // y - 16, // radius + 96, // x + 86, // y + 16, // radius YELLOW, "mix"} { - EnsureTextureLoaded(); + EnsureTextureLoaded(); } Chorus::~Chorus() { UnloadTexture(icon_); } @@ -46,53 +45,53 @@ const char *Chorus::GetIconPath() const { return icon_path_; } const char *Chorus::GetName() const { return name_; } void Chorus::Render(Interface &interface) { - knob_depth_.Render(interface); - knob_width_.Render(interface); - knob_speed_.Render(interface); - knob_mix_.Render(interface); + knob_depth_.Render(interface); + knob_width_.Render(interface); + knob_speed_.Render(interface); + knob_mix_.Render(interface); } void Chorus::HandleEvent(const Event &event) { - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() - 0.125); + break; case KEY_TWO: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_width_.param_.SetNorm(knob_width_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_speed_.param_.SetNorm(knob_speed_.param_.GetNorm() + 0.125); + break; case KEY_SEVEN: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); + break; case KEY_EIGHT: - LOG_VAR(knob_depth_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_depth_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/compressor.cc b/src/plugin/compressor.cc index 2e9e364..c70f6db 100644 --- a/src/plugin/compressor.cc +++ b/src/plugin/compressor.cc @@ -4,36 +4,35 @@ namespace box { -Texture2D Compressor::icon_; // Define the static member +Texture2D Compressor::icon_; // Define the static member Compressor::Compressor(te::Plugin *p) - : Plugin(p), - base_plugin_{static_cast(p)}, + : Plugin(p), base_plugin_{static_cast(p)}, knob_threshold_{Parameter{base_plugin_->thresholdGain.parameter}, - 32, // x - 22, // y - 16, // radius + 32, // x + 22, // y + 16, // radius GREEN, "threshold"}, knob_ratio_{Parameter{base_plugin_->ratio.parameter}, - 96, // x - 22, // y - 16, // radius + 96, // x + 22, // y + 16, // radius RED, "ratio"}, knob_attack_{Parameter{base_plugin_->attackMs.parameter}, - 32, // x - 86, // y - 16, // radius + 32, // x + 86, // y + 16, // radius BLUE, "attack"}, knob_release_{Parameter{base_plugin_->releaseMs.parameter}, - 96, // x - 86, // y - 16, // radius + 96, // x + 86, // y + 16, // radius YELLOW, "release"} { - EnsureTextureLoaded(); + EnsureTextureLoaded(); } Compressor::~Compressor() { UnloadTexture(icon_); } @@ -45,55 +44,57 @@ const char *Compressor::GetIconPath() const { return icon_path_; } const char *Compressor::GetName() const { return name_; } void Compressor::Render(Interface &interface) { - knob_threshold_.Render(interface); - knob_ratio_.Render(interface); - knob_attack_.Render(interface); - knob_release_.Render(interface); + knob_threshold_.Render(interface); + knob_ratio_.Render(interface); + knob_attack_.Render(interface); + knob_release_.Render(interface); } void Compressor::HandleEvent(const Event &event) { - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - - 0.125); - break; + LOG_VAR(knob_threshold_.param_.GetNorm()); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - + 0.125); + break; case KEY_TWO: - LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + - 0.125); - break; + LOG_VAR(knob_threshold_.param_.GetNorm()); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_ratio_.param_.GetNorm()); - knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_ratio_.param_.GetNorm()); + knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_ratio_.param_.GetNorm()); - knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_ratio_.param_.GetNorm()); + knob_ratio_.param_.SetNorm(knob_ratio_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_attack_.param_.GetNorm()); - knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_attack_.param_.GetNorm()); + knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_attack_.param_.GetNorm()); - knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_attack_.param_.GetNorm()); + knob_attack_.param_.SetNorm(knob_attack_.param_.GetNorm() + 0.125); + break; case KEY_SEVEN: - LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_release_.param_.GetNorm()); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - + 0.125); + break; case KEY_EIGHT: - LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_release_.param_.GetNorm()); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/delay.cc b/src/plugin/delay.cc index 63c1e0b..7623c12 100644 --- a/src/plugin/delay.cc +++ b/src/plugin/delay.cc @@ -4,30 +4,29 @@ namespace box { -Texture2D Delay::icon_; // Define the static member +Texture2D Delay::icon_; // Define the static member Delay::Delay(te::Plugin *p) - : Plugin(p), - base_plugin_{static_cast(p)}, + : Plugin(p), base_plugin_{static_cast(p)}, knob_feedback_{Parameter{base_plugin_->feedbackDb}, - 32, // x - 22, // y - 16, // radius + 32, // x + 22, // y + 16, // radius GREEN, "feedback"}, knob_mix_{Parameter{base_plugin_->mixProportion}, - 96, // x - 22, // y - 16, // radius + 96, // x + 22, // y + 16, // radius RED, "mix"}, knob_length_{Parameter{CV{base_plugin_->lengthMs, 0, 10}}, - 32, // x - 86, // y - 16, // radius + 32, // x + 86, // y + 16, // radius BLUE, "speed"} { - EnsureTextureLoaded(); + EnsureTextureLoaded(); } Delay::~Delay() { UnloadTexture(icon_); } @@ -39,46 +38,46 @@ const char *Delay::GetIconPath() const { return icon_path_; } const char *Delay::GetName() const { return name_; } void Delay::Render(Interface &interface) { - knob_feedback_.Render(interface); - knob_mix_.Render(interface); - knob_length_.Render(interface); + knob_feedback_.Render(interface); + knob_mix_.Render(interface); + knob_length_.Render(interface); } void Delay::HandleEvent(const Event &event) { - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - - 0.125); - break; + LOG_VAR(knob_feedback_.param_.GetNorm()); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - + 0.125); + break; case KEY_TWO: - LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + - 0.125); - break; + LOG_VAR(knob_feedback_.param_.GetNorm()); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + + 0.125); + break; case KEY_THREE: - LOG_VAR(knob_mix_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_mix_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() - 0.125); + break; case KEY_FOUR: - LOG_VAR(knob_mix_.param_.GetNorm()); - knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); - break; + LOG_VAR(knob_mix_.param_.GetNorm()); + knob_mix_.param_.SetNorm(knob_mix_.param_.GetNorm() + 0.125); + break; case KEY_FIVE: - LOG_VAR(knob_length_.param_.GetNorm()); - knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_length_.param_.GetNorm()); + knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() - 0.125); + break; case KEY_SIX: - LOG_VAR(knob_length_.param_.GetNorm()); - knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_length_.param_.GetNorm()); + knob_length_.param_.SetNorm(knob_length_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box diff --git a/src/plugin/four_osc.cc b/src/plugin/four_osc.cc index 4be9256..c2081a1 100644 --- a/src/plugin/four_osc.cc +++ b/src/plugin/four_osc.cc @@ -2,25 +2,24 @@ namespace box { -Texture2D FourOsc::icon_; // Define the static member +Texture2D FourOsc::icon_; // Define the static member FourOsc::FourOsc(te::Plugin *p) - : Plugin(p), - base_plugin_{static_cast(p)}, + : Plugin(p), base_plugin_{static_cast(p)}, // knob_master_level_{32, 64, 16, {255,0,0}, // base_plugin_->masterLevelValue, base_plugin_->masterLevel} knob_master_level_{Parameter(base_plugin_->masterLevel), - 32, // x - 22, // y - 16, // radius + 32, // x + 22, // y + 16, // radius GREEN, "volume"} { - EnsureTextureLoaded(); - // TODO for testing effects - for (int i = 0; i < base_plugin_->oscParams.size(); i++) { - base_plugin_->oscParams[i]->waveShapeValue.setValue(2, nullptr); - } + EnsureTextureLoaded(); + // TODO for testing effects + for (int i = 0; i < base_plugin_->oscParams.size(); i++) { + base_plugin_->oscParams[i]->waveShapeValue.setValue(2, nullptr); + } } FourOsc::~FourOsc() { UnloadTexture(icon_); } @@ -32,35 +31,35 @@ const char *FourOsc::GetIconPath() const { return icon_path_; } const char *FourOsc::GetName() const { return name_; } void FourOsc::Render(Interface &interface) { - for (int y = 0; y < Interface::HEIGHT; ++y) { - for (int x = 0; x < Interface::WIDTH; ++x) { - if (x % 2 == 0 && y % 2 == 0) { - DrawPixel(x, y, RED); - } + for (int y = 0; y < Interface::HEIGHT; ++y) { + for (int x = 0; x < Interface::WIDTH; ++x) { + if (x % 2 == 0 && y % 2 == 0) { + DrawPixel(x, y, RED); + } + } } - } - knob_master_level_.Render(interface); + knob_master_level_.Render(interface); } void FourOsc::HandleEvent(const Event &event) { - switch (event.type) { + switch (event.type) { case EventType::KeyPress: - switch (event.value) { + switch (event.value) { case KEY_ONE: - LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm( - knob_master_level_.param_.GetNorm() - 0.125); - break; + LOG_VAR(knob_master_level_.param_.GetNorm()); + knob_master_level_.param_.SetNorm( + knob_master_level_.param_.GetNorm() - 0.125); + break; case KEY_TWO: - LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm( - knob_master_level_.param_.GetNorm() + 0.125); - break; - } - break; + LOG_VAR(knob_master_level_.param_.GetNorm()); + knob_master_level_.param_.SetNorm( + knob_master_level_.param_.GetNorm() + 0.125); + break; + } + break; case EventType::KeyRelease: - break; - } + break; + } } -} // namespace box +} // namespace box From 5bd69bc7068775a1132438497b9b7b79f399b9c8 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:15:36 -0500 Subject: [PATCH 08/12] allman braces and don't allow single-line functions --- .clang-format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-format b/.clang-format index 4fbc004..b507d02 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,5 @@ --- BasedOnStyle: LLVM IndentWidth: 4 +BreakBeforeBraces: Allman +AllowShortFunctionsOnASingleLine: None From 7ba474605ed992e936bc23214b8a783576a71749 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:15:45 -0500 Subject: [PATCH 09/12] autoformat --- include/component/knob.hh | 16 ++- include/component/switch.hh | 17 ++- include/core/app.hh | 12 ++- include/core/cv.hh | 22 ++-- include/core/interface.hh | 6 +- include/core/parameter.hh | 54 +++++++--- include/core/plugin.hh | 6 +- include/core/plugin_selector.hh | 6 +- include/core/timeline.hh | 50 ++++++--- include/core/track.hh | 9 +- include/core/util.hh | 26 +++-- include/plugin/chorus.hh | 6 +- include/plugin/compressor.hh | 6 +- include/plugin/delay.hh | 6 +- include/plugin/four_osc.hh | 6 +- src/core/app.cc | 111 +++++++++++++------- src/core/interface.cc | 51 ++++++--- src/core/plugin.cc | 23 +++-- src/core/plugin_selector.cc | 43 +++++--- src/core/timeline.cc | 176 ++++++++++++++++++++++---------- src/core/track.cc | 90 +++++++++++----- src/core/util.cc | 44 +++++--- src/main.cc | 26 +++-- src/plugin/chorus.cc | 38 +++++-- src/plugin/compressor.cc | 38 +++++-- src/plugin/delay.cc | 38 +++++-- src/plugin/four_osc.cc | 50 ++++++--- 27 files changed, 684 insertions(+), 292 deletions(-) diff --git a/include/component/knob.hh b/include/component/knob.hh index 5eaf07d..3bf4324 100644 --- a/include/component/knob.hh +++ b/include/component/knob.hh @@ -3,9 +3,11 @@ #include "core/parameter.hh" #include "core/util.hh" -namespace box { +namespace box +{ -template struct Knob { +template struct Knob +{ Parameter param_; uint8_t x_, y_, radius_; Color color_; @@ -13,10 +15,12 @@ template struct Knob { Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, std::string name = "") - : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} { + : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} + { } - virtual void Render(Interface &interface) { + virtual void Render(Interface &interface) + { auto angle = param_.GetNorm() * 360; auto x = static_cast(x_); auto y = static_cast(y_); @@ -26,7 +30,9 @@ template struct Knob { int width = MeasureText(name_.c_str(), font_size); DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, WHITE); } - virtual void HandleEvent(const Event &event) {} + virtual void HandleEvent(const Event &event) + { + } }; } // namespace box diff --git a/include/component/switch.hh b/include/component/switch.hh index e4d344c..69e440f 100644 --- a/include/component/switch.hh +++ b/include/component/switch.hh @@ -4,9 +4,11 @@ // instead of using cv.hh, we directly use juce::CachedValue -namespace box { +namespace box +{ -struct Switch { +struct Switch +{ juce::CachedValue &value_; uint8_t x_, y_; Color color_; @@ -14,16 +16,21 @@ struct Switch { Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, std::string name) - : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} {} + : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} + { + } - virtual void Render(Interface &interface) { + virtual void Render(Interface &interface) + { Color text_color = value_ ? color_ : WHITE; const int font_size = 10; int width = MeasureText(name_.c_str(), font_size); DrawText(name_.c_str(), x - (width / 2), y + 20, font_size, text_color); } - virtual void HandleEvent(const Event &event) {} + virtual void HandleEvent(const Event &event) + { + } }; } // namespace box diff --git a/include/core/app.hh b/include/core/app.hh index 68b1365..dc1c774 100644 --- a/include/core/app.hh +++ b/include/core/app.hh @@ -4,16 +4,20 @@ #include "core/track.hh" #include "core/util.hh" -namespace box { +namespace box +{ -struct App { - enum class ScreenState { +struct App +{ + enum class ScreenState + { Timeline, Track, PluginSelector, }; - enum class Mode { + enum class Mode + { Normal, Insert, }; diff --git a/include/core/cv.hh b/include/core/cv.hh index 099f851..245f34a 100644 --- a/include/core/cv.hh +++ b/include/core/cv.hh @@ -4,26 +4,36 @@ #include "core/util.hh" -template struct CV { +template struct CV +{ juce::CachedValue &value_; T min_, max_; // TODO add default value? CV(juce::CachedValue &cv, T min, T max) - : value_{cv}, min_{min}, max_{max} { + : value_{cv}, min_{min}, max_{max} + { assert(min <= max); } - void SetValue(T new_value) { value_ = std::clamp(new_value, min_, max_); } + void SetValue(T new_value) + { + value_ = std::clamp(new_value, min_, max_); + } - void SetNorm(T norm) { + void SetNorm(T norm) + { norm = std::clamp(norm, static_cast(0), static_cast(1)); const auto range = max_ - min_; value_ = range * norm; } - T GetValue() const { return value_.get(); } - T GetNorm() const { + T GetValue() const + { + return value_.get(); + } + T GetNorm() const + { const auto range = max_ - min_; return value_ / range; } diff --git a/include/core/interface.hh b/include/core/interface.hh index 2ba933c..3cb598e 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -3,9 +3,11 @@ #include "core/util.hh" -namespace box { +namespace box +{ -class Interface { +class Interface +{ public: static const int WIDTH = 128; static const int HEIGHT = 128; diff --git a/include/core/parameter.hh b/include/core/parameter.hh index 6841f2a..9033eb1 100644 --- a/include/core/parameter.hh +++ b/include/core/parameter.hh @@ -6,52 +6,74 @@ #include "core/interface.hh" #include "core/util.hh" -namespace box { +namespace box +{ using AP = te::AutomatableParameter; -template class Parameter { +template class Parameter +{ std::variant, AP *> param_; public: - Parameter(CV cv) : param_{cv} {} + Parameter(CV cv) : param_{cv} + { + } - Parameter(AP *p) : param_{p} {} + Parameter(AP *p) : param_{p} + { + } - void SetValue(T new_value) { - if (std::holds_alternative>(param_)) { + void SetValue(T new_value) + { + if (std::holds_alternative>(param_)) + { auto v = std::get>(param_); v.SetValue(new_value); - } else if (std::holds_alternative(param_)) { + } + else if (std::holds_alternative(param_)) + { auto v = std::get(param_); v->setParameter(new_value, juce::NotificationType::dontSendNotification); } } - void SetNorm(T new_value) { - if (std::holds_alternative>(param_)) { + void SetNorm(T new_value) + { + if (std::holds_alternative>(param_)) + { auto v = std::get>(param_); v.SetNorm(new_value); - } else if (std::holds_alternative(param_)) { + } + else if (std::holds_alternative(param_)) + { auto v = std::get(param_); v->setNormalisedParameter( new_value, juce::NotificationType::dontSendNotification); } } - T GetValue() const { - if (std::holds_alternative>(param_)) { + T GetValue() const + { + if (std::holds_alternative>(param_)) + { auto v = std::get>(param_); return v.GetValue(); - } else if (std::holds_alternative(param_)) { + } + else if (std::holds_alternative(param_)) + { auto v = std::get(param_); return v->getCurrentValue(); } } - T GetNorm() const { - if (std::holds_alternative>(param_)) { + T GetNorm() const + { + if (std::holds_alternative>(param_)) + { auto v = std::get>(param_); return v.GetNorm(); - } else if (std::holds_alternative(param_)) { + } + else if (std::holds_alternative(param_)) + { auto v = std::get(param_); return v->getCurrentNormalisedValue(); } diff --git a/include/core/plugin.hh b/include/core/plugin.hh index 6edd573..12b01bf 100644 --- a/include/core/plugin.hh +++ b/include/core/plugin.hh @@ -2,9 +2,11 @@ #include "core/interface.hh" #include "core/util.hh" -namespace box { +namespace box +{ -struct Plugin { +struct Plugin +{ te::Plugin *const plugin_; public: diff --git a/include/core/plugin_selector.hh b/include/core/plugin_selector.hh index 2701b11..d22afae 100644 --- a/include/core/plugin_selector.hh +++ b/include/core/plugin_selector.hh @@ -2,9 +2,11 @@ #include "core/interface.hh" #include "core/util.hh" -namespace box { +namespace box +{ -struct PluginSelector { +struct PluginSelector +{ PluginSelector(); void Render(Interface &interface); void HandleEvent(const Event &event); diff --git a/include/core/timeline.hh b/include/core/timeline.hh index aed8922..ab15c02 100644 --- a/include/core/timeline.hh +++ b/include/core/timeline.hh @@ -3,35 +3,59 @@ #include "interface.hh" #include "util.hh" -namespace box { +namespace box +{ -struct Timeline { - enum class ScreenState { +struct Timeline +{ + enum class ScreenState + { Overview, }; - enum class PlayheadMode { + enum class PlayheadMode + { Detached, Locked, }; - struct BeatWindow { + struct BeatWindow + { float start; float len; - float LeftEdge() const { return start; } - float RightEdge() const { return start + len; } + float LeftEdge() const + { + return start; + } + float RightEdge() const + { + return start + len; + } }; - struct BeatFrame { + struct BeatFrame + { float center; float radius; - float LeftEdge() const { return center - radius; } - float RightEdge() const { return center + radius; } - float Width() const { return radius * 2; } - BeatFrame(float c, float &r) : center{c}, radius{r} {} + float LeftEdge() const + { + return center - radius; + } + float RightEdge() const + { + return center + radius; + } + float Width() const + { + return radius * 2; + } + BeatFrame(float c, float &r) : center{c}, radius{r} + { + } }; - struct Position { + struct Position + { float secs; float beats; }; diff --git a/include/core/track.hh b/include/core/track.hh index c127b99..33c15bf 100644 --- a/include/core/track.hh +++ b/include/core/track.hh @@ -7,10 +7,13 @@ #include "core/plugin.hh" #include "core/util.hh" -namespace box { +namespace box +{ -class Track { - enum class ScreenState { +class Track +{ + enum class ScreenState + { Overview, Plugin, }; diff --git a/include/core/util.hh b/include/core/util.hh index 9f0a941..31ffbdf 100644 --- a/include/core/util.hh +++ b/include/core/util.hh @@ -11,7 +11,8 @@ namespace te = tracktion; -namespace box { +namespace box +{ struct App; extern App *APP; @@ -44,28 +45,41 @@ std::string format_cursor_pos(size_t track_pos, float cursor_pos); size_t clamp_decrement(size_t x); size_t clamp_increment(size_t x, size_t max); -enum class LogLevel { Off, Debug, Warn, Err }; +enum class LogLevel +{ + Off, + Debug, + Warn, + Err +}; LogLevel string_to_loglevel(const std::string &s); std::string loglevel_to_string(LogLevel l); LogLevel get_loglevel(); const LogLevel LOGLEVEL = get_loglevel(); void LOG_MSG(const std::string &msg, LogLevel l = LogLevel::Debug); template -void log_var(const std::string &var_name, const T &var_value) { +void log_var(const std::string &var_name, const T &var_value) +{ LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); } #define LOG_VAR(var) log_var(#var, var) -enum class DeviceType { Emulator, Hardware }; +enum class DeviceType +{ + Emulator, + Hardware +}; -enum class EventType { +enum class EventType +{ KeyPress, KeyRelease, PotDown, PotUp, }; -struct Event { +struct Event +{ EventType type; int value; }; diff --git a/include/plugin/chorus.hh b/include/plugin/chorus.hh index a3551ef..09b8ea8 100644 --- a/include/plugin/chorus.hh +++ b/include/plugin/chorus.hh @@ -3,9 +3,11 @@ #include "core/interface.hh" #include "core/plugin.hh" -namespace box { +namespace box +{ -struct Chorus : public Plugin { +struct Chorus : public Plugin +{ static Texture2D icon_; static constexpr const char *icon_path_ = "assets/star_16x16.png"; static constexpr const char *name_ = "chrs"; diff --git a/include/plugin/compressor.hh b/include/plugin/compressor.hh index 28e1dd2..89415eb 100644 --- a/include/plugin/compressor.hh +++ b/include/plugin/compressor.hh @@ -3,9 +3,11 @@ #include "core/interface.hh" #include "core/plugin.hh" -namespace box { +namespace box +{ -struct Compressor : public Plugin { +struct Compressor : public Plugin +{ static Texture2D icon_; static constexpr const char *icon_path_ = "assets/star_16x16.png"; static constexpr const char *name_ = "cmpr"; diff --git a/include/plugin/delay.hh b/include/plugin/delay.hh index 7bac72b..97f7524 100644 --- a/include/plugin/delay.hh +++ b/include/plugin/delay.hh @@ -3,9 +3,11 @@ #include "core/interface.hh" #include "core/plugin.hh" -namespace box { +namespace box +{ -struct Delay : public Plugin { +struct Delay : public Plugin +{ static Texture2D icon_; static constexpr const char *icon_path_ = "assets/star_16x16.png"; static constexpr const char *name_ = "dlay"; diff --git a/include/plugin/four_osc.hh b/include/plugin/four_osc.hh index 8b8bca8..6ec05b3 100644 --- a/include/plugin/four_osc.hh +++ b/include/plugin/four_osc.hh @@ -3,9 +3,11 @@ #include "core/interface.hh" #include "core/plugin.hh" -namespace box { +namespace box +{ -struct FourOsc : public Plugin { +struct FourOsc : public Plugin +{ static Texture2D icon_; static constexpr const char *icon_path_ = "assets/four_16x16.png"; static constexpr const char *name_ = "4osc"; diff --git a/src/core/app.cc b/src/core/app.cc index 199c7ea..7f02071 100644 --- a/src/core/app.cc +++ b/src/core/app.cc @@ -2,19 +2,24 @@ #include -namespace box { +namespace box +{ static void assert_tracks(const std::vector> &tracks, - size_t index, const std::string &name) { - if (tracks.size() == 0 || index >= tracks.size()) { + size_t index, const std::string &name) +{ + if (tracks.size() == 0 || index >= tracks.size()) + { throw std::runtime_error{ "App::" + name + "(): index [" + std::to_string(index) + "] out of range: [0, " + std::to_string(tracks.size()) + "]"}; } } -void print_tracks(App a) { - for (auto &t : a.tracks_) { +void print_tracks(App a) +{ + for (auto &t : a.tracks_) + { // std::cout << "Wave Input Device: " << t->track_.getWaveInputDevice() // << std::endl; WaveInputDevice& getWaveInputDevice() const noexcept { // jassert (waveInputDevice); return *waveInputDevice; } @@ -25,24 +30,36 @@ void print_tracks(App a) { App::App(te::Engine &engine, te::Edit &edit) : engine_{engine}, edit_{edit}, current_track_{0}, - base_tracks_{te::getAudioTracks(edit)} { + base_tracks_{te::getAudioTracks(edit)} +{ AddTrack(); // ensure there's always at least 1 LOG_VAR(tracks_.size()); ArmMidi(current_track_); // turn on midi for it } -void App::AddTrack() { +void App::AddTrack() +{ tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); } -Track &App::CurrTrack() { return *tracks_[current_track_]; } +Track &App::CurrTrack() +{ + return *tracks_[current_track_]; +} -size_t App::GetCurrTrack() { return current_track_; } -void App::SetCurrTrack(size_t track_index) { +size_t App::GetCurrTrack() +{ + return current_track_; +} +void App::SetCurrTrack(size_t track_index) +{ size_t old = current_track_; - if (track_index >= 0 && track_index < MAX_TRACKS) { + if (track_index >= 0 && track_index < MAX_TRACKS) + { current_track_ = track_index; - } else { + } + else + { throw std::runtime_error{"SetCurrTrack() out of range: "}; } @@ -50,14 +67,18 @@ void App::SetCurrTrack(size_t track_index) { ArmMidi(current_track_); } -void App::ArmMidi(size_t index) { +void App::ArmMidi(size_t index) +{ assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) { + for (auto instance : edit_.getAllInputDevices()) + { auto device_type = instance->getInputDevice().getDeviceType(); if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) { + device_type == te::InputDevice::virtualMidiDevice) + { auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) { + if (t != nullptr) + { [[maybe_unused]] auto res = instance->setTarget( t->itemID, true, &edit_.getUndoManager(), 0); instance->setRecordingEnabled(t->itemID, true); @@ -65,28 +86,34 @@ void App::ArmMidi(size_t index) { } } } -void App::UnarmMidi(size_t index) { +void App::UnarmMidi(size_t index) +{ assert(0 <= index && index < tracks_.size()); - for (auto instance : edit_.getAllInputDevices()) { + for (auto instance : edit_.getAllInputDevices()) + { auto device_type = instance->getInputDevice().getDeviceType(); if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) { + device_type == te::InputDevice::virtualMidiDevice) + { auto t = te::getAudioTracks(edit_)[index]; - if (t != nullptr) { + if (t != nullptr) + { instance->removeTarget(t->itemID, &edit_.getUndoManager()); } } } } -void App::Render(Interface &interface) { +void App::Render(Interface &interface) +{ assert_tracks(tracks_, current_track_, "render"); // TODO this is for debugging fps // std::string text = std::to_string(GetFPS()); // DrawText(text.c_str(), 115, 0, 10, WHITE); - switch (screen_state_) { + switch (screen_state_) + { case ScreenState::Timeline: timeline_.Render(interface); break; @@ -98,39 +125,51 @@ void App::Render(Interface &interface) { break; } - if (mode_ == Mode::Insert) { + if (mode_ == Mode::Insert) + { DrawRectangleLines(0, 0, 128, 127, PURPLE); // -1 so bottom row shows } - if (edit_.getTransport().isRecording()) { + if (edit_.getTransport().isRecording()) + { DrawRectangleLines(1, 1, 126, 125, RED); // -1 so bottom row shows } } -void App::HandleEvent(const Event &event) { +void App::HandleEvent(const Event &event) +{ assert_tracks(tracks_, current_track_, "handleEvent"); - if (event.type == EventType::KeyPress && event.value == KEY_I) { - if (mode_ == Mode::Normal) { + if (event.type == EventType::KeyPress && event.value == KEY_I) + { + if (mode_ == Mode::Normal) + { mode_ = Mode::Insert; - } else if (mode_ == Mode::Insert) { + } + else if (mode_ == Mode::Insert) + { mode_ = Mode::Normal; } } - if (mode_ == Mode::Insert) { - switch (event.type) { + if (mode_ == Mode::Insert) + { + switch (event.type) + { case EventType::KeyPress: LOG_VAR(event.value); - if (event.value == KEY_UP) { + if (event.value == KEY_UP) + { APP->key_offset_ += 1; break; } - if (event.value == KEY_DOWN) { + if (event.value == KEY_DOWN) + { APP->key_offset_ -= 1; break; } if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && - active_notes_.find(event.value) == active_notes_.end()) { + active_notes_.find(event.value) == active_notes_.end()) + { int note = (12 * key_offset_) + KEY_TO_MIDI.at(event.value); active_notes_[event.value] = note; @@ -143,7 +182,8 @@ void App::HandleEvent(const Event &event) { case EventType::KeyRelease: if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() && - active_notes_.find(event.value) != active_notes_.end()) { + active_notes_.find(event.value) != active_notes_.end()) + { int note = active_notes_[event.value]; active_notes_.erase(event.value); @@ -157,7 +197,8 @@ void App::HandleEvent(const Event &event) { return; } - switch (screen_state_) { + switch (screen_state_) + { case ScreenState::Timeline: timeline_.HandleEvent(event); break; diff --git a/src/core/interface.cc b/src/core/interface.cc index 4d55815..46623b3 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -3,34 +3,42 @@ #include #include -namespace box { +namespace box +{ -Interface::Interface() { +Interface::Interface() +{ SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(512, 512, "raylib - Rescalable 128x128 render"); target_ = LoadRenderTexture(WIDTH, HEIGHT); SetTargetFPS(60); SetExitKey(0); // esc doesn't close program - if constexpr (INPUT_TYPE == DeviceType::Hardware) { + if constexpr (INPUT_TYPE == DeviceType::Hardware) + { // Initialize microcontroller input handling (e.g., serial interface) } } -Interface::~Interface() { - if (DISPLAY_TYPE == DeviceType::Emulator) { +Interface::~Interface() +{ + if (DISPLAY_TYPE == DeviceType::Emulator) + { UnloadRenderTexture(target_); CloseWindow(); } } -void Interface::PreRender() { +void Interface::PreRender() +{ BeginTextureMode(target_); // matches PostRender ClearBackground(BLACK); } -void Interface::PostRender() { - if (DISPLAY_TYPE == DeviceType::Emulator) { +void Interface::PostRender() +{ + if (DISPLAY_TYPE == DeviceType::Emulator) + { int screen_width = GetScreenWidth(); int screen_height = GetScreenHeight(); @@ -48,7 +56,9 @@ void Interface::PostRender() { Vector2{0, 0}, 0.0f, WHITE); EndDrawing(); // hardware rendering - } else if (DISPLAY_TYPE == DeviceType::Hardware) { + } + else if (DISPLAY_TYPE == DeviceType::Hardware) + { Image image = LoadImageFromTexture(target_.texture); Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) } @@ -56,18 +66,24 @@ void Interface::PostRender() { // this code has really bad performance. keys often get stuck, // but for the purpose of being an emulator this is fine. -bool Interface::PollEvent(Event &event) { - for (auto &[key, is_pressed] : keys_) { - if (IsKeyDown(key)) { - if (is_pressed == false) { +bool Interface::PollEvent(Event &event) +{ + for (auto &[key, is_pressed] : keys_) + { + if (IsKeyDown(key)) + { + if (is_pressed == false) + { is_pressed = !is_pressed; event.type = EventType::KeyPress; event.value = key; return true; } } - if (IsKeyUp(key)) { - if (is_pressed == true) { + if (IsKeyUp(key)) + { + if (is_pressed == true) + { is_pressed = !is_pressed; event.type = EventType::KeyRelease; event.value = key; @@ -79,6 +95,9 @@ bool Interface::PollEvent(Event &event) { return false; } -bool Interface::ShouldClose() const { return WindowShouldClose(); } +bool Interface::ShouldClose() const +{ + return WindowShouldClose(); +} } // namespace box diff --git a/src/core/plugin.cc b/src/core/plugin.cc index c247652..17f7b41 100644 --- a/src/core/plugin.cc +++ b/src/core/plugin.cc @@ -1,19 +1,30 @@ #include "core/plugin.hh" -namespace box { +namespace box +{ -Plugin::Plugin(te::Plugin *p) : plugin_{p} {} +Plugin::Plugin(te::Plugin *p) : plugin_{p} +{ +} -Plugin::~Plugin() { plugin_->deleteFromParent(); } +Plugin::~Plugin() +{ + plugin_->deleteFromParent(); +} -void Plugin::EnsureTextureLoaded() const { - if (GetIcon().id == 0) { +void Plugin::EnsureTextureLoaded() const +{ + if (GetIcon().id == 0) + { Image icon = LoadImage(GetIconPath()); GetIcon() = LoadTextureFromImage(icon); UnloadImage(icon); } } -te::Plugin *const Plugin::GetPlugin() const { return plugin_; } +te::Plugin *const Plugin::GetPlugin() const +{ + return plugin_; +} } // namespace box diff --git a/src/core/plugin_selector.cc b/src/core/plugin_selector.cc index 0bd9a68..d8ef173 100644 --- a/src/core/plugin_selector.cc +++ b/src/core/plugin_selector.cc @@ -6,7 +6,8 @@ #include "plugin/delay.hh" #include "plugin/four_osc.hh" -namespace box { +namespace box +{ const std::vector PluginSelector::PLUGIN_NAMES = { te::FourOscPlugin::xmlTypeName, te::ChorusPlugin::xmlTypeName, @@ -15,16 +16,21 @@ const std::vector PluginSelector::PLUGIN_NAMES = { te::ReverbPlugin::xmlTypeName, }; -void assert_index(std::vector v, size_t curr) { +void assert_index(std::vector v, size_t curr) +{ if (curr >= v.size()) throw std::runtime_error{"PluginSelector index out of range: " + std::to_string(curr)}; } -PluginSelector::PluginSelector() {} +PluginSelector::PluginSelector() +{ +} -void PluginSelector::Render(Interface &interface) { - for (size_t i = 0; i < interface.HEIGHT / 8; i++) { +void PluginSelector::Render(Interface &interface) +{ + for (size_t i = 0; i < interface.HEIGHT / 8; i++) + { if (i >= PLUGIN_NAMES.size()) break; auto name = PLUGIN_NAMES[i]; @@ -33,7 +39,8 @@ void PluginSelector::Render(Interface &interface) { float width = 128; float height = 15; Color color = RED; - if (current_index_ == i) { + if (current_index_ == i) + { color = BLUE; } DrawRectangleRec(Rectangle{x, y, width, height}, DARKGRAY); @@ -41,10 +48,13 @@ void PluginSelector::Render(Interface &interface) { } } -void PluginSelector::HandleEvent(const Event &event) { - switch (event.type) { +void PluginSelector::HandleEvent(const Event &event) +{ + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ESCAPE: APP->screen_state_ = App::ScreenState::Track; break; @@ -65,13 +75,20 @@ void PluginSelector::HandleEvent(const Event &event) { .createNewPlugin(name.c_str(), {}) .get(); // TODO use cast? - if (name == te::ChorusPlugin::xmlTypeName) { + if (name == te::ChorusPlugin::xmlTypeName) + { p = std::make_unique(base); - } else if (name == te::FourOscPlugin::xmlTypeName) { + } + else if (name == te::FourOscPlugin::xmlTypeName) + { p = std::make_unique(base); - } else if (name == te::CompressorPlugin::xmlTypeName) { + } + else if (name == te::CompressorPlugin::xmlTypeName) + { p = std::make_unique(base); - } else if (name == te::DelayPlugin::xmlTypeName) { + } + else if (name == te::DelayPlugin::xmlTypeName) + { p = std::make_unique(base); } diff --git a/src/core/timeline.cc b/src/core/timeline.cc index ac594e5..47bec71 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -2,9 +2,11 @@ #include "core/app.hh" -namespace box { +namespace box +{ -Timeline::Timeline() { +Timeline::Timeline() +{ { Image tmp_l = LoadImage(METRONOME_PATH_L); metronome_l_ = LoadTextureFromImage(tmp_l); @@ -18,13 +20,15 @@ Timeline::Timeline() { } } -Timeline::~Timeline() { +Timeline::~Timeline() +{ UnloadTexture(metronome_l_); UnloadTexture(metronome_r_); UnloadTexture(metronome_off_); } -void Timeline::Render(Interface &interface) { +void Timeline::Render(Interface &interface) +{ /* terminology: - row = the relative index of a track. @@ -47,14 +51,16 @@ void Timeline::Render(Interface &interface) { BeatFrame screen{curr_pos.beats, radius_}; - if (playhead_mode_ == PlayheadMode::Detached) { + if (playhead_mode_ == PlayheadMode::Detached) + { screen = frame_; } assert(is_close(screen.radius, radius_)); // draw track outlines - for (size_t i = 0; i < num_rows; i++) { + for (size_t i = 0; i < num_rows; i++) + { float x = 0; float y = (ROW_HEIGHT * i) + HEADER_HEIGHT; DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, DARKGRAY); @@ -74,16 +80,22 @@ void Timeline::Render(Interface &interface) { // render metronome { - if (APP->edit_.clickTrackEnabled == true) { + if (APP->edit_.clickTrackEnabled == true) + { const int beat = static_cast(curr_pos.beats); - if (beat % 2 == 0) { + if (beat % 2 == 0) + { DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); - } else { + } + else + { DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } - } else { + } + else + { DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } @@ -117,7 +129,8 @@ void Timeline::Render(Interface &interface) { std::floor(screen.LeftEdge() / bar_width_) * bar_width_; for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); - bar_start += bar_width_) { + bar_start += bar_width_) + { float bar_position_pct = (bar_start - screen.LeftEdge()) / screen.Width(); int x = static_cast(bar_position_pct * SCREEN_WIDTH); @@ -127,15 +140,19 @@ void Timeline::Render(Interface &interface) { } // render current live clip (if recording) - if (transport.isRecording()) { + if (transport.isRecording()) + { const float start_time = tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); - if (screen.LeftEdge() < start_time) { + if (screen.LeftEdge() < start_time) + { float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); float left_px = (left_pct * SCREEN_WIDTH); DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - left_px), ROW_HEIGHT, RED); - } else { + } + else + { DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - 0), ROW_HEIGHT, RED); // 64 - 0 means full half bar @@ -144,10 +161,12 @@ void Timeline::Render(Interface &interface) { // render clips { - for (size_t i = 0; i < num_rows; i++) { + for (size_t i = 0; i < num_rows; i++) + { const size_t track_idx = i + scroll_offset_; const auto &t = APP->tracks_[track_idx]; - for (const auto &c : t->base_.getClips()) { + for (const auto &c : t->base_.getClips()) + { const te::ClipPosition c_pos = c->getPosition(); te::BeatRange t_br = te::toBeats(c_pos.time, tempo); BeatWindow clip = { @@ -192,7 +211,8 @@ void Timeline::Render(Interface &interface) { } // render cursor - if (!transport.isRecording() && !transport.isPlaying()) { + if (!transport.isRecording() && !transport.isPlaying()) + { const float left_pct = (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); const float right_pct = @@ -209,7 +229,8 @@ void Timeline::Render(Interface &interface) { // render playhead { if (screen.LeftEdge() < curr_pos.beats && - curr_pos.beats < screen.RightEdge()) { + curr_pos.beats < screen.RightEdge()) + { const float left_pct = (curr_pos.beats - screen.LeftEdge()) / screen.Width(); const int left_px = static_cast(left_pct * SCREEN_WIDTH); @@ -240,7 +261,8 @@ void Timeline::Render(Interface &interface) { // return false; // } -void Timeline::print_timeline() { +void Timeline::print_timeline() +{ std::cout << std::endl; const auto &track = APP->CurrTrack().base_; std::cout << "name: " << track.getName() << std::endl; @@ -267,7 +289,8 @@ void Timeline::print_timeline() { const auto clips = track.getClips(); std::cout << "num clips: " << clips.size() << std::endl; - for (auto c : clips) { + for (auto c : clips) + { std::cout << "\t" << "name: " << c->getName() << std::endl; std::cout << "\t\t" @@ -299,23 +322,31 @@ void Timeline::print_timeline() { } } -void Timeline::FocusCursor() { +void Timeline::FocusCursor() +{ assert(cursor_.len < frame_.Width()); - if (cursor_.LeftEdge() < frame_.LeftEdge()) { + if (cursor_.LeftEdge() < frame_.LeftEdge()) + { const float diff = frame_.LeftEdge() - cursor_.LeftEdge(); frame_.center -= diff; - } else if (cursor_.RightEdge() > frame_.RightEdge()) { + } + else if (cursor_.RightEdge() > frame_.RightEdge()) + { const float diff = cursor_.RightEdge() - frame_.RightEdge(); frame_.center += diff; } } -void Timeline::HandleEvent(const Event &event) { - switch (screen_state_) { +void Timeline::HandleEvent(const Event &event) +{ + switch (screen_state_) + { case ScreenState::Overview: - switch (event.type) { + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ENTER: APP->screen_state_ = App::ScreenState::Track; break; @@ -330,19 +361,23 @@ void Timeline::HandleEvent(const Event &event) { FocusCursor(); break; case KEY_J: - if (!APP->edit_.getTransport().isRecording()) { + if (!APP->edit_.getTransport().isRecording()) + { APP->SetCurrTrack(clamp_increment(APP->GetCurrTrack(), APP->tracks_.size())); - if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) { + if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) + { scroll_offset_ = clamp_increment(scroll_offset_, APP->tracks_.size()); } } break; case KEY_K: - if (!APP->edit_.getTransport().isRecording()) { + if (!APP->edit_.getTransport().isRecording()) + { APP->SetCurrTrack(clamp_decrement(APP->GetCurrTrack())); - if (APP->GetCurrTrack() < scroll_offset_) { + if (APP->GetCurrTrack() < scroll_offset_) + { scroll_offset_ = clamp_decrement(scroll_offset_); } } @@ -355,43 +390,56 @@ void Timeline::HandleEvent(const Event &event) { clamp_increment(scroll_offset_, APP->tracks_.size()); break; case KEY_O: // add track - if (APP->tracks_.size() < MAX_TRACKS) { + if (APP->tracks_.size() < MAX_TRACKS) + { APP->AddTrack(); } break; - case KEY_W: { + case KEY_W: + { const te::TempoSequence &tempo = APP->edit_.tempoSequence; auto pos = tempo.toTime( te::BeatPosition::fromBeats(cursor_.RightEdge())); te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) { + if (item == nullptr) + { LOG_MSG("KEY_W found NONE"); - } else { - if (auto clip = dynamic_cast(item)) { + } + else + { + if (auto clip = dynamic_cast(item)) + { cursor_.start = clip->getStartBeat().inBeats(); FocusCursor(); } } - } break; - case KEY_D: { + } + break; + case KEY_D: + { const te::TempoSequence &tempo = APP->edit_.tempoSequence; auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); - if (item == nullptr) { + if (item == nullptr) + { LOG_MSG("KEY_D found NONE"); - } else { + } + else + { LOG_MSG("deleting item of type:"); LOG_MSG(te::TrackItem::typeToString(item->type)); - if (auto clip = dynamic_cast(item)) { + if (auto clip = dynamic_cast(item)) + { clip->removeFromParent(); } } - } break; + } + break; case KEY_P: print_timeline(); LOG_VAR(frame_.center); @@ -400,11 +448,13 @@ void Timeline::HandleEvent(const Event &event) { // toggle metronome APP->edit_.clickTrackEnabled = !APP->edit_.clickTrackEnabled; break; - case KEY_R: { + case KEY_R: + { auto &transport = APP->edit_.getTransport(); LOG_VAR(transport.getPosition().inSeconds()); LOG_VAR(transport.isRecording()); - if (transport.isRecording()) { + if (transport.isRecording()) + { transport.stop(false, false); // TODO should this discard? te::EditFileOperations(APP->edit_).save(true, true, false); playhead_mode_ = PlayheadMode::Detached; @@ -419,17 +469,22 @@ void Timeline::HandleEvent(const Event &event) { frame_.center = curr_pos; } assert_multiple(cursor_.start, bar_width_); - } else { + } + else + { const te::TempoSequence &tempo = APP->edit_.tempoSequence; transport.setPosition(tempo.toTime( te::BeatPosition::fromBeats(cursor_.LeftEdge()))); transport.record(false); playhead_mode_ = PlayheadMode::Locked; } - } break; - case KEY_T: { + } + break; + case KEY_T: + { auto &transport = APP->edit_.getTransport(); - if (transport.isPlaying()) { + if (transport.isPlaying()) + { transport.stop(false, false); // TODO should this discard? playhead_mode_ = PlayheadMode::Detached; @@ -443,33 +498,42 @@ void Timeline::HandleEvent(const Event &event) { frame_.center = curr_pos; } assert_multiple(cursor_.start, bar_width_); - } else { + } + else + { const te::TempoSequence &tempo = APP->edit_.tempoSequence; transport.setPosition(tempo.toTime( te::BeatPosition::fromBeats(cursor_.LeftEdge()))); transport.play(false); playhead_mode_ = PlayheadMode::Locked; } - } break; - case KEY_S: { + } + break; + case KEY_S: + { LOG_MSG("move to origin"); auto &transport = APP->edit_.getTransport(); transport.setPosition(te::TimePosition::fromSeconds(0.f)); cursor_.start = 0; frame_.center = 0; - } break; - case KEY_COMMA: { + } + break; + case KEY_COMMA: + { LOG_MSG("move left"); auto &transport = APP->edit_.getTransport(); transport.setPosition(te::TimePosition::fromSeconds( transport.getPosition().inSeconds() - 2.f)); - } break; - case KEY_PERIOD: { + } + break; + case KEY_PERIOD: + { LOG_MSG("move right"); auto &transport = APP->edit_.getTransport(); transport.setPosition(te::TimePosition::fromSeconds( transport.getPosition().inSeconds() + 2.f)); - } break; + } + break; case KEY_MINUS: radius_ *= 2; frame_.radius *= 2; // TODO centralize this diff --git a/src/core/track.cc b/src/core/track.cc index 3f009d7..7846434 100644 --- a/src/core/track.cc +++ b/src/core/track.cc @@ -5,22 +5,30 @@ #include "core/app.hh" #include "core/util.hh" -namespace box { +namespace box +{ static void assert_plugins(const std::vector> &plugins, - int index, std::string function_name) { - if (index >= plugins.size()) { + int index, std::string function_name) +{ + if (index >= plugins.size()) + { throw std::runtime_error{ "Track::" + function_name + " => index [" + std::to_string(index) + "] out of range: [0, " + std::to_string(plugins.size()) + "]"}; } } -Track::Track(te::AudioTrack &base) : base_{base} {} +Track::Track(te::AudioTrack &base) : base_{base} +{ +} -Track::~Track() {} +Track::~Track() +{ +} -void Track::AddPlugin(std::unique_ptr plugin) { +void Track::AddPlugin(std::unique_ptr plugin) +{ if (active_plugin_ == -1) active_plugin_ = 0; // TODO better way to handle this int index = plugins_.size(); @@ -28,12 +36,15 @@ void Track::AddPlugin(std::unique_ptr plugin) { plugins_.push_back(std::move(plugin)); } -void Track::RemoveActivePlugin() { - if (plugins_.size() == 0) { +void Track::RemoveActivePlugin() +{ + if (plugins_.size() == 0) + { LOG_MSG("tried to remove plugin from empty track", LogLevel::Warn); return; } - if (active_plugin_ == -1) { + if (active_plugin_ == -1) + { LOG_MSG("tried to remove active_plugin == -1", LogLevel::Warn); return; } @@ -43,11 +54,18 @@ void Track::RemoveActivePlugin() { std::min(active_plugin_, static_cast(plugins_.size()) - 1); } -void Track::SetActivePlugin(int index) { active_plugin_ = index; } +void Track::SetActivePlugin(int index) +{ + active_plugin_ = index; +} -int Track::GetActivePlugin() { return active_plugin_; } +int Track::GetActivePlugin() +{ + return active_plugin_; +} -int clamp_index(int i, int len) { +int clamp_index(int i, int len) +{ int range = len; int val = i % range; if (val < 0) @@ -55,14 +73,19 @@ int clamp_index(int i, int len) { return val; } -void Track::HandleEvent(const Event &event) { - switch (screen_state_) { +void Track::HandleEvent(const Event &event) +{ + switch (screen_state_) + { case ScreenState::Overview: - switch (APP->mode_) { + switch (APP->mode_) + { case App::Mode::Normal: - switch (event.type) { + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ESCAPE: APP->screen_state_ = App::ScreenState::Timeline; break; @@ -72,13 +95,16 @@ void Track::HandleEvent(const Event &event) { case KEY_X: RemoveActivePlugin(); break; - case KEY_P: { + case KEY_P: + { auto l = base_.pluginList.getPlugins(); - for (auto p : l) { + for (auto p : l) + { std::cout << p->getName() << ", "; } std::cout << std::endl; - } break; + } + break; // TODO KEY_J and KEY_K move up and down case KEY_H: LOG_MSG("left"); @@ -106,11 +132,13 @@ void Track::HandleEvent(const Event &event) { } break; case ScreenState::Plugin: - if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) { + if (event.type == EventType::KeyPress && event.value == KEY_ESCAPE) + { screen_state_ = ScreenState::Overview; return; } - switch (APP->mode_) { + switch (APP->mode_) + { case App::Mode::Normal: plugins_[active_plugin_]->HandleEvent(event); break; @@ -121,17 +149,21 @@ void Track::HandleEvent(const Event &event) { } } -void Track::Render(Interface &interface) { - switch (screen_state_) { +void Track::Render(Interface &interface) +{ + switch (screen_state_) + { case ScreenState::Overview: // draw grid - for (int i = 1; i < GRID_SIZE; i++) { + for (int i = 1; i < GRID_SIZE; i++) + { float pos = static_cast(i); DrawLineV(Vector2{0, pos * 32}, Vector2{128, pos * 32}, WHITE); DrawLineV(Vector2{pos * 32, 0}, Vector2{pos * 32, 128}, WHITE); } - for (int i = 0; i < plugins_.size(); i++) { + for (int i = 0; i < plugins_.size(); i++) + { auto x = static_cast((i % 4) * 32 + 16); auto y = static_cast((i / 4) * 32 + 64 + 16); DrawTexture(plugins_[i]->GetIcon(), x - 8, y - 8, WHITE); @@ -141,13 +173,15 @@ void Track::Render(Interface &interface) { DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, WHITE); - if (i == active_plugin_) { + if (i == active_plugin_) + { DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, 5.0f, GREEN); } } - for (int i = plugins_.size(); i < MAX_PLUGINS; i++) { + for (int i = plugins_.size(); i < MAX_PLUGINS; i++) + { auto x = static_cast((i % 4) * 32 + 16); auto y = static_cast((i / 4) * 32 + 64 + 16); DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, diff --git a/src/core/util.cc b/src/core/util.cc index e27294f..cd70ef7 100644 --- a/src/core/util.cc +++ b/src/core/util.cc @@ -1,17 +1,23 @@ #include "core/util.hh" -namespace box { +namespace box +{ App *APP = nullptr; // Define the global APP variable -void assert_multiple(float a, float b) { +void assert_multiple(float a, float b) +{ const float epsilon = 1e-6; // Small tolerance for floating-point precision assert(std::fabs(std::fmod(a, b)) < epsilon && "a is not a multiple of b"); } -bool is_close(float a, float b) { return std::abs(a - b) < 1e-6; } +bool is_close(float a, float b) +{ + return std::abs(a - b) < 1e-6; +} -std::string format_time(float time) { +std::string format_time(float time) +{ int minutes = static_cast(time) / 60; int seconds = static_cast(time) % 60; int decimal = @@ -25,32 +31,37 @@ std::string format_time(float time) { return oss.str(); } -std::string format_key_offset(int key_offset) { +std::string format_key_offset(int key_offset) +{ if (key_offset > 0) return "+" + std::to_string(key_offset); else return std::to_string(key_offset); } -std::string format_cursor_pos(size_t track_pos, float cursor_pos) { +std::string format_cursor_pos(size_t track_pos, float cursor_pos) +{ std::ostringstream oss; oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') << cursor_pos; return oss.str(); } -size_t clamp_decrement(size_t x) { +size_t clamp_decrement(size_t x) +{ if (x == 0) return 0; else return x - 1; } -size_t clamp_increment(size_t x, size_t max) { +size_t clamp_increment(size_t x, size_t max) +{ return std::min(x + 1, clamp_decrement(max)); } -LogLevel string_to_loglevel(const std::string &s) { +LogLevel string_to_loglevel(const std::string &s) +{ if (s == "OFF") return LogLevel::Off; if (s == "DEBUG") @@ -62,7 +73,8 @@ LogLevel string_to_loglevel(const std::string &s) { throw std::runtime_error{"string_to_loglevel(" + s + ") not found"}; } -std::string loglevel_to_string(LogLevel l) { +std::string loglevel_to_string(LogLevel l) +{ if (l == LogLevel::Off) return "OFF"; if (l == LogLevel::Debug) @@ -76,18 +88,22 @@ std::string loglevel_to_string(LogLevel l) { } // get loglevel from env -LogLevel get_loglevel() { +LogLevel get_loglevel() +{ const char *env = std::getenv("BOX_LOG"); - if (env) { + if (env) + { return string_to_loglevel(env); } return LogLevel::Off; // default } -void LOG_MSG(const std::string &msg, LogLevel l) { +void LOG_MSG(const std::string &msg, LogLevel l) +{ static LogLevel curr = get_loglevel(); - if (l < curr) { + if (l < curr) + { return; } // get time diff --git a/src/main.cc b/src/main.cc index 83a87a4..eee6c85 100644 --- a/src/main.cc +++ b/src/main.cc @@ -6,7 +6,8 @@ #include "core/util.hh" #include "raylib.h" -int main() { +int main() +{ const juce::ScopedJuceInitialiser_GUI initialiser; // need this SetTargetFPS(60); @@ -23,27 +24,34 @@ int main() { box::App app(engine, edit); box::APP = &app; - try { + try + { // arm { auto &dm = engine.getDeviceManager(); - for (int i = 0; i < dm.getNumWaveInDevices(); i++) { - if (auto wip = dm.getWaveInDevice(i)) { + for (int i = 0; i < dm.getNumWaveInDevices(); i++) + { + if (auto wip = dm.getWaveInDevice(i)) + { wip->setStereoPair(false); // wip->setEndToEnd(true); // TODO update ? wip->setEnabled(true); - } else if (auto mip = dm.getMidiInDevice(i)) { + } + else if (auto mip = dm.getMidiInDevice(i)) + { // mip->setEndToEndEnabled(true); // TODO update ? mip->setEnabled(true); } } } - while (!interface.ShouldClose()) { + while (!interface.ShouldClose()) + { // poll and handle events box::Event event; - if (interface.PollEvent(event)) { + if (interface.PollEvent(event)) + { app.HandleEvent(event); } @@ -56,7 +64,9 @@ int main() { interface.PostRender(); } - } catch (std::exception &e) { + } + catch (std::exception &e) + { std::cerr << e.what() << std::endl; } return 0; diff --git a/src/plugin/chorus.cc b/src/plugin/chorus.cc index bc99174..2efa810 100644 --- a/src/plugin/chorus.cc +++ b/src/plugin/chorus.cc @@ -2,7 +2,8 @@ #include "core/cv.hh" -namespace box { +namespace box +{ Texture2D Chorus::icon_; // Define the static member @@ -32,29 +33,46 @@ Chorus::Chorus(te::Plugin *p) 86, // y 16, // radius YELLOW, - "mix"} { + "mix"} +{ EnsureTextureLoaded(); } -Chorus::~Chorus() { UnloadTexture(icon_); } +Chorus::~Chorus() +{ + UnloadTexture(icon_); +} -Texture2D &Chorus::GetIcon() const { return icon_; } +Texture2D &Chorus::GetIcon() const +{ + return icon_; +} -const char *Chorus::GetIconPath() const { return icon_path_; } +const char *Chorus::GetIconPath() const +{ + return icon_path_; +} -const char *Chorus::GetName() const { return name_; } +const char *Chorus::GetName() const +{ + return name_; +} -void Chorus::Render(Interface &interface) { +void Chorus::Render(Interface &interface) +{ knob_depth_.Render(interface); knob_width_.Render(interface); knob_speed_.Render(interface); knob_mix_.Render(interface); } -void Chorus::HandleEvent(const Event &event) { - switch (event.type) { +void Chorus::HandleEvent(const Event &event) +{ + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ONE: LOG_VAR(knob_depth_.param_.GetNorm()); knob_depth_.param_.SetNorm(knob_depth_.param_.GetNorm() - 0.125); diff --git a/src/plugin/compressor.cc b/src/plugin/compressor.cc index c70f6db..bf3db20 100644 --- a/src/plugin/compressor.cc +++ b/src/plugin/compressor.cc @@ -2,7 +2,8 @@ #include "core/cv.hh" -namespace box { +namespace box +{ Texture2D Compressor::icon_; // Define the static member @@ -31,29 +32,46 @@ Compressor::Compressor(te::Plugin *p) 86, // y 16, // radius YELLOW, - "release"} { + "release"} +{ EnsureTextureLoaded(); } -Compressor::~Compressor() { UnloadTexture(icon_); } +Compressor::~Compressor() +{ + UnloadTexture(icon_); +} -Texture2D &Compressor::GetIcon() const { return icon_; } +Texture2D &Compressor::GetIcon() const +{ + return icon_; +} -const char *Compressor::GetIconPath() const { return icon_path_; } +const char *Compressor::GetIconPath() const +{ + return icon_path_; +} -const char *Compressor::GetName() const { return name_; } +const char *Compressor::GetName() const +{ + return name_; +} -void Compressor::Render(Interface &interface) { +void Compressor::Render(Interface &interface) +{ knob_threshold_.Render(interface); knob_ratio_.Render(interface); knob_attack_.Render(interface); knob_release_.Render(interface); } -void Compressor::HandleEvent(const Event &event) { - switch (event.type) { +void Compressor::HandleEvent(const Event &event) +{ + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ONE: LOG_VAR(knob_threshold_.param_.GetNorm()); knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - diff --git a/src/plugin/delay.cc b/src/plugin/delay.cc index 7623c12..9bd1339 100644 --- a/src/plugin/delay.cc +++ b/src/plugin/delay.cc @@ -2,7 +2,8 @@ #include "core/cv.hh" -namespace box { +namespace box +{ Texture2D Delay::icon_; // Define the static member @@ -25,28 +26,45 @@ Delay::Delay(te::Plugin *p) 86, // y 16, // radius BLUE, - "speed"} { + "speed"} +{ EnsureTextureLoaded(); } -Delay::~Delay() { UnloadTexture(icon_); } +Delay::~Delay() +{ + UnloadTexture(icon_); +} -Texture2D &Delay::GetIcon() const { return icon_; } +Texture2D &Delay::GetIcon() const +{ + return icon_; +} -const char *Delay::GetIconPath() const { return icon_path_; } +const char *Delay::GetIconPath() const +{ + return icon_path_; +} -const char *Delay::GetName() const { return name_; } +const char *Delay::GetName() const +{ + return name_; +} -void Delay::Render(Interface &interface) { +void Delay::Render(Interface &interface) +{ knob_feedback_.Render(interface); knob_mix_.Render(interface); knob_length_.Render(interface); } -void Delay::HandleEvent(const Event &event) { - switch (event.type) { +void Delay::HandleEvent(const Event &event) +{ + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ONE: LOG_VAR(knob_feedback_.param_.GetNorm()); knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - diff --git a/src/plugin/four_osc.cc b/src/plugin/four_osc.cc index c2081a1..3efaf5d 100644 --- a/src/plugin/four_osc.cc +++ b/src/plugin/four_osc.cc @@ -1,6 +1,7 @@ #include "plugin/four_osc.hh" -namespace box { +namespace box +{ Texture2D FourOsc::icon_; // Define the static member @@ -14,26 +15,44 @@ FourOsc::FourOsc(te::Plugin *p) 22, // y 16, // radius GREEN, - "volume"} { + "volume"} +{ EnsureTextureLoaded(); // TODO for testing effects - for (int i = 0; i < base_plugin_->oscParams.size(); i++) { + for (int i = 0; i < base_plugin_->oscParams.size(); i++) + { base_plugin_->oscParams[i]->waveShapeValue.setValue(2, nullptr); } } -FourOsc::~FourOsc() { UnloadTexture(icon_); } +FourOsc::~FourOsc() +{ + UnloadTexture(icon_); +} -Texture2D &FourOsc::GetIcon() const { return icon_; } +Texture2D &FourOsc::GetIcon() const +{ + return icon_; +} -const char *FourOsc::GetIconPath() const { return icon_path_; } +const char *FourOsc::GetIconPath() const +{ + return icon_path_; +} -const char *FourOsc::GetName() const { return name_; } +const char *FourOsc::GetName() const +{ + return name_; +} -void FourOsc::Render(Interface &interface) { - for (int y = 0; y < Interface::HEIGHT; ++y) { - for (int x = 0; x < Interface::WIDTH; ++x) { - if (x % 2 == 0 && y % 2 == 0) { +void FourOsc::Render(Interface &interface) +{ + for (int y = 0; y < Interface::HEIGHT; ++y) + { + for (int x = 0; x < Interface::WIDTH; ++x) + { + if (x % 2 == 0 && y % 2 == 0) + { DrawPixel(x, y, RED); } } @@ -41,10 +60,13 @@ void FourOsc::Render(Interface &interface) { knob_master_level_.Render(interface); } -void FourOsc::HandleEvent(const Event &event) { - switch (event.type) { +void FourOsc::HandleEvent(const Event &event) +{ + switch (event.type) + { case EventType::KeyPress: - switch (event.value) { + switch (event.value) + { case KEY_ONE: LOG_VAR(knob_master_level_.param_.GetNorm()); knob_master_level_.param_.SetNorm( From 6bed8f4951895cd7bf6b34743d4bafef10e46002 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:33:33 -0500 Subject: [PATCH 10/12] 120 column and dont pack initializer list --- .clang-format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-format b/.clang-format index b507d02..170962f 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,7 @@ --- BasedOnStyle: LLVM IndentWidth: 4 +ColumnLimit: 120 BreakBeforeBraces: Allman AllowShortFunctionsOnASingleLine: None +PackConstructorInitializers: Never From 510c0469658347cc91b7b3db0e940dfb36e9c8f8 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 14:33:36 -0500 Subject: [PATCH 11/12] autoformat --- include/component/knob.hh | 10 +- include/component/switch.hh | 9 +- include/core/cv.hh | 4 +- include/core/interface.hh | 68 +++++++++---- include/core/parameter.hh | 12 +-- include/core/timeline.hh | 7 +- include/core/util.hh | 3 +- src/core/app.cc | 27 ++--- src/core/interface.cc | 9 +- src/core/plugin.cc | 3 +- src/core/plugin_selector.cc | 15 +-- src/core/timeline.cc | 194 ++++++++++++------------------------ src/core/track.cc | 31 +++--- src/core/util.cc | 17 ++-- src/plugin/chorus.cc | 16 +-- src/plugin/compressor.cc | 15 ++- src/plugin/delay.cc | 9 +- src/plugin/four_osc.cc | 9 +- 18 files changed, 204 insertions(+), 254 deletions(-) diff --git a/include/component/knob.hh b/include/component/knob.hh index 3bf4324..2ca3ceb 100644 --- a/include/component/knob.hh +++ b/include/component/knob.hh @@ -13,9 +13,13 @@ template struct Knob Color color_; std::string name_; - Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, - std::string name = "") - : param_{p}, x_{x}, y_{y}, radius_{radius}, color_{color}, name_{name} + Knob(Parameter p, uint8_t x, uint8_t y, uint8_t radius, Color color, std::string name = "") + : param_{p}, + x_{x}, + y_{y}, + radius_{radius}, + color_{color}, + name_{name} { } diff --git a/include/component/switch.hh b/include/component/switch.hh index 69e440f..905f630 100644 --- a/include/component/switch.hh +++ b/include/component/switch.hh @@ -14,9 +14,12 @@ struct Switch Color color_; std::string name_; - Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, - std::string name) - : value_{value}, x_{x}, y_{y}, color_{color}, name_{name} + Switch(juce::CachedValue &value, uint8_t x, uint8_t y, Color color, std::string name) + : value_{value}, + x_{x}, + y_{y}, + color_{color}, + name_{name} { } diff --git a/include/core/cv.hh b/include/core/cv.hh index 245f34a..9bba3b9 100644 --- a/include/core/cv.hh +++ b/include/core/cv.hh @@ -11,7 +11,9 @@ template struct CV // TODO add default value? CV(juce::CachedValue &cv, T min, T max) - : value_{cv}, min_{min}, max_{max} + : value_{cv}, + min_{min}, + max_{max} { assert(min <= max); } diff --git a/include/core/interface.hh b/include/core/interface.hh index 3cb598e..48f5408 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -25,24 +25,58 @@ class Interface private: RenderTexture2D target_; + // clang-format off std::map keys_ = { - {KEY_ZERO, false}, {KEY_ONE, false}, {KEY_TWO, false}, - {KEY_THREE, false}, {KEY_FOUR, false}, {KEY_FIVE, false}, - {KEY_SIX, false}, {KEY_SEVEN, false}, {KEY_EIGHT, false}, - {KEY_NINE, false}, {KEY_A, false}, {KEY_B, false}, - {KEY_C, false}, {KEY_D, false}, {KEY_E, false}, - {KEY_F, false}, {KEY_G, false}, {KEY_H, false}, - {KEY_I, false}, {KEY_J, false}, {KEY_K, false}, - {KEY_L, false}, {KEY_M, false}, {KEY_N, false}, - {KEY_O, false}, {KEY_P, false}, {KEY_Q, false}, - {KEY_R, false}, {KEY_S, false}, {KEY_T, false}, - {KEY_U, false}, {KEY_V, false}, {KEY_W, false}, - {KEY_X, false}, {KEY_Y, false}, {KEY_Z, false}, - {KEY_SPACE, false}, {KEY_ESCAPE, false}, {KEY_ENTER, false}, - {KEY_TAB, false}, {KEY_BACKSPACE, false}, {KEY_COMMA, false}, - {KEY_PERIOD, false}, {KEY_DELETE, false}, {KEY_MINUS, false}, - {KEY_EQUAL, false}, {KEY_RIGHT, false}, {KEY_LEFT, false}, - {KEY_DOWN, false}, {KEY_UP, false}, + {KEY_ZERO, false}, + {KEY_ONE, false}, + {KEY_TWO, false}, + {KEY_THREE, false}, + {KEY_FOUR, false}, + {KEY_FIVE, false}, + {KEY_SIX, false}, + {KEY_SEVEN, false}, + {KEY_EIGHT, false}, + {KEY_NINE, false}, + {KEY_A, false}, + {KEY_B, false}, + {KEY_C, false}, + {KEY_D, false}, + {KEY_E, false}, + {KEY_F, false}, + {KEY_G, false}, + {KEY_H, false}, + {KEY_I, false}, + {KEY_J, false}, + {KEY_K, false}, + {KEY_L, false}, + {KEY_M, false}, + {KEY_N, false}, + {KEY_O, false}, + {KEY_P, false}, + {KEY_Q, false}, + {KEY_R, false}, + {KEY_S, false}, + {KEY_T, false}, + {KEY_U, false}, + {KEY_V, false}, + {KEY_W, false}, + {KEY_X, false}, + {KEY_Y, false}, + {KEY_Z, false}, + {KEY_SPACE, false}, + {KEY_ESCAPE, false}, + {KEY_ENTER, false}, + {KEY_TAB, false}, + {KEY_BACKSPACE, false}, + {KEY_COMMA, false}, + {KEY_PERIOD, false}, + {KEY_DELETE, false}, + {KEY_MINUS, false}, + {KEY_EQUAL, false}, + {KEY_RIGHT, false}, + {KEY_LEFT, false}, + {KEY_DOWN, false}, + {KEY_UP, false}, }; }; diff --git a/include/core/parameter.hh b/include/core/parameter.hh index 9033eb1..7633397 100644 --- a/include/core/parameter.hh +++ b/include/core/parameter.hh @@ -16,11 +16,13 @@ template class Parameter std::variant, AP *> param_; public: - Parameter(CV cv) : param_{cv} + Parameter(CV cv) + : param_{cv} { } - Parameter(AP *p) : param_{p} + Parameter(AP *p) + : param_{p} { } @@ -34,8 +36,7 @@ template class Parameter else if (std::holds_alternative(param_)) { auto v = std::get(param_); - v->setParameter(new_value, - juce::NotificationType::dontSendNotification); + v->setParameter(new_value, juce::NotificationType::dontSendNotification); } } void SetNorm(T new_value) @@ -48,8 +49,7 @@ template class Parameter else if (std::holds_alternative(param_)) { auto v = std::get(param_); - v->setNormalisedParameter( - new_value, juce::NotificationType::dontSendNotification); + v->setNormalisedParameter(new_value, juce::NotificationType::dontSendNotification); } } T GetValue() const diff --git a/include/core/timeline.hh b/include/core/timeline.hh index ab15c02..4e6094d 100644 --- a/include/core/timeline.hh +++ b/include/core/timeline.hh @@ -49,7 +49,9 @@ struct Timeline { return radius * 2; } - BeatFrame(float c, float &r) : center{c}, radius{r} + BeatFrame(float c, float &r) + : center{c}, + radius{r} { } }; @@ -73,8 +75,7 @@ struct Timeline static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; static constexpr const char *METRONOME_PATH_R = "assets/metronome_r.png"; - static constexpr const char *METRONOME_PATH_OFF = - "assets/metronome_off.png"; + static constexpr const char *METRONOME_PATH_OFF = "assets/metronome_off.png"; Texture2D metronome_l_; Texture2D metronome_r_; Texture2D metronome_off_; diff --git a/include/core/util.hh b/include/core/util.hh index 31ffbdf..031401c 100644 --- a/include/core/util.hh +++ b/include/core/util.hh @@ -57,8 +57,7 @@ std::string loglevel_to_string(LogLevel l); LogLevel get_loglevel(); const LogLevel LOGLEVEL = get_loglevel(); void LOG_MSG(const std::string &msg, LogLevel l = LogLevel::Debug); -template -void log_var(const std::string &var_name, const T &var_value) +template void log_var(const std::string &var_name, const T &var_value) { LOG_MSG(var_name + ": " + std::to_string(var_value), LogLevel::Debug); } diff --git a/src/core/app.cc b/src/core/app.cc index 7f02071..6fdb76a 100644 --- a/src/core/app.cc +++ b/src/core/app.cc @@ -5,14 +5,12 @@ namespace box { -static void assert_tracks(const std::vector> &tracks, - size_t index, const std::string &name) +static void assert_tracks(const std::vector> &tracks, size_t index, const std::string &name) { if (tracks.size() == 0 || index >= tracks.size()) { - throw std::runtime_error{ - "App::" + name + "(): index [" + std::to_string(index) + - "] out of range: [0, " + std::to_string(tracks.size()) + "]"}; + throw std::runtime_error{"App::" + name + "(): index [" + std::to_string(index) + "] out of range: [0, " + + std::to_string(tracks.size()) + "]"}; } } @@ -29,7 +27,9 @@ void print_tracks(App a) } App::App(te::Engine &engine, te::Edit &edit) - : engine_{engine}, edit_{edit}, current_track_{0}, + : engine_{engine}, + edit_{edit}, + current_track_{0}, base_tracks_{te::getAudioTracks(edit)} { AddTrack(); // ensure there's always at least 1 @@ -73,14 +73,12 @@ void App::ArmMidi(size_t index) for (auto instance : edit_.getAllInputDevices()) { auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) + if (device_type == te::InputDevice::physicalMidiDevice || device_type == te::InputDevice::virtualMidiDevice) { auto t = te::getAudioTracks(edit_)[index]; if (t != nullptr) { - [[maybe_unused]] auto res = instance->setTarget( - t->itemID, true, &edit_.getUndoManager(), 0); + [[maybe_unused]] auto res = instance->setTarget(t->itemID, true, &edit_.getUndoManager(), 0); instance->setRecordingEnabled(t->itemID, true); } } @@ -92,8 +90,7 @@ void App::UnarmMidi(size_t index) for (auto instance : edit_.getAllInputDevices()) { auto device_type = instance->getInputDevice().getDeviceType(); - if (device_type == te::InputDevice::physicalMidiDevice || - device_type == te::InputDevice::virtualMidiDevice) + if (device_type == te::InputDevice::physicalMidiDevice || device_type == te::InputDevice::virtualMidiDevice) { auto t = te::getAudioTracks(edit_)[index]; if (t != nullptr) @@ -174,8 +171,7 @@ void App::HandleEvent(const Event &event) active_notes_[event.value] = note; auto message = juce::MidiMessage::noteOn(1, note, 1.0f); - te::MidiInputDevice *dev = - engine_.getDeviceManager().getDefaultMidiInDevice(); + te::MidiInputDevice *dev = engine_.getDeviceManager().getDefaultMidiInDevice(); dev->keyboardState.noteOn(1, note, 1.0); } break; @@ -188,8 +184,7 @@ void App::HandleEvent(const Event &event) active_notes_.erase(event.value); auto message = juce::MidiMessage::noteOff(1, note); - te::MidiInputDevice *dev = - engine_.getDeviceManager().getDefaultMidiInDevice(); + te::MidiInputDevice *dev = engine_.getDeviceManager().getDefaultMidiInDevice(); dev->keyboardState.noteOff(1, note, 1.0); } break; diff --git a/src/core/interface.cc b/src/core/interface.cc index 46623b3..bca1115 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -48,12 +48,9 @@ void Interface::PostRender() EndTextureMode(); // matches PreRender BeginDrawing(); - DrawTexturePro(target_.texture, - Rectangle{0, 0, float(target_.texture.width), - float(-target_.texture.height)}, - Rectangle{float(pos_x), float(pos_y), float(square_len), - float(square_len)}, - Vector2{0, 0}, 0.0f, WHITE); + DrawTexturePro(target_.texture, Rectangle{0, 0, float(target_.texture.width), float(-target_.texture.height)}, + Rectangle{float(pos_x), float(pos_y), float(square_len), float(square_len)}, Vector2{0, 0}, 0.0f, + WHITE); EndDrawing(); // hardware rendering } diff --git a/src/core/plugin.cc b/src/core/plugin.cc index 17f7b41..49e3f5b 100644 --- a/src/core/plugin.cc +++ b/src/core/plugin.cc @@ -3,7 +3,8 @@ namespace box { -Plugin::Plugin(te::Plugin *p) : plugin_{p} +Plugin::Plugin(te::Plugin *p) + : plugin_{p} { } diff --git a/src/core/plugin_selector.cc b/src/core/plugin_selector.cc index d8ef173..9d84b33 100644 --- a/src/core/plugin_selector.cc +++ b/src/core/plugin_selector.cc @@ -10,17 +10,15 @@ namespace box { const std::vector PluginSelector::PLUGIN_NAMES = { - te::FourOscPlugin::xmlTypeName, te::ChorusPlugin::xmlTypeName, - te::CompressorPlugin::xmlTypeName, te::DelayPlugin::xmlTypeName, - te::EqualiserPlugin::xmlTypeName, te::PhaserPlugin::xmlTypeName, + te::FourOscPlugin::xmlTypeName, te::ChorusPlugin::xmlTypeName, te::CompressorPlugin::xmlTypeName, + te::DelayPlugin::xmlTypeName, te::EqualiserPlugin::xmlTypeName, te::PhaserPlugin::xmlTypeName, te::ReverbPlugin::xmlTypeName, }; void assert_index(std::vector v, size_t curr) { if (curr >= v.size()) - throw std::runtime_error{"PluginSelector index out of range: " + - std::to_string(curr)}; + throw std::runtime_error{"PluginSelector index out of range: " + std::to_string(curr)}; } PluginSelector::PluginSelector() @@ -62,8 +60,7 @@ void PluginSelector::HandleEvent(const Event &event) current_index_ = clamp_decrement(current_index_); break; case KEY_J: - current_index_ = - std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); + current_index_ = std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); break; case KEY_ENTER: // TODO proper back button? @@ -71,9 +68,7 @@ void PluginSelector::HandleEvent(const Event &event) const auto &name = PLUGIN_NAMES[current_index_]; std::unique_ptr p; - auto base = APP->edit_.getPluginCache() - .createNewPlugin(name.c_str(), {}) - .get(); + auto base = APP->edit_.getPluginCache().createNewPlugin(name.c_str(), {}).get(); // TODO use cast? if (name == te::ChorusPlugin::xmlTypeName) { diff --git a/src/core/timeline.cc b/src/core/timeline.cc index 47bec71..27057b0 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -38,16 +38,14 @@ void Timeline::Render(Interface &interface) */ assert(is_close(frame_.radius, radius_)); - const size_t num_rows = - std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); + const size_t num_rows = std::min(APP->tracks_.size() - scroll_offset_, MAX_TRACKS); const size_t curr_row = APP->GetCurrTrack() - scroll_offset_; const te::TransportControl &transport = APP->edit_.getTransport(); const te::TempoSequence &tempo = APP->edit_.tempoSequence; - const Position curr_pos = { - static_cast(APP->edit_.getTransport().getPosition().inSeconds()), - static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; + const Position curr_pos = {static_cast(APP->edit_.getTransport().getPosition().inSeconds()), + static_cast(tempo.toBeats(transport.getPosition()).inBeats())}; BeatFrame screen{curr_pos.beats, radius_}; @@ -71,10 +69,8 @@ void Timeline::Render(Interface &interface) auto text = format_time(curr_pos.secs); Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), (SCREEN_HALF - text_size.x / 2), - (HEADER_HEIGHT / 2 - text_size.y / 2), HEADER_FONT_SIZE, + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), (SCREEN_HALF - text_size.x / 2), (HEADER_HEIGHT / 2 - text_size.y / 2), HEADER_FONT_SIZE, WHITE); } @@ -85,19 +81,16 @@ void Timeline::Render(Interface &interface) const int beat = static_cast(curr_pos.beats); if (beat % 2 == 0) { - DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + DrawTexture(metronome_l_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } else { - DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + DrawTexture(metronome_r_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } } else { - DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, - HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); + DrawTexture(metronome_off_, SCREEN_EIGHTH / 2 - ICON_RADIUS, HEADER_HEIGHT / 2 - ICON_RADIUS, WHITE); } } @@ -106,55 +99,45 @@ void Timeline::Render(Interface &interface) DrawRectangle(SCREEN_EIGHTH, 0, ICON_WIDTH, ICON_HEIGHT, YELLOW); auto text = format_key_offset(APP->key_offset_); Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), - SCREEN_EIGHTH + SCREEN_EIGHTH / 2 - text_size.x / 2, - HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, BLACK); + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), SCREEN_EIGHTH + SCREEN_EIGHTH / 2 - text_size.x / 2, HEADER_HEIGHT / 2 - text_size.y / 2, + HEADER_FONT_SIZE, BLACK); } // render cursor position { auto text = format_cursor_pos(APP->GetCurrTrack(), cursor_.LeftEdge()); Vector2 text_size = - MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, - HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); - DrawText(text.c_str(), SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x / 2, - HEADER_HEIGHT / 2 - text_size.y / 2, HEADER_FONT_SIZE, WHITE); + MeasureTextEx(GetFontDefault(), text.c_str(), HEADER_FONT_SIZE, HEADER_FONT_SIZE / DEFAULT_FONT_SIZE); + DrawText(text.c_str(), SCREEN_WIDTH - SCREEN_EIGHTH - text_size.x / 2, HEADER_HEIGHT / 2 - text_size.y / 2, + HEADER_FONT_SIZE, WHITE); } // render bar lines { - float first_bar_start = - std::floor(screen.LeftEdge() / bar_width_) * bar_width_; + float first_bar_start = std::floor(screen.LeftEdge() / bar_width_) * bar_width_; - for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); - bar_start += bar_width_) + for (float bar_start = first_bar_start; bar_start < screen.RightEdge(); bar_start += bar_width_) { - float bar_position_pct = - (bar_start - screen.LeftEdge()) / screen.Width(); + float bar_position_pct = (bar_start - screen.LeftEdge()) / screen.Width(); int x = static_cast(bar_position_pct * SCREEN_WIDTH); - DrawLine(x, HEADER_HEIGHT, x, - HEADER_HEIGHT + (ROW_HEIGHT * num_rows), DARKGRAY); + DrawLine(x, HEADER_HEIGHT, x, HEADER_HEIGHT + (ROW_HEIGHT * num_rows), DARKGRAY); } } // render current live clip (if recording) if (transport.isRecording()) { - const float start_time = - tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); + const float start_time = tempo.toBeats(transport.getTimeWhenStarted()).inBeats(); if (screen.LeftEdge() < start_time) { float left_pct = (start_time - screen.LeftEdge()) / screen.Width(); float left_px = (left_pct * SCREEN_WIDTH); - DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, - (SCREEN_HALF - left_px), ROW_HEIGHT, RED); + DrawRectangle(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - left_px), ROW_HEIGHT, RED); } else { - DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, - (SCREEN_HALF - 0), ROW_HEIGHT, + DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - 0), ROW_HEIGHT, RED); // 64 - 0 means full half bar } } @@ -169,34 +152,24 @@ void Timeline::Render(Interface &interface) { const te::ClipPosition c_pos = c->getPosition(); te::BeatRange t_br = te::toBeats(c_pos.time, tempo); - BeatWindow clip = { - static_cast(t_br.getStart().inBeats()), - static_cast(t_br.getLength().inBeats())}; + BeatWindow clip = {static_cast(t_br.getStart().inBeats()), + static_cast(t_br.getLength().inBeats())}; // Determine overlap with visible range - const float visible_start = - std::max(screen.LeftEdge(), clip.LeftEdge()); - const float visible_end = - std::min(screen.RightEdge(), clip.RightEdge()); + const float visible_start = std::max(screen.LeftEdge(), clip.LeftEdge()); + const float visible_end = std::min(screen.RightEdge(), clip.RightEdge()); if (visible_start < visible_end) // Clip is visible { - float start_pct = - (visible_start - screen.LeftEdge()) / screen.Width(); - float end_pct = - (visible_end - screen.LeftEdge()) / screen.Width(); - - const int left_px = - static_cast(start_pct * SCREEN_WIDTH); - const int right_px = - static_cast(end_pct * SCREEN_WIDTH); + float start_pct = (visible_start - screen.LeftEdge()) / screen.Width(); + float end_pct = (visible_end - screen.LeftEdge()) / screen.Width(); + + const int left_px = static_cast(start_pct * SCREEN_WIDTH); + const int right_px = static_cast(end_pct * SCREEN_WIDTH); int clip_width = right_px - left_px; - DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, - clip_width, ROW_HEIGHT, GREEN); - DrawRectangleLines(left_px, - (i * ROW_HEIGHT) + HEADER_HEIGHT, - clip_width, ROW_HEIGHT, LIGHTGRAY); + DrawRectangle(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, ROW_HEIGHT, GREEN); + DrawRectangleLines(left_px, (i * ROW_HEIGHT) + HEADER_HEIGHT, clip_width, ROW_HEIGHT, LIGHTGRAY); } } } @@ -213,26 +186,21 @@ void Timeline::Render(Interface &interface) // render cursor if (!transport.isRecording() && !transport.isPlaying()) { - const float left_pct = - (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); - const float right_pct = - (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); + const float left_pct = (cursor_.LeftEdge() - screen.LeftEdge()) / screen.Width(); + const float right_pct = (cursor_.RightEdge() - screen.LeftEdge()) / screen.Width(); const int left_px = static_cast(left_pct * SCREEN_WIDTH); const int right_px = static_cast(right_pct * SCREEN_WIDTH); const int width = right_px - left_px; - DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, - width, ROW_HEIGHT, ORANGE); + DrawRectangleLines(left_px, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, width, ROW_HEIGHT, ORANGE); } // render playhead { - if (screen.LeftEdge() < curr_pos.beats && - curr_pos.beats < screen.RightEdge()) + if (screen.LeftEdge() < curr_pos.beats && curr_pos.beats < screen.RightEdge()) { - const float left_pct = - (curr_pos.beats - screen.LeftEdge()) / screen.Width(); + const float left_pct = (curr_pos.beats - screen.LeftEdge()) / screen.Width(); const int left_px = static_cast(left_pct * SCREEN_WIDTH); // -1 so that you can see the tick DrawLine(left_px, HEADER_HEIGHT - 1, left_px, SCREEN_HEIGHT, WHITE); @@ -272,20 +240,15 @@ void Timeline::print_timeline() const te::TempoSequence &tempo = APP->edit_.tempoSequence; const te::TransportControl &transport = APP->edit_.getTransport(); const te::TimePosition &curr_time_pos = transport.getPosition(); - const te::BeatPosition &curr_beat_pos = - te::toBeats(te::EditTime{transport.getPosition()}, tempo); + const te::BeatPosition &curr_beat_pos = te::toBeats(te::EditTime{transport.getPosition()}, tempo); const te::TimeSigSetting &time_sig = tempo.getTimeSigAt(curr_time_pos); - std::cout << "TIME curr position: " << curr_time_pos.inSeconds() - << std::endl; - std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() - << std::endl; + std::cout << "TIME curr position: " << curr_time_pos.inSeconds() << std::endl; + std::cout << "BEATS curr position: " << curr_beat_pos.inBeats() << std::endl; std::cout << "bpm: " << tempo.getBpmAt(curr_time_pos) << std::endl; std::cout << "time signature: " << time_sig.getStringTimeSig() << std::endl; - std::cout << "time signature numerator: " << time_sig.numerator - << std::endl; - std::cout << "time signature denominator: " << time_sig.denominator - << std::endl; + std::cout << "time signature numerator: " << time_sig.numerator << std::endl; + std::cout << "time signature denominator: " << time_sig.denominator << std::endl; const auto clips = track.getClips(); std::cout << "num clips: " << clips.size() << std::endl; @@ -297,28 +260,20 @@ void Timeline::print_timeline() << "isMidi: " << c->isMidi() << std::endl; const te::ClipPosition pos = c->getPosition(); auto edit_range = te::EditTimeRange{pos.time}; - te::TimeRange time_range = - te::toTime(edit_range, APP->edit_.tempoSequence); - te::BeatRange beat_range = - te::toBeats(edit_range, APP->edit_.tempoSequence); + te::TimeRange time_range = te::toTime(edit_range, APP->edit_.tempoSequence); + te::BeatRange beat_range = te::toBeats(edit_range, APP->edit_.tempoSequence); std::cout << "\t\t" - << "TIME start: " << time_range.getStart().inSeconds() - << std::endl; + << "TIME start: " << time_range.getStart().inSeconds() << std::endl; std::cout << "\t\t" - << "TIME end: " << time_range.getEnd().inSeconds() - << std::endl; + << "TIME end: " << time_range.getEnd().inSeconds() << std::endl; std::cout << "\t\t" - << "TIME length: " << pos.getLength().inSeconds() - << std::endl; + << "TIME length: " << pos.getLength().inSeconds() << std::endl; std::cout << "\t\t" - << "BEATS start: " << beat_range.getStart().inBeats() - << std::endl; + << "BEATS start: " << beat_range.getStart().inBeats() << std::endl; std::cout << "\t\t" - << "BEATS end: " << beat_range.getEnd().inBeats() - << std::endl; + << "BEATS end: " << beat_range.getEnd().inBeats() << std::endl; std::cout << "\t\t" - << "BEATS length: " << beat_range.getLength().inBeats() - << std::endl; + << "BEATS length: " << beat_range.getLength().inBeats() << std::endl; } } @@ -363,12 +318,10 @@ void Timeline::HandleEvent(const Event &event) case KEY_J: if (!APP->edit_.getTransport().isRecording()) { - APP->SetCurrTrack(clamp_increment(APP->GetCurrTrack(), - APP->tracks_.size())); + APP->SetCurrTrack(clamp_increment(APP->GetCurrTrack(), APP->tracks_.size())); if (APP->GetCurrTrack() - scroll_offset_ >= MAX_ROWS) { - scroll_offset_ = clamp_increment(scroll_offset_, - APP->tracks_.size()); + scroll_offset_ = clamp_increment(scroll_offset_, APP->tracks_.size()); } } break; @@ -386,8 +339,7 @@ void Timeline::HandleEvent(const Event &event) scroll_offset_ = clamp_decrement(scroll_offset_); break; case KEY_DOWN: - scroll_offset_ = - clamp_increment(scroll_offset_, APP->tracks_.size()); + scroll_offset_ = clamp_increment(scroll_offset_, APP->tracks_.size()); break; case KEY_O: // add track if (APP->tracks_.size() < MAX_TRACKS) @@ -398,11 +350,9 @@ void Timeline::HandleEvent(const Event &event) case KEY_W: { const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime( - te::BeatPosition::fromBeats(cursor_.RightEdge())); + auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.RightEdge())); - te::TrackItem *item = - APP->CurrTrack().base_.getNextTrackItemAt(pos); + te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); if (item == nullptr) { LOG_MSG("KEY_W found NONE"); @@ -420,11 +370,9 @@ void Timeline::HandleEvent(const Event &event) case KEY_D: { const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = - tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); + auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); - te::TrackItem *item = - APP->CurrTrack().base_.getNextTrackItemAt(pos); + te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); if (item == nullptr) { LOG_MSG("KEY_D found NONE"); @@ -460,12 +408,8 @@ void Timeline::HandleEvent(const Event &event) playhead_mode_ = PlayheadMode::Detached; { - const float curr_pos = - APP->edit_.tempoSequence - .toBeats(transport.getPosition()) - .inBeats(); - cursor_.start = - std::floor(curr_pos / bar_width_) * bar_width_; + const float curr_pos = APP->edit_.tempoSequence.toBeats(transport.getPosition()).inBeats(); + cursor_.start = std::floor(curr_pos / bar_width_) * bar_width_; frame_.center = curr_pos; } assert_multiple(cursor_.start, bar_width_); @@ -473,8 +417,7 @@ void Timeline::HandleEvent(const Event &event) else { const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime( - te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.setPosition(tempo.toTime(te::BeatPosition::fromBeats(cursor_.LeftEdge()))); transport.record(false); playhead_mode_ = PlayheadMode::Locked; } @@ -489,12 +432,8 @@ void Timeline::HandleEvent(const Event &event) playhead_mode_ = PlayheadMode::Detached; { - const float curr_pos = - APP->edit_.tempoSequence - .toBeats(transport.getPosition()) - .inBeats(); - cursor_.start = - std::floor(curr_pos / bar_width_) * bar_width_; + const float curr_pos = APP->edit_.tempoSequence.toBeats(transport.getPosition()).inBeats(); + cursor_.start = std::floor(curr_pos / bar_width_) * bar_width_; frame_.center = curr_pos; } assert_multiple(cursor_.start, bar_width_); @@ -502,8 +441,7 @@ void Timeline::HandleEvent(const Event &event) else { const te::TempoSequence &tempo = APP->edit_.tempoSequence; - transport.setPosition(tempo.toTime( - te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.setPosition(tempo.toTime(te::BeatPosition::fromBeats(cursor_.LeftEdge()))); transport.play(false); playhead_mode_ = PlayheadMode::Locked; } @@ -522,16 +460,14 @@ void Timeline::HandleEvent(const Event &event) { LOG_MSG("move left"); auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds( - transport.getPosition().inSeconds() - 2.f)); + transport.setPosition(te::TimePosition::fromSeconds(transport.getPosition().inSeconds() - 2.f)); } break; case KEY_PERIOD: { LOG_MSG("move right"); auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds( - transport.getPosition().inSeconds() + 2.f)); + transport.setPosition(te::TimePosition::fromSeconds(transport.getPosition().inSeconds() + 2.f)); } break; case KEY_MINUS: diff --git a/src/core/track.cc b/src/core/track.cc index 7846434..dcb5339 100644 --- a/src/core/track.cc +++ b/src/core/track.cc @@ -8,18 +8,17 @@ namespace box { -static void assert_plugins(const std::vector> &plugins, - int index, std::string function_name) +static void assert_plugins(const std::vector> &plugins, int index, std::string function_name) { if (index >= plugins.size()) { - throw std::runtime_error{ - "Track::" + function_name + " => index [" + std::to_string(index) + - "] out of range: [0, " + std::to_string(plugins.size()) + "]"}; + throw std::runtime_error{"Track::" + function_name + " => index [" + std::to_string(index) + + "] out of range: [0, " + std::to_string(plugins.size()) + "]"}; } } -Track::Track(te::AudioTrack &base) : base_{base} +Track::Track(te::AudioTrack &base) + : base_{base} { } @@ -50,8 +49,7 @@ void Track::RemoveActivePlugin() } plugins_.erase(plugins_.begin() + active_plugin_); // TODO check for underflow messing up min - active_plugin_ = - std::min(active_plugin_, static_cast(plugins_.size()) - 1); + active_plugin_ = std::min(active_plugin_, static_cast(plugins_.size()) - 1); } void Track::SetActivePlugin(int index) @@ -108,14 +106,12 @@ void Track::HandleEvent(const Event &event) // TODO KEY_J and KEY_K move up and down case KEY_H: LOG_MSG("left"); - active_plugin_ = - clamp_index(active_plugin_ - 1, plugins_.size()); + active_plugin_ = clamp_index(active_plugin_ - 1, plugins_.size()); LOG_VAR(active_plugin_); break; case KEY_L: LOG_MSG("right"); - active_plugin_ = - clamp_index(active_plugin_ + 1, plugins_.size()); + active_plugin_ = clamp_index(active_plugin_ + 1, plugins_.size()); LOG_VAR(active_plugin_); break; case KEY_ENTER: @@ -170,13 +166,11 @@ void Track::Render(Interface &interface) constexpr int font_size = 10; int width = MeasureText(plugins_[i]->GetName(), font_size); - DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, - WHITE); + DrawText(plugins_[i]->GetName(), (x - width / 2), y + 6, font_size, WHITE); if (i == active_plugin_) { - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, - static_cast(i / 4) * 32 + 64 + 16}, + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, 5.0f, GREEN); } } @@ -184,9 +178,8 @@ void Track::Render(Interface &interface) { auto x = static_cast((i % 4) * 32 + 16); auto y = static_cast((i / 4) * 32 + 64 + 16); - DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, - static_cast(i / 4) * 32 + 64 + 16}, - 1.0f, RED); + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, 1.0f, + RED); DrawTextPro(GetFontDefault(), "none", Vector2{x, y}, Vector2{ 11, diff --git a/src/core/util.cc b/src/core/util.cc index cd70ef7..4c5666b 100644 --- a/src/core/util.cc +++ b/src/core/util.cc @@ -20,13 +20,11 @@ std::string format_time(float time) { int minutes = static_cast(time) / 60; int seconds = static_cast(time) % 60; - int decimal = - static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places + int decimal = static_cast(std::fmod(time, 1.0f) * 100); // Two decimal places std::ostringstream oss; - oss << std::setw(2) << std::setfill('0') << minutes << "." << std::setw(2) - << std::setfill('0') << seconds << "." << std::setw(2) - << std::setfill('0') << decimal; + oss << std::setw(2) << std::setfill('0') << minutes << "." << std::setw(2) << std::setfill('0') << seconds << "." + << std::setw(2) << std::setfill('0') << decimal; return oss.str(); } @@ -42,8 +40,7 @@ std::string format_key_offset(int key_offset) std::string format_cursor_pos(size_t track_pos, float cursor_pos) { std::ostringstream oss; - oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') - << cursor_pos; + oss << std::setw(1) << track_pos << ":" << std::setw(3) << std::setfill('0') << cursor_pos; return oss.str(); } @@ -83,8 +80,7 @@ std::string loglevel_to_string(LogLevel l) return "WARN"; if (l == LogLevel::Err) return "ERR"; - throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + - ") not found"}; + throw std::runtime_error{"loglevel_to_string(" + loglevel_to_string(l) + ") not found"}; } // get loglevel from env @@ -112,8 +108,7 @@ void LOG_MSG(const std::string &msg, LogLevel l) std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); // print - std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg - << std::endl; + std::cout << "[" << buf << "] " << loglevel_to_string(l) << ": " << msg << std::endl; } } // namespace box diff --git a/src/plugin/chorus.cc b/src/plugin/chorus.cc index 2efa810..f74caff 100644 --- a/src/plugin/chorus.cc +++ b/src/plugin/chorus.cc @@ -8,7 +8,8 @@ namespace box Texture2D Chorus::icon_; // Define the static member Chorus::Chorus(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, + : Plugin(p), + base_plugin_{static_cast(p)}, knob_depth_{Parameter{CV{base_plugin_->depthMs, 0.0, 10.0}}, 32, // x 22, // y @@ -27,13 +28,12 @@ Chorus::Chorus(te::Plugin *p) 16, // radius BLUE, "speed"}, - knob_mix_{ - Parameter{CV{base_plugin_->mixProportion, 0.0, 1.0}}, - 96, // x - 86, // y - 16, // radius - YELLOW, - "mix"} + knob_mix_{Parameter{CV{base_plugin_->mixProportion, 0.0, 1.0}}, + 96, // x + 86, // y + 16, // radius + YELLOW, + "mix"} { EnsureTextureLoaded(); } diff --git a/src/plugin/compressor.cc b/src/plugin/compressor.cc index bf3db20..2c78e23 100644 --- a/src/plugin/compressor.cc +++ b/src/plugin/compressor.cc @@ -8,7 +8,8 @@ namespace box Texture2D Compressor::icon_; // Define the static member Compressor::Compressor(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, + : Plugin(p), + base_plugin_{static_cast(p)}, knob_threshold_{Parameter{base_plugin_->thresholdGain.parameter}, 32, // x 22, // y @@ -74,13 +75,11 @@ void Compressor::HandleEvent(const Event &event) { case KEY_ONE: LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - - 0.125); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() - 0.125); break; case KEY_TWO: LOG_VAR(knob_threshold_.param_.GetNorm()); - knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + - 0.125); + knob_threshold_.param_.SetNorm(knob_threshold_.param_.GetNorm() + 0.125); break; case KEY_THREE: LOG_VAR(knob_ratio_.param_.GetNorm()); @@ -100,13 +99,11 @@ void Compressor::HandleEvent(const Event &event) break; case KEY_SEVEN: LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - - 0.125); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() - 0.125); break; case KEY_EIGHT: LOG_VAR(knob_release_.param_.GetNorm()); - knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + - 0.125); + knob_release_.param_.SetNorm(knob_release_.param_.GetNorm() + 0.125); break; } break; diff --git a/src/plugin/delay.cc b/src/plugin/delay.cc index 9bd1339..de1869a 100644 --- a/src/plugin/delay.cc +++ b/src/plugin/delay.cc @@ -8,7 +8,8 @@ namespace box Texture2D Delay::icon_; // Define the static member Delay::Delay(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, + : Plugin(p), + base_plugin_{static_cast(p)}, knob_feedback_{Parameter{base_plugin_->feedbackDb}, 32, // x 22, // y @@ -67,13 +68,11 @@ void Delay::HandleEvent(const Event &event) { case KEY_ONE: LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - - 0.125); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() - 0.125); break; case KEY_TWO: LOG_VAR(knob_feedback_.param_.GetNorm()); - knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + - 0.125); + knob_feedback_.param_.SetNorm(knob_feedback_.param_.GetNorm() + 0.125); break; case KEY_THREE: LOG_VAR(knob_mix_.param_.GetNorm()); diff --git a/src/plugin/four_osc.cc b/src/plugin/four_osc.cc index 3efaf5d..a33b8d4 100644 --- a/src/plugin/four_osc.cc +++ b/src/plugin/four_osc.cc @@ -6,7 +6,8 @@ namespace box Texture2D FourOsc::icon_; // Define the static member FourOsc::FourOsc(te::Plugin *p) - : Plugin(p), base_plugin_{static_cast(p)}, + : Plugin(p), + base_plugin_{static_cast(p)}, // knob_master_level_{32, 64, 16, {255,0,0}, // base_plugin_->masterLevelValue, base_plugin_->masterLevel} @@ -69,13 +70,11 @@ void FourOsc::HandleEvent(const Event &event) { case KEY_ONE: LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm( - knob_master_level_.param_.GetNorm() - 0.125); + knob_master_level_.param_.SetNorm(knob_master_level_.param_.GetNorm() - 0.125); break; case KEY_TWO: LOG_VAR(knob_master_level_.param_.GetNorm()); - knob_master_level_.param_.SetNorm( - knob_master_level_.param_.GetNorm() + 0.125); + knob_master_level_.param_.SetNorm(knob_master_level_.param_.GetNorm() + 0.125); break; } break; From de15288125944281a45c65bfc078a76bb9b9f7f2 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 2 Jan 2025 16:17:37 -0500 Subject: [PATCH 12/12] end wrapper for interface.hh --- include/core/interface.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/include/core/interface.hh b/include/core/interface.hh index 48f5408..ba468f6 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -78,6 +78,7 @@ class Interface {KEY_DOWN, false}, {KEY_UP, false}, }; + // clang-format on }; } // namespace box