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 "FloatArray.h"
7 #include "PatchParameter.h"
8 #include "SmoothValue.h"
9 #include "OpenWareMidiControl.h"
10 #ifdef USE_SCREEN
11 #include "ScreenBuffer.h"
12 #endif /* USE_SCREEN */
13 
14 #ifdef USE_MIDI_CALLBACK
15 #include "MidiMessage.h"
16 #endif /* USE_MIDI_CALLBACK */
17 
21 };
22 
23 class AudioBuffer {
24 public:
25  virtual ~AudioBuffer();
26  virtual FloatArray getSamples(int channel) = 0;
27  virtual int getChannels() = 0;
28  virtual int getSize() = 0;
29  virtual void clear() = 0;
30  static AudioBuffer* create(int channels, int samples);
31 };
32 
33 class Patch {
34 public:
35  Patch();
36  virtual ~Patch();
38  static const float EXP;
39  static const float LIN;
40  static const float LOG;
41  static const uint16_t ON;
42  static const uint16_t OFF;
43  /* Get a float or int parameter with optional smoothing, hysteresis and exponentiation.
44  * The parameter value will be scaled to the range given by min and max.
45  * Lambda specifies smoothing factor 0 to 1.0, or 0.0 for no smoothing (default).
46  * Delta specifies hysteresis, or stiffness, as the absolute value change required to update the parameter, or 0.0 for no hysteresis (default).
47  * Skew specifies exponentiation: > 1.0 for logarithmic, < 1.0 for exponential, or 1.0 for linear scaling (default).
48  */
49  FloatParameter getParameter(const char* name, float defaultValue);
50  FloatParameter getFloatParameter(const char* name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN);
51  IntParameter getIntParameter(const char* name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN);
52  void registerParameter(PatchParameterId pid, const char* name);
53  void registerParameter(PatchParameterId pid, const char* name, const char* desc){
54  registerParameter(pid, name);
55  }
57  void setParameterValue(PatchParameterId pid, float value);
61  void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0);
62  int getBlockSize();
63  float getSampleRate();
64  AudioBuffer* createMemoryBuffer(int channels, int samples);
65  float getElapsedBlockTime();
66  int getElapsedCycles();
67  virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples){};
68  virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples){}
69  /* virtual void parameterChanged(PatchParameterId pid, float value, int samples){} */
70  virtual void processAudio(AudioBuffer& audio) = 0;
71 #ifdef USE_SCREEN
72  uint16_t getScreenWidth();
73  uint16_t getScreenHeight();
74  virtual void processScreen(ScreenBuffer& screen);
75 #endif /* USE_SCREEN */
76 #ifdef USE_MIDI_CALLBACK
77  virtual void processMidi(MidiMessage msg);
78  virtual void sendMidi(MidiMessage msg);
79 #endif /* USE_MIDI_CALLBACK */
80 };
81 
82 #endif // __Patch_h__
int getElapsedCycles()
Definition: Patch.cpp:74
static const uint16_t ON
Definition: Patch.h:41
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:11
AudioBuffer * createMemoryBuffer(int channels, int samples)
Definition: Patch.cpp:64
int getBlockSize()
Definition: Patch.cpp:27
PatchParameterId
virtual void clear()=0
Patch()
Definition: Patch.cpp:14
static const float LIN
Definition: Patch.h:39
static const float LOG
Definition: Patch.h:40
void setButton(PatchButtonId bid, uint16_t value, uint16_t samples=0)
Definition: Patch.cpp:51
float getElapsedBlockTime()
Definition: Patch.cpp:70
virtual FloatArray getSamples(int channel)=0
float getSampleRate()
Definition: Patch.cpp:23
Definition: Patch.h:33
int getSamplesSinceButtonPressed(PatchButtonId bid)
Definition: Patch.cpp:59
PatchButtonId
static const uint16_t OFF
Definition: Patch.h:42
PatchChannelId
Definition: Patch.h:18
static AudioBuffer * create(int channels, int samples)
Definition: Patch.cpp:113
#define min(a, b)
Definition: basicmaths.h:41
FloatParameter getParameter(const char *name, float defaultValue)
Definition: Patch.cpp:117
bool isButtonPressed(PatchButtonId bid)
Definition: Patch.cpp:55
void registerParameter(PatchParameterId pid, const char *name)
Definition: Patch.cpp:18
virtual ~AudioBuffer()
Definition: Patch.cpp:10
float getParameterValue(PatchParameterId pid)
Definition: Patch.cpp:31
void setParameterValue(PatchParameterId pid, float value)
Definition: Patch.cpp:44
virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples)
Definition: Patch.h:68
#define max(a, b)
Definition: basicmaths.h:44
virtual int getChannels()=0
virtual void processAudio(AudioBuffer &audio)=0
virtual void encoderChanged(PatchParameterId pid, int16_t delta, uint16_t samples)
Definition: Patch.h:67
void registerParameter(PatchParameterId pid, const char *name, const char *desc)
Definition: Patch.h:53
IntParameter getIntParameter(const char *name, int min, int max, int defaultValue=0, float lambda=0.0f, float delta=0.0, float skew=LIN)
Definition: Patch.cpp:125
virtual int getSize()=0
static const float EXP
constant skew values for exponential, linear and logarithmic parameters
Definition: Patch.h:38
virtual ~Patch()
Definition: Patch.cpp:16
FloatParameter getFloatParameter(const char *name, float min, float max, float defaultValue=0.0f, float lambda=0.0f, float delta=0.0, float skew=LIN)
Definition: Patch.cpp:121