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#include "tuning.h"
7
8class LineGenerator;
9
10namespace vital {
11 // Forward declarations
12 class PeakMeter;
13 class ReorderableEffectChain;
14 class EffectsModulationHandler;
15 class Sample;
16 class StereoMemory;
17 class SynthLfo;
18 class Upsampler;
19 class Value;
20 class ValueSwitch;
21 class Wavetable;
22
32 class SoundEngine : public SynthModule, public NoteHandler {
33 public:
37 static constexpr int kDefaultOversamplingAmount = 2;
38
42 static constexpr int kDefaultSampleRate = 44100;
43
48
52 virtual ~SoundEngine();
53
57 void init() override;
58
67 void processWithInput(const poly_float* audio_in, int num_samples) override;
68
74 void correctToTime(double seconds) override;
75
82
88 void connectModulation(const modulation_change& change);
89
95 void disconnectModulation(const modulation_change& change);
96
102 int getNumActiveVoices();
103
110
117
123 void setTuning(const Tuning* tuning);
124
131 void setOversamplingAmount(int oversampling_amount, int sample_rate);
132
136 void allSoundsOff() override;
137
143 void allNotesOff(int sample) override;
144
151 void allNotesOff(int sample, int channel) override;
152
160 void allNotesOffRange(int sample, int from_channel, int to_channel);
161
170 void noteOn(int note, mono_float velocity, int sample, int channel) override;
171
180 void noteOff(int note, mono_float lift, int sample, int channel) override;
181
188 void setModWheel(mono_float value, int channel);
189
196
203 void setPitchWheel(mono_float value, int channel);
204
212 void setZonedPitchWheel(mono_float value, int from_channel, int to_channel);
213
218
224 void enableModSource(const std::string& source);
225
231 void disableModSource(const std::string& source);
232
239 bool isModSourceEnabled(const std::string& source);
240
247
253 void setBpm(mono_float bpm);
254
263 void setAftertouch(mono_float note, mono_float value, int sample, int channel);
264
272 void setChannelAftertouch(int channel, mono_float value, int sample);
273
282 void setChannelRangeAftertouch(int from_channel, int to_channel, mono_float value, int sample);
283
291 void setChannelSlide(int channel, mono_float value, int sample);
292
301 void setChannelRangeSlide(int from_channel, int to_channel, mono_float value, int sample);
302
309 Wavetable* getWavetable(int index);
310
316 Sample* getSample();
317
324 LineGenerator* getLfoSource(int index);
325
331 void sustainOn(int channel);
332
339 void sustainOff(int sample, int channel);
340
346 void sostenutoOn(int channel);
347
354 void sostenutoOff(int sample, int channel);
355
362 void sustainOnRange(int from_channel, int to_channel);
363
371 void sustainOffRange(int sample, int from_channel, int to_channel);
372
379 void sostenutoOnRange(int from_channel, int to_channel);
380
388 void sostenutoOffRange(int sample, int from_channel, int to_channel);
389
395 force_inline int getOversamplingAmount() const { return last_oversampling_amount_; }
396
400 void checkOversampling();
401
402 private:
406 EffectsModulationHandler* modulation_handler_;
407
411 Upsampler* upsampler_;
412
416 ReorderableEffectChain* effect_chain_;
417
421 int last_oversampling_amount_;
422
426 int last_sample_rate_;
427
431 Value* oversampling_;
432
436 Value* bps_;
437
441 Value* legato_;
442
446 PeakMeter* peak_meter_;
447
451 CircularQueue<Processor*> modulation_processors_;
452
453 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SoundEngine)
454 };
455} // 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
A generic circular buffer (FIFO) data structure that allows adding and removing elements efficiently.
Definition circular_queue.h:32
A VoiceHandler extension managing various modulation sources for effects processing.
Definition effects_modulation_handler.h:33
A container managing a fixed number of ModulationConnections.
Definition synth_types.h:87
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 mod wheel value for all MIDI channels.
Definition sound_engine.cpp:395
void setPitchWheel(mono_float value, int channel)
Sets the pitch wheel value for a specified MIDI channel.
Definition sound_engine.cpp:405
LineGenerator * getLfoSource(int index)
Retrieves a pointer to the LFO source line generator for the given index.
Definition sound_engine.cpp:553
void sustainOnRange(int from_channel, int to_channel)
Engages sustain on a range of MIDI channels.
Definition sound_engine.cpp:601
Wavetable * getWavetable(int index)
Retrieves a pointer to a Wavetable by index (not implemented here).
Definition sound_engine.cpp:536
void sustainOn(int channel)
Engages sustain on a single MIDI channel (holding all pressed notes).
Definition sound_engine.cpp:562
void correctToTime(double seconds) override
Synchronizes all time-based modules to a given time, e.g. for timeline-based automation.
Definition sound_engine.cpp:314
void sostenutoOff(int sample, int channel)
Disengages sostenuto on a single MIDI channel.
Definition sound_engine.cpp:591
void allSoundsOff() override
Stops and resets all currently playing notes and any lingering states in the effect chain.
Definition sound_engine.cpp:322
void setChannelAftertouch(int channel, mono_float value, int sample)
Sets channel-wide aftertouch on a given channel.
Definition sound_engine.cpp:494
void sostenutoOnRange(int from_channel, int to_channel)
Engages sostenuto on a range of MIDI channels.
Definition sound_engine.cpp:622
void allNotesOff(int sample) override
Turns off all notes on all channels at the specified sample index.
Definition sound_engine.cpp:331
static constexpr int kDefaultOversamplingAmount
Default oversampling factor.
Definition sound_engine.h:37
bool isModSourceEnabled(const std::string &source)
Checks if a given named modulation source is currently enabled.
Definition sound_engine.cpp:451
SoundEngine()
Constructs a SoundEngine and initializes internal state and controls.
Definition sound_engine.cpp:20
void setZonedPitchWheel(mono_float value, int from_channel, int to_channel)
Applies a pitch wheel value to a range of MIDI channels.
Definition sound_engine.cpp:416
void disconnectModulation(const modulation_change &change)
Disconnects a previously established modulation route.
Definition sound_engine.cpp:195
void checkOversampling()
Checks if the oversampling setting or sample rate has changed, and reconfigures if needed.
Definition sound_engine.cpp:256
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)
Engages sostenuto on a single MIDI channel (holding only currently pressed notes).
Definition sound_engine.cpp:581
void setChannelSlide(int channel, mono_float value, int sample)
Sets channel slide (e.g., an expression or glide parameter) on a specific channel.
Definition sound_engine.cpp:517
ModulationConnectionBank & getModulationBank()
Provides access to the internal ModulationConnectionBank for managing mod routes.
Definition sound_engine.cpp:231
int getNumActiveVoices()
Returns the number of active voices in the engine.
Definition sound_engine.cpp:222
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)
Disengages sustain on a range of MIDI channels.
Definition sound_engine.cpp:612
void setTuning(const Tuning *tuning)
Sets a custom Tuning object for note-to-frequency mapping.
Definition sound_engine.cpp:249
void setChannelRangeSlide(int from_channel, int to_channel, mono_float value, int sample)
Applies channel slide to all channels in a specified range.
Definition sound_engine.cpp:529
void noteOn(int note, mono_float velocity, int sample, int channel) override
Handles a note-on event, triggering the engine’s voice handling.
Definition sound_engine.cpp:364
void setChannelRangeAftertouch(int from_channel, int to_channel, mono_float value, int sample)
Applies aftertouch to all channels in a specified range.
Definition sound_engine.cpp:506
void enableModSource(const std::string &source)
Enables a specific named modulation source by making its owner active.
Definition sound_engine.cpp:432
void disableUnnecessaryModSources()
Disables unnecessary modulation sources in the engine to save CPU.
Definition sound_engine.cpp:423
const StereoMemory * getEqualizerMemory()
Retrieves the internal equalizer memory (used for certain effect processing).
Definition sound_engine.cpp:460
void connectModulation(const modulation_change &change)
Connects a modulation source to a destination via the given modulation_change structure.
Definition sound_engine.cpp:152
void sustainOff(int sample, int channel)
Disengages sustain on a single MIDI channel, releasing notes if their keys are up.
Definition sound_engine.cpp:572
force_inline int getOversamplingAmount() const
Retrieves the current oversampling factor (e.g., 1, 2, 4).
Definition sound_engine.h:395
Sample * getSample()
Retrieves a pointer to a Sample object (not implemented here).
Definition sound_engine.cpp:543
virtual ~SoundEngine()
Destroys the SoundEngine, cleaning up submodules and modulation resources.
Definition sound_engine.cpp:35
void processWithInput(const poly_float *audio_in, int num_samples) override
Processes a block of samples using the current state of the SoundEngine.
Definition sound_engine.cpp:294
void init() override
Initializes the engine by creating base controls and submodules (effects chain, etc....
Definition sound_engine.cpp:42
mono_float getLastActiveNote() const
Retrieves the most recently active note number.
Definition sound_engine.cpp:240
void allNotesOffRange(int sample, int from_channel, int to_channel)
Turns off all notes within a range of channels.
Definition sound_engine.cpp:352
void setModWheel(mono_float value, int channel)
Sets the mod wheel value for a given MIDI channel.
Definition sound_engine.cpp:386
void disableModSource(const std::string &source)
Disables a specific named modulation source.
Definition sound_engine.cpp:441
void sostenutoOffRange(int sample, int from_channel, int to_channel)
Disengages sostenuto on a range of MIDI channels.
Definition sound_engine.cpp:633
int getNumPressedNotes()
Returns the number of currently pressed notes across all channels.
Definition sound_engine.cpp:188
void setBpm(mono_float bpm)
Updates the engine’s tempo in BPM, converting to beats per second for internal usage.
Definition sound_engine.cpp:469
void noteOff(int note, mono_float lift, int sample, int channel) override
Handles a note-off event, releasing the voice allocated to the note.
Definition sound_engine.cpp:376
void setAftertouch(mono_float note, mono_float value, int sample, int channel)
Sets polyphonic aftertouch for a specific note on a given channel.
Definition sound_engine.cpp:483
A specialized MemoryTemplate for two-channel (stereo) audio.
Definition memory.h:216
A simple upsampler that duplicates samples to increase the sample rate by an integral factor.
Definition upsampler.h:24
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
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...