-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap_parameters.hpp
More file actions
126 lines (110 loc) · 3.37 KB
/
wrap_parameters.hpp
File metadata and controls
126 lines (110 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include <juce_audio_processors/juce_audio_processors.h>
namespace pluginshared {
// -------------------- warpper of juce parameters --------------------
class FloatParam {
public:
FloatParam(juce::StringRef name, juce::NormalisableRange<float> range, float default_value)
: name_(name)
, range_(range)
, default_value_(default_value) {
}
std::unique_ptr<juce::AudioParameterFloat> Build() {
jassert(ptr_ == nullptr);
auto p = std::make_unique<juce::AudioParameterFloat>(
juce::ParameterID{name_, 1},
name_,
range_,
default_value_
);
ptr_ = p.get();
return p;
}
float Get() noexcept {
return ptr_->get();
}
juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(
juce::AudioProcessorValueTreeState::ParameterLayout& layout
) {
layout.add(Build());
return layout;
}
juce::AudioParameterFloat* ptr_{};
juce::String name_;
juce::NormalisableRange<float> range_;
float default_value_;
};
class ChoiceParam {
public:
ChoiceParam(juce::StringRef name, juce::StringArray choice, juce::StringRef default_name)
: name_(name)
, choices_(choice)
, default_value_(choice.indexOf(default_name)) {
jassert(default_value_ != -1);
}
std::unique_ptr<juce::AudioParameterChoice> Build() {
auto p = std::make_unique<juce::AudioParameterChoice>(
juce::ParameterID{name_, 1},
name_,
choices_,
default_value_
);
ptr_ = p.get();
return p;
}
int Get() noexcept {
return ptr_->getIndex();
}
juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(
juce::AudioProcessorValueTreeState::ParameterLayout& layout
) {
layout.add(Build());
return layout;
}
juce::AudioParameterChoice* ptr_{};
private:
juce::StringRef name_;
juce::StringArray choices_;
int default_value_;
};
class BoolParam {
public:
BoolParam(juce::StringRef name, bool default_value)
: name_(name)
, default_value_(default_value) {}
std::unique_ptr<juce::AudioParameterBool> Build() {
auto p = std::make_unique<juce::AudioParameterBool>(
juce::ParameterID{name_, 1},
name_,
default_value_
);
ptr_ = p.get();
return p;
}
bool Get() noexcept {
return ptr_->get();
}
juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(
juce::AudioProcessorValueTreeState::ParameterLayout& layout
) {
layout.add(Build());
return layout;
}
juce::AudioParameterBool* ptr_{};
private:
juce::StringRef name_;
bool default_value_;
};
inline juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(juce::AudioProcessorValueTreeState::ParameterLayout& layout, FloatParam& f) {
layout.add(f.Build());
return layout;
}
inline juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(juce::AudioProcessorValueTreeState::ParameterLayout& layout, ChoiceParam& f) {
layout.add(f.Build());
return layout;
}
inline juce::AudioProcessorValueTreeState::ParameterLayout& operator+=(juce::AudioProcessorValueTreeState::ParameterLayout& layout, BoolParam& f) {
layout.add(f.Build());
return layout;
}
}