OpenWareLaboratory
Patch.h
Go to the documentation of this file.
1 #ifndef __Patch_h__
2 #define __Patch_h__
3 
4 #include "basicmaths.h"
5 #include "FloatArray.h"
6 #include "PatchParameter.h"
7 #include "SmoothValue.h"
8 
18 
27 
36 
45 
54 };
55 
61  MIDI_NOTE_BUTTON = 0x80 // values over 127 are mapped to note numbers
62 };
63 
67 };
68 
69 class AudioBuffer {
70 public:
71  virtual ~AudioBuffer();
72  virtual FloatArray getSamples(int channel) = 0;
73  virtual int getChannels() = 0;
74  virtual int getSize() = 0;
75  virtual void clear() = 0;
76  static AudioBuffer* create(int channels, int samples);
77 };
78 
79 class Patch {
80 public:
81  Patch();
82  virtual ~Patch();
84  static const float EXP;
85  static const float LIN;
86  static const float LOG;
87  static const uint16_t ON;
88  static const uint16_t OFF;
89  /* Get a float or int parameter with optional smoothing, hysteresis and exponentiation.
90  * The parameter value will be scaled to the range given by min and max.
91  * Lambda specifies smoothing factor 0 to 1.0, or 0.0 for no smoothing (default).
92  * Delta specifies hysteresis, or stiffness, as the absolute value change required to update the parameter, or 0.0 for no hysteresis (default).
93  * Skew specifies exponentiation: > 1.0 for logarithmic, < 1.0 for exponential, or 1.0 for linear scaling (default).
94  */
95  FloatParameter getParameter(const char* name, float defaultValue);
96  FloatParameter getFloatParameter(const char* name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN);
97  IntParameter getIntParameter(const char* name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN);
98  void registerParameter(PatchParameterId pid, const char* name);
100  void setParameterValue(PatchParameterId pid, float value);
101  bool isButtonPressed(PatchButtonId bid);
104  void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0);
105  int getBlockSize();
106  float getSampleRate();
107  AudioBuffer* createMemoryBuffer(int channels, int samples);
108  float getElapsedBlockTime();
109  int getElapsedCycles();
110  virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples){};
111  virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples){}
112  /* virtual void parameterChanged(PatchParameterId pid, float value, int samples){} */
113  virtual void processAudio(AudioBuffer& output) = 0;
114 };
115 
116 #endif // __Patch_h__