synth class
This commit is contained in:
parent
fbdbc998b9
commit
cb7445434c
@ -25,13 +25,26 @@ Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no progr
|
||||
|
||||
// Initialisation functions
|
||||
|
||||
// void Chassis::initParameter(uint32_t index, Parameter ¶meter) {
|
||||
// }
|
||||
|
||||
/*
|
||||
void Chassis::setParameterValue(uint32_t index, float value) {
|
||||
void Chassis::initParameter(uint32_t index, Parameter ¶meter) {
|
||||
switch (index) {
|
||||
case k_saw:
|
||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
||||
parameter.name = "Saw";
|
||||
parameter.symbol = "saw";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 127.0f;
|
||||
parameter.ranges.def = 127.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Chassis::setParameterValue(uint32_t index, float value) {
|
||||
switch (index) {
|
||||
case k_saw:
|
||||
s.p.saw = value / 127.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
float Chassis::getParameterValue(uint32_t index) const {
|
||||
return 0;
|
||||
}
|
||||
@ -71,23 +84,23 @@ void Chassis::noteOn(uint8_t note) {
|
||||
for (i = 0; i < NUM_VOICES; i++) {
|
||||
vPtr++;
|
||||
if (vPtr == NUM_VOICES) vPtr = 0;
|
||||
if (voice[vPtr].isFree()) {
|
||||
if (s.voice[vPtr].isFree()) {
|
||||
// if it's an existing note don't reset
|
||||
voice[vPtr].on(note, voice[i].note != note);
|
||||
s.voice[vPtr].on(note, s.voice[i].note != note);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == NUM_VOICES) { // didn't find a free voice
|
||||
vPtr++;
|
||||
if (vPtr == NUM_VOICES) vPtr = 0;
|
||||
voice[vPtr].on(note, true);
|
||||
s.voice[vPtr].on(note, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Chassis::noteOff(uint8_t note) {
|
||||
for (uint32_t i = 0; i < NUM_VOICES; i++) {
|
||||
if (voice[i].note == note && !voice[i].isFree()) {
|
||||
voice[i].off();
|
||||
if (s.voice[i].note == note && !s.voice[i].isFree()) {
|
||||
s.voice[i].off();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -108,7 +121,7 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv
|
||||
// run each synth voice
|
||||
bzero(outputs[0], sizeof(float) * frames);
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
||||
voice[i].run(outputs[0], frames);
|
||||
s.voice[i].run(outputs[0], frames);
|
||||
}
|
||||
// copy left to right
|
||||
memmove(outputs[1], outputs[0], sizeof(float) * frames);
|
||||
|
@ -29,6 +29,7 @@ START_NAMESPACE_DISTRHO
|
||||
class Chassis : public Plugin {
|
||||
public:
|
||||
enum Parameters {
|
||||
k_saw,
|
||||
kParameterCount
|
||||
};
|
||||
|
||||
@ -46,9 +47,9 @@ class Chassis : public Plugin {
|
||||
|
||||
// Initialisation
|
||||
void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
|
||||
// void initParameter(uint32_t index, Parameter ¶meter) override;
|
||||
void initParameter(uint32_t index, Parameter ¶meter) override;
|
||||
|
||||
// void setParameterValue(uint32_t index, float value) override;
|
||||
void setParameterValue(uint32_t index, float value) override;
|
||||
// float getParameterValue(uint32_t index) const override;
|
||||
|
||||
// void initProgramName(uint32_t index, String &programName) override;
|
||||
@ -63,9 +64,11 @@ class Chassis : public Plugin {
|
||||
void noteOff(uint8_t note);
|
||||
|
||||
private:
|
||||
Voice voice[NUM_VOICES];
|
||||
// Voice voice[NUM_VOICES];
|
||||
uint8_t vPtr;
|
||||
|
||||
Synth s;
|
||||
|
||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Chassis);
|
||||
};
|
||||
|
||||
|
@ -16,11 +16,16 @@
|
||||
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _VOICE_HPP
|
||||
#define _VOICE_HPP
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class Patch {
|
||||
public:
|
||||
float saw,sqr;
|
||||
|
||||
};
|
||||
|
||||
class Voice {
|
||||
public:
|
||||
uint8_t note;
|
||||
@ -45,4 +50,8 @@ class Voice {
|
||||
float env, target;
|
||||
};
|
||||
|
||||
#endif // _VOICE_HPP
|
||||
class Synth {
|
||||
public:
|
||||
Patch p;
|
||||
Voice voice[8];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user