reasonable key assigner

This commit is contained in:
Gordon JC Pearce 2024-10-09 22:10:51 +01:00
commit 332b18220f
10 changed files with 341 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "dpf"]
path = dpf
url = https://github.com/DISTRHO/DPF

7
LICENCE Normal file
View File

@ -0,0 +1,7 @@
ISC License
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.

35
Makefile Normal file
View File

@ -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

1
dpf Submodule

@ -0,0 +1 @@
Subproject commit f5815166356e85a5fe244f6024c2e401f04b10fa

View File

@ -0,0 +1,33 @@
/*
Peacock-8 VA polysynth
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.
*/
#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

22
plugin/Makefile Normal file
View File

@ -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)

91
plugin/ic1.cpp Normal file
View File

@ -0,0 +1,91 @@
/*
Peacock-8 VA polysynth
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 "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);
}

34
plugin/ic1.hpp Normal file
View File

@ -0,0 +1,34 @@
/*
Peacock-8 VA polysynth
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 "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];
};

46
plugin/peacock.cpp Normal file
View File

@ -0,0 +1,46 @@
/*
Peacock-8 VA polysynth
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 "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<midiEventCount; i++) {
ic1.handleMidi((const MidiEvent *) &midiEvents[i]);
}
}
Plugin *createPlugin() { return new Peacock(); }
END_NAMESPACE_DISTRHO

69
plugin/peacock.hpp Normal file
View File

@ -0,0 +1,69 @@
/*
Peacock-8 VA polysynth
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.
*/
#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 &parameter) 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