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 #include "MemoryBuffer.hpp"
79 AudioBuffer* AudioBuffer::create(int channels, int samples){
80  return new ManagedMemoryBuffer(channels, samples);
81 }
82 
83 FloatParameter Patch::getParameter(const char* name, float defaultValue){
84  return getFloatParameter(name, 0.0f, 1.0f, defaultValue, 0.0f, 0.0f, LIN);
85 }
86 
87 FloatParameter Patch::getFloatParameter(const char* name, float min, float max, float defaultValue, float lambda, float delta, float skew){
88  return getInitialisingPatchProcessor()->getParameter(name, min, max, defaultValue, lambda, delta, skew);
89 }
90 
91 IntParameter Patch::getIntParameter(const char* name, int min, int max, int defaultValue, float lambda, float delta, float skew){
92  return getInitialisingPatchProcessor()->getParameter(name, min, max, defaultValue, lambda, delta, skew);
93 }
94 
95 const float Patch::EXP = 0.5;
96 const float Patch::LIN = 1.0;
97 const float Patch::LOG = 2.0;
98 const uint16_t Patch::ON = 4095;
99 const uint16_t Patch::OFF = 0;