[go: up one dir, main page]

Menu

[r40]: / Source / Synth.h  Maximize  Restore  History

Download this file

122 lines (95 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**************************************************************************
Copyright (C) 2019 Arnaud Champenois arthelion@free.fr
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
#include "Chorus.h"
#include "StereoDelay.h"
#include "Metronome.h"
#include <list>
/*!
* The Synth class is the sound generator. It take care of :
* - affecting voice according to mode and polyphony,
* - mixing
* - applying effects Chorus, Delay and Reverb,
* - Adjusting output gain.
* Every computation is done in double precision, to allow algos such as FM
* to be coded very simply without having to manage rounding effects.
* The most of processing is done "inline" as in JUCE philosophy.
*/
class Synth : public Synthesiser {
public:
typedef enum {
POLY = 0,
MONO = 1,
MONO_LEGATO = 2,
POLY_RINGING = 3
} PolyMode;
Synth(SynthParameters&param) :
mChorus(param), mDelay(param), mSynthParameters(param) {}
virtual void handleController(int midiChannel,
int controllerNumber,
int controllerValue) override;
virtual void handleProgramChange(int midiChannel, int programNumber) override;
virtual void setCurrentPlaybackSampleRate(double sampleRate) override;
void updateInternalValues();
bool isPlaying() const {
for (auto* voice : voices) {
if (voice->isVoiceActive())
return true;
}
return false;
}
bool isMuted() const {
for (auto* voice : voices) {
if (voice->isVoiceActive())
return false;
}
return true;
}
virtual void noteOn(const int midiChannel, const int midiNoteNumber, const float velocity) override;
virtual void noteOff(int midiChannel,
int midiNoteNumber,
float velocity,
bool allowTailOff) override;
void setMonoVoice() {
mMonoVoice = voices[0];
}
bool isMono() const { return (( mPolyMode == MONO) || (mPolyMode == MONO_LEGATO)); }
void lockVoices();
void unlockVoices();
protected:
virtual void renderVoices(AudioBuffer<float>& outputAudio,
int startSample, int numSamples) override;
virtual SynthesiserVoice* findFreeVoice(SynthesiserSound* soundToPlay,
int midiChannel,
int midiNoteNumber,
bool stealIfNoneAvailable) const;
private:
struct NoteDescr {
int midiNoteNumber; float velocity;
bool operator==(const NoteDescr& d) const { return d.midiNoteNumber == midiNoteNumber; }
};
std::list<NoteDescr> mNoteList;
Chorus mChorus;
StereoDelay mDelay;
Reverb mReverb;
double mGain = 1.0;
bool mGainAutoset = true;
bool mReverbActive = false;
PolyMode mPolyMode = POLY;
SynthParameters& mSynthParameters;
SynthesiserVoice* mMonoVoice;
Metronome mMetronome;
bool mMetronomOn = false;
};