SynthLab SDK
synthlabcore.h
1 #pragma once
2 
3 #include "synthbase.h"
4 #include "synthfunctions.h"
5 
6 namespace SynthLab
7 {
8 
9  class SynthLabCore : public ModuleCore
10  {
11  public:
12  // --- constructor/destructor
13  SynthLabCore(); /* C-TOR */
14  virtual ~SynthLabCore(); /* D-TOR */
15 
16  virtual bool reset(CoreProcData& processInfo);
17  virtual bool update(CoreProcData& processInfo);
18  virtual bool render(CoreProcData& processInfo);
19  virtual bool doNoteOn(CoreProcData& processInfo);
20  virtual bool doNoteOff(CoreProcData& processInfo);
21 
22  virtual bool shutdown()
23  {
24  // --- calculate the linear inc values based on current outputs
25  incShutdown = -(1000.0*envelopeOutput) / SHUTDOWN_TIME_MSEC / sampleRate;
26 
27  // --- set state and reset counter
28  state = EGState::kShutdown;
29 
30  // --- for sustain pedal
31  sustainOverride = false;
32  releasePending = false;
33  return true;
34  }
35 
36  protected:
37  double sampleRate = 1.0;
38 
39  // --- core specific stuff
40  double egStepInc = 0.0;
41  double attackTimeScalar = 0.0;
42  double decayTimeScalar = 0.0;
43  EGState state = EGState::kOff;
44  double envelopeOutput = 0.0;
45  inline double setStepInc(double timeMsec, double scale = 1.0)
46  {
47  double freq = 1000.0 / timeMsec; // was 1.0/timeMsec
48  egStepInc = scale * (1000.0 / (timeMsec*sampleRate));
49  return egStepInc;
50  }
51 
53  inline void setSustainOverride(bool b)
54  {
55  sustainOverride = b;
56 
58  {
59  releasePending = false;
60  MIDINoteEvent noteEvent;
61  CoreProcData cpd;
62  doNoteOff(cpd);
63  }
64  }
65 
66  bool sustainOverride = false;
67  bool releasePending = false;
68  bool resetToZero = false;
69 
70  // --- inc value for shutdown
71  double incShutdown = 0.0;
72 
73 
74  };
75 
76 
77 
78 } // namespace
79 
virtual bool render(CoreProcData &processInfo)
Renders the output of the module.
Definition: synthlabcore.cpp:164
virtual bool reset(CoreProcData &processInfo)
Resets object to initialized state.
Definition: synthlabcore.cpp:29
SynthLabCore()
Construction: Cores follow the same construction pattern.
Definition: synthlabcore.cpp:7
const double SHUTDOWN_TIME_MSEC
short shutdown time when stealing a voice
Definition: synthconstants.h:89
virtual bool update(CoreProcData &processInfo)
Updates the object for the next block of audio processing.
Definition: synthlabcore.cpp:41
void setSustainOverride(bool b)
set the sustain pedal override to keep the EG stuck in the sustain state until the pedal is released ...
Definition: synthlabcore.h:53
virtual bool doNoteOn(CoreProcData &processInfo)
Note-on handler for the ModuleCore.
Definition: synthlabcore.cpp:202
Definition: synthlabcore.cpp:4
double sampleRate
sample rate
Definition: synthlabcore.h:31
bool sustainOverride
if true, places the EG into sustain mode
Definition: synthlabcore.h:66
bool resetToZero
notes the EG is in reset-to-zero mode
Definition: synthlabcore.h:68
virtual bool doNoteOff(CoreProcData &processInfo)
Note-off handler for the ModuleCore.
Definition: synthlabcore.cpp:212
EGState
Definition: synthlabparams.h:556
bool releasePending
a flag set when a note off event occurs while the sustain pedal is held, telling the EG to go to the ...
Definition: synthlabcore.h:67
double incShutdown
shutdown linear incrementer
Definition: synthlabcore.h:71
This structure holds all of the information needed to call functions on a ModuleCore object...
Definition: synthbase.h:1233
Information about a MIDI note event (note on or note off).
Definition: synthstructures.h:228