Vital
Loading...
Searching...
No Matches
sample_module.cpp
Go to the documentation of this file.
1#include "sample_module.h"
2#include "synth_constants.h"
3
4namespace vital {
5
9 SampleModule::SampleModule() : SynthModule(kNumInputs, kNumOutputs), on_(nullptr) {
10 sampler_ = new SampleSource();
11 was_on_ = std::make_shared<bool>(true);
12 }
13
21 on_ = createBaseControl("sample_on");
22 Value* random_phase = createBaseControl("sample_random_phase");
23 Value* loop = createBaseControl("sample_loop");
24 Value* bounce = createBaseControl("sample_bounce");
25 Value* keytrack = createBaseControl("sample_keytrack");
26 Value* transpose_quantize = createBaseControl("sample_transpose_quantize");
27 Output* transpose = createPolyModControl("sample_transpose");
28 Output* tune = createPolyModControl("sample_tune");
29 Output* level = createPolyModControl("sample_level", true, true);
30 Output* pan = createPolyModControl("sample_pan");
31
32 // Connect inputs to the sampler.
36
37 // Connect control parameters to the sampler.
47
48 // Map sampler outputs.
51
54 }
55
61 void SampleModule::process(int num_samples) {
62 bool on = on_->value();
63
64 if (on)
65 SynthModule::process(num_samples);
66 else if (*was_on_) {
67 // Clear outputs if we're turning off the sample.
70 getPhaseOutput()->buffer[0] = 0.0f;
71 }
72
73 *was_on_ = on;
74 }
75} // namespace vital
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
void useInput(Input *input)
Uses an existing Input object as this Processor's first input.
Definition processor.cpp:126
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
virtual void process(int num_samples)=0
Main processing function. Called by the ProcessorRouter.
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void init()
Called after constructor, used for any additional initialization. Subclasses can override....
Definition processor.h:258
virtual void addProcessor(Processor *processor)
Adds a Processor to be managed by this router.
Definition processor_router.cpp:121
Value * on_
Definition sample_module.h:90
@ kMidi
Definition sample_module.h:24
@ kReset
Definition sample_module.h:23
@ kNoteCount
Definition sample_module.h:25
force_inline Output * getPhaseOutput() const
Retrieves the phase output of the sampler.
Definition sample_module.h:85
void process(int num_samples) override
Processes a block of samples for the given number of samples.
Definition sample_module.cpp:61
@ kLevelled
Definition sample_module.h:35
@ kRaw
Definition sample_module.h:34
SampleSource * sampler_
Definition sample_module.h:89
std::shared_ptr< bool > was_on_
Definition sample_module.h:88
void init() override
Initializes the sample module by creating controls and plugging them into the sampler.
Definition sample_module.cpp:20
SampleModule()
Constructs a SampleModule.
Definition sample_module.cpp:9
A Processor that reads from a Sample object, providing audio output with controls for looping,...
Definition sample_source.h:214
@ kRandomPhase
If true, randomize phase on note start.
Definition sample_source.h:237
@ kLevel
Overall amplitude scale.
Definition sample_source.h:236
@ kKeytrack
Boolean-like input indicating if MIDI note should track pitch.
Definition sample_source.h:235
@ kTune
Fine-tune in cents.
Definition sample_source.h:240
@ kTransposeQuantize
Quantize transposition to scale or semitones.
Definition sample_source.h:239
@ kNoteCount
Tracks how many notes have been pressed.
Definition sample_source.h:244
@ kLoop
If non-zero, the sample loops.
Definition sample_source.h:241
@ kMidi
MIDI note input.
Definition sample_source.h:234
@ kPan
Stereo panning control.
Definition sample_source.h:243
@ kReset
Reset signal (trigger) to re-initialize playback.
Definition sample_source.h:233
@ kBounce
If non-zero, sample playback bounces (back/forth).
Definition sample_source.h:242
@ kTranspose
Transposition in semitones from the current note.
Definition sample_source.h:238
@ kRaw
The raw sample output (before final amplitude).
Definition sample_source.h:253
@ kLevelled
The amplitude-scaled output.
Definition sample_source.h:254
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Output * createPolyModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr, Input *reset=nullptr)
Creates a polyphonic mod control, including applying parameter scaling.
Definition synth_module.cpp:173
Value * createBaseControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a simple control processor for a given parameter name.
Definition synth_module.cpp:22
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
force_inline mono_float value() const
Returns the current mono_float value of the first lane.
Definition value.h:60
Contains classes and functions used within the Vital synthesizer framework.
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
void clearBuffer()
Zeros out the entire output buffer.
Definition processor.h:81
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110