Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatter #137

Merged
merged 13 commits into from
Jan 2, 2025
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 120
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: None
PackConstructorInitializers: Never
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions include/component/knob.hh
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#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 <typename T>
struct Knob
template <typename T> struct Knob
{
Parameter<T> param_;
uint8_t x_, y_, radius_;
Color color_;
std::string name_;

Knob(Parameter<T> 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<float>(x_);
Expand All @@ -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

16 changes: 10 additions & 6 deletions include/component/switch.hh
Original file line number Diff line number Diff line change
@@ -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<bool>

Expand All @@ -15,20 +15,24 @@ struct Switch
std::string name_;

Switch(juce::CachedValue<bool> &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)
{

}
};

Expand Down
32 changes: 18 additions & 14 deletions include/core/app.hh
Original file line number Diff line number Diff line change
@@ -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,
};
Expand All @@ -23,34 +27,34 @@ struct App {
int key_offset_ = 0;
std::map<int, int> active_notes_;

te::Engine &engine_ ;
te::Edit &edit_ ;
te::Engine &engine_;
te::Edit &edit_;

std::vector<std::unique_ptr<Track>> tracks_;
juce::Array<te::AudioTrack*> base_tracks_;
juce::Array<te::AudioTrack *> base_tracks_;

PluginSelector plugin_sel_;
Timeline timeline_;

const std::vector<Color> 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},
};

// 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();
void SetCurrTrack(size_t track_index);
void AddTrack();
void ChangeArmMidi(size_t new_index);

private:
private:
size_t current_track_;
void ArmMidi(size_t index);
void UnarmMidi(size_t index);
Expand Down
16 changes: 11 additions & 5 deletions include/core/cv.hh
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#pragma once

#include "core/util.hh"
#include <algorithm>

template <typename T>
struct CV {
#include "core/util.hh"

template <typename T> struct CV
{
juce::CachedValue<T> &value_;
T min_, max_;

// TODO add default value?
CV(juce::CachedValue<T> &cv, T min, T max)
: value_{cv}, min_{min}, max_{max}
: value_{cv},
min_{min},
max_{max}
{
assert(min <= max);
}
Expand All @@ -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_;
Expand Down
96 changes: 50 additions & 46 deletions include/core/interface.hh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once
#include <array>

#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;
Expand All @@ -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<KeyboardKey, bool> 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
Loading
Loading