151 lines
4.3 KiB
C++
151 lines
4.3 KiB
C++
/*
|
|
Chassis polysynth framework
|
|
|
|
Copyright 2024 Gordon JC Pearce <gordonjcp@gjcp.net>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include "chassis.hpp"
|
|
|
|
START_NAMESPACE_DISTRHO
|
|
|
|
Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no programs, no states
|
|
}
|
|
|
|
// Initialisation functions
|
|
|
|
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 = 0.0f;
|
|
break;
|
|
|
|
case k_sqr:
|
|
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
parameter.name = "Square";
|
|
parameter.symbol = "sqr";
|
|
parameter.ranges.min = 0.0f;
|
|
parameter.ranges.max = 127.0f;
|
|
parameter.ranges.def = 0.0f;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
void Chassis::setParameterValue(uint32_t index, float value) {
|
|
switch (index) {
|
|
case k_saw:
|
|
s.p.saw = value / 127.0f;
|
|
break;
|
|
case k_sqr:
|
|
s.p.sqr = value / 127.0f;
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
/*
|
|
float Chassis::getParameterValue(uint32_t index) const {
|
|
return 0;
|
|
}
|
|
*/
|
|
void Chassis::initAudioPort(bool input, uint32_t index, AudioPort &port) {
|
|
port.groupId = kPortGroupStereo;
|
|
Plugin::initAudioPort(input, index, port);
|
|
|
|
if (!input && index == 0) port.name = "Left Out";
|
|
if (!input && index == 1) port.name = "Right Out";
|
|
}
|
|
/*
|
|
void Chassis::initProgramName(uint32_t index, String &programName) {
|
|
programName = "init";
|
|
}
|
|
|
|
void Chassis::loadProgram(uint32_t index) {
|
|
prog_offset = (index & 0x3f) << 7;
|
|
program = index + 1;
|
|
}
|
|
*/
|
|
// Processing functions
|
|
|
|
void Chassis::activate() {
|
|
// calculate filter coefficients
|
|
printf("called activate()\n");
|
|
}
|
|
|
|
void Chassis::deactivate() {
|
|
// zero out the outputs, maybe
|
|
printf("called deactivate()\n");
|
|
// printf("%02x", assign[1]);
|
|
}
|
|
|
|
void Chassis::noteOn(uint8_t note) {
|
|
uint32_t i;
|
|
for (i = 0; i < NUM_VOICES; i++) {
|
|
vPtr++;
|
|
if (vPtr == NUM_VOICES) vPtr = 0;
|
|
if (s.voice[vPtr].isFree()) {
|
|
// if it's an existing note don't reset
|
|
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;
|
|
s.voice[vPtr].on(note, true);
|
|
}
|
|
}
|
|
|
|
void Chassis::noteOff(uint8_t note) {
|
|
for (uint32_t i = 0; i < NUM_VOICES; i++) {
|
|
if (s.voice[i].note == note && !s.voice[i].isFree()) {
|
|
s.voice[i].off();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) {
|
|
// if (midiEventCount > 0) printf("\n--------------------\n");
|
|
for (uint32_t i = 0; i < midiEventCount; i++) {
|
|
// printf("%4d %02x %02x\n", MidiEvents[i].frame, MidiEvents[i].data[0], MidiEvents[i].data[1]);
|
|
if (MidiEvents[i].data[0] == 0x90) {
|
|
noteOn(MidiEvents[i].data[1]);
|
|
}
|
|
if (MidiEvents[i].data[0] == 0x80) {
|
|
noteOff(MidiEvents[i].data[1]);
|
|
}
|
|
}
|
|
|
|
// run each synth voice
|
|
bzero(outputs[0], sizeof(float) * frames);
|
|
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
|
s.voice[i].run(s, outputs[0], frames);
|
|
}
|
|
// copy left to right
|
|
memmove(outputs[1], outputs[0], sizeof(float) * frames);
|
|
}
|
|
|
|
// create the plugin
|
|
Plugin *createPlugin() { return new Chassis(); }
|
|
|
|
END_NAMESPACE_DISTRHO
|