Skip to content

Commit a0eae3b

Browse files
authored
Merge pull request #183 from anokta/macro-dev
cleans up enum definitions
2 parents cf71704 + 9e74458 commit a0eae3b

File tree

9 files changed

+185
-870
lines changed

9 files changed

+185
-870
lines changed

include/barelymusician.h

Lines changed: 106 additions & 336 deletions
Large diffs are not rendered by default.

platforms/godot/instrument.cpp

Lines changed: 24 additions & 301 deletions
Large diffs are not rendered by default.

platforms/godot/instrument.h

Lines changed: 45 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,55 @@
55

66
#include <cstdint>
77

8+
#include "godot/engine.h"
89
#include "godot_cpp/classes/node.hpp"
910
#include "godot_cpp/classes/wrapped.hpp"
1011

1112
namespace barely::godot {
1213

14+
#define BARELY_GODOT_INSTRUMENT_CONTROLS(X) \
15+
X(Gain, gain, float, 1.0f) \
16+
X(PitchShift, pitch_shift, float, 0.0f) \
17+
X(StereoPan, stereo_pan, float, 0.0f) \
18+
X(Attack, attack, float, 0.05f) \
19+
X(Decay, decay, float, 0.0f) \
20+
X(Sustain, sustain, float, 1.0f) \
21+
X(Release, release, float, 0.1f) \
22+
X(SliceMode, slice_mode, int, BarelySliceMode_kSustain) \
23+
X(OscMix, osc_mix, float, 1.0f) \
24+
X(OscMode, osc_mode, int, BarelyOscMode_kCrossfade) \
25+
X(OscNoiseMix, osc_noise_mix, float, 0.0f) \
26+
X(OscPitchShift, osc_pitch_shift, float, 0.0f) \
27+
X(OscShape, osc_shape, float, 0.0f) \
28+
X(OscSkew, osc_skew, float, 0.0f) \
29+
X(CrushDepth, crush_depth, float, 0.0f) \
30+
X(CrushRate, crush_rate, float, 0.0f) \
31+
X(DistortionMix, distortion_mix, float, 0.0f) \
32+
X(DistortionDrive, distortion_drive, float, 0.0f) \
33+
X(FilterCutoff, filter_cutoff, float, 1.0f) \
34+
X(FilterResonance, filter_resonance, float, 0.5f) \
35+
X(FilterTone, filter_tone, float, 0.0f) \
36+
X(DelaySend, delay_send, float, 0.2f) \
37+
X(ReverbSend, reverb_send, float, 0.2f) \
38+
X(SidechainSend, sidechain_send, float, 0.0f) \
39+
X(ArpMode, arp_mode, int, BarelyArpMode_kNone) \
40+
X(ArpGate, arp_gate, float, 0.5f) \
41+
X(ArpRate, arp_rate, float, 2.0f) \
42+
X(Retrigger, retrigger, bool, false) \
43+
X(VoiceCount, voice_count, int, 8)
44+
45+
#define BARELY_DECLARE_GODOT_INSTRUMENT_CONTROL(Name, name, type, default) \
46+
private: \
47+
type name##_; \
48+
\
49+
public: \
50+
void set_##name(type name) { \
51+
name##_ = name; \
52+
BarelyInstrument_SetControl(BarelyEngine::get_singleton()->get(), instrument_id_, \
53+
BarelyInstrumentControlType_k##Name, static_cast<float>(name##_)); \
54+
} \
55+
type get_##name() const { return name##_; }
56+
1357
class BarelyInstrument : public ::godot::Node {
1458
public:
1559
~BarelyInstrument();
@@ -19,93 +63,6 @@ class BarelyInstrument : public ::godot::Node {
1963
void set_note_on(float pitch, float gain = 1.0f, float pitch_shift = 0.0f);
2064
bool is_note_on(float pitch) const;
2165

22-
void set_gain(float gain);
23-
float get_gain() const { return gain_; }
24-
25-
void set_pitch_shift(float pitch_shift);
26-
float get_pitch_shift() const { return pitch_shift_; }
27-
28-
void set_stereo_pan(float stereo_pan);
29-
float get_stereo_pan() const { return stereo_pan_; }
30-
31-
void set_attack(float attack);
32-
float get_attack() const { return attack_; }
33-
34-
void set_decay(float decay);
35-
float get_decay() const { return decay_; }
36-
37-
void set_sustain(float sustain);
38-
float get_sustain() const { return sustain_; }
39-
40-
void set_release(float release);
41-
float get_release() const { return release_; }
42-
43-
void set_slice_mode(int slice_mode);
44-
int get_slice_mode() const { return slice_mode_; }
45-
46-
void set_osc_mix(float osc_mix);
47-
float get_osc_mix() const { return osc_mix_; }
48-
49-
void set_osc_mode(int osc_mode);
50-
int get_osc_mode() const { return osc_mode_; }
51-
52-
void set_osc_noise_mix(float osc_noise_mix);
53-
float get_osc_noise_mix() const { return osc_noise_mix_; }
54-
55-
void set_osc_pitch_shift(float osc_pitch_shift);
56-
float get_osc_pitch_shift() const { return osc_pitch_shift_; }
57-
58-
void set_osc_shape(float osc_shape);
59-
float get_osc_shape() const { return osc_shape_; }
60-
61-
void set_osc_skew(float osc_skew);
62-
float get_osc_skew() const { return osc_skew_; }
63-
64-
void set_crush_depth(float crush_depth);
65-
float get_crush_depth() const { return crush_depth_; }
66-
67-
void set_crush_rate(float crush_rate);
68-
float get_crush_rate() const { return crush_rate_; }
69-
70-
void set_distortion_mix(float distortion_mix);
71-
float get_distortion_mix() const { return distortion_mix_; }
72-
73-
void set_distortion_drive(float distortion_drive);
74-
float get_distortion_drive() const { return distortion_drive_; }
75-
76-
void set_filter_cutoff(float filter_cutoff);
77-
float get_filter_cutoff() const { return filter_cutoff_; }
78-
79-
void set_filter_resonance(float filter_resonance);
80-
float get_filter_resonance() const { return filter_resonance_; }
81-
82-
void set_filter_tone(float filter_tone);
83-
float get_filter_tone() const { return filter_tone_; }
84-
85-
void set_delay_send(float delay_send);
86-
float get_delay_send() const { return delay_send_; }
87-
88-
void set_reverb_send(float reverb_send);
89-
float get_reverb_send() const { return reverb_send_; }
90-
91-
void set_sidechain_send(float sidechain_send);
92-
float get_sidechain_send() const { return sidechain_send_; }
93-
94-
void set_arp_mode(int arp_mode);
95-
int get_arp_mode() const { return arp_mode_; }
96-
97-
void set_arp_gate(float arp_gate);
98-
float get_arp_gate() const { return arp_gate_; }
99-
100-
void set_arp_rate(float arp_rate);
101-
float get_arp_rate() const { return arp_rate_; }
102-
103-
void set_retrigger(bool retrigger);
104-
bool get_retrigger() const { return retrigger_; }
105-
106-
void set_voice_count(int voice_count);
107-
int get_voice_count() const { return voice_count_; }
108-
10966
void _ready() override;
11067
void _process(double delta) override;
11168

@@ -115,35 +72,7 @@ class BarelyInstrument : public ::godot::Node {
11572

11673
uint32_t instrument_id_ = 0;
11774

118-
float gain_ = 1.0f;
119-
float pitch_shift_ = 0.0f;
120-
float stereo_pan_ = 0.0f;
121-
float attack_ = 0.0f;
122-
float decay_ = 0.0f;
123-
float sustain_ = 1.0f;
124-
float release_ = 0.0f;
125-
int slice_mode_ = BarelySliceMode_kSustain;
126-
float osc_mix_ = 1.0f;
127-
int osc_mode_ = BarelyOscMode_kCrossfade;
128-
float osc_noise_mix_ = 0.0f;
129-
float osc_pitch_shift_ = 0.0f;
130-
float osc_shape_ = 0.0f;
131-
float osc_skew_ = 0.0f;
132-
float crush_depth_ = 0.0f;
133-
float crush_rate_ = 0.0f;
134-
float distortion_mix_ = 0.0f;
135-
float distortion_drive_ = 0.0f;
136-
float filter_cutoff_ = 1.0f;
137-
float filter_resonance_ = 0.5f;
138-
float filter_tone_ = 0.0f;
139-
float delay_send_ = 0.0f;
140-
float reverb_send_ = 0.0f;
141-
float sidechain_send_ = 0.0f;
142-
int arp_mode_ = BarelyArpMode_kNone;
143-
float arp_gate_ = 0.5f;
144-
float arp_rate_ = 1.0f;
145-
bool retrigger_ = false;
146-
int voice_count_ = 8;
75+
BARELY_GODOT_INSTRUMENT_CONTROLS(BARELY_DECLARE_GODOT_INSTRUMENT_CONTROL)
14776
};
14877

14978
} // namespace barely::godot

platforms/godot/project/demo/instrument_demo.gd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ func _ready():
1616
audioStreamPlayer.stream = BarelyAudioStream.new()
1717
audioStreamPlayer.play()
1818

19-
instrument.attack = 0.05
20-
instrument.release = 0.1
21-
instrument.arp_rate = 2
22-
2319
func _input(event):
2420
if event is InputEventKey and event.pressed:
2521
if event.keycode == KEY_ESCAPE:

platforms/vst/controller.cpp

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,13 @@ using ::Steinberg::Vst::RangeParameter;
1111

1212
namespace {
1313

14+
#define BARELY_DEFINE_VST_PARAM(EnumType, Name, Default, Min, Max, Label) \
15+
RangeParameter(STR16(#Label), Barely##EnumType##_k##Name, STR16(""), Min, Max, Default),
16+
1417
const std::array<RangeParameter, BarelyInstrumentControlType_kCount> kParams = {
15-
RangeParameter(STR16("Gain"), BarelyInstrumentControlType_kGain, STR16(""), 0.0, 1.0, 1.0),
16-
RangeParameter(STR16("Pitch Shift"), BarelyInstrumentControlType_kPitchShift, STR16(""), -4.0,
17-
4.0, 0.0),
18-
RangeParameter(STR16("Stereo Pan"), BarelyInstrumentControlType_kStereoPan, STR16(""), -1.0,
19-
1.0, 0.0),
20-
RangeParameter(STR16("Attack"), BarelyInstrumentControlType_kAttack, STR16("sec"), 0.0, 8.0,
21-
0.01),
22-
RangeParameter(STR16("Decay"), BarelyInstrumentControlType_kDecay, STR16("sec"), 0.0, 8.0, 0.0),
23-
RangeParameter(STR16("Sustain"), BarelyInstrumentControlType_kSustain, STR16(""), 0.0, 1.0,
24-
1.0),
25-
RangeParameter(STR16("Release"), BarelyInstrumentControlType_kRelease, STR16("sec"), 0.0, 8.0,
26-
0.05),
27-
RangeParameter(STR16("Slice Mode"), BarelyInstrumentControlType_kSliceMode, STR16(""), 0,
28-
BarelySliceMode_kCount - 1, 0, BarelySliceMode_kCount - 1),
29-
RangeParameter(STR16("Osc Mix"), BarelyInstrumentControlType_kOscMix, STR16(""), 0.0, 1.0, 1.0),
30-
RangeParameter(STR16("Osc Mode"), BarelyInstrumentControlType_kOscMode, STR16(""), 0,
31-
BarelyOscMode_kCount - 1, 0, BarelyOscMode_kCount - 1),
32-
RangeParameter(STR16("Osc Noise Mix"), BarelyInstrumentControlType_kOscNoiseMix, STR16(""), 0.0,
33-
1.0, 0.0),
34-
RangeParameter(STR16("Osc Pitch Shift"), BarelyInstrumentControlType_kOscPitchShift, STR16(""),
35-
-4.0, 4.0, 0.0),
36-
RangeParameter(STR16("Osc Shape"), BarelyInstrumentControlType_kOscShape, STR16(""), 0.0, 1.0,
37-
0.0),
38-
RangeParameter(STR16("Osc Skew"), BarelyInstrumentControlType_kOscSkew, STR16(""), -1.0, 1.0,
39-
0.0),
40-
RangeParameter(STR16("Crush Depth"), BarelyInstrumentControlType_kCrushDepth, STR16(""), 0.0,
41-
1.0, 0.0),
42-
RangeParameter(STR16("Crush Rate"), BarelyInstrumentControlType_kCrushRate, STR16(""), 0.0, 1.0,
43-
0.0),
44-
RangeParameter(STR16("Distortion Mix"), BarelyInstrumentControlType_kDistortionMix, STR16(""),
45-
0.0, 1.0, 0.0),
46-
RangeParameter(STR16("Distortion Drive"), BarelyInstrumentControlType_kDistortionDrive,
47-
STR16(""), 0.0, 1.0, 0.0),
48-
RangeParameter(STR16("Filter Cutoff"), BarelyInstrumentControlType_kFilterCutoff, STR16(""),
49-
0.0, 1.0, 1.0),
50-
RangeParameter(STR16("Filter Resonance"), BarelyInstrumentControlType_kFilterResonance,
51-
STR16(""), 0.0, 1.0, 0.5),
52-
RangeParameter(STR16("Filter Tone"), BarelyInstrumentControlType_kFilterTone, STR16(""), -1.0,
53-
1.0, 0.0),
54-
RangeParameter(STR16("Delay Send"), BarelyInstrumentControlType_kDelaySend, STR16(""), 0.0, 1.0,
55-
0.0),
56-
RangeParameter(STR16("Reverb Send"), BarelyInstrumentControlType_kReverbSend, STR16(""), 0.0,
57-
1.0, 0.0),
58-
RangeParameter(STR16("Sidechain Send"), BarelyInstrumentControlType_kSidechainSend, STR16(""),
59-
-1.0, 1.0, 0.0),
60-
RangeParameter(STR16("Arp Mode"), BarelyInstrumentControlType_kArpMode, STR16(""), 0,
61-
BarelyArpMode_kCount - 1, 0, BarelyArpMode_kCount - 1),
62-
RangeParameter(STR16("Arp Gate"), BarelyInstrumentControlType_kArpGate, STR16(""), 0.0, 1.0,
63-
0.5),
64-
RangeParameter(STR16("Arp Rate"), BarelyInstrumentControlType_kArpRate, STR16(""), 0.0, 16.0,
65-
1.0),
66-
RangeParameter(STR16("Retrigger"), BarelyInstrumentControlType_kRetrigger, STR16(""), 0, 1, 0,
67-
1),
68-
RangeParameter(STR16("Voice Count"), BarelyInstrumentControlType_kVoiceCount, STR16(""), 1, 16,
69-
8, 15),
70-
};
18+
BARELY_INSTRUMENT_CONTROL_TYPES(InstrumentControlType, BARELY_DEFINE_VST_PARAM)};
7119

72-
}
20+
} // namespace
7321

7422
const Steinberg::FUID Controller::kId(0x3bd2bd7a, 0x5e0940bb, 0x8b9db4af, 0x6175e06f);
7523

src/core/control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ inline float GetFrequency(float cutoff, float max_freq) noexcept {
4949
return std::min(kMinFilterFreq * std::pow(max_freq * kMinFreqInverse, cutoff), max_freq);
5050
}
5151

52+
#define BARELY_DEFINE_CONTROL(EnumType, Name, Default, Min, Max, Label) Control(Default, Min, Max),
53+
5254
} // namespace barely
5355

5456
#endif // BARELYMUSICIAN_CORE_CONTROL_H_

src/engine/engine_state.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,7 @@ struct EngineState {
4848

4949
// Array of engine controls.
5050
std::array<Control, BarelyEngineControlType_kCount> controls = {
51-
Control(1.0f, 0.0f, 1.0f), // CompMix
52-
Control(0.0f, 0.0f, 8.0f), // CompAttack
53-
Control(0.0f, 0.0f, 8.0f), // CompRelease
54-
Control(1.0f, 0.0f, 1.0f), // CompThreshold
55-
Control(0.0f, 0.0f, 1.0f), // CompRatio
56-
Control(1.0f, 0.0f, 1.0f), // kDelayMix
57-
Control(0.0f, 0.0f, 8.0f), // kDelayTime
58-
Control(0.0f, 0.0f, 1.0f), // kDelayFeedback
59-
Control(1.0f, 0.0f, 1.0f), // kDelayLpfCutoff
60-
Control(0.0f, 0.0f, 1.0f), // kDelayHpfCutoff
61-
Control(0.0f, 0.0f, 1.0f), // kDelayPingPong
62-
Control(0.0f, 0.0f, 2.0f), // kDelayReverbSend
63-
Control(1.0f, 0.0f, 1.0f), // kReverbMix
64-
Control(0.0f, 0.0f, 1.0f), // kReverbDamping
65-
Control(0.0f, 0.0f, 1.0f), // kReverbRoomSize
66-
Control(1.0f, 0.0f, 1.0f), // kReverbStereoWidth
67-
Control(false), // kReverbFreeze
68-
Control(1.0f, 0.0f, 1.0f), // kSidechainMix
69-
Control(0.0f, 0.0f, 8.0f), // kSidechainAttack
70-
Control(0.0f, 0.0f, 8.0f), // kSidechainRelease
71-
Control(1.0f, 0.0f, 1.0f), // kSidechainThreshold
72-
Control(0.0f, 0.0f, 1.0f), // kSidechainRatio
73-
};
51+
BARELY_ENGINE_CONTROL_TYPES(EngineControlType, BARELY_DEFINE_CONTROL)};
7452

7553
// Random number generator for the main thread.
7654
MainRng main_rng = {};

src/engine/instrument_state.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,7 @@ namespace barely {
1717

1818
struct InstrumentState {
1919
std::array<Control, BarelyInstrumentControlType_kCount> controls = {
20-
Control(1.0f, 0.0f, 1.0f), // kGain
21-
Control(0.0f), // kPitchShift
22-
Control(0.0f, -1.0f, 1.0f), // kStereoPan
23-
Control(0.0f, 0.0f, 8.0f), // kAttack
24-
Control(0.0f, 0.0f, 8.0f), // kDecay
25-
Control(1.0f, 0.0f, 1.0f), // kSustain
26-
Control(0.0f, 0.0f, 8.0f), // kRelease
27-
Control(0, 0, BarelySliceMode_kCount - 1), // kSliceMode
28-
Control(0.0f, 0.0f, 1.0f), // kOscMix
29-
Control(0, 0, BarelyOscMode_kCount - 1), // kOscMode
30-
Control(0.0f, 0.0f, 1.0f), // kOscNoiseMix
31-
Control(0.0f), // kOscPitchShift
32-
Control(0.0f, 0.0f, 1.0f), // kOscShape
33-
Control(0.0f, -1.0f, 1.0f), // kOscSkew
34-
Control(0.0f, 0.0f, 1.0f), // kCrushDepth
35-
Control(0.0f, 0.0f, 1.0f), // kCrushRate
36-
Control(0.0f, 0.0f, 1.0f), // kDistortionMix
37-
Control(0.0f, 0.0f, 1.0f), // kDistortionDrive
38-
Control(1.0f, 0.0f, 1.0f), // kFilterCutoff
39-
Control(0.5f, 0.0f, 1.0f), // kFilterResonance
40-
Control(0.0f, -1.0f, 1.0f), // kFilterTone
41-
Control(0.0f, 0.0f, 1.0f), // kDelaySend
42-
Control(0.0f, 0.0f, 2.0f), // kReverbSend
43-
Control(0.0f, -1.0f, 1.0f), // kSidechainSend
44-
Control(0, 0, BarelyArpMode_kCount - 1), // kArpMode
45-
Control(0.5f, 0.0f, 1.0f), // kArpGate
46-
Control(1.0f, 0.0f, 16.0f), // kArpRate
47-
Control(false), // kRetrigger
48-
Control(8, 1, 16), // kVoiceCount
49-
};
20+
BARELY_INSTRUMENT_CONTROL_TYPES(InstrumentControlType, BARELY_DEFINE_CONTROL)};
5021

5122
Callback<BarelyNoteEventCallback> note_event_callback = {};
5223

src/engine/note_state.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ namespace barely {
1212

1313
struct NoteState {
1414
std::array<Control, BarelyNoteControlType_kCount> controls = {
15-
Control(1.0f, 0.0f, 1.0f), // kGain
16-
Control(0.0f), // kPitchShift
17-
};
15+
BARELY_NOTE_CONTROL_TYPES(NoteControlType, BARELY_DEFINE_CONTROL)};
1816

1917
float pitch = 0.0;
2018

0 commit comments

Comments
 (0)