SynthLab SDK
synthengine.h
1 #ifndef __synthCore_h__
2 #define __synthCore_h__
3 
4 // --- we need these
5 #include "synthbase.h"
6 #include "synthvoice.h"
7 #include "audiodelay.h"
8 
9 namespace SynthLab
10 {
31  {
33 
34  // --- enable/disable keyboard (MIDI note event) input; when disabled, synth goes into manual mode (Will's VCS3)
35  bool enableMIDINoteEvents = true;
36 
37  // --- global synth mode
38  uint32_t synthModeIndex = enumToInt(SynthMode::kMono);
39 
40  // --- global volume control, controls each output DCA's master volume
41  double globalVolume_dB = 0.0;
42 
43  // --- master pitch bend, in semitones and cents
44  unsigned int globalPitchBendSensCoarse = 7; // --- this number is always positive (parse as +/- value) 7 semitones = perfect 5th
45  unsigned int globalPitchBendSensFine = 0; // --- this number is always positive (parse as +/- value) see MIDI RPN 00 00 (sensitivity) and 00 01 (fine tuning, cents -100/+100) and 00 02 (coarse tuning, semintones -63/+64)
46 
47  // --- these are actually really important, especially for non-western music styles and
48  // eccentric electronic music composers too...
49  int globalTuningCoarse = 0; // --- (+/-) semitones, see MIDI spec
50  int globalTuningFine = 0; // --- (+/-) cents see MIDI spec
51 
52  // --- unison Detune - this is the max detuning value NOTE a standard (or RPN or NRPN) parameter :/
53  double globalUnisonDetune_Cents = 0.0;
54 
55  // --- VOICE layer parameters
56  std::shared_ptr<SynthVoiceParameters> voiceParameters = std::make_shared<SynthVoiceParameters>();
57 
58 #ifdef SYNTHLAB_WS
59  // --- meters/lights for wavesequencer: note this is for the FIRST voice only
60  // otherwise becomes very confusing for users
61  WaveSequencerStatusMeters wsStatusMeters;
62 #endif
63  // --- FX is unique to engine, not part of voice
64  std::shared_ptr<AudioDelayParameters> audioDelayParameters = std::make_shared<AudioDelayParameters>();
65  bool enableDelayFX = false;
66  };
67 
68 
86  {
87  public:
88  SynthEngine(uint32_t blockSize = 64);
89  virtual ~SynthEngine();
90 
92  virtual bool reset(double _sampleRate);
93  virtual bool render(SynthProcessInfo& synthProcessInfo);
94  virtual bool processMIDIEvent(midiEvent& event);
95  virtual bool initialize(const char* dllPath = nullptr);
96 
98  void accumulateVoice(SynthProcessInfo& synthProcessInfo, double scaling = 0.707);
99  void applyGlobalVolume(SynthProcessInfo& synthProcessInfo);
100 
101  // --- get parameters
102  void getParameters(std::shared_ptr<SynthEngineParameters>& _parameters) { _parameters = parameters; }
103 
104  // --- set parameters
105  void setParameters(std::shared_ptr<SynthEngineParameters>& _parameters);
106 
108  int getFreeVoiceIndex();
109  int getVoiceIndexToSteal();
110  int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber);
111  int getStealingVoiceIndexInNoteOn(unsigned int midiNoteNumber);
112 
114  std::vector<std::string> getModuleStrings(uint32_t mask);
115  std::vector<std::string> getModKnobStrings(uint32_t mask);
116 
122  void setDynamicModules(std::vector<std::shared_ptr<SynthLab::ModuleCore>> modules);
123  std::vector<std::string> getModuleCoreNames(uint32_t moduleType);
124 
125  protected:
126  // --- only need one for iteration
127  SynthProcessInfo voiceProcessInfo;
128 
129  // --- our modifiers (parameters)
130  // --- SynthEngineParameters parameters;
131  std::shared_ptr<SynthEngineParameters> parameters = std::make_shared<SynthEngineParameters>();
132 
133  // --- shared MIDI tables, via IMIDIData
134  std::shared_ptr<MidiInputData> midiInputData = std::make_shared<MidiInputData>();
135  std::shared_ptr<MidiOutputData> midiOutputData = std::make_shared<MidiOutputData>();
136 
137  // --- array of voice object, via pointers
138  std::unique_ptr<SynthVoice> synthVoices[MAX_VOICES] = { 0, 0, 0, 0 };
139 
140  // --- shared tables, in case they are huge or need a long creation time
141  std::shared_ptr<WavetableDatabase> wavetableDatabase = nullptr;
142 
143  // --- shared tables, in case they are huge or need a long creation time
144  std::shared_ptr<PCMSampleDatabase> sampleDatabase = nullptr;
145 
146  // --- ADD FX Here...
147  std::unique_ptr<AudioDelay> pingPongDelay = nullptr;
148  };
149 
150 }
151 
152 #endif /* defined(__synthCore_h__) */
#define enumToInt(ENUM)
macro helper to cast a typed enum to an int
Definition: synthfunctions.h:234
virtual bool reset(double _sampleRate)
Resets all voices and the audio delay object.
Definition: synthengine.cpp:168
std::vector< std::string > getModuleCoreNames(uint32_t moduleType)
Gets module core names, four per object.
Definition: synthengine.cpp:120
void accumulateVoice(SynthProcessInfo &synthProcessInfo, double scaling=0.707)
Accumulates voice buffers into a single mix buffer for each channel.
Definition: synthengine.cpp:338
int getFreeVoiceIndex()
Helper function to find a free voice to use.
Definition: synthengine.cpp:623
int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber)
Helper function to find the voice that is playing a certain MIDI note.
Definition: synthengine.cpp:672
SynthEngine(uint32_t blockSize=64)
Construction:
Definition: synthengine.cpp:20
virtual bool render(SynthProcessInfo &synthProcessInfo)
Render a buffer of output audio samples.
Definition: synthengine.cpp:220
Contains parameters for the Synth Engine component.
Definition: synthengine.h:30
Definition: analogegcore.cpp:4
std::vector< std::string > getModuleStrings(uint32_t mask)
Gets module-specific core STRINGS (e.g. waveform names for oscillators, filter types for filters...
Definition: synthengine.cpp:132
std::unique_ptr< SynthVoice > synthVoices[MAX_VOICES]
array of voice objects for the engine
Definition: synthengine.h:138
int getStealingVoiceIndexInNoteOn(unsigned int midiNoteNumber)
Helper function to find the voice that is playing a certain MIDI note and that will be stolen...
Definition: synthengine.cpp:692
int getVoiceIndexToSteal()
Helper function to find a free voice to steal based on some kind of heuristic.
Definition: synthengine.cpp:641
void setAllCustomUpdateCodes()
Forwards custom code settings to first voice (since all voices share the same architecture) ...
Definition: synthengine.cpp:95
void setParameters(std::shared_ptr< SynthEngineParameters > &_parameters)
Function to update the engine and voice parameters.
Definition: synthengine.cpp:523
const uint32_t MAX_VOICES
Definition: synthconstants.h:24
Definition: sequencer.h:553
virtual bool initialize(const char *dllPath=nullptr)
Initializes all voices with the DLL path.
Definition: synthengine.cpp:192
void applyGlobalVolume(SynthProcessInfo &synthProcessInfo)
Apply a single global volume control to output mix buffers.
Definition: synthengine.cpp:303
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1316
Encapsulates an entire synth engine, producing one type of synthesizer set of voices (e...
Definition: synthengine.h:85
virtual ~SynthEngine()
Destruction:
Definition: synthengine.cpp:83
virtual bool processMIDIEvent(midiEvent &event)
The MIDI event handler function; for note on/off messages it finds the voices to turn on/off...
Definition: synthengine.cpp:363
void setDynamicModules(std::vector< std::shared_ptr< SynthLab::ModuleCore >> modules)
Adds dynamic module cores to the voice&#39;s member obejcts.
Definition: synthengine.cpp:106
std::vector< std::string > getModKnobStrings(uint32_t mask)
Gets module-specific Mod Knob label STRINGS.
Definition: synthengine.cpp:149
Information about a MIDI event.
Definition: synthstructures.h:155