CommonWidgets.hpp
1 #pragma once
2 #include <Control/Widgets.hpp>
3 
4 #include <ossia/detail/enum_map.hpp>
5 
6 #include <array>
7 namespace Control
8 {
9 namespace Widgets
10 {
11 
12 static const constexpr std::array<std::pair<const char*, float>, 14> durations{
13  {{"Inf", -1.},
14  {"Whole", 1.},
15  {"Half", 1. / 2.},
16  {"4th", 1. / 4.},
17  {"8th", 1. / 8.},
18  {"16th", 1. / 16.},
19  {"32th", 1. / 32.},
20  {"64th", 1. / 64.},
21  {"Dotted Half", 3. / 4.},
22  {"Dotted 4th", 3. / 8.},
23  {"Dotted 8th", 3. / 16.},
24  {"Dotted 16th", 3. / 32.},
25  {"Dotted 32th", 3. / 64.},
26  {"None", 0.}}};
27 static const constexpr std::array<std::pair<const char*, float>, 13> notes{
28  {{"None", 0.},
29  {"Whole", 1.},
30  {"Half", 1. / 2.},
31  {"4th", 1. / 4.},
32  {"8th", 1. / 8.},
33  {"16th", 1. / 16.},
34  {"32th", 1. / 32.},
35  {"64th", 1. / 64.},
36  {"Dotted Half", 3. / 4.},
37  {"Dotted 4th", 3. / 8.},
38  {"Dotted 8th", 3. / 16.},
39  {"Dotted 16th", 3. / 32.},
40  {"Dotted 32th", 3. / 64.}}};
41 
42 static const constexpr std::array<std::pair<const char*, float>, 12> nonnull_notes{
43  {{"Whole", 1.},
44  {"Half", 1. / 2.},
45  {"4th", 1. / 4.},
46  {"8th", 1. / 8.},
47  {"16th", 1. / 16.},
48  {"32th", 1. / 32.},
49  {"64th", 1. / 64.},
50  {"Dotted Half", 3. / 4.},
51  {"Dotted 4th", 3. / 8.},
52  {"Dotted 8th", 3. / 16.},
53  {"Dotted 16th", 3. / 32.},
54  {"Dotted 32th", 3. / 64.}}};
55 
56 static const constexpr std::array<std::pair<const char*, int>, 5> arpeggios{
57  {{"Forward", 0}, {"Backward", 1}, {"F->B", 2}, {"B->F", 3}, {"Chord", 4}}};
58 
59 enum Waveform
60 {
61  Sin,
62  Triangle,
63  Saw,
64  Square,
65  SampleAndHold,
66  Noise1,
67  Noise2,
68  Noise3
69 };
70 
71 inline auto& waveformMap()
72 {
73  static const ossia::enum_map<Waveform, std::string_view, 8> waveform_map{
74  {Sin, "Sin"},
75  {Triangle, "Triangle"},
76  {Saw, "Saw"},
77  {Square, "Square"},
78  {SampleAndHold, "Sample & Hold"},
79  {Noise1, "Noise 1"},
80  {Noise2, "Noise 2"},
81  {Noise3, "Noise 3"}};
82  return waveform_map;
83 }
84 static constexpr auto WaveformChooser()
85 {
86  return Control::make_enum(
87  "Waveform", 0U,
88  ossia::make_array(
89  "Sin", "Triangle", "Saw", "Square", "Sample & Hold", "Noise 1", "Noise 2",
90  "Noise 3"),
91  std::array<const char*, 16>{
92  ":/icons/wave_sin_off.png", ":/icons/wave_sin_on.png",
93  ":/icons/wave_triangle_off.png", ":/icons/wave_triangle_on.png",
94  ":/icons/wave_saw_off.png", ":/icons/wave_saw_on.png",
95  ":/icons/wave_square_off.png", ":/icons/wave_square_on.png",
96  ":/icons/wave_sample_and_hold_off.png", ":/icons/wave_sample_and_hold_on.png",
97  ":/icons/wave_noise1_off.png", ":/icons/wave_noise1_on.png",
98  ":/icons/wave_noise2_off.png", ":/icons/wave_noise2_on.png",
99  ":/icons/wave_noise3_off.png", ":/icons/wave_noise3_on.png"});
100 }
101 
102 enum LoopMode
103 {
104  Play,
105  Record,
106  Overdub,
107  Stop
108 };
109 constexpr auto LoopChooser()
110 {
111  return Control::make_enum(
112  "Loop", 0U, ossia::make_array("Play", "Record", "Overdub", "Stop"));
113 }
114 constexpr auto LoopPostActionChooser()
115 {
116  return Control::make_enum("Loop", 0U, ossia::make_array("Play", "Overdub"));
117 }
118 constexpr LoopMode GetLoopMode(std::string_view str) noexcept
119 {
120  if(str == "Play")
121  return LoopMode::Play;
122  else if(str == "Record")
123  return LoopMode::Record;
124  else if(str == "Overdub")
125  return LoopMode::Overdub;
126  else if(str == "Stop")
127  return LoopMode::Stop;
128  return LoopMode::Stop;
129 }
130 
131 constexpr auto QuantificationChooser()
132 {
133  return Control::ComboBox<float, std::size(notes)>("Quantification", 2, notes);
134 }
135 constexpr auto ArpeggioChooser()
136 {
137  return Control::ComboBox<int, std::size(arpeggios)>("Arpeggios", 0, arpeggios);
138 }
139 
140 constexpr auto MusicalDurationChooser()
141 {
143  "Duration", 2, nonnull_notes);
144 }
145 constexpr auto DurationChooser()
146 {
147  return Control::ComboBox<float, std::size(durations)>("Duration", 2, durations);
148 }
149 constexpr auto FreqSlider()
150 {
151  return Control::LogFloatSlider("Frequency", 1.f, 20000.f, 200.f);
152 }
153 constexpr auto LFOFreqSlider()
154 {
155  return Control::LogFloatSlider("Frequency", 0.01f, 100.f, 1.f);
156 }
157 constexpr auto FreqKnob()
158 {
159  return Control::LogFloatKnob("Frequency", 1.f, 20000.f, 200.f);
160 }
161 constexpr auto LFOFreqKnob()
162 {
163  return Control::LogFloatKnob("Frequency", 0.0001f, 100.f, 1.f);
164 }
165 constexpr auto TempoChooser()
166 {
167  return Control::FloatSlider("Tempo", 20, 300, 120);
168 }
169 
170 template <typename T>
171 constexpr auto MidiSpinbox(const T& name)
172 {
173  return Control::IntSpinBox{name, 0, 127, 64};
174 }
175 template <typename T>
176 constexpr auto MidiChannel(const T& name)
177 {
178  return Control::IntSpinBox{name, 1, 16, 1};
179 }
180 template <typename T>
181 constexpr auto MidiSlider(const T& name)
182 {
183  return Control::IntSlider{name, 0, 127, 64};
184 }
185 template <typename T>
186 constexpr auto DefaultSlider(const T& name)
187 {
188  return Control::FloatSlider{name, 0., 1., 0.5};
189 }
190 
191 template <typename T>
192 constexpr auto OctaveSlider(const T& name, int neg_octaves, int octaves)
193 {
194  return Control::IntSlider{name, 12 * neg_octaves, 12 * octaves, 0};
195 }
196 }
197 }
Definition: score-lib-process/Control/Widgets.hpp:486
Definition: score-lib-process/Control/Widgets.hpp:77
Definition: score-lib-process/Control/Widgets.hpp:178
Definition: score-lib-process/Control/Widgets.hpp:223