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 "SmoothValue.h"
10 #include "AudioBuffer.h"
11 #include "OpenWareMidiControl.h"
12 
13 #ifdef USE_MIDI_CALLBACK
14 #include "MidiMessage.h"
15 #endif /* USE_MIDI_CALLBACK */
16 
20 };
21 
22 class Patch {
23 public:
24  Patch();
25  virtual ~Patch();
27  static const float EXP;
28  static const float LIN;
29  static const float LOG;
30  static const uint16_t ON;
31  static const uint16_t OFF;
32  /* Get a float or int parameter with optional smoothing, hysteresis and exponentiation.
33  * The parameter value will be scaled to the range given by min and max.
34  * Lambda specifies smoothing factor 0 to 1.0, or 0.0 for no smoothing (default).
35  * Delta specifies hysteresis, or stiffness, as the absolute value change required to update the parameter, or 0.0 for no hysteresis (default).
36  * Skew specifies exponentiation: > 1.0 for logarithmic, < 1.0 for exponential, or 1.0 for linear scaling (default).
37  */
38  FloatParameter getParameter(const char* name, float defaultValue);
39  FloatParameter getFloatParameter(const char* name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN);
40  IntParameter getIntParameter(const char* name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN);
41  void registerParameter(PatchParameterId pid, const char* name);
42  [[deprecated]]
43  void registerParameter(PatchParameterId pid, const char* name, const char* desc){
44  registerParameter(pid, name);
45  }
47  void setParameterValue(PatchParameterId pid, float value);
49  [[deprecated]]
51  void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0);
52  int getBlockSize();
53  int getNumberOfChannels();
54  float getSampleRate();
55  float getBlockRate();
56  AudioBuffer* createMemoryBuffer(int channels, int samples);
57  float getElapsedBlockTime();
58  int getElapsedCycles();
59  [[deprecated]]
60  virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples){};
61  virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples){}
62  /* virtual void parameterChanged(PatchParameterId pid, float value, int samples){} */
63  virtual void processAudio(AudioBuffer& audio) = 0;
64 #ifdef USE_MIDI_CALLBACK
65  virtual void processMidi(MidiMessage msg);
66  virtual void sendMidi(MidiMessage msg);
67 #endif /* USE_MIDI_CALLBACK */
68 
73  Resource* getResource(const char* name);
74 };
75 
76 #endif // __Patch_h__
int getElapsedCycles()
static const uint16_t ON
Definition: Patch.h:30
int getBlockSize()
PatchParameterId
static const float LIN
Definition: Patch.h:28
static const float LOG
Definition: Patch.h:29
class deprecated("use UpSampler and DownSampler instead.")]] Resampler
Implements 4x oversampling.
Definition: Resample.h:10
void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0)
float getElapsedBlockTime()
float getSampleRate()
Definition: Patch.h:22
int getSamplesSinceButtonPressed(PatchButtonId bid)
PatchButtonId
static const uint16_t OFF
Definition: Patch.h:31
PatchChannelId
Definition: Patch.h:17
#define min(a, b)
Definition: basicmaths.h:41
FloatParameter getParameter(const char *name, float defaultValue)
bool isButtonPressed(PatchButtonId bid)
float getBlockRate()
void registerParameter(PatchParameterId pid, const char *name)
float getParameterValue(PatchParameterId pid)
void setParameterValue(PatchParameterId pid, float value)
virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples)
Definition: Patch.h:61
#define max(a, b)
Definition: basicmaths.h:44
virtual void processAudio(AudioBuffer &audio)=0
int getNumberOfChannels()
virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples)
Definition: Patch.h:60
void registerParameter(PatchParameterId pid, const char *name, const char *desc)
Definition: Patch.h:43
AudioBuffer * createMemoryBuffer(int channels, int samples)
Resource * getResource(const char *name)
Get a resource (such as a stored FloatArray) from the firmware.
IntParameter getIntParameter(const char *name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN)
static const float EXP
constant skew values for exponential, linear and logarithmic parameters
Definition: Patch.h:27
virtual ~Patch()
FloatParameter getFloatParameter(const char *name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN)