//============================================================================== void MPESynthesiser::noteAdded (MPENote newNote) { const ScopedLock sl (voicesLock); if (MPESynthesiserVoice* voice = findFreeVoice (newNote, shouldStealVoices)) startVoice (voice, newNote); }
//============================================================================== void Synthesiser::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity) { const ScopedLock sl (lock); for (int i = sounds.size(); --i >= 0;) { SynthesiserSound* const sound = sounds.getUnchecked(i); if (sound->appliesToNote (midiNoteNumber) && sound->appliesToChannel (midiChannel)) { // If hitting a note that's still ringing, stop it first (it could be // still playing because of the sustain or sostenuto pedal). for (int j = voices.size(); --j >= 0;) { SynthesiserVoice* const voice = voices.getUnchecked (j); if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel)) stopVoice (voice, true); } startVoice (findFreeVoice (sound, shouldStealNotes), sound, midiChannel, midiNoteNumber, velocity); } } }
void EMISound::restoreState(SaveGame *savedState) { // Clear any current music flushStack(); setMusicState(0); freeAllChannels(); // Actually load: savedState->beginSection('SOUN'); _musicPrefix = savedState->readString(); // Stack: uint32 stackSize = savedState->readLEUint32(); for (uint32 i = 0; i < stackSize; i++) { SoundTrack *track = nullptr; Common::String soundName = savedState->readString(); if (!soundName.empty()) { track = createEmptyMusicTrack(); if (initTrack(soundName, track)) { track->play(); track->pause(); } else { error("Couldn't reopen %s", soundName.c_str()); } } _stateStack.push(track); } // Currently playing music: uint32 hasActiveTrack = savedState->readLEUint32(); if (hasActiveTrack) { _music = createEmptyMusicTrack(); Common::String soundName = savedState->readString(); if (initTrack(soundName, _music)) { _music->play(); } else { error("Couldn't reopen %s", soundName.c_str()); } } // Channels: uint32 numChannels = savedState->readLEUint32(); if (numChannels > NUM_CHANNELS) { error("Save game made with more channels than we have now: %d > %d", numChannels, NUM_CHANNELS); } for (uint32 i = 0; i < numChannels; i++) { uint32 channelIsActive = savedState->readLEUint32(); if (channelIsActive) { Common::String soundName = savedState->readString(); uint32 volume = savedState->readLEUint32(); uint32 pan = savedState->readLEUint32(); /*uint32 pos = */savedState->readLEUint32(); /*bool isPlaying = */savedState->readByte(); startVoice(soundName.c_str(), volume, pan); } } savedState->endSection(); }
//============================================================================== void Synthesiser::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity) { const ScopedLock sl (lock); for (auto* sound : sounds) { if (sound->appliesToNote (midiNoteNumber) && sound->appliesToChannel (midiChannel)) { // If hitting a note that's still ringing, stop it first (it could be // still playing because of the sustain or sostenuto pedal). for (auto* voice : voices) if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel)) stopVoice (voice, 1.0f, true); startVoice (findFreeVoice (sound, midiChannel, midiNoteNumber, shouldStealNotes), sound, midiChannel, midiNoteNumber, velocity); } } }