/* Chassis softsynth framework Copyright 2024 Gordon JC Pearce 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) { } void Chassis::setParameterValue(uint32_t index, float value) { } 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++) { // printf("note on, finding free voice in %02x for %d\n", assign[i], note); if (voice[i].state == V_OFF) { // top bit is voice free flag voice[i].state = V_ON; // enable voice[i].note = note; printf("voice %d set to note %d\n", i, note); break; } } if (i == NUM_VOICES) { // didn't find a free voice // Voice v = voice[0]; memmove(voice, voice + 1, sizeof(Voice) * (NUM_VOICES - 1)); // shunt all voices down by one // lessvoice[NUM_VOICES - 1] = v; // oldest voice goes at the top of the queue voice[NUM_VOICES - 1].note = note; // set note, assume state is still set printf("no free voices, reused %d for note %d\n", 0, note); } printf("note table is now\n"); for (i = 0; i < NUM_VOICES; i++) { printf("%2d = %3d %01x\n", i, voice[i].note, voice[i].state); } printf("----------------------------\n"); } void Chassis::noteOff(uint8_t note) { uint32_t v; printf("note off called for %3d\n", note); printf("trying voice "); for (uint32_t i = 0; i < NUM_VOICES; i++) { printf("%02x ", i); if (voice[i].note == note && voice[i].state != V_OFF) { printf("note off for %d playing %02x\n", i, note); //memmove(voice + i, voice + i + 1, sizeof(Voice) * (NUM_VOICES - i)); voice[i].state = V_OFF; break; } } printf("\n note table is now\n"); for (uint32_t i = 0; i < NUM_VOICES; i++) { printf("%2d = %3d %01x\n", i, voice[i].note, voice[i].state); } } 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]); } } } // create the plugin Plugin *createPlugin() { return new Chassis(); } END_NAMESPACE_DISTRHO