synth class

This commit is contained in:
Gordon JC Pearce 2024-09-03 23:30:08 +01:00
parent fbdbc998b9
commit cb7445434c
3 changed files with 42 additions and 17 deletions

View File

@ -25,13 +25,26 @@ Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no progr
// Initialisation functions // Initialisation functions
// void Chassis::initParameter(uint32_t index, Parameter &parameter) { void Chassis::initParameter(uint32_t index, Parameter &parameter) {
// } switch (index) {
case k_saw:
/* parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
void Chassis::setParameterValue(uint32_t index, float value) { 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 { float Chassis::getParameterValue(uint32_t index) const {
return 0; return 0;
} }
@ -71,23 +84,23 @@ void Chassis::noteOn(uint8_t note) {
for (i = 0; i < NUM_VOICES; i++) { for (i = 0; i < NUM_VOICES; i++) {
vPtr++; vPtr++;
if (vPtr == NUM_VOICES) vPtr = 0; if (vPtr == NUM_VOICES) vPtr = 0;
if (voice[vPtr].isFree()) { if (s.voice[vPtr].isFree()) {
// if it's an existing note don't reset // 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; break;
} }
} }
if (i == NUM_VOICES) { // didn't find a free voice if (i == NUM_VOICES) { // didn't find a free voice
vPtr++; vPtr++;
if (vPtr == NUM_VOICES) vPtr = 0; if (vPtr == NUM_VOICES) vPtr = 0;
voice[vPtr].on(note, true); s.voice[vPtr].on(note, true);
} }
} }
void Chassis::noteOff(uint8_t note) { void Chassis::noteOff(uint8_t note) {
for (uint32_t i = 0; i < NUM_VOICES; i++) { for (uint32_t i = 0; i < NUM_VOICES; i++) {
if (voice[i].note == note && !voice[i].isFree()) { if (s.voice[i].note == note && !s.voice[i].isFree()) {
voice[i].off(); s.voice[i].off();
break; break;
} }
} }
@ -108,7 +121,7 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv
// run each synth voice // run each synth voice
bzero(outputs[0], sizeof(float) * frames); bzero(outputs[0], sizeof(float) * frames);
for (uint8_t i = 0; i < NUM_VOICES; i++) { 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 // copy left to right
memmove(outputs[1], outputs[0], sizeof(float) * frames); memmove(outputs[1], outputs[0], sizeof(float) * frames);

View File

@ -29,6 +29,7 @@ START_NAMESPACE_DISTRHO
class Chassis : public Plugin { class Chassis : public Plugin {
public: public:
enum Parameters { enum Parameters {
k_saw,
kParameterCount kParameterCount
}; };
@ -46,9 +47,9 @@ class Chassis : public Plugin {
// Initialisation // Initialisation
void initAudioPort(bool input, uint32_t index, AudioPort &port) override; void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
// void initParameter(uint32_t index, Parameter &parameter) override; void initParameter(uint32_t index, Parameter &parameter) override;
// void setParameterValue(uint32_t index, float value) override; void setParameterValue(uint32_t index, float value) override;
// float getParameterValue(uint32_t index) const override; // float getParameterValue(uint32_t index) const override;
// void initProgramName(uint32_t index, String &programName) override; // void initProgramName(uint32_t index, String &programName) override;
@ -63,9 +64,11 @@ class Chassis : public Plugin {
void noteOff(uint8_t note); void noteOff(uint8_t note);
private: private:
Voice voice[NUM_VOICES]; // Voice voice[NUM_VOICES];
uint8_t vPtr; uint8_t vPtr;
Synth s;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Chassis); DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Chassis);
}; };

View File

@ -16,11 +16,16 @@
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifndef _VOICE_HPP #pragma once
#define _VOICE_HPP
#include <cstdint> #include <cstdint>
class Patch {
public:
float saw,sqr;
};
class Voice { class Voice {
public: public:
uint8_t note; uint8_t note;
@ -45,4 +50,8 @@ class Voice {
float env, target; float env, target;
}; };
#endif // _VOICE_HPP class Synth {
public:
Patch p;
Voice voice[8];
};