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 
10 // -----------------------------
11 // --- SynthLab SDK File --- //
12 // ----------------------------
20 // -----------------------------------------------------------------------------
21 namespace SynthLab
22 {
43  {
45 
46  // --- enable/disable keyboard (MIDI note event) input; when disabled, synth goes into manual mode (Will's VCS3)
47  bool enableMIDINoteEvents = true;
48 
49  // --- global synth mode
50  uint32_t synthModeIndex = enumToInt(SynthMode::kMono);
51 
52  // --- global volume control, controls each output DCA's master volume
53  double globalVolume_dB = 0.0;
54 
55  // --- master pitch bend, in semitones and cents
56  unsigned int globalPitchBendSensCoarse = 7; // --- this number is always positive (parse as +/- value) 7 semitones = perfect 5th
57  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)
58 
59  // --- these are actually really important, especially for non-western music styles and
60  // eccentric electronic music composers too...
61  int globalTuningCoarse = 0; // --- (+/-) semitones, see MIDI spec
62  int globalTuningFine = 0; // --- (+/-) cents see MIDI spec
63 
64  // --- unison Detune - this is the max detuning value NOTE a standard (or RPN or NRPN) parameter :/
65  double globalUnisonDetune_Cents = 0.0;
66 
67  // --- VOICE layer parameters
68  std::shared_ptr<SynthVoiceParameters> voiceParameters = std::make_shared<SynthVoiceParameters>();
69  };
70 
71 
89  {
90  public:
91  SynthEngine(uint32_t blockSize = 64);
92  virtual ~SynthEngine();
93 
95  virtual bool reset(double _sampleRate);
96  virtual bool render(SynthProcessInfo& synthProcessInfo);
97  virtual bool processMIDIEvent(midiEvent& event);
98  virtual bool initialize(const char* dllPath = nullptr);
99 
101  void accumulateVoice(SynthProcessInfo& synthProcessInfo, double scaling = 0.707);
102  void applyGlobalVolume(SynthProcessInfo& synthProcessInfo);
103 
104  // --- get parameters
105  void getParameters(std::shared_ptr<SynthEngineParameters>& _parameters) { _parameters = parameters; }
106 
107  // --- set parameters
108  void setParameters(std::shared_ptr<SynthEngineParameters>& _parameters);
109 
111  int getFreeVoiceIndex();
112  int getVoiceIndexToSteal();
113  int getActiveVoiceIndexInNoteOn(unsigned int midiNoteNumber);
114  int getStealingVoiceIndexInNoteOn(unsigned int midiNoteNumber);
115 
116  protected:
117  // --- only need one for iteration
118  SynthProcessInfo voiceProcessInfo;
119 
120  // --- our modifiers (parameters)
121  // --- SynthEngineParameters parameters;
122  std::shared_ptr<SynthEngineParameters> parameters = std::make_shared<SynthEngineParameters>();
123 
124  // --- shared MIDI tables, via IMIDIData
125  std::shared_ptr<MidiInputData> midiInputData = std::make_shared<MidiInputData>();
126  std::shared_ptr<MidiOutputData> midiOutputData = std::make_shared<MidiOutputData>();
127 
128  // --- array of voice object, via pointers
129  std::unique_ptr<SynthVoice> synthVoices[MAX_VOICES] = { 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0 };
130 
131  // --- shared tables, in case they are huge or need a long creation time
132  std::shared_ptr<WavetableDatabase> wavetableDatabase = nullptr;
133 
134  // --- shared tables, in case they are huge or need a long creation time
135  std::shared_ptr<PCMSampleDatabase> sampleDatabase = nullptr;
136  };
137 
138 }
139 
140 #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
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
Contains parameters for the Synth Engine component.
Definition: synthengine.h:42
Definition: addosccore.cpp:4
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 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
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1384
Encapsulates an entire synth engine, producing one type of synthesizer set of voices (e...
Definition: synthengine.h:88
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
Information about a MIDI event.
Definition: synthstructures.h:166