SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Source.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Martin Hansen
3  *
4  * This file is part of SPAOP (Spatial Audio Object Positioner).
5  *
6  * SPAOP is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * SPAOP is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPAOP. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef SOURCE_H_INCLUDED
21 #define SOURCE_H_INCLUDED
22 
23 #include <iostream>
24 #include <sstream>
25 #include <iomanip>
26 #include <stdint.h>
27 #include "Colours.h"
28 #include "WonderHeader.h"
29 
30 #define ANGLE_MAX 360.0
31 #define ANGLE_MIN 0.0
32 
33 #define NORMALIZE(min, max, val) ((val)-(min)) / ((max)-(min))
34 #define DENORMALIZE(min, max, val) ((val) * ((max)-(min))) + (min)
35 
36 #define SATURATE(x) ((x) < 0.0) ? 0.0 : (((x) > 1.0) ? 1.0 : (x))
37 
38 #define COORD_NORM(x) NORMALIZE(COORD_MIN, COORD_MAX, (x))
39 #define COORD_DENORM(x) DENORMALIZE(COORD_MIN, COORD_MAX, (x))
40 
45 namespace wonder {
46 
60 class Source
61 {
62 public:
63 
70  Source(int id=0);
71 
73  virtual ~Source();
74 
75  //==============================================================================
76  // Enums:
77 
82  {
83  typeParam = 0,
91  };
92 
95  {
96  plane = 0,
98  };
99 
100  //==============================================================================
101  // Methods for (automated) parameters by index:
102 
106  int getNumParameters() const;
107 
113  float getParameter (int index) const;
114 
122  void setParameter (int index, float newValue);
123 
131  void setParameterUnnormalized(int index, float newUnnormalizedValue);
132 
139  const std::string getParameterName (int index) const;
140 
148  const std::string getParameterText (int index) const;
149 
160  static std::string getParameterTextByValue (int index, float value);
161 
175  float getParameterByText(int index, const std::string& parameterText) const;
176 
183  static float getParameterDefaultValue (int index);
184 
197  static float normalizeParameter (int index, float unnormalized);
198 
210  static float denormalizeParameter (int index, float normalized);
211 
220  float getDenormalizedParameter (int index) const;
221 
228  bool getBooleanizedParameter (int index) const;
229 
230  //==============================================================================
231  // For convenience: getters on the same parameters by name (denormalized):
232 
236  int getType() const;
237 
239  float getXPos() const;
240 
242  float getYPos() const;
243 
247  float getAngle() const;
248 
250  bool dopplerIsEnabled() const;
251 
252 
253  //==============================================================================
254  // Methods for other parameters:
255 
257  int getID() const;
258 
260  bool setID(int id);
261 
263  std::string getName() const;
264 
266  void setName(const std::string& name);
267 
272  const Colour getCoulour() const;
273 
275  void setColour(uint8_t red, uint8_t green, uint8_t blue);
276 
278  void setColour(Colour colour);
279 
281  uint8_t getRed() const;
282 
284  void setRed(uint8_t red);
285 
287  uint8_t getGreen() const;
288 
290  void setGreen(uint8_t green);
291 
293  uint8_t getBlue() const;
294 
296  void setBlue(uint8_t blue);
297 
302  bool isActive() const;
303 
305  void setIsActive(bool isActive);
306 
307 private:
308  float params_[totalNumParams]; // the (normalized) parameters
309  int id_; // the WONDER-specific source ID
310  std::string name_; // the source's name in WONDER
311  Colour colour_; // the colour the source is displayed in
312  bool active_; // source has been activated
313 
315  static std::string floatString(float f);
316 };
317 
318 }
319 
320 #endif // SOURCE_H_INCLUDED
Doppler effect (on/off).
Definition: Source.h:87
void setGreen(uint8_t green)
Sets the green value of this source's colour (as in RGB).
Definition: Source.cpp:295
static std::string getParameterTextByValue(int index, float value)
Returns the parameter's (denormalized) string representation for a given (normalized) value...
Definition: Source.cpp:90
The source's x-axis coordinate.
Definition: Source.h:84
void setIsActive(bool isActive)
Sets the "source is active" status.
Definition: Source.cpp:315
void setParameter(int index, float newValue)
Sets a parameter from its normalized value.
Definition: Source.cpp:57
float getParameterByText(int index, const std::string &parameterText) const
Returns the value a parameter would have if it was set to the value represented by the parameterText ...
Definition: Source.cpp:105
int getID() const
Returns the WONDER source ID.
Definition: Source.cpp:238
void setColour(uint8_t red, uint8_t green, uint8_t blue)
Sets the source's colour (for use in GUIs).
Definition: Source.cpp:268
float getDenormalizedParameter(int index) const
Returns the denormalized value of the parameter.
Definition: Source.cpp:197
virtual ~Source()
Destructor.
Definition: Source.cpp:36
float getAngle() const
Returns the angle of a plain source in degree (irrelevant for point sources).
Definition: Source.cpp:225
The angle of a plain source.
Definition: Source.h:86
uint8_t getGreen() const
Returns the green value of this source's colour (as in RGB).
Definition: Source.cpp:290
int getType() const
Returns 0, if this is a "plane" source, or 1, it's a point source.
Definition: Source.cpp:210
bool isActive() const
Returns true, if the source is active within WONDER.
Definition: Source.cpp:310
SourceTypes
WONDER's different source types.
Definition: Source.h:94
std::string getName() const
Returns the source's name.
Definition: Source.cpp:258
const Colour getCoulour() const
Returns the source's colour.
Definition: Source.cpp:253
A struct representing a (RGB) colour.
Definition: Colours.h:28
void setParameterUnnormalized(int index, float newUnnormalizedValue)
Sets a parameter from its unnormalized value.
Definition: Source.cpp:65
static float denormalizeParameter(int index, float normalized)
Scales a parameter from the range of [0.0 ; 1.0] to the value it represents to the user (for GUI...
Definition: Source.cpp:182
The source's y-axis coordinate.
Definition: Source.h:85
bool setID(int id)
Sets the WONDER source ID.
Definition: Source.cpp:243
AutomatedParameters
Parameters that can be automated by the host must be accessed using this enum.
Definition: Source.h:81
A plane wave source.
Definition: Source.h:96
const std::string getParameterName(int index) const
Returns the name of the parameter.
Definition: Source.cpp:70
The (WONDER) source type.
Definition: Source.h:83
void setRed(uint8_t red)
Sets the red value of this source's colour (as in RGB).
Definition: Source.cpp:285
bool getBooleanizedParameter(int index) const
Returns false, if the parameter's value is 0.0 (otherwise true).
Definition: Source.cpp:202
bool dopplerIsEnabled() const
Returns true, if the doppler effect is enabled.
Definition: Source.cpp:230
void setBlue(uint8_t blue)
Sets the red value of this source's colour (as in RGB).
Definition: Source.cpp:305
void setName(const std::string &name)
Sets the source's name.
Definition: Source.cpp:263
int getNumParameters() const
Returns the total numbers of parameters that can be accessed via enum AutomatedParameters.
Definition: Source.cpp:43
const std::string getParameterText(int index) const
Returns the string representation of the parameter's current value.
Definition: Source.cpp:85
uint8_t getBlue() const
Returns the blue value of this source's colour (as in RGB).
Definition: Source.cpp:300
float getYPos() const
Returns the y-axis coordinate of this source.
Definition: Source.cpp:220
static float normalizeParameter(int index, float unnormalized)
Normalizes a parameter to the range of [0.0 ; 1.0].
Definition: Source.cpp:154
A point source.
Definition: Source.h:97
A class for objects representing a WONDER source with all its properties.
Definition: Source.h:60
float getXPos() const
Returns the x-axis coordinate of this source.
Definition: Source.cpp:215
static float getParameterDefaultValue(int index)
Returns the default (=initial) value of the parameter.
Definition: Source.cpp:139
Source(int id=0)
Constructor.
Definition: Source.cpp:24
float getParameter(int index) const
Returns the normalized value of the parameter.
Definition: Source.cpp:48
uint8_t getRed() const
Returns the red value of this source's colour (as in RGB).
Definition: Source.cpp:280
Total number of (automated) parameters.
Definition: Source.h:89