OpenWareLaboratory
Patch.h
Go to the documentation of this file.
1 #ifndef __Patch_h__
2 #define __Patch_h__
3 
4 #include "device.h"
5 #include "basicmaths.h"
6 #include "Resource.h"
7 #include "FloatArray.h"
8 #include "PatchParameter.h"
9 #include "AudioBuffer.h"
10 #include "OpenWareMidiControl.h"
11 
12 #ifdef USE_MIDI_CALLBACK
13 #include "MidiMessage.h"
14 #endif /* USE_MIDI_CALLBACK */
15 
18  RIGHT_CHANNEL = 1
19 };
20 
21 class Patch {
22 public:
23  Patch();
24  virtual ~Patch();
26  static const float EXP;
27  static const float LIN;
28  static const float LOG;
29  static const uint16_t ON;
30  static const uint16_t OFF;
31  /* Get a float or int parameter with optional smoothing, hysteresis and exponentiation.
32  * The parameter value will be scaled to the range given by min and max.
33  * Lambda specifies smoothing factor 0 to 1.0, or 0.0 for no smoothing (default).
34  * Delta specifies hysteresis, or stiffness, as the absolute value change required to update the parameter, or 0.0 for no hysteresis (default).
35  * Skew specifies exponentiation: > 1.0 for logarithmic, < 1.0 for exponential, or 1.0 for linear scaling (default).
36  */
37  FloatParameter getParameter(const char* name, float defaultValue);
38  FloatParameter getFloatParameter(const char* name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN);
39  IntParameter getIntParameter(const char* name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN);
40  void registerParameter(PatchParameterId pid, const char* name);
41  [[deprecated]]
42  void registerParameter(PatchParameterId pid, const char* name, const char* desc){
43  registerParameter(pid, name);
44  }
46  void setParameterValue(PatchParameterId pid, float value);
48  [[deprecated]]
50  void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0);
51  int getBlockSize();
53  float getSampleRate();
54  float getBlockRate();
55  AudioBuffer* createMemoryBuffer(int channels, int samples);
58  [[deprecated]]
59  virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples){};
60  virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples){}
61  /* virtual void parameterChanged(PatchParameterId pid, float value, int samples){} */
62  virtual void processAudio(AudioBuffer& audio) = 0;
63 #ifdef USE_MIDI_CALLBACK
64  virtual void processMidi(MidiMessage msg);
65  virtual void sendMidi(MidiMessage msg);
66 #endif /* USE_MIDI_CALLBACK */
72  Resource* getResource(const char* name);
73 };
74 
75 #endif // __Patch_h__
PatchParameterId
PatchButtonId
PatchChannelId
Definition: Patch.h:16
@ RIGHT_CHANNEL
Definition: Patch.h:18
@ LEFT_CHANNEL
Definition: Patch.h:17
#define min(a, b)
Definition: basicmaths.h:38
#define max(a, b)
Definition: basicmaths.h:41
Definition: Patch.h:21
float getElapsedBlockTime()
float getParameterValue(PatchParameterId pid)
IntParameter getIntParameter(const char *name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN)
int getElapsedCycles()
AudioBuffer * createMemoryBuffer(int channels, int samples)
float getSampleRate()
void setParameterValue(PatchParameterId pid, float value)
int getBlockSize()
FloatParameter getParameter(const char *name, float defaultValue)
virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples)
Definition: Patch.h:60
bool isButtonPressed(PatchButtonId bid)
static const float LOG
Definition: Patch.h:28
static const uint16_t OFF
Definition: Patch.h:30
virtual ~Patch()
static const uint16_t ON
Definition: Patch.h:29
static const float EXP
constant skew values for exponential, linear and logarithmic parameters
Definition: Patch.h:26
FloatParameter getFloatParameter(const char *name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN)
virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples)
Definition: Patch.h:59
void registerParameter(PatchParameterId pid, const char *name, const char *desc)
Definition: Patch.h:42
void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0)
int getSamplesSinceButtonPressed(PatchButtonId bid)
virtual void processAudio(AudioBuffer &audio)=0
int getNumberOfChannels()
void registerParameter(PatchParameterId pid, const char *name)
static const float LIN
Definition: Patch.h:27
Resource * getResource(const char *name)
Get a resource (such as a stored FloatArray) from the firmware.
float getBlockRate()