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 {
43  struct SynthEngineParameters
44  {
45  SynthEngineParameters() {}
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  uint32_t globalPitchBendSensCoarse = 7; // --- this number is always positive (parse as +/- value) 7 semitones = perfect 5th
58  uint32_t 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  int32_t globalTuningCoarse = 0; // --- (+/-) semitones, see MIDI spec
63  int32_t 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 
98  class SynthEngine
99  {
100  public:
101  SynthEngine(uint32_t blockSize = 64, DMConfig* config = nullptr);
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(uint32_t midiNoteNumber);
124  int getStealingVoiceIndexInNoteOn(uint32_t midiNoteNumber);
125 
127  std::vector<std::string> getModuleStrings(uint32_t mask);
128  std::vector<std::string> getModKnobStrings(uint32_t mask);
129 
135  uint32_t getVoiceCount() { return MAX_VOICES; }
136  void setDynamicModules(std::vector<std::shared_ptr<SynthLab::ModuleCore>> modules, uint32_t voiceIndex);
137  std::vector<std::string> getModuleCoreNames(uint32_t moduleType);
138 
139  protected:
140  // --- only need one for iteration
141  SynthProcessInfo voiceProcessInfo;
142 
143  // --- our modifiers (parameters)
144  // --- SynthEngineParameters parameters;
145  std::shared_ptr<SynthEngineParameters> parameters = std::make_shared<SynthEngineParameters>();
146 
147  // --- shared MIDI tables, via IMIDIData
148  std::shared_ptr<MidiInputData> midiInputData = std::make_shared<MidiInputData>();
149  std::shared_ptr<MidiOutputData> midiOutputData = std::make_shared<MidiOutputData>();
150 
151  // --- array of voice object, via pointers
152  std::unique_ptr<SynthVoice> synthVoices[MAX_VOICES] = { 0, 0, 0, 0 };
153 
154  // --- shared tables, in case they are huge or need a long creation time
155  std::shared_ptr<WavetableDatabase> wavetableDatabase = nullptr;
156 
157  // --- shared tables, in case they are huge or need a long creation time
158  std::shared_ptr<PCMSampleDatabase> sampleDatabase = nullptr;
159 
160  // --- ADD FX Here...
161  std::unique_ptr<AudioDelay> pingPongDelay = nullptr;
162  };
163 
164 }
165 
166 #endif /* defined(__synthCore_h__) */
#define enumToInt(ENUM)
macro helper to cast a typed enum to an int
Definition: synthfunctions.h:251
virtual bool reset(double _sampleRate)
Resets all voices and the audio delay object.
Definition: synthengine.cpp:82
std::vector< std::string > getModuleCoreNames(uint32_t moduleType)
Gets module core names, four per object.
Definition: synthengine.cpp:113
void accumulateVoice(SynthProcessInfo &synthProcessInfo, double scaling=0.707)
Accumulates voice buffers into a single mix buffer for each channel.
Definition: synthengine.cpp:230
int getFreeVoiceIndex()
Helper function to find a free voice to use.
Definition: synthengine.cpp:451
int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber)
Helper function to find the voice that is playing a certain MIDI note.
Definition: synthengine.cpp:500
std::unique_ptr< SynthVoice > synthVoices[MAX_VOICES]
array of voice objects for the engine
Definition: synthengine.h:129
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:131
Definition: addosccore.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:125
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:520
int getVoiceIndexToSteal()
Helper function to find a free voice to steal based on some kind of heuristic.
Definition: synthengine.cpp:469
void setAllCustomUpdateCodes()
Forwards custom code settings to first voice (since all voices share the same architecture) ...
Definition: synthengine.cpp:88
void setParameters(std::shared_ptr< SynthEngineParameters > &_parameters)
Function to update the engine and voice parameters.
Definition: synthengine.cpp:396
const uint32_t MAX_VOICES
Definition: synthconstants.h:35
virtual bool initialize(const char *dllPath=nullptr)
Initializes all voices with the DLL path.
Definition: synthengine.cpp:103
void applyGlobalVolume(SynthProcessInfo &synthProcessInfo)
Apply a single global volume control to output mix buffers.
Definition: synthengine.cpp:195
void setDynamicModules(std::vector< std::shared_ptr< SynthLab::ModuleCore >> modules, uint32_t voiceIndex)
Adds dynamic module cores to the voice&#39;s member obejcts.
Definition: synthengine.cpp:99
virtual ~SynthEngine()
Destruction:
Definition: synthengine.cpp:68
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:255
std::vector< std::string > getModKnobStrings(uint32_t mask)
Gets module-specific Mod Knob label STRINGS.
Definition: synthengine.cpp:142