OpenWareLaboratory
Patch.cpp
Go to the documentation of this file.
1 #include <cstddef>
2 #include <string.h>
3 #include "Patch.h"
4 #include "device.h"
5 #include "ProgramVector.h"
6 #include "PatchProcessor.h"
7 #include "basicmaths.h"
8 #include "main.h"
9 
11 
12 PatchProcessor* getInitialisingPatchProcessor();
13 
15 
17 
18 void Patch::registerParameter(PatchParameterId pid, const char* name){
19  if(getProgramVector()->registerPatchParameter != NULL)
20  getProgramVector()->registerPatchParameter(pid, name);
21 }
22 
24  return getProgramVector()->audio_samplingrate;
25 }
26 
28  return getProgramVector()->audio_blocksize;
29 }
30 
32  // return getInitialisingPatchProcessor()->getParameterValue(pid);
33  // if(pid < getProgramVector()->parameters_size)
34  if(pid < getProgramVector()->parameters_size){
35  if(getProgramVector()->hardware_version == OWL_MODULAR_HARDWARE && pid < 4){
36  return (4095 - getProgramVector()->parameters[pid])/4096.0f;
37  }else{
38  return getProgramVector()->parameters[pid]/4096.0f;
39  }
40  }
41  return 0.0f;
42 }
43 
45  if(getProgramVector()->hardware_version == OWL_MODULAR_HARDWARE && pid < 4)
46  doSetPatchParameter(pid, 4095 - (int16_t)(value*4096.0f));
47  else
48  doSetPatchParameter(pid, (int16_t)(value*4096));
49 }
50 
51 void Patch::setButton(PatchButtonId bid, uint16_t value, uint16_t samples){
52  doSetButton(bid, value, samples);
53 }
54 
56  return getProgramVector()->buttons & (1<<bid);
57 }
58 
60  // deprecated
61  return 0;
62 }
63 
64 AudioBuffer* Patch::createMemoryBuffer(int channels, int samples){
65  return AudioBuffer::create(channels, samples);
66 }
67 
68 #define DWT_CYCCNT ((volatile unsigned int *)0xE0001004)
69 
71  return (*DWT_CYCCNT)/getBlockSize()/3500.0;
72 }
73 
75  return *DWT_CYCCNT;
76 }
77 
78 #ifdef USE_SCREEN
79  void drawMessage(ScreenBuffer& screen){
80  ProgramVector* pv = getProgramVector();
81  if(pv->message != NULL){
82  screen.setTextSize(1);
83  screen.setTextWrap(true);
84  screen.print(0, 26, pv->message);
85  }
86  }
87  void drawTitle(const char* title, ScreenBuffer& screen){
88  // draw title
89  screen.setTextSize(2);
90  screen.print(0, 16, title);
91  }
92 void Patch::processScreen(ScreenBuffer& screen){
93  // screen.clear();
94  const char* title = getInitialisingPatchProcessor()->getPatchName();
95  drawTitle(title, screen);
96  drawMessage(screen);
97  // const char title[] = "KickBox";
98  // screen.setTextSize(2);
99  // screen.print(0, 16, title);
100 }
101 #endif /* USE_SCREEN */
102 
103 #ifdef USE_MIDI_CALLBACK
104 void Patch::processMidi(MidiMessage msg){}
105 
106 void Patch::sendMidi(MidiMessage msg){
107  doMidiSend(msg.data[0], msg.data[1], msg.data[2], msg.data[3]);
108 }
109 
110 #endif /* USE_MIDI_CALLBACK */
111 
112 #include "MemoryBuffer.hpp"
113 AudioBuffer* AudioBuffer::create(int channels, int samples){
114  return new ManagedMemoryBuffer(channels, samples);
115 }
116 
117 FloatParameter Patch::getParameter(const char* name, float defaultValue){
118  return getFloatParameter(name, 0.0f, 1.0f, defaultValue, 0.0f, 0.0f, LIN);
119 }
120 
121 FloatParameter Patch::getFloatParameter(const char* name, float min, float max, float defaultValue, float lambda, float delta, float skew){
122  return getInitialisingPatchProcessor()->getParameter(name, min, max, defaultValue, lambda, delta, skew);
123 }
124 
125 IntParameter Patch::getIntParameter(const char* name, int min, int max, int defaultValue, float lambda, float delta, float skew){
126  return getInitialisingPatchProcessor()->getParameter(name, min, max, defaultValue, lambda, delta, skew);
127 }
128 
129 const float Patch::EXP = 0.5;
130 const float Patch::LIN = 1.0;
131 const float Patch::LOG = 2.0;
132 const uint16_t Patch::ON = 4095;
133 const uint16_t Patch::OFF = 0;
int getElapsedCycles()
Definition: Patch.cpp:74
static const uint16_t ON
Definition: Patch.h:41
AudioBuffer * createMemoryBuffer(int channels, int samples)
Definition: Patch.cpp:64
int getBlockSize()
Definition: Patch.cpp:27
PatchParameterId
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
float getSampleRate()
Definition: Patch.cpp:23
int getSamplesSinceButtonPressed(PatchButtonId bid)
Definition: Patch.cpp:59
PatchButtonId
static const uint16_t OFF
Definition: Patch.h:42
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
#define DWT_CYCCNT
Definition: Patch.cpp:68
void setParameterValue(PatchParameterId pid, float value)
Definition: Patch.cpp:44
#define max(a, b)
Definition: basicmaths.h:44
void setTextWrap(bool w)
uint8_t data[4]
Definition: MidiMessage.h:10
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
PatchProcessor * getInitialisingPatchProcessor()
static const float EXP
constant skew values for exponential, linear and logarithmic parameters
Definition: Patch.h:38
void print(int x, int y, const char *text)
void setTextSize(uint8_t s)
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