initial import, just shows debug info

This commit is contained in:
Gordon JC Pearce 2025-08-22 21:25:16 +01:00
commit 1ef2cc9965
10 changed files with 417 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 @@
###############################
#
# tonewheel plugin makefile
# 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,36 @@
/*
tonewheel organ plugin
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 "tonewheel"
#define DISTRHO_PLUGIN_URI "https://gjcp.net/plugins/tonewheel"
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_HAS_UI 0
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_WANT_PROGRAMS 0
#define DISTRHO_PLUGIN_IS_SYNTH 1
#define NUM_VOICES 8
#endif

19
plugin/Makefile Normal file
View File

@ -0,0 +1,19 @@
###############################
#
# tonewheel organ plugin
# based on the work of falkTX
#
# for full licence, see LICENCE in the root of the project
#
###############################
NAME = tonewheel
FILES_DSP = assigner.cpp tonewheel.cpp
include ../dpf/Makefile.plugins.mk
TARGETS += vst2 vst3 jack lv2_dsp
all: $(TARGETS)

141
plugin/assigner.cpp Normal file
View File

@ -0,0 +1,141 @@
/*
tonewheel organ plugin
Copyright 2025 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 "assigner.hpp"
#define DEBUG
void Assigner::dumpTables() {
#ifdef DEBUG
printf("table state is:\n");
for (uint8_t i = 0; i < NUM_VOICES; i++) {
uint8_t e = voiceTbl[i];
uint8_t a = noteTbl[e];
printf("%2d=%3d%c ", e, a & 0x7f, (a & 0x80) ? '^' : 'v');
}
printf("\n");
#endif
}
Assigner::Assigner() {
d_debug("assigner constructor");
// set up the assigner tables
for (uint8_t i = 0; i < NUM_VOICES; i++) {
voiceTbl[i] = i;
noteTbl[i] = 0x80;
}
}
void Assigner::handleMidi(MidiEvent *ev) {
uint8_t status = ev->data[0];
switch (status & 0xf0) {
case 0x80:
noteOff(ev->data[1]);
dumpTables();
break;
case 0x90:
// dumpTables();
noteOn(ev->data[1]);
dumpTables();
break;
case 0xb0:
switch (ev->data[1]) {
// maybe handle the following
// CC 1 - modwheel
// CC 64 - sustain
default:
break;
}
break; // nothing to do here except in special cases where we don't expect the host to pass on controls
case 0xc0: // program change
break;
case 0xe0: // pitch bend;
break;
case 0xf0: // sysex
break;
default:
d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]);
break;
}
}
void Assigner::noteOff(uint8_t note) {
d_debug("note off %3d", note);
uint8_t i, v;
// scan for note in table
for (i = 0; i < NUM_VOICES; i++) {
if ((noteTbl[voiceTbl[i]] & 0x7f) == note) break;
}
if (i == NUM_VOICES) return; // got note off for note that isn't in the table
// get the voice at this slot
// then move the rest down and place this at the end
// and mark the note for this voice as "off" by setting bit 7
v = voiceTbl[i];
memmove(voiceTbl + i, voiceTbl + i + 1, NUM_VOICES - i - 1);
voiceTbl[NUM_VOICES - 1] = v;
noteTbl[v] |= 0x80;
}
void Assigner::noteOn(uint8_t note) {
d_debug("note on %3d", note);
int8_t i, a, v;
// don't even attempt to steal voices
// by overwriting the last voice in the table
// we could actually do voice stealing
if ((noteTbl[voiceTbl[NUM_VOICES - 1]] & 0x80) == 0x00) {
d_debug("note table full");
return;
}
// loop around the voices
for (i = NUM_VOICES - 1; i >= 0; i--) {
v = voiceTbl[i];
a = noteTbl[v];
// if this note is playing we've gone too far
// we need to back up a slot and consider it for use
if ((a & 0x80) == 0) {
i++;
// shunt them all up to the end
v = voiceTbl[i];
memmove(voiceTbl + 1, voiceTbl, i);
voiceTbl[0] = v;
break; // note is already playing in table
}
if ((a & 0x7f) == note) {
memmove(voiceTbl + 1, voiceTbl, i);
voiceTbl[0] = v;
a &= 0x7f;
break;
}
}
noteTbl[v] = note;
// limit lowest note to C2 and highest note to C7
while(note>96) note -= 12;
while(note<36) note += 12;
d_debug("send voice on note %3d to voice %d", note, v);
}

38
plugin/assigner.hpp Normal file
View File

@ -0,0 +1,38 @@
/*
tonewheel organ plugin
Copyright 2025 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 _ASSIGNER_HPP
#define _ASSIGNER_HPP
#include "DistrhoPlugin.hpp"
class Assigner {
public:
Assigner();
void handleMidi(MidiEvent *ev);
private:
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
void noteOff(uint8_t note); // incoming note off
void dumpTables();
uint8_t voiceTbl[NUM_VOICES]; // voices in order of use
uint8_t noteTbl[NUM_VOICES]; // note played by voice
};
#endif

63
plugin/tonewheel.cpp Normal file
View File

@ -0,0 +1,63 @@
/*
tonewheel organ plugin
Copyright 2025 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 "tonewheel.hpp"
double sampleRate;
uint32_t bufferSize;
START_NAMESPACE_DISTRHO
Tonewheel::Tonewheel() : Plugin(kParameterCount, 0, 0) {
assigner = new Assigner;
}
Tonewheel::~Tonewheel() {
delete assigner;
}
void Tonewheel::initAudioPort(bool input, uint32_t index, AudioPort& port) {
port.groupId = kPortGroupStereo;
Plugin::initAudioPort(input, index, port);
if (!input && index == 0) port.symbol = "Left";
if (!input && index == 1) port.symbol = "Right";
}
void Tonewheel::activate() {
sampleRate = getSampleRate();
bufferSize = getBufferSize();
printf("In activate, bufSz=%d smpRt=%f\n", bufferSize, sampleRate);
}
void Tonewheel::deactivate() {
}
void Tonewheel::run(const float**, float** outputs, uint32_t frames,
const MidiEvent* ev, uint32_t evCount) {
(void) frames;
(void) outputs;
for (uint32_t i = 0; i < evCount; i++) {
assigner->handleMidi((MidiEvent*)&ev[i]);
}
}
Plugin* createPlugin() { return new Tonewheel(); }
END_NAMESPACE_DISTRHO

74
plugin/tonewheel.hpp Normal file
View File

@ -0,0 +1,74 @@
/*
tonewheel organ plugin
Copyright 2025 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 TONEWHEEL_HPP
#define TONEWHEEL_HPP
#include "DistrhoPlugin.hpp"
#include "assigner.hpp"
START_NAMESPACE_DISTRHO
class Program {
public:
float viola = 0, violin = 0, bassVolume = 0;
float attack, sustain;
};
class Tonewheel : public Plugin {
public:
enum Parameters {
kParameterCount
};
Tonewheel();
~Tonewheel();
protected:
const char *getLabel() const override { return "tonewheel"; }
const char *getDescription() const override {
return "toy tonewheel organ";
}
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('T', '0', 'N', 'E'); }
//void initParameter(uint32_t index, Parameter &parameter) override;
//void setParameterValue(uint32_t index, float value) override;
//float getParameterValue(uint32_t index) const override;
// Initialisation
void initAudioPort(bool input, uint32_t index, AudioPort &port) 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:
Assigner *assigner;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Tonewheel);
};
END_NAMESPACE_DISTRHO
#endif // TONEWHEEL_HPP