/* Peacock-8 VA polysynth 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 "peacock.hpp" #include "ic1.hpp" #include "ic29.hpp" START_NAMESPACE_DISTRHO Assigner ic1; Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) { s.run(); } void Peacock::runMidi(const MidiEvent *ev, uint32_t count, uint32_t timeLimit) { // handle MIDI events, starting at lastEvent and continuing until timeLimit if (count == 0) return; // no events to do, at all for (uint32_t i = lastEvent; i < count; i++) { if (ev[i].frame > timeLimit) break; // exceeded the time limit ic1.handleMidi((const MidiEvent *)&ev[i]); } } void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) { // no content yet // dispose of parameters (void)outputs; // calculate an entire jack period's worth of samples // harder than it sounds because for short jack periods there may be many // such calls between 4.3ms control updates, or there may be many updates // within a single update uint32_t framePos = 0; // sample position within current frame // blockLeft is how many samples are left within this 4.3ms block // framesleft is how many samples are left within this jack period // the names are awful, I should FIXME this for legibility uint32_t sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft; framesLeft = frames; // number of frames left to calculate // now we'll handle MIDI events up to however long is left in this block lastEvent = 0; runMidi(midiEvents, midiEventCount, blockLeft); while (framePos < frames) { if (blockLeft == 0) { blockLeft = (int)(getSampleRate() * 0.0043); // how many samples per 4.3ms block? // handle all MIDI events for this block, up to the end of the block and frame runMidi(midiEvents, midiEventCount, framePos + blockLeft); s.run(); } sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft; // run every synth voice into the buffer here FIXME framePos += sizeThisTime; // move along the frame framesLeft -= sizeThisTime; blockLeft -= sizeThisTime; } } Plugin *createPlugin() { return new Peacock(); } END_NAMESPACE_DISTRHO