![]() |
Klang C++ 0.7.15
Language Reference (draft)
|
Language Guide / Plugin Architecture
klang::Stereo::Synth
Base class for polyphonic stereo synthesisers.
Use Stereo::Note for voices that render two channels. Register them in the synth’s note pool just as you would for a mono synth. Inside a Stereo::Synth subclass, use Mono::Note for a mono voice whose output should feed both channels.
Stereo::Synth inherits the Plugin interface through Stereo::Effect. Use controls to expose patch parameters such as filter cutoff or attack time, and presets to provide named patches.
Inside the synth class, Mono::Note selects the mono-voice adapter. Each voice generates one sample, and the adapter adds that sample to both channels of the stereo mix. The inherited note-off behaviour stops the voice.
struct StereoOrgan : Stereo::Synth {
struct Voice : Mono::Note {
Sine sine;
event on(Pitch pitch, Amplitude velocity) {
sine.set(pitch -> Frequency);
}
void process() {
sine * 0.1 >> out;
}
};
StereoOrgan() {
notes.add<Voice>(8);
}
};Inside the synth class, Note selects its stereo note type. Each voice writes its left and right outputs separately. This example detunes the right oscillator slightly to give the voice stereo width.
struct WideOrgan : Stereo::Synth {
struct Voice : Note {
Sine left, right;
event on(Pitch pitch, Amplitude velocity) {
const param hz = pitch -> Frequency;
left.set(hz);
right.set(hz * 1.003);
}
void process() {
left * 0.1 >> out.l;
right * 0.1 >> out.r;
}
};
WideOrgan() {
notes.add<Voice>(8);
}
};After summing the voices, the synth feeds the combined left and right signals to its own effect stage. Its process() reads the mix through in.l and in.r and writes the final output to out.l and out.r. This uses exactly the same form as a Stereo::Effect.
Here the synth filters the complete stereo mix with independent history for each channel. The stereo note’s internals are abbreviated from the earlier example.
struct FilteredStereoOrgan : Stereo::Synth {
struct Voice : Note { /* ... */ };
FilteredStereoOrgan() {
notes.add<Voice>(8);
}
LPF leftFilter, rightFilter;
void process() {
in.l >> leftFilter(2000, 0.707) >> out.l;
in.r >> rightFilter(2000, 0.707) >> out.r;
}
};See also Synth.
Synthesier mini-plugin (stereo) More...
#include <klang.h>
Inheritance diagram for klang::Stereo::Synth:Classes | |
| struct | Mono |
| struct | Notes |
| Synthesiser note array (stereo) More... | |
Public Types | |
| typedef Stereo::Note | Note |
Public Member Functions | |
| Synth () | |
| virtual | ~Synth () |
| int | indexOf (Note *note) const |
| virtual event | onControl (int index, float value) override |
| virtual event | onMIDI (int status, int byte1, int byte2) override |
| virtual event | onPreset (int index) override |
| virtual event | noteOn (int pitch, float velocity) |
| virtual event | noteOff (int pitch, float velocity) |
| virtual event | allNotesOff (float velocity=0.f) |
| virtual void | process () override |
| virtual void | process (buffer buffer) override |
| virtual bool | playing () const |
| virtual void | process (float **buffers, int length, float *parameters=nullptr) |
| virtual void | prepare () |
| virtual void | process (interleaved::buffer buffer) |
| Process interleaved host frames; inherited by the current Stereo::Sound. | |
| operator const signal & () override | |
| operator const signal & () const override | |
| Modifier< signal > & | operator() (params &&... p) |
| virtual const signal & | input () const |
| virtual void | input (const signal &source) |
| virtual void | operator<< (const signal &source) |
| virtual const signal & | output () const |
| TYPE & | operator>> (TYPE &destination) |
| signal | operator+ (TYPE &other) |
| signal | operator* (TYPE &other) |
| signal | operator- (TYPE &other) |
| signal | operator/ (TYPE &other) |
| void | reset () |
Static Public Member Functions | |
| template<typename DERIVED , typename... ARGS> | |
| static DERIVED * | Create (ARGS &&... args) |
Public Attributes | |
| klang::Stereo::Synth::Notes | notes |
| Controls | controls |
| Presets | presets |
| signal | in |
| signal | out |
| struct klang::Stereo::Synth::Mono |
|
inline |
|
inlinevirtual |
|
inlinevirtual |
|
inlineprotectedvirtualinherited |
|
inlinestaticinherited |
|
inline |
|
inlineprotectedvirtualinherited |
Reimplemented in klang::Debug, klang::Delay< SIZE >, klang::Delay< 0 >, klang::Generic::Function< signal, Args... >, klang::Generic::Graph< SIZE >::Series, and klang::Modifiers::Modal.
Definition at line 2955 of file klang.h.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
|
inlineprotectedvirtualinherited |
|
inlinevirtual |
|
inlinevirtual |
|
inlineoverridevirtual |
Reimplemented from klang::Controller.
|
inlineoverridevirtual |
Reimplemented from klang::Controller.
|
inlineoverridevirtual |
Reimplemented from klang::Controller.
|
inlineoverridevirtualinherited |
|
inlineoverridevirtualinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlinevirtualinherited |
Reimplemented in klang::Debug.
|
inlineinherited |
|
inlinevirtualinherited |
|
inlinevirtual |
|
inlinevirtualinherited |
|
inlineprotectedvirtualinherited |
|
inlinevirtualinherited |
Reimplemented in klang::Stereo::Sound.
Definition at line 6080 of file klang.h.
References klang::Debug::buffer, klang::debug, and klang::Stereo::buffer::finished().
|
inlineoverridevirtual |
Reimplemented from klang::Stereo::Effect.
|
inlineoverridevirtual |
Reimplemented from klang::Stereo::Effect.
Definition at line 6216 of file klang.h.
|
inlinevirtual |
Definition at line 6225 of file klang.h.
References klang::Stereo::Note::process(), klang::NoteBase< SYNTH >::stage, and klang::NoteBase< SYNTH >::stop().
|
inlineinherited |
|
inherited |
Definition at line 2944 of file klang.h.
Referenced by klang::Generic::Graph< SIZE >::Series::input(), klang::Generic::Graph< SIZE >::Series::operator!=(), and klang::Generic::Graph< SIZE >::Series::operator==().
| klang::Stereo::Synth::Notes klang::Stereo::Synth::notes |
|
inherited |