Allolib  1.0
C++ Components For Interactive Multimedia
al_ControlGUI.hpp
1 #ifndef AL_ControlGUI_HPP
2 #define AL_ControlGUI_HPP
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology,
8  UCSB. Copyright (C) 2012-2018. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are
13  met:
14 
15  Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17 
18  Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the following disclaimer in the
20  documentation and/or other materials provided with the
21  distribution.
22 
23  Neither the name of the University of California nor the names
24  of its contributors may be used to endorse or promote products derived from
25  this software without specific prior written permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39  File description:
40  ControlGUI class for simple GUI for Synth classes
41 
42  File author(s):
43  AndrĂ©s Cabrera mantaraya36@gmail.com
44 */
45 
46 #include <map>
47 #include <string>
48 
49 #include "al/io/al_ControlNav.hpp"
50 #include "al/io/al_Imgui.hpp"
51 #include "al/scene/al_DynamicScene.hpp"
52 #include "al/scene/al_SynthRecorder.hpp"
53 #include "al/scene/al_SynthSequencer.hpp"
54 #include "al/ui/al_Parameter.hpp"
55 #include "al/ui/al_ParameterBundle.hpp"
56 #include "al/ui/al_ParameterGUI.hpp"
57 #include "al/ui/al_ParameterMIDI.hpp"
58 #include "al/ui/al_PresetHandler.hpp"
59 #include "al/ui/al_PresetSequencer.hpp"
60 
61 namespace al {
62 
63 class GUIMarker {
64  public:
65  enum class MarkerType { GROUP_BEGIN, GROUP_END, SEPARATOR };
66  GUIMarker(MarkerType type, const char *name = nullptr) {
67  mMarkerType = type;
68  mName = name;
69  }
70 
71  MarkerType getType() { return mMarkerType; }
72  const char *getName() { return mName; }
73 
74  private:
75  MarkerType mMarkerType;
76  const char *mName;
77 };
78 
85 class ControlGUI {
86  public:
87  ControlGUI &registerParameterMeta(ParameterMeta &param);
88 
91  return registerParameterMeta(newParam);
92  }
93  ControlGUI &add(ParameterMeta &newParam) {
94  return registerParameterMeta(newParam);
95  }
96 
99  return registerParameterMeta(*newParam);
100  }
101  ControlGUI &add(ParameterMeta *newParam) {
102  return registerParameterMeta(*newParam);
103  }
104 
105  ControlGUI &registerParameterBundle(ParameterBundle &bundle);
106 
109  return registerParameterBundle(newBundle);
110  }
111  ControlGUI &add(ParameterBundle &newBundle) {
112  return registerParameterBundle(newBundle);
113  }
114 
117  return registerParameterBundle(*newBundle);
118  }
119  ControlGUI &add(ParameterBundle *newBundle) {
120  return registerParameterBundle(*newBundle);
121  }
122 
123  ControlGUI &registerNav(Nav &nav);
124 
127  ControlGUI &operator<<(Nav &nav) { return registerNav(nav); }
128  ControlGUI &add(Nav &nav) { return registerNav(nav); }
129 
130  ControlGUI &registerPresetHandler(PresetHandler &presetHandler,
131  int numRows = -1, int numColumns = -1);
132 
136  return registerPresetHandler(ph);
137  }
138  ControlGUI &add(PresetHandler &ph) { return registerPresetHandler(ph); }
139 
143  return registerPresetHandler(*ph);
144  }
145  ControlGUI &add(PresetHandler *ph) { return registerPresetHandler(*ph); }
146 
147  ControlGUI &registerPresetSequencer(PresetSequencer &presetSequencer);
148 
152  return registerPresetSequencer(ps);
153  }
154  ControlGUI &add(PresetSequencer &ps) { return registerPresetSequencer(ps); }
155 
156  ControlGUI &registerSequenceRecorder(SequenceRecorder &recorder);
157 
161  return registerSequenceRecorder(ps);
162  }
163  ControlGUI &add(SequenceRecorder &ps) { return registerSequenceRecorder(ps); }
164 
165  ControlGUI &registerSynthRecorder(SynthRecorder &recorder);
166 
169  return registerSynthRecorder(recorder);
170  }
171  ControlGUI &add(SynthRecorder &recorder) {
172  return registerSynthRecorder(recorder);
173  }
174 
175  ControlGUI &registerSynthSequencer(SynthSequencer &seq);
176 
180  return registerSynthSequencer(seq);
181  }
182  ControlGUI &add(SynthSequencer &seq) { return registerSynthSequencer(seq); }
183 
184  ControlGUI &registerDynamicScene(DynamicScene &scene);
185 
189  return registerDynamicScene(scene);
190  }
191  ControlGUI &add(DynamicScene &scene) { return registerDynamicScene(scene); }
192 
193  ControlGUI &registerMarker(GUIMarker &marker);
194 
197  ControlGUI &operator<<(GUIMarker marker) { return registerMarker(marker); }
198  ControlGUI &add(GUIMarker marker) { return registerMarker(marker); }
199 
200  void setTitle(std::string title) { mName = title; }
201 
202  void fixedPosition(bool fixed = true) { mFixed = fixed; }
203 
207  void draw(Graphics &g);
208 
216  void manageImGUI(bool manage) { mManageIMGUI = manage; }
217 
228  void init(int x = 5, int y = 5, bool manageImgui = true);
229 
230  void cleanup();
231 
248  bool usingInput() { return ParameterGUI::usingInput(); }
249 
258  int getBundleCurrent(std::string bundleName) {
259  if (mBundles.find(bundleName) != mBundles.end()) {
260  return mBundles[bundleName]->currentBundle();
261  }
262  return -1;
263  }
264 
269  bool getBundleIsGlobal(std::string bundleName) {
270  if (mBundles.find(bundleName) != mBundles.end()) {
271  return mBundles[bundleName]->bundleGlobal();
272  }
273  return false;
274  }
275 
281  void backgroundAlpha(float a) { mGUIBackgroundAlpha = a; }
282 
288  float backgroundAlpha() const { return mGUIBackgroundAlpha; }
289 
290  static GUIMarker beginGroup(const char *groupName = nullptr) {
291  return GUIMarker(GUIMarker::MarkerType::GROUP_BEGIN, groupName);
292  }
293  static GUIMarker endGroup() {
294  return GUIMarker(GUIMarker::MarkerType::GROUP_END);
295  }
296  static GUIMarker separator() {
297  return GUIMarker(GUIMarker::MarkerType::SEPARATOR);
298  }
299 
300  protected:
301  private:
302  // std::map<std::string, std::vector<Parameter *>> mParameters;
303  // std::map<std::string, std::vector<ParameterBool *>> mParameterBools;
304  std::map<std::string, std::vector<ParameterVec3 *>> mParameterVec3s;
305  std::map<std::string, std::vector<ParameterVec4 *>> mParameterVec4s;
306 
307  std::map<std::string, std::vector<ParameterMeta *>> mElements;
308  ParameterMeta *mLatestElement{nullptr};
309  std::vector<ParameterMeta *>
310  mGroupBeginAnchors; // refs to the parameters marking beginning and
311  // ending of groups
312  std::vector<std::string> mGroupNames;
313  std::vector<ParameterMeta *>
314  mGroupEndAnchors; // refs to the parameters marking beginning and ending
315  // of groups
316  std::vector<ParameterMeta *> mSeparatorAnchors;
317 
318 // ParameterGUI mParameterGUI;
319 
320  PresetHandler *mPresetHandler{nullptr};
321  int mPresetColumns, mPresetRows;
322  PresetSequencer *mPresetSequencer{nullptr};
323  SequenceRecorder *mSequenceRecorder{nullptr};
324  SynthRecorder *mSynthRecorder{nullptr};
325  SynthSequencer *mSynthSequencer{nullptr};
326  PolySynth *mPolySynth{nullptr};
327  DynamicScene *mScene{nullptr};
328  std::map<std::string, BundleGUIManager *> mBundles;
329  Nav *mNav{nullptr};
330 
331  std::string mName;
332  bool mFixed{true};
333  int mX, mY;
334 
335  float mGUIBackgroundAlpha = 0;
336 
337  bool mManageIMGUI{true};
338 
339 // int mCurrentSequencerItem{0};
340  int mCurrentPresetSequencerItem{0};
341 // bool mRecordButtonValue{false};
342  char **mSequencerItems;
343 
344  std::map<std::string, int> mCurrentBundle;
345  std::map<std::string, bool> mBundleGlobal;
346 
347  void begin();
348  void end();
349 };
350 
351 } // namespace al
352 
353 #endif
The ControlGUI class.
ControlGUI & operator<<(Nav &nav)
void backgroundAlpha(float a)
Set background alpha value.
ControlGUI & operator<<(PresetSequencer &ps)
bool usingInput()
usingInput returns true if the mouse is within the imgui window
ControlGUI & operator<<(ParameterBundle *newBundle)
Register parameter using the streaming operator.
ControlGUI & operator<<(PresetHandler &ph)
int getBundleCurrent(std::string bundleName)
get currently active index for a parameter bundle registerd with the GUI
ControlGUI & operator<<(SynthRecorder &recorder)
Register a SynthRecorder. This will display GUI widgets to control it.
ControlGUI & operator<<(PresetHandler *ph)
ControlGUI & operator<<(SynthSequencer &seq)
void manageImGUI(bool manage)
Call to set if this GUI manages ImGUI.
bool getBundleIsGlobal(std::string bundleName)
Returns true if global controls is enabled for bundle.
ControlGUI & operator<<(SequenceRecorder &ps)
ControlGUI & operator<<(ParameterBundle &newBundle)
Register parameter using the streaming operator.
void init(int x=5, int y=5, bool manageImgui=true)
initialize ImGUI.
ControlGUI & operator<<(ParameterMeta *newParam)
Register parameter using the streaming operator.
void draw(Graphics &g)
draws the GUI
float backgroundAlpha() const
Get background alpha value.
ControlGUI & operator<<(GUIMarker marker)
ControlGUI & operator<<(ParameterMeta &newParam)
Register parameter using the streaming operator.
ControlGUI & operator<<(DynamicScene &scene)
The DynamicScene class.
Interface for loading fonts and rendering text.
Definition: al_Graphics.hpp:63
The ParameterMeta class defines the base interface for Parameter metadata.
The PresetHandler class handles sorting and recalling of presets.
The PresetSequencer class allows triggering presets from a PresetHandler over time.
The SequenceRecorder class records preset changes in a ".sequence" file.
The SynthRecorder class records the events arriving at a PolySynth.
Event Sequencer triggering audio visual "notes".
Definition: al_App.hpp:23