SynthLab SDK
synthengine.h
1 #ifndef __synthCore_h__
2 #define __synthCore_h__
3 
4 // --- The voice object
5 #include "synthvoice.h"
6 
7 // --- SynthLab SDK items
8 #include "../source/synthbase.h"
9 #include "../source/audiodelay.h"
10 
11 // -----------------------------
12 // --- SynthLab SDK File --- //
13 // ----------------------------
21 // -----------------------------------------------------------------------------
22 namespace SynthLab
23 {
44  {
46 
47  // --- enable/disable keyboard (MIDI note event) input; when disabled, synth goes into manual mode (Will's VCS3)
48  bool enableMIDINoteEvents = true;
49 
50  // --- global synth mode
51  uint32_t synthModeIndex = enumToInt(SynthMode::kMono);
52 
53  // --- global volume control, controls each output DCA's master volume
54  double globalVolume_dB = 0.0;
55 
56  // --- master pitch bend, in semitones and cents
57  unsigned int globalPitchBendSensCoarse = 7; // --- this number is always positive (parse as +/- value) 7 semitones = perfect 5th
58  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)
59 
60  // --- these are actually really important, especially for non-western music styles and
61  // eccentric electronic music composers too...
62  int globalTuningCoarse = 0; // --- (+/-) semitones, see MIDI spec
63  int globalTuningFine = 0; // --- (+/-) cents see MIDI spec
64 
65  // --- unison Detune - this is the max detuning value NOTE a standard (or RPN or NRPN) parameter :/
66  double globalUnisonDetune_Cents = 0.0;
67 
68  // --- VOICE layer parameters
69  std::shared_ptr<SynthVoiceParameters> voiceParameters = std::make_shared<SynthVoiceParameters>();
70 
71 #ifdef SYNTHLAB_WS
72  // --- meters/lights for wavesequencer: note this is for the FIRST voice only
73  // otherwise becomes very confusing for users
74  WaveSequencerStatusMeters wsStatusMeters;
75 #endif
76  // --- FX is unique to engine, not part of voice
77  std::shared_ptr<AudioDelayParameters> audioDelayParameters = std::make_shared<AudioDelayParameters>();
78  bool enableDelayFX = false;
79  };
80 
81 
99  {
100  public:
101  SynthEngine(uint32_t blockSize = 64);
102  virtual ~SynthEngine();
103 
105  virtual bool reset(double _sampleRate);
106  virtual bool render(SynthProcessInfo& synthProcessInfo);
107  virtual bool processMIDIEvent(midiEvent& event);
108  virtual bool initialize(const char* dllPath = nullptr);
109 
111  void accumulateVoice(SynthProcessInfo& synthProcessInfo, double scaling = 0.707);
112  void applyGlobalVolume(SynthProcessInfo& synthProcessInfo);
113 
114  // --- get parameters
115  void getParameters(std::shared_ptr<SynthEngineParameters>& _parameters) { _parameters = parameters; }
116 
117  // --- set parameters
118  void setParameters(std::shared_ptr<SynthEngineParameters>& _parameters);
119 
121  int getFreeVoiceIndex();
122  int getVoiceIndexToSteal();
123  int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber);
124  int getStealingVoiceIndexInNoteOn(unsigned int midiNoteNumber);
125 
127  std::vector<std::string> getModuleStrings(uint32_t mask);
128  std::vector<std::string> getModKnobStrings(uint32_t mask);
129 
135  void setDynamicModules(std::vector<std::shared_ptr<SynthLab::ModuleCore>> modules);
136  std::vector<std::string> getModuleCoreNames(uint32_t moduleType);
137 
138  protected:
139  // --- only need one for iteration
140  SynthProcessInfo voiceProcessInfo;
141 
142  // --- our modifiers (parameters)
143  // --- SynthEngineParameters parameters;
144  std::shared_ptr<SynthEngineParameters> parameters = std::make_shared<SynthEngineParameters>();
145 
146  // --- shared MIDI tables, via IMIDIData
147  std::shared_ptr<MidiInputData> midiInputData = std::make_shared<MidiInputData>();
148  std::shared_ptr<MidiOutputData> midiOutputData = std::make_shared<MidiOutputData>();
149 
150  // --- array of voice object, via pointers
151  std::unique_ptr<SynthVoice> synthVoices[MAX_VOICES] = { 0, 0, 0, 0 };
152 
153  // --- shared tables, in case they are huge or need a long creation time
154  std::shared_ptr<WavetableDatabase> wavetableDatabase = nullptr;
155 
156  // --- shared tables, in case they are huge or need a long creation time
157  std::shared_ptr<PCMSampleDatabase> sampleDatabase = nullptr;
158 
159  // --- ADD FX Here...
160  std::unique_ptr<AudioDelay> pingPongDelay = nullptr;
161  };
162 
163 }
164 
165 #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:157
std::vector< std::string > getModuleCoreNames(uint32_t moduleType)
Gets module core names, four per object.
Definition: synthengine.cpp:109
void accumulateVoice(SynthProcessInfo &synthProcessInfo, double scaling=0.707)
Accumulates voice buffers into a single mix buffer for each channel.
Definition: synthengine.cpp:327
int getFreeVoiceIndex()
Helper function to find a free voice to use.
Definition: synthengine.cpp:612
int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber)
Helper function to find the voice that is playing a certain MIDI note.
Definition: synthengine.cpp:661
std::unique_ptr< SynthVoice > synthVoices[MAX_VOICES]
array of voice objects for the engine
Definition: synthengine.h:151
SynthEngine(uint32_t blockSize=64)
Construction:
Definition: synthengine.cpp:31
virtual bool render(SynthProcessInfo &synthProcessInfo)
Render a buffer of output audio samples.
Definition: synthengine.cpp:209
Contains parameters for the Synth Engine component.
Definition: synthengine.h:43
Definition: synthlabcore.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:121
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:681
int getVoiceIndexToSteal()
Helper function to find a free voice to steal based on some kind of heuristic.
Definition: synthengine.cpp:630
void setAllCustomUpdateCodes()
Forwards custom code settings to first voice (since all voices share the same architecture) ...
Definition: synthengine.cpp:84
void setParameters(std::shared_ptr< SynthEngineParameters > &_parameters)
Function to update the engine and voice parameters.
Definition: synthengine.cpp:512
const uint32_t MAX_VOICES
Definition: synthconstants.h:24
Definition: sequencer.h:564
virtual bool initialize(const char *dllPath=nullptr)
Initializes all voices with the DLL path.
Definition: synthengine.cpp:181
void applyGlobalVolume(SynthProcessInfo &synthProcessInfo)
Apply a single global volume control to output mix buffers.
Definition: synthengine.cpp:292
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1539
Encapsulates an entire synth engine, producing one type of synthesizer set of voices (e...
Definition: synthengine.h:98
virtual ~SynthEngine()
Destruction:
Definition: synthengine.cpp:72
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:352
void setDynamicModules(std::vector< std::shared_ptr< SynthLab::ModuleCore >> modules)
Adds dynamic module cores to the voice&#39;s member obejcts.
Definition: synthengine.cpp:95
std::vector< std::string > getModKnobStrings(uint32_t mask)
Gets module-specific Mod Knob label STRINGS.
Definition: synthengine.cpp:138
Information about a MIDI event.
Definition: synthstructures.h:155