From 332b18220ffd9c544f2c7f1c9e059925aa6a4aae Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Wed, 9 Oct 2024 22:10:51 +0100 Subject: [PATCH] reasonable key assigner --- .gitmodules | 3 ++ LICENCE | 7 +++ Makefile | 35 +++++++++++++++ dpf | 1 + plugin/DistrhoPluginInfo.h | 33 ++++++++++++++ plugin/Makefile | 22 +++++++++ plugin/ic1.cpp | 91 ++++++++++++++++++++++++++++++++++++++ plugin/ic1.hpp | 34 ++++++++++++++ plugin/peacock.cpp | 46 +++++++++++++++++++ plugin/peacock.hpp | 69 +++++++++++++++++++++++++++++ 10 files changed, 341 insertions(+) create mode 100644 .gitmodules create mode 100644 LICENCE create mode 100644 Makefile create mode 160000 dpf create mode 100644 plugin/DistrhoPluginInfo.h create mode 100644 plugin/Makefile create mode 100644 plugin/ic1.cpp create mode 100644 plugin/ic1.hpp create mode 100644 plugin/peacock.cpp create mode 100644 plugin/peacock.hpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..924d963 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dpf"] + path = dpf + url = https://github.com/DISTRHO/DPF diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..538859e --- /dev/null +++ b/LICENCE @@ -0,0 +1,7 @@ +ISC License + +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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..051d16e --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +############################### +# +# Makefile for Peacock +# based on the work of falkTX +# +# for full licence, see LICENCE in the root of the project +# +############################### + +include dpf/Makefile.base.mk + +all: plugins gen + +plugins: + $(MAKE) all -C plugin + +ifneq ($(CROSS_COMPILING),true) +gen: plugins dpf/utils/lv2_ttl_generator + @$(CURDIR)/dpf/utils/generate-ttl.sh +ifeq ($(MACOS),true) + @$(CURDIR)/dpf/utils/generate-vst-bundles.sh +endif + +dpf/utils/lv2_ttl_generator: + $(MAKE) -C dpf/utils/lv2-ttl-generator +else +gen: +endif + +clean: + $(MAKE) clean -C dpf/utils/lv2-ttl-generator + $(MAKE) clean -C plugin + rm -rf bin build + +.PHONY: plugins diff --git a/dpf b/dpf new file mode 160000 index 0000000..f581516 --- /dev/null +++ b/dpf @@ -0,0 +1 @@ +Subproject commit f5815166356e85a5fe244f6024c2e401f04b10fa diff --git a/plugin/DistrhoPluginInfo.h b/plugin/DistrhoPluginInfo.h new file mode 100644 index 0000000..2bd3b6c --- /dev/null +++ b/plugin/DistrhoPluginInfo.h @@ -0,0 +1,33 @@ +/* + 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. +*/ + +#ifndef DISTRHO_PLUGIN_INFO_H +#define DISTRHO_PLUGIN_INFO_H + +#define DISTRHO_PLUGIN_NAME "peacock-8" +#define DISTRHO_PLUGIN_URI "https://gjcp.net/plugins/peacock" + +#define DISTRHO_PLUGIN_NUM_INPUTS 0 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 +#define DISTRHO_PLUGIN_IS_SYNTH 1 +#define DISTRHO_PLUGIN_IS_RT_SAFE 1 + +// +#define DISTRHO_PLUGIN_WANT_PROGRAMS 0 + +#endif diff --git a/plugin/Makefile b/plugin/Makefile new file mode 100644 index 0000000..540f73b --- /dev/null +++ b/plugin/Makefile @@ -0,0 +1,22 @@ +############################### +# +# Makefile for Peacock +# based on the work of falkTX, in the DPF example plugins +# +# for full licence, see LICENCE in the root of the project +# +############################### + +NAME = peacock + +FILES_DSP = \ + peacock.cpp \ + ic1.cpp + +include ../dpf/Makefile.plugins.mk + +TARGETS += jack lv2 + +all: $(TARGETS) + + diff --git a/plugin/ic1.cpp b/plugin/ic1.cpp new file mode 100644 index 0000000..794de7b --- /dev/null +++ b/plugin/ic1.cpp @@ -0,0 +1,91 @@ +/* + 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 "ic1.hpp" + +#include "peacock.hpp" + +Assigner::Assigner() { + // set up the assigner + for (uint8_t i = 0; i < NUM_VOICES; i++) { + voicemap[i] = 0x80 + i; + keymap[i] = 0x3c | 0x80; + } +} + +void Assigner::handleMidi(const MidiEvent *ev) { + // + uint8_t status = ev->data[0]; + switch (status & 0xf0) { + case 0x80: + noteOff(ev->data[1]); + break; + case 0x90: + noteOn(ev->data[1]); + break; + default: + printf("handle event, status %02x value %02x\n", ev->data[0], ev->data[1]); + break; + } +} +void Assigner::noteOff(uint8_t note) { + // Poly 1 note off + d_debug("Note Off %02x", note); + for (uint8_t i = 0; i < NUM_VOICES; i++) { + if (keymap[i] == note) { + d_debug("Found note at slot %02x, moving to last", i); + uint8_t voice = voicemap[i]; // save the voice + memmove(voicemap + i, voicemap + i + 1, NUM_VOICES - i - 1); + memmove(keymap + i, keymap + i + 1, NUM_VOICES - i - 1); + voicemap[NUM_VOICES - 1] = voice; + keymap[NUM_VOICES - 1] = note | 0x80; + } + } + /* + printf("note memory:\n"); + for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]); + printf("\n"); + for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", keymap[i]); + printf("\n"); + */ +} +void Assigner::noteOn(uint8_t note) { + // Poly 1 assigner + + // scan for the same note + for (uint8_t i = 0; i < NUM_VOICES; i++) { + if ((keymap[i] & 0x7f) == note) { + keymap[i] &= 0x7f; // show note as on + d_debug("voice %02x on in slot %02x, existing note %02x", voicemap[i], i, keymap[i]); + return; + } + } + + // note is not in the queue, assign a new voice + for (uint8_t i = 0; i < NUM_VOICES; i++) { + if (keymap[i] & 0x80) { + // voice is free + keymap[i] = note; + d_debug("voice %02x on in slot %02x, setting note %02x", voicemap[i], i, keymap[i]); + return; + } + } + + d_debug("unable to allocate a voice for note %02x\n", note); + +} diff --git a/plugin/ic1.hpp b/plugin/ic1.hpp new file mode 100644 index 0000000..bf9d759 --- /dev/null +++ b/plugin/ic1.hpp @@ -0,0 +1,34 @@ +/* + 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" + +class Assigner { + public: + Assigner(); + void handleMidi(const MidiEvent *ev); + + private: + void noteOn(uint8_t note); + void noteOff(uint8_t note); + + void voiceAssign(uint8_t a, uint8_t b, uint8_t c); + + uint8_t keymap[NUM_VOICES]; + uint8_t voicemap[NUM_VOICES]; +}; diff --git a/plugin/peacock.cpp b/plugin/peacock.cpp new file mode 100644 index 0000000..7a86bcf --- /dev/null +++ b/plugin/peacock.cpp @@ -0,0 +1,46 @@ +/* + 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" + +START_NAMESPACE_DISTRHO + +Assigner ic1; + +Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) { +} + +void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) { + // no content yet + // dispose of parameters + (void)outputs; + (void)frames; + + //printf("got %d MIDI events\n", midiEventCount); + for(uint32_t i=0; i + + 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. +*/ + +#pragma once + +#define NUM_VOICES 8 +#define DEBUG + +#include "DistrhoPlugin.hpp" + +START_NAMESPACE_DISTRHO + + +class Peacock : public Plugin { + public: + enum Parameters { + paramCount + }; + + Peacock(); + + protected: + + float sampleRate; + + const char *getLabel() const override { return "peacock-8"; } + const char *getDescription() const override { + return "simple polysynth"; + } + const char *getMaker() const override { return "Gordonjcp"; } + const char *getLicense() const override { return "ISC"; } + uint32_t getVersion() const override { return d_version(1, 0, 0); } + int64_t getUniqueId() const override { return d_cconst('P', 'f', 'a', 'u'); } + + // Initialisation + //void initAudioPort(bool input, uint32_t index, AudioPort &port) override; + //void initParameter(uint32_t index, Parameter ¶meter) override; + + //void setParameterValue(uint32_t index, float value) override; + //float getParameterValue(uint32_t index) const override; + + // Processing + //void activate() override; + //void deactivate() override; + void run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) override; + + + private: + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock); +}; + +END_NAMESPACE_DISTRHO +