diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..170962f --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 120 +BreakBeforeBraces: Allman +AllowShortFunctionsOnASingleLine: None +PackConstructorInitializers: Never diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45557d5..1f2bfd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,7 +39,10 @@ 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 clang-format 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 + - 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. id: strings @@ -64,7 +67,6 @@ jobs: -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -S ${{ github.workspace }} - - name: Build run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel $(nproc) - name: Print ccache stats diff --git a/include/component/knob.hh b/include/component/knob.hh index b5515e2..2ca3ceb 100644 --- a/include/component/knob.hh +++ b/include/component/knob.hh @@ -1,12 +1,12 @@ #pragma once -#include "core/util.hh" -#include "core/parameter.hh" #include "core/cv.hh" +#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_; @@ -14,10 +14,16 @@ struct Knob 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} - {} + : 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_); @@ -28,11 +34,9 @@ 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 e343a24..905f630 100644 --- a/include/component/switch.hh +++ b/include/component/switch.hh @@ -1,6 +1,6 @@ #pragma once -#include "core/util.hh" #include "core/parameter.hh" +#include "core/util.hh" // instead of using cv.hh, we directly use juce::CachedValue @@ -15,10 +15,15 @@ struct Switch 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} - {} + : 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; @@ -26,9 +31,8 @@ struct Switch 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) { - } }; diff --git a/include/core/app.hh b/include/core/app.hh index cfe9d53..dc1c774 100644 --- a/include/core/app.hh +++ b/include/core/app.hh @@ -1,19 +1,23 @@ #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 { +namespace box +{ -struct App { - enum class ScreenState { +struct App +{ + enum class ScreenState + { Timeline, Track, PluginSelector, }; - enum class Mode { + enum class Mode + { Normal, Insert, }; @@ -23,17 +27,17 @@ struct App { int key_offset_ = 0; std::map active_notes_; - te::Engine &engine_ ; - te::Edit &edit_ ; + te::Engine &engine_; + te::Edit &edit_; std::vector> tracks_; - juce::Array base_tracks_; + juce::Array base_tracks_; PluginSelector plugin_sel_; Timeline timeline_; - + const std::vector colors_ = { - Color{0x29, 0x73, 0x55, 0xff}, + Color{0x29, 0x73, 0x55, 0xff}, Color{0x1e, 0x4d, 0x3f, 0xff}, Color{0xdd, 0xe6, 0x63, 0xff}, Color{0x7d, 0x54, 0x39, 0xff}, @@ -41,8 +45,8 @@ struct App { // functions App(te::Engine &engine, te::Edit &edit); - void Render(Interface& interface); - void HandleEvent(const Event& event); + void Render(Interface &interface); + void HandleEvent(const Event &event); Track &CurrTrack(); size_t GetCurrTrack(); @@ -50,7 +54,7 @@ struct App { void AddTrack(); void ChangeArmMidi(size_t new_index); -private: + private: size_t current_track_; void ArmMidi(size_t index); void UnarmMidi(size_t index); diff --git a/include/core/cv.hh b/include/core/cv.hh index 43a84e6..9bba3b9 100644 --- a/include/core/cv.hh +++ b/include/core/cv.hh @@ -1,16 +1,19 @@ #pragma once -#include "core/util.hh" #include -template -struct CV { +#include "core/util.hh" + +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); } @@ -27,7 +30,10 @@ struct CV { value_ = range * norm; } - T GetValue() const { return value_.get(); } + T GetValue() const + { + return value_.get(); + } T GetNorm() const { const auto range = max_ - min_; diff --git a/include/core/interface.hh b/include/core/interface.hh index 0998161..ba468f6 100644 --- a/include/core/interface.hh +++ b/include/core/interface.hh @@ -1,11 +1,14 @@ #pragma once #include + #include "core/util.hh" -namespace box { +namespace box +{ -class Interface { -public: +class Interface +{ + public: static const int WIDTH = 128; static const int HEIGHT = 128; constexpr static DeviceType DISPLAY_TYPE = DeviceType::Emulator; @@ -17,64 +20,65 @@ public: void PreRender(); void PostRender(); - bool PollEvent(Event& event); + bool PollEvent(Event &event); bool ShouldClose() const; -private: + private: RenderTexture2D target_; + // clang-format off std::map keys_ = { - {KEY_ZERO, false}, - {KEY_ONE, false}, - {KEY_TWO, false}, - {KEY_THREE, 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_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_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_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_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_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_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_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_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_EQUAL, false}, + {KEY_RIGHT, false}, + {KEY_LEFT, false}, + {KEY_DOWN, false}, {KEY_UP, false}, }; - + // clang-format on }; } // namespace box diff --git a/include/core/parameter.hh b/include/core/parameter.hh index d723a37..7633397 100644 --- a/include/core/parameter.hh +++ b/include/core/parameter.hh @@ -1,25 +1,30 @@ #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 { +namespace box +{ using AP = te::AutomatableParameter; -template -class Parameter { - std::variant, AP*> param_; -public: +template class Parameter +{ + std::variant, AP *> param_; + + public: Parameter(CV cv) - : param_{cv} - {} + : param_{cv} + { + } Parameter(AP *p) - : param_{p} - {} + : param_{p} + { + } void SetValue(T new_value) { @@ -28,9 +33,9 @@ public: 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_); + auto v = std::get(param_); v->setParameter(new_value, juce::NotificationType::dontSendNotification); } } @@ -41,9 +46,9 @@ public: 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_); + auto v = std::get(param_); v->setNormalisedParameter(new_value, juce::NotificationType::dontSendNotification); } } @@ -54,9 +59,9 @@ public: 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_); + auto v = std::get(param_); return v->getCurrentValue(); } } @@ -67,13 +72,12 @@ public: 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_); + auto v = std::get(param_); return v->getCurrentNormalisedValue(); } } }; - } // namespace box diff --git a/include/core/plugin.hh b/include/core/plugin.hh index eb0c29f..12b01bf 100644 --- a/include/core/plugin.hh +++ b/include/core/plugin.hh @@ -1,19 +1,20 @@ #pragma once -#include "core/util.hh" #include "core/interface.hh" +#include "core/util.hh" -namespace box { - +namespace box +{ -struct Plugin { +struct Plugin +{ te::Plugin *const plugin_; -public: + public: Plugin(te::Plugin *p); virtual ~Plugin(); void EnsureTextureLoaded() const; - te::Plugin *const GetPlugin() const; + te::Plugin *const GetPlugin() const; virtual Texture2D &GetIcon() const = 0; virtual const char *GetIconPath() const = 0; @@ -22,5 +23,4 @@ public: virtual void HandleEvent(const Event &event) = 0; }; - } // namespace box diff --git a/include/core/plugin_selector.hh b/include/core/plugin_selector.hh index 1557125..d22afae 100644 --- a/include/core/plugin_selector.hh +++ b/include/core/plugin_selector.hh @@ -1,10 +1,12 @@ #pragma once -#include "core/util.hh" #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 9f51546..4e6094d 100644 --- a/include/core/timeline.hh +++ b/include/core/timeline.hh @@ -1,50 +1,76 @@ #pragma once -#include "util.hh" #include "interface.hh" +#include "util.hh" -namespace box { - -struct Timeline { +namespace box +{ - 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; }; - float bar_width_ = 4.0; // Assuming a 4/4 time signature by default TODO update with time signature changes + 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; + PlayheadMode playhead_mode_ = PlayheadMode::Detached; size_t scroll_offset_ = 0; static constexpr const char *METRONOME_PATH_L = "assets/metronome_l.png"; @@ -59,11 +85,11 @@ struct Timeline { void FocusCursor(); - void Render(Interface& interface); - void HandleEvent(const Event& event); -private: + void Render(Interface &interface); + void HandleEvent(const Event &event); + + private: void print_timeline(); }; } // namespace box - diff --git a/include/core/track.hh b/include/core/track.hh index 4449dda..33c15bf 100644 --- a/include/core/track.hh +++ b/include/core/track.hh @@ -2,18 +2,23 @@ #include #include -#include "core/util.hh" + #include "core/interface.hh" #include "core/plugin.hh" +#include "core/util.hh" -namespace box { +namespace box +{ -class Track { - enum class ScreenState { +class Track +{ + enum class ScreenState + { Overview, Plugin, }; -public: + + public: static constexpr int MAX_PLUGINS = 8; static constexpr int GRID_SIZE = 4; std::vector> plugins_; @@ -21,8 +26,6 @@ public: te::AudioTrack &base_; ScreenState screen_state_ = ScreenState::Overview; - - Track(te::AudioTrack &base); ~Track(); @@ -31,9 +34,8 @@ public: int GetActivePlugin(); void RemoveActivePlugin(); - void HandleEvent(const Event& event); - void Render(Interface& Interface); - + void HandleEvent(const Event &event); + void Render(Interface &Interface); }; } // namespace box diff --git a/include/core/util.hh b/include/core/util.hh index bdcb829..031401c 100644 --- a/include/core/util.hh +++ b/include/core/util.hh @@ -1,16 +1,18 @@ #pragma once +#include + #include -#include #include +#include #include #include "raylib.h" -#include namespace te = tracktion; -namespace box { +namespace box +{ struct App; extern App *APP; @@ -43,51 +45,60 @@ 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_var(const std::string &var_name, const T &var_value) { +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); } #define LOG_VAR(var) log_var(#var, var) -enum class DeviceType { +enum class DeviceType +{ Emulator, Hardware }; -enum class EventType { +enum class EventType +{ KeyPress, KeyRelease, PotDown, PotUp, }; -struct Event { +struct Event +{ 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 diff --git a/include/plugin/chorus.hh b/include/plugin/chorus.hh index 32c5646..09b8ea8 100644 --- a/include/plugin/chorus.hh +++ b/include/plugin/chorus.hh @@ -1,12 +1,11 @@ #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_; @@ -19,16 +18,15 @@ struct Chorus : public Plugin Knob knob_speed_; Knob knob_mix_; -public: - + public: Chorus(te::Plugin *p); - ~Chorus() override; + ~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; + void HandleEvent(const Event &event) override; }; } // namespace box diff --git a/include/plugin/compressor.hh b/include/plugin/compressor.hh index 4761953..89415eb 100644 --- a/include/plugin/compressor.hh +++ b/include/plugin/compressor.hh @@ -1,7 +1,7 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" namespace box { @@ -18,8 +18,7 @@ struct Compressor : public Plugin Knob knob_attack_; Knob knob_release_; -public: - + public: Compressor(te::Plugin *p); ~Compressor() override; @@ -27,7 +26,7 @@ public: const char *GetIconPath() const override; const char *GetName() const override; void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + void HandleEvent(const Event &event) override; }; -} +} // namespace box diff --git a/include/plugin/delay.hh b/include/plugin/delay.hh index 8d8c995..97f7524 100644 --- a/include/plugin/delay.hh +++ b/include/plugin/delay.hh @@ -1,7 +1,7 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.hh" namespace box { @@ -17,8 +17,7 @@ struct Delay : public Plugin Knob knob_mix_; Knob knob_length_; -public: - + public: Delay(te::Plugin *p); ~Delay() override; @@ -26,7 +25,7 @@ public: const char *GetIconPath() const override; const char *GetName() const override; void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + void HandleEvent(const Event &event) override; }; } // namespace box diff --git a/include/plugin/four_osc.hh b/include/plugin/four_osc.hh index fd8d8be..6ec05b3 100644 --- a/include/plugin/four_osc.hh +++ b/include/plugin/four_osc.hh @@ -1,12 +1,13 @@ #pragma once +#include "component/knob.hh" #include "core/interface.hh" #include "core/plugin.hh" -#include "component/knob.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"; @@ -14,8 +15,7 @@ struct FourOsc : public Plugin { te::FourOscPlugin *base_plugin_; Knob knob_master_level_; -public: - + public: FourOsc(te::Plugin *p); ~FourOsc() override; @@ -23,8 +23,7 @@ public: const char *GetIconPath() const override; const char *GetName() const override; void Render(Interface &interface) override; - void HandleEvent(const Event& event) override; + void HandleEvent(const Event &event) override; }; - } // namespace box diff --git a/src/core/app.cc b/src/core/app.cc index bc05664..6fdb76a 100644 --- a/src/core/app.cc +++ b/src/core/app.cc @@ -1,14 +1,16 @@ #include "core/app.hh" + #include -namespace box { +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()) + 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()) + "]"}; } } @@ -16,41 +18,43 @@ 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; } + // 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)} +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() +void App::AddTrack() { tracks_.push_back(std::make_unique(*base_tracks_[tracks_.size()])); } -Track &App:: CurrTrack() +Track &App::CurrTrack() { return *tracks_[current_track_]; } -size_t App:: GetCurrTrack() +size_t App::GetCurrTrack() { return current_track_; } -void App:: SetCurrTrack(size_t track_index) +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; } @@ -63,32 +67,30 @@ 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()) { 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); - instance->setRecordingEnabled (t->itemID, true); + [[maybe_unused]] auto res = instance->setTarget(t->itemID, true, &edit_.getUndoManager(), 0); + instance->setRecordingEnabled(t->itemID, true); } } } } -void App:: UnarmMidi(size_t index) +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) + if (device_type == te::InputDevice::physicalMidiDevice || device_type == te::InputDevice::virtualMidiDevice) { auto t = te::getAudioTracks(edit_)[index]; if (t != nullptr) @@ -99,7 +101,7 @@ void App:: UnarmMidi(size_t index) } } -void App:: Render(Interface& interface) +void App::Render(Interface &interface) { assert_tracks(tracks_, current_track_, "render"); @@ -107,7 +109,7 @@ void App:: Render(Interface& interface) // 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); @@ -130,16 +132,16 @@ void App:: Render(Interface& interface) } } -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 (event.type == EventType::KeyPress && event.value == KEY_I) { - if (mode_ == Mode::Normal) + if (mode_ == Mode::Normal) { mode_ = Mode::Insert; - } - else if (mode_ == Mode::Insert) + } + else if (mode_ == Mode::Insert) { mode_ = Mode::Normal; } @@ -162,27 +164,27 @@ void App:: HandleEvent(const Event& event) break; } - if (KEY_TO_MIDI.find(event.value) != KEY_TO_MIDI.end() - && active_notes_.find(event.value) == active_notes_.end()) + 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(); + 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()) + 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(); + te::MidiInputDevice *dev = engine_.getDeviceManager().getDefaultMidiInDevice(); dev->keyboardState.noteOff(1, note, 1.0); } break; @@ -190,7 +192,7 @@ void App:: HandleEvent(const Event& event) return; } - switch (screen_state_) + switch (screen_state_) { case ScreenState::Timeline: timeline_.HandleEvent(event); @@ -202,7 +204,6 @@ void App:: HandleEvent(const Event& event) plugin_sel_.HandleEvent(event); break; } - } } // namespace box diff --git a/src/core/interface.cc b/src/core/interface.cc index 23d2c4f..bca1115 100644 --- a/src/core/interface.cc +++ b/src/core/interface.cc @@ -1,10 +1,12 @@ #include "core/interface.hh" -#include + #include +#include -namespace box { +namespace box +{ -Interface:: Interface() +Interface::Interface() { SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(512, 512, "raylib - Rescalable 128x128 render"); @@ -12,32 +14,31 @@ Interface:: Interface() 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() +Interface::~Interface() { - if (DISPLAY_TYPE == DeviceType::Emulator) + if (DISPLAY_TYPE == DeviceType::Emulator) { UnloadRenderTexture(target_); CloseWindow(); } } -void Interface:: PreRender() +void Interface::PreRender() { BeginTextureMode(target_); // matches PostRender ClearBackground(BLACK); } -void Interface:: PostRender() +void Interface::PostRender() { - if (DISPLAY_TYPE == DeviceType::Emulator) + if (DISPLAY_TYPE == DeviceType::Emulator) { - int screen_width = GetScreenWidth(); int screen_height = GetScreenHeight(); @@ -47,18 +48,13 @@ 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 - } - else if (DISPLAY_TYPE == DeviceType::Hardware) + // hardware rendering + } + else if (DISPLAY_TYPE == DeviceType::Hardware) { Image image = LoadImageFromTexture(target_.texture); Color c = GetImageColor(image, 0, 0); // get pixel (0, 0) @@ -67,9 +63,10 @@ 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) +bool Interface::PollEvent(Event &event) { - for (auto &[key, is_pressed] : keys_) { + for (auto &[key, is_pressed] : keys_) + { if (IsKeyDown(key)) { if (is_pressed == false) @@ -80,7 +77,8 @@ bool Interface:: PollEvent(Event& event) return true; } } - if (IsKeyUp(key)) { + if (IsKeyUp(key)) + { if (is_pressed == true) { is_pressed = !is_pressed; @@ -90,13 +88,13 @@ 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 84d6fa0..49e3f5b 100644 --- a/src/core/plugin.cc +++ b/src/core/plugin.cc @@ -1,28 +1,31 @@ #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::~Plugin() { plugin_->deleteFromParent(); } -void Plugin:: EnsureTextureLoaded() const +void Plugin::EnsureTextureLoaded() const { - if (GetIcon().id == 0) { + if (GetIcon().id == 0) + { Image icon = LoadImage(GetIconPath()); GetIcon() = LoadTextureFromImage(icon); UnloadImage(icon); } } -te::Plugin *const Plugin:: GetPlugin() const +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..9d84b33 100644 --- a/src/core/plugin_selector.cc +++ b/src/core/plugin_selector.cc @@ -1,45 +1,43 @@ #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 { +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) +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() +PluginSelector::PluginSelector() { - } -void PluginSelector:: Render(Interface &interface) +void PluginSelector::Render(Interface &interface) { - for (size_t i = 0; i < interface.HEIGHT / 8; i++) + for (size_t i = 0; i < interface.HEIGHT / 8; i++) { - if (i >= PLUGIN_NAMES.size()) break; + if (i >= PLUGIN_NAMES.size()) + break; auto name = PLUGIN_NAMES[i]; - float x = 0; + float x = 0; float y = 16 * i; float width = 128; float height = 15; Color color = RED; - if (current_index_ == i) + if (current_index_ == i) { color = BLUE; } @@ -48,12 +46,12 @@ void PluginSelector:: Render(Interface &interface) } } -void PluginSelector:: HandleEvent(const Event &event) +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; @@ -64,7 +62,7 @@ void PluginSelector:: HandleEvent(const Event &event) case KEY_J: current_index_ = std::min(current_index_ + 1, PLUGIN_NAMES.size() - 1); break; - case KEY_ENTER: + case KEY_ENTER: // TODO proper back button? APP->screen_state_ = App::ScreenState::Track; const auto &name = PLUGIN_NAMES[current_index_]; @@ -72,11 +70,11 @@ void PluginSelector:: HandleEvent(const Event &event) std::unique_ptr p; auto base = APP->edit_.getPluginCache().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); } diff --git a/src/core/timeline.cc b/src/core/timeline.cc index ba0c8f2..27057b0 100644 --- a/src/core/timeline.cc +++ b/src/core/timeline.cc @@ -1,9 +1,11 @@ #include "core/timeline.hh" + #include "core/app.hh" -namespace box { +namespace box +{ -Timeline:: Timeline() +Timeline::Timeline() { { Image tmp_l = LoadImage(METRONOME_PATH_L); @@ -18,14 +20,14 @@ 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: @@ -42,9 +44,8 @@ void Timeline:: Render(Interface &interface) 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_}; @@ -67,8 +68,10 @@ 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, WHITE); + 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 @@ -78,16 +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); } } @@ -95,42 +98,26 @@ 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); + 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); + 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_) + 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); @@ -148,8 +135,10 @@ void Timeline:: Render(Interface &interface) 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 + else + { + DrawRectangle(0, (curr_row * ROW_HEIGHT) + HEADER_HEIGHT, (SCREEN_HALF - 0), ROW_HEIGHT, + RED); // 64 - 0 means full half bar } } @@ -163,9 +152,8 @@ 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()); @@ -195,7 +183,6 @@ void Timeline:: Render(Interface &interface) DrawRectangleLines(x, y, ROW_WIDTH, ROW_HEIGHT, RED); } - // render cursor if (!transport.isRecording() && !transport.isPlaying()) { @@ -211,8 +198,7 @@ void Timeline:: Render(Interface &interface) // 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 int left_px = static_cast(left_pct * SCREEN_WIDTH); @@ -243,7 +229,7 @@ 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_; @@ -268,22 +254,30 @@ void Timeline:: print_timeline() 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::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; + 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() +void Timeline::FocusCursor() { assert(cursor_.len < frame_.Width()); if (cursor_.LeftEdge() < frame_.LeftEdge()) @@ -298,15 +292,15 @@ void Timeline:: FocusCursor() } } -void Timeline:: HandleEvent(const Event &event) +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; @@ -324,8 +318,7 @@ 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()); @@ -349,52 +342,52 @@ void Timeline:: HandleEvent(const Event &event) scroll_offset_ = 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: - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.RightEdge())); + { + 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 + te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos); + if (item == nullptr) + { + LOG_MSG("KEY_W found NONE"); + } + else + { + if (auto clip = dynamic_cast(item)) { - if (auto clip = dynamic_cast(item)) - { - cursor_.start = clip->getStartBeat().inBeats(); - FocusCursor(); - } + cursor_.start = clip->getStartBeat().inBeats(); + FocusCursor(); } } - break; + } + break; case KEY_D: - { - const te::TempoSequence &tempo = APP->edit_.tempoSequence; - auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.start)); + { + 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 + 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)) { - LOG_MSG("deleting item of type:"); - LOG_MSG(te::TrackItem::typeToString(item->type)); - if (auto clip = dynamic_cast(item)) - { - clip->removeFromParent(); - } + clip->removeFromParent(); } } - break; + } + break; case KEY_P: print_timeline(); LOG_VAR(frame_.center); @@ -404,79 +397,79 @@ void Timeline:: HandleEvent(const Event &event) 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()) { - 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; + 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_; + 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_); } - break; + 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()) { - auto &transport = APP->edit_.getTransport(); - if (transport.isPlaying()) - { - transport.stop(false, false); // TODO should this discard? - playhead_mode_ = PlayheadMode::Detached; + 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_; + 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_); } - break; - case KEY_S: + else { - LOG_MSG("move to origin"); - auto &transport = APP->edit_.getTransport(); - transport.setPosition(te::TimePosition::fromSeconds(0.f)); - cursor_.start = 0; - frame_.center = 0; + const te::TempoSequence &tempo = APP->edit_.tempoSequence; + transport.setPosition(tempo.toTime(te::BeatPosition::fromBeats(cursor_.LeftEdge()))); + transport.play(false); + playhead_mode_ = PlayheadMode::Locked; } - break; + } + 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; + { + 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; + { + 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 diff --git a/src/core/track.cc b/src/core/track.cc index c52b628..dcb5339 100644 --- a/src/core/track.cc +++ b/src/core/track.cc @@ -1,35 +1,41 @@ #include "core/track.hh" -#include "core/util.hh" -#include "core/app.hh" + #include -namespace box { +#include "core/app.hh" +#include "core/util.hh" + +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()) + 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} { } -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 + 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() +void Track::RemoveActivePlugin() { if (plugins_.size() == 0) { @@ -46,35 +52,37 @@ void Track:: RemoveActivePlugin() active_plugin_ = std::min(active_plugin_, static_cast(plugins_.size()) - 1); } -void Track:: SetActivePlugin(int index) +void Track::SetActivePlugin(int index) { active_plugin_ = index; } -int Track:: GetActivePlugin() +int Track::GetActivePlugin() { return active_plugin_; } -int clamp_index(int i, int len) +int clamp_index(int i, int len) { - int range = len ; + int range = len; int val = i % range; - if (val < 0) val += range; + if (val < 0) + val += range; return val; } -void Track:: HandleEvent(const Event& event) +void Track::HandleEvent(const Event &event) { - switch (screen_state_) + 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; @@ -86,15 +94,15 @@ void Track:: HandleEvent(const Event& event) RemoveActivePlugin(); break; case KEY_P: + { + auto l = base_.pluginList.getPlugins(); + for (auto p : l) { - auto l = base_.pluginList.getPlugins(); - for (auto p : l) - { - std::cout << p->getName() << ", "; - } - std::cout << std::endl; + std::cout << p->getName() << ", "; } - break; + std::cout << std::endl; + } + break; // TODO KEY_J and KEY_K move up and down case KEY_H: LOG_MSG("left"); @@ -108,7 +116,8 @@ void Track:: HandleEvent(const Event& event) break; case KEY_ENTER: // TODO sketchy - if (active_plugin_ != -1) screen_state_ = ScreenState::Plugin; + if (active_plugin_ != -1) + screen_state_ = ScreenState::Plugin; break; } break; @@ -119,7 +128,7 @@ 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; @@ -136,45 +145,52 @@ void Track:: HandleEvent(const Event& event) } } -void Track:: Render(Interface& interface) +void Track::Render(Interface &interface) { - switch (screen_state_) + 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); - } + 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); + 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); + 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++) + if (i == active_plugin_) { - 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); + DrawCircleV(Vector2{static_cast(i % 4) * 32 + 16, static_cast(i / 4) * 32 + 64 + 16}, + 5.0f, GREEN); } - break; - case ScreenState::Plugin: - plugins_[active_plugin_]->Render(interface); - break; + } + 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; } } diff --git a/src/core/util.cc b/src/core/util.cc index 295f0ac..4c5666b 100644 --- a/src/core/util.cc +++ b/src/core/util.cc @@ -1,8 +1,9 @@ #include "core/util.hh" -namespace box { +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) { @@ -15,20 +16,21 @@ 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 = 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 << "." + 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(); } -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 @@ -38,15 +40,16 @@ 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(); } -size_t clamp_decrement(size_t x) +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) @@ -54,40 +57,48 @@ 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") return LogLevel::Debug; - if (s == "WARN") return LogLevel::Warn; - if (s == "ERR") return LogLevel::Err; + 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) +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"; + 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() +LogLevel get_loglevel() { - const char* env = std::getenv("BOX_LOG"); - if (env) + 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) +void LOG_MSG(const std::string &msg, LogLevel l) { static LogLevel curr = get_loglevel(); - if (l < curr) + if (l < curr) { return; } diff --git a/src/main.cc b/src/main.cc index 78cf8d1..eee6c85 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,21 +1,19 @@ -#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() +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"}}; + 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; @@ -30,7 +28,7 @@ int main() { // arm { - auto& dm = engine.getDeviceManager(); + auto &dm = engine.getDeviceManager(); for (int i = 0; i < dm.getNumWaveInDevices(); i++) { @@ -48,11 +46,11 @@ int main() } } - while (!interface.ShouldClose()) + while (!interface.ShouldClose()) { // poll and handle events box::Event event; - if (interface.PollEvent(event)) + if (interface.PollEvent(event)) { app.HandleEvent(event); } @@ -66,8 +64,8 @@ int main() interface.PostRender(); } - } - catch (std::exception &e) + } + catch (std::exception &e) { std::cerr << e.what() << std::endl; } diff --git a/src/plugin/chorus.cc b/src/plugin/chorus.cc index 3b0b518..f74caff 100644 --- a/src/plugin/chorus.cc +++ b/src/plugin/chorus.cc @@ -1,54 +1,49 @@ #include "plugin/chorus.hh" + #include "core/cv.hh" -namespace box { +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)}, - 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" - } + : 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() +Chorus::~Chorus() { UnloadTexture(icon_); } -Texture2D &Chorus:: GetIcon() const +Texture2D &Chorus::GetIcon() const { return icon_; } @@ -76,7 +71,7 @@ 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()); diff --git a/src/plugin/compressor.cc b/src/plugin/compressor.cc index 24a8123..2c78e23 100644 --- a/src/plugin/compressor.cc +++ b/src/plugin/compressor.cc @@ -1,59 +1,54 @@ #include "plugin/compressor.hh" + #include "core/cv.hh" -namespace box { +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)}, - 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" - } + : 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() +Compressor::~Compressor() { UnloadTexture(icon_); } -Texture2D &Compressor:: GetIcon() const +Texture2D &Compressor::GetIcon() const { return icon_; } -const char *Compressor:: GetIconPath() const +const char *Compressor::GetIconPath() const { return icon_path_; } @@ -76,7 +71,7 @@ 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()); diff --git a/src/plugin/delay.cc b/src/plugin/delay.cc index e0500b5..de1869a 100644 --- a/src/plugin/delay.cc +++ b/src/plugin/delay.cc @@ -1,51 +1,48 @@ #include "plugin/delay.hh" + #include "core/cv.hh" -namespace box { +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)}, - 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" - } + : 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() +Delay::~Delay() { UnloadTexture(icon_); } -Texture2D &Delay:: GetIcon() const +Texture2D &Delay::GetIcon() const { return icon_; } -const char *Delay:: GetIconPath() const +const char *Delay::GetIconPath() const { return icon_path_; } @@ -67,7 +64,7 @@ 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()); diff --git a/src/plugin/four_osc.cc b/src/plugin/four_osc.cc index d992893..a33b8d4 100644 --- a/src/plugin/four_osc.cc +++ b/src/plugin/four_osc.cc @@ -1,21 +1,22 @@ #include "plugin/four_osc.hh" -namespace box { +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)}, - // 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" - } + knob_master_level_{Parameter(base_plugin_->masterLevel), + 32, // x + 22, // y + 16, // radius + GREEN, + "volume"} { EnsureTextureLoaded(); // TODO for testing effects @@ -25,17 +26,17 @@ FourOsc:: FourOsc(te::Plugin *p): } } -FourOsc:: ~FourOsc() +FourOsc::~FourOsc() { UnloadTexture(icon_); } -Texture2D &FourOsc:: GetIcon() const +Texture2D &FourOsc::GetIcon() const { return icon_; } -const char *FourOsc:: GetIconPath() const +const char *FourOsc::GetIconPath() const { return icon_path_; } @@ -45,7 +46,7 @@ const char *FourOsc::GetName() const return name_; } -void FourOsc:: Render(Interface &interface) +void FourOsc::Render(Interface &interface) { for (int y = 0; y < Interface::HEIGHT; ++y) { @@ -60,12 +61,12 @@ void FourOsc:: Render(Interface &interface) knob_master_level_.Render(interface); } -void FourOsc:: HandleEvent(const Event &event) +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());