Vital
Loading...
Searching...
No Matches
sound_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include "circular_queue.h"
4#include "synth_module.h"
5#include "note_handler.h"
6
7class LineGenerator;
8class Tuning;
9
10namespace vital {
11 class Decimator;
12 class PeakMeter;
13 class Sample;
14 class ReorderableEffectChain;
15 class StereoMemory;
16 class SynthVoiceHandler;
17 class SynthLfo;
18 class Value;
19 class ValueSwitch;
20 class WaveFrame;
21 class Wavetable;
22
33 class SoundEngine : public SynthModule, public NoteHandler {
34 public:
38 static constexpr int kDefaultOversamplingAmount = 2;
39
43 static constexpr int kDefaultSampleRate = 44100;
44
49
53 virtual ~SoundEngine();
54
61 void init() override;
62
67 void process(int num_samples) override;
68
73 void correctToTime(double seconds) override;
74
80
86
92
98
104
110
115 void setTuning(const Tuning* tuning);
116
120 void allSoundsOff() override;
121
126 void allNotesOff(int sample) override;
127
133 void allNotesOff(int sample, int channel) override;
134
141 void allNotesOffRange(int sample, int from_channel, int to_channel);
142
150 void noteOn(int note, mono_float velocity, int sample, int channel) override;
151
159 void noteOff(int note, mono_float lift, int sample, int channel) override;
160
166 void setModWheel(mono_float value, int channel);
167
173
179 void setPitchWheel(mono_float value, int channel);
180
187 void setZonedPitchWheel(mono_float value, int from_channel, int to_channel);
188
193
198 void enableModSource(const std::string& source);
199
204 void disableModSource(const std::string& source);
205
211 bool isModSourceEnabled(const std::string& source);
212
218
224
232 void setAftertouch(mono_float note, mono_float value, int sample, int channel);
233
240 void setChannelAftertouch(int channel, mono_float value, int sample);
241
249 void setChannelRangeAftertouch(int from_channel, int to_channel, mono_float value, int sample);
250
257 void setChannelSlide(int channel, mono_float value, int sample);
258
266 void setChannelRangeSlide(int from_channel, int to_channel, mono_float value, int sample);
267
274
280
287
292 void sustainOn(int channel);
293
299 void sustainOff(int sample, int channel);
300
305 void sostenutoOn(int channel);
306
312 void sostenutoOff(int sample, int channel);
313
319 void sustainOnRange(int from_channel, int to_channel);
320
327 void sustainOffRange(int sample, int from_channel, int to_channel);
328
334 void sostenutoOnRange(int from_channel, int to_channel);
335
342 void sostenutoOffRange(int sample, int from_channel, int to_channel);
343
348 force_inline int getOversamplingAmount() const { return last_oversampling_amount_; }
349
354
355 private:
361 void setOversamplingAmount(int oversampling_amount, int sample_rate);
362
363 SynthVoiceHandler* voice_handler_;
364 ReorderableEffectChain* effect_chain_;
365 Add* output_total_;
366
367 int last_oversampling_amount_;
368 int last_sample_rate_;
369 Value* oversampling_;
370 Value* bps_;
371 Value* legato_;
372 Decimator* decimator_;
373 PeakMeter* peak_meter_;
374
375 CircularQueue<Processor*> modulation_processors_;
376
377 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SoundEngine)
378 };
379} // namespace vital
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
A class for managing microtonal tunings and custom pitch mappings in Vital.
Definition tuning.h:23
Adds two input buffers sample-by-sample.
Definition operators.h:205
A generic circular buffer (FIFO) data structure that allows adding and removing elements efficiently.
Definition circular_queue.h:32
A ProcessorRouter that intelligently reduces audio sample rate based on configured stages.
Definition decimator.h:19
A container managing a fixed number of ModulationConnections.
Definition synth_types.h:87
An interface for handling MIDI note events within a synthesizer or audio system.
Definition note_handler.h:16
A processor that computes both instantaneous peak and a "memory peak" of an incoming audio signal.
Definition peak_meter.h:27
A module that manages a chain of audio effects whose order can be dynamically changed.
Definition reorderable_effect_chain.h:17
Holds and manages a single sampled waveform, including stereo or mono data and multiple band-limited ...
Definition sample_source.h:25
Core class responsible for handling note events, oversampling, and the main effects chain.
Definition sound_engine.h:33
void setModWheelAllChannels(mono_float value)
Sets the modulation wheel value for all channels.
void setPitchWheel(mono_float value, int channel)
Sets the pitch wheel value for a given channel.
LineGenerator * getLfoSource(int index)
Gets a pointer to an LFO source by index.
void sustainOnRange(int from_channel, int to_channel)
Turns sustain on for a range of channels.
Wavetable * getWavetable(int index)
Gets a pointer to a wavetable by index.
void sustainOn(int channel)
Turns sustain on for a given channel.
void correctToTime(double seconds) override
Corrects internal timing to a given absolute time in seconds.
void sostenutoOff(int sample, int channel)
Turns sostenuto off for a given channel at a specific sample.
void process(int num_samples) override
Processes a block of samples through the voice handler and effects chain.
Definition sound_engine.cpp:234
void allSoundsOff() override
Turns off all sounds immediately.
void setChannelAftertouch(int channel, mono_float value, int sample)
Sets aftertouch values for an entire channel.
void sostenutoOnRange(int from_channel, int to_channel)
Turns sostenuto on for a range of channels.
void allNotesOff(int sample) override
Sends all voices a note-off command at a given sample.
static constexpr int kDefaultOversamplingAmount
Default oversampling factor.
Definition sound_engine.h:37
bool isModSourceEnabled(const std::string &source)
Checks if a modulation source is enabled.
SoundEngine()
Constructs a new SoundEngine instance.
void setZonedPitchWheel(mono_float value, int from_channel, int to_channel)
Sets the pitch wheel value for a range of channels.
void disconnectModulation(const modulation_change &change)
Disconnects a previously connected modulation source from its destination.
void checkOversampling()
Checks if the oversampling settings have changed and updates accordingly.
void setOversamplingAmount(int oversampling_amount, int sample_rate)
Configures the engine’s oversampling factor and sample rate.
Definition sound_engine.cpp:272
void sostenutoOn(int channel)
Turns sostenuto on for a given channel.
void setChannelSlide(int channel, mono_float value, int sample)
Sets channel-based slide (MPE/MIDI CC glides).
ModulationConnectionBank & getModulationBank()
Gets the modulation connection bank for this engine.
int getNumActiveVoices()
Gets the number of currently active voices.
static constexpr int kDefaultSampleRate
Default sample rate used before explicit configuration.
Definition sound_engine.h:42
void sustainOffRange(int sample, int from_channel, int to_channel)
Turns sustain off for a range of channels at a given sample.
void setTuning(const Tuning *tuning)
Sets the tuning to use for pitch calculations.
void setChannelRangeSlide(int from_channel, int to_channel, mono_float value, int sample)
Sets slide values for a range of channels.
void noteOn(int note, mono_float velocity, int sample, int channel) override
Triggers a note-on event.
void setChannelRangeAftertouch(int from_channel, int to_channel, mono_float value, int sample)
Sets aftertouch values for a range of channels.
void enableModSource(const std::string &source)
Enables a modulation source by name.
void disableUnnecessaryModSources()
Disables any modulation sources that are not required.
const StereoMemory * getEqualizerMemory()
Gets a pointer to the stereo memory used by the equalizer.
void connectModulation(const modulation_change &change)
Connects a modulation source to its destination.
void sustainOff(int sample, int channel)
Turns sustain off for a given channel at a specific sample.
force_inline int getOversamplingAmount() const
Gets the current oversampling amount.
Definition sound_engine.h:348
Sample * getSample()
Gets a pointer to the Sample object.
void init() override
Initializes the SoundEngine, setting up controls, voices, and effects.
mono_float getLastActiveNote() const
Gets the last active note played.
void allNotesOffRange(int sample, int from_channel, int to_channel)
Sends all voices in a range of channels a note-off command.
void allNotesOff(int sample, int channel) override
Sends all voices on a given channel a note-off command.
void setModWheel(mono_float value, int channel)
Sets the modulation wheel value for a given channel.
void disableModSource(const std::string &source)
Disables a modulation source by name.
void sostenutoOffRange(int sample, int from_channel, int to_channel)
Turns sostenuto off for a range of channels at a given sample.
int getNumPressedNotes()
Gets the number of currently pressed notes.
void setBpm(mono_float bpm)
Sets the BPM (beats per minute) value for the engine.
void noteOff(int note, mono_float lift, int sample, int channel) override
Triggers a note-off event.
virtual ~SoundEngine()
Destroys the SoundEngine instance.
void setAftertouch(mono_float note, mono_float value, int sample, int channel)
Sets note-based aftertouch values.
A specialized MemoryTemplate for two-channel (stereo) audio.
Definition memory.h:216
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Manages per-voice processing of audio signals within the Vital synthesizer.
Definition synth_voice_handler.h:31
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain rep...
Definition wavetable.h:20
#define force_inline
Definition common.h:23
Contains classes and functions used within the Vital synthesizer framework.
float mono_float
Definition common.h:33
A structure describing changes to the modulation routing in the engine.
Definition synth_types.h:199
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...