28 #include "../../system/log.h"
29 #include "../../system/eptexception.h"
30 #include "../../system/simplethreadhandler.h"
31 #include "../../messages/messagechangetuningcurve.h"
32 #include "../../messages/messagekeyselectionchanged.h"
33 #include "../../messages/messagerecorderenergychanged.h"
34 #include "../../messages/messagepreliminarykey.h"
35 #include "../../messages/messagehandler.h"
36 #include "../../messages/messagemidievent.h"
37 #include "../../messages/messagemodechanged.h"
38 #include "../../messages/messageprojectfile.h"
39 #include "../../messages/messagefinalkey.h"
40 #include "../../piano/piano.h"
41 #include "../../piano/key.h"
42 #include "../../math/mathtools.h"
43 #include "../../settings.h"
92 auto message(std::static_pointer_cast<MessageKeySelectionChanged>(m));
114 auto message(std::static_pointer_cast<MessagePreliminaryKey>(m));
115 int recognizedkey = message->getKeyNumber();
135 auto message(std::static_pointer_cast<MessageRecorderEnergyChanged>(m));
146 auto message(std::static_pointer_cast<MessageModeChanged>(m));
156 auto mpf(std::static_pointer_cast<MessageProjectFile>(m));
157 mPiano = &(mpf->getPiano());
168 auto message(std::static_pointer_cast<MessageMidiEvent>(m));
188 if (data.
byte1 < 64 or data.
byte1 > 67)
break;
206 auto message(std::static_pointer_cast<MessageFinalKey>(m));
207 int keynumber = message->getKeyNumber();
208 auto spectrum = message->getFinalKey()->getPeaks();
223 auto message(std::static_pointer_cast<MessageChangeTuningCurve>(m));
253 double volume = pow(static_cast<double>(data.
byte2) / 128, 2);
255 const double decay = (key <= 12 ? 1.0/6 : 1.0/210*pow(key,1.43));
257 Envelope envelope (40,decay,0,release,
true);
271 MessageHandler::send<MessageKeySelectionChanged>(key, &(
mPiano->
getKey(key)));
278 MessageHandler::send<MessageKeySelectionChanged>(key, &(
mPiano->
getKey(key)));
346 const double volume = 0.2;
348 double frequencyshift = frequency /
397 if (mResonatingKey < 0 or mResonatingKey >=
mNumberOfKeys)
return;
399 double truncatedlevel = std::min(0.8,level);
400 double volume = pow(truncatedlevel,2.0);
423 if (peaks.size()==0 or frequency==0 or volume==0)
return;
425 auto it = peaks.begin();
426 double factor = frequency / it->first;
430 double frequ = it->first*factor;
478 for (
int keynumber = 0; keynumber <
mNumberOfKeys; keynumber++)
double getRecordedFrequency() const
Get recorded frequency.
void preCalculateSoundOfAllKeys()
Calculate the sound of all keys in advance.
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
void handleMessage(MessagePtr m) overridefinal
Sound generator message listener and dispatcher.
OperationMode
Operation mode of the tuner.
void stopResonatingReferenceSound()
Stop the resonating reference sound.
int mResonatingKey
Keynumber of the resonating sound.
bool isPlaying(const int id) const
Check whether a sound with given id is still playing.
double mResonatingVolume
Volume of the resonating sound.
static Settings & getSingleton()
Get a pointer to the singleton instance.
MidiEvent event
Midi event, encoded by the enumeration MidiEvent.
void preCalculateSoundOfKey(const int keynumber)
Calculate the sound of a given key in advance, using the spectrum of the given key.
Synthesizer mSynthesizer
Instance of the synthesizer.
const PeakListType & getPeaks() const
Get a read-only reference to mPeaks.
const Piano * mPiano
Pointer to the piano.
Message that a change was made with the current project file.
SoundGenerator(AudioPlayerAdapter *audioAdapter)
Constructor, initializes the member variables.
Message that the operation mode has changed.
Midi event when a key is pressed.
The input level changed (actual signal)
OperationMode mOperationMode
Copy of the operation mode.
void playSound(const int id, const double frequency, const double volume, const Envelope &env, const bool waitforcomputation=false, const bool stereo=true)
Function which plays a single note (sound)
double getEqualTempFrequency(int keynumber, double cents=0, double A4=0) const
Function returning the equal temperament.
Midi event for changing voice.
Mode where the entropy optimization is carried out.
void playResonatingSineWave(int keynumber, double frequency, double volume)
Play a permanent sine wave as a resonating background sound for tuning.
Mode for recording the piano keys.
Message that a key has been selected.
const Keyboard & getKeyboard() const
recording input level has changed
double getComputedFrequency() const
Get computed frequency.
int byte1
Data byte, usually representing the MIDI key index.
int mSelectedKey
Copy of selected key.
number of the key recognized during recording
void releaseSound(const int id)
Terminate a sound.
int mNumberOfKeys
Copy of the number of keys.
bool isSoundGeneratorVolumeDynamic() const
Get flag for dynamic volume adaption in the tuning mode.
Message that the tuning curve has been adapted.
Midi event when a key is released.
Mode for manually tuning the piano.
void setNumberOfKeys(int numberOfKeys)
Tell the synthesizer to change the total number of keys.
final key information after recording
void playResonatingReferenceSound(int keynumber)
Play a resonating reference sound in the tuning mode.
Produce a sound which imitates the string.
void handleMidiKeypress(MidiAdapter::Data &data)
Handle MIDI keypress.
int getKeyNumberOfA4() const
void setWriter(PCMWriterInterface *interface)
Connect the audio adapter to a PCM writer interface.
Produce a simple sine wave as reference.
const double & getConcertPitch() const
new event from MIDI keyboard received
void preCalculateWaveform(const int id, const Spectrum &spectrum)
Pre-calculate the PCM waveform of a sound.
void ModifySustainLevel(const int id, const double level)
Change the level (sustain level) of a constantly playing sound.
std::map< double, double > Spectrum
int byte2
Data byte, usually representing the keystroke intensity.
int getNumberOfKeys() const
Abstract adapter class for PCM-based audio output drivers.
Structure describing the envelope (dynamics) of a sound.
int mKeyNumberOfA4
Copy of A-key position.
void changeVolumeOfResonatingReferenceSound(double level)
Change the volume of the resonating reference sound.
keystroke recognized and recording started
Structure of the data associated with a MIDI event.
const Key & getKey(int i) const