Language Guide / Plugin Architecture
Note
klang::Note
Base class for a mono synth voice.
A note owns the DSP state for a single voice. Initialise that state in on(Pitch, Amplitude) when a note starts. Use off(Amplitude) to begin the release stage, and call stop() when the voice is finished so the synth can reuse it.
Example · Play a sine voice
Set the oscillator’s pitch when the note starts and write one sample to out each time it processes. This voice uses the inherited note-off behaviour, which stops it immediately.
struct SineVoice : Note {
Sine sine;
event on(Pitch pitch, Amplitude velocity) {
sine.set(pitch -> Frequency);
}
void process() {
sine * 0.1 >> out;
}
};
Example · Release a voice with an envelope
These methods belong in a Note subclass with a configured Sine sine; and ADSR adsr;.
event off(Amplitude velocity) {
adsr.release();
}
void process() {
sine * adsr >> out;
if (adsr.finished())
stop();
}
Synthesiser note (mono)
More...
#include <klang.h>
Definition at line 5633 of file klang.h.
◆ Stage
Definition at line 5625 of file klang.h.
enum klang::NoteBase::Stage stage
◆ attach()
Definition at line 5590 of file klang.h.
5590 {
5591 NoteBase::synth = synth;
5594 }
◆ control()
| virtual event klang::Controller::control |
( |
int | index, |
|
|
float | value ) |
|
inlineprotectedvirtualinherited |
◆ controlChange()
Definition at line 5627 of file klang.h.
5627{
midi(0xB0, controller, value); };
virtual event midi(int status, int byte1, int byte2)
◆ finished()
◆ getSynth()
Definition at line 5581 of file klang.h.
5581{ return static_cast<std::remove_pointer_t<decltype(synth)>*>(synth); }
◆ init()
◆ midi()
| virtual event klang::Controller::midi |
( |
int | status, |
|
|
int | byte1, |
|
|
int | byte2 ) |
|
inlineprotectedvirtualinherited |
◆ off()
|
|
inlineprotectedvirtualinherited |
◆ on()
|
|
inlineprotectedvirtualinherited |
◆ onControl()
| virtual void klang::Controller::onControl |
( |
int | index, |
|
|
float | value ) |
|
inlinevirtualinherited |
◆ onMIDI()
| virtual void klang::Controller::onMIDI |
( |
int | status, |
|
|
int | byte1, |
|
|
int | byte2 ) |
|
inlinevirtualinherited |
◆ onPreset()
| virtual void klang::Controller::onPreset |
( |
int | index | ) |
|
|
inlinevirtualinherited |
◆ operator const signal &() [1/2]
|
|
inlineoverridevirtualinherited |
◆ operator const signal &() [2/2]
|
|
inlineoverridevirtualinherited |
◆ operator()()
Definition at line 3050 of file klang.h.
3050 {
3051 set(std::forward<params>(p)...); return *this;
3052 }
◆ operator*()
◆ operator+()
◆ operator-()
◆ operator/()
◆ operator>>()
◆ output()
◆ prepare()
| virtual void klang::Note::prepare |
( |
| ) |
|
|
inlinevirtual |
◆ preset()
| virtual event klang::Controller::preset |
( |
int | index | ) |
|
|
inlineprotectedvirtualinherited |
◆ process() [1/3]
| virtual void klang::Note::process |
( |
| ) |
|
|
overridepure virtual |
◆ process() [2/3]
| virtual bool klang::Note::process |
( |
buffer * | buffer | ) |
|
|
inlinevirtual |
Definition at line 5647 of file klang.h.
5647 {
5648 return this->
process(buffer[0]);
5649 }
virtual void process() override=0
◆ process() [3/3]
| virtual bool klang::Note::process |
( |
buffer | buffer | ) |
|
|
inlinevirtual |
◆ release()
Definition at line 5606 of file klang.h.
5606 {
5608 return true;
5609
5613 }
5614
5616 }
virtual event off(Velocity v=0)
◆ reset()
◆ start()
Definition at line 5598 of file klang.h.
5598 {
5604 }
virtual event on(Pitch p, Velocity v)
◆ stop()
Definition at line 5618 of file klang.h.
5618 {
5620 return true;
5621 }
◆ controls
◆ out
◆ pitch
◆ stage
◆ velocity