--- linuxsampler/trunk/src/engines/EngineBase.h 2009/11/03 19:27:42 2027 +++ linuxsampler/trunk/src/engines/EngineBase.h 2011/02/08 18:22:50 2162 @@ -3,8 +3,8 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005-2009 Christian Schoenebeck * - * Copyright (C) 2009 Grigor Iliev * + * Copyright (C) 2005-2008 Christian Schoenebeck * + * Copyright (C) 2009-2011 Christian Schoenebeck and Grigor Iliev * * * * 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 * @@ -190,6 +190,15 @@ // been deleted by the disk thread if (iPendingStreamDeletions) ProcessPendingStreamDeletions(); + // Release the instrument change command. (This has to + // be done after all voices have been rendered and not + // in HandleInstrumentChanges, as the RegionsInUse + // list has been built up by the voice renderers.) + for (int i = 0; i < engineChannels.size(); i++) { + EngineChannelBase* channel = + static_cast*>(engineChannels[i]); + channel->InstrumentChangeCommandReader.Unlock(); + } FrameTime += Samples; EngineDisabled.RttDone(); @@ -299,7 +308,7 @@ // lower minimum release time const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; for (VoiceIterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { - iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate); + iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate); } pVoicePool->clear(); } @@ -339,6 +348,13 @@ } } pVoicePool->clear(); + + // (re)create dedicated voice audio buffers + //TODO: we could optimize resource usage a bit by just allocating these dedicated voice buffers when there is at least one engine channel with FX sends, because only in this case those special buffers are used actually, but since it would usually only save couple bytes in total, its probably not worth it + if (pDedicatedVoiceChannelLeft) delete pDedicatedVoiceChannelLeft; + if (pDedicatedVoiceChannelRight) delete pDedicatedVoiceChannelRight; + pDedicatedVoiceChannelLeft = new AudioChannel(0, MaxSamplesPerCycle); + pDedicatedVoiceChannelRight = new AudioChannel(1, MaxSamplesPerCycle); } /** @@ -530,6 +546,8 @@ //friend class EngineChannelBase; + static IM instruments; + protected: class SuspensionVoiceHandler : public MidiKeyboardManager::VoiceHandler { public: @@ -558,8 +576,6 @@ } }; - static IM instruments; - Pool* pRegionPool[2]; ///< Double buffered pool, used by the engine channels to keep track of regions in use. int MinFadeOutSamples; ///< The number of samples needed to make an instant fade out (e.g. for voice stealing) without leading to clicks. D* pDiskThread; @@ -765,12 +781,6 @@ //TODO: this is a lazy solution ATM and not safe in case somebody is currently editing the instrument we're currently switching to (we should store all suspended regions on instrument manager side and when switching to another instrument copy that list to the engine's local list of suspensions ResetSuspendedRegions(); } - - for (int i = 0; i < engineChannels.size(); i++) { - EngineChannelBase* channel = - static_cast*>(engineChannels[i]); - channel->InstrumentChangeCommandReader.Unlock(); - } } /** @@ -857,6 +867,14 @@ pChannel->ClearEventLists(); } + /** + * Process MIDI control change events with hard coded behavior, + * that is controllers whose behavior is defined independently + * of the actual sampler engine type and instrument. + * + * @param pEngineChannel - engine channel on which the MIDI CC event was received + * @param itControlChangeEvent - the actual MIDI CC event + */ void ProcessHardcodedControllers ( EngineChannel* pEngineChannel, Pool::Iterator& itControlChangeEvent @@ -869,18 +887,65 @@ pChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; break; } - case 6: { // data entry (currently only used for RPN controllers) - if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones - int transpose = (int) itControlChangeEvent->Param.CC.Value - 64; - // limit to +- two octaves for now - transpose = RTMath::Min(transpose, 24); - transpose = RTMath::Max(transpose, -24); - pChannel->GlobalTranspose = transpose; - // workaround, so we won't have hanging notes - pChannel->ReleaseAllVoices(itControlChangeEvent); + case 6: { // data entry (currently only used for RPN and NRPN controllers) + //dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value)); + if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ... + dmsg(4,("Guess it's an RPN ...\n")); + if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones + int transpose = (int) itControlChangeEvent->Param.CC.Value - 64; + // limit to +- two octaves for now + transpose = RTMath::Min(transpose, 24); + transpose = RTMath::Max(transpose, -24); + pChannel->GlobalTranspose = transpose; + // workaround, so we won't have hanging notes + pChannel->ReleaseAllVoices(itControlChangeEvent); + } + // to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data + pChannel->ResetMidiRpnController(); + } else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ... + dmsg(4,("Guess it's an NRPN ...\n")); + const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8; + const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff; + dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value)); + switch (NrpnCtrlMSB) { + case 0x1a: { // volume level of note (Roland GS NRPN) + const uint note = NrpnCtrlLSB; + const uint vol = itControlChangeEvent->Param.CC.Value; + dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol)); + if (note < 128 && vol < 128) + pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol]; + break; + } + case 0x1c: { // panpot of note (Roland GS NRPN) + const uint note = NrpnCtrlLSB; + const uint pan = itControlChangeEvent->Param.CC.Value; + dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan)); + if (note < 128 && pan < 128) { + pChannel->pMIDIKeyInfo[note].PanLeft = PanCurve[128 - pan]; + pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan]; + } + break; + } + case 0x1d: { // reverb send of note (Roland GS NRPN) + const uint note = NrpnCtrlLSB; + const float reverb = float(itControlChangeEvent->Param.CC.Value) / 127.0f; + dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%d).\n", note, reverb)); + if (note < 128) + pChannel->pMIDIKeyInfo[note].ReverbSend = reverb; + break; + } + case 0x1e: { // chorus send of note (Roland GS NRPN) + const uint note = NrpnCtrlLSB; + const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f; + dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%d).\n", note, chorus)); + if (note < 128) + pChannel->pMIDIKeyInfo[note].ChorusSend = chorus; + break; + } + } + // to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data + pChannel->ResetMidiNrpnController(); } - // to avoid other MIDI CC #6 messages to be misenterpreted as RPN controller data - pChannel->ResetMidiRpnController(); break; } case 7: { // volume @@ -969,11 +1034,23 @@ } break; } + case 98: { // NRPN controller LSB + dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); + pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value); + break; + } + case 99: { // NRPN controller MSB + dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); + pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value); + break; + } case 100: { // RPN controller LSB + dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value); break; } case 101: { // RPN controller MSB + dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value); break; } @@ -1064,7 +1141,7 @@ VoiceIterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); VoiceIterator end = pOtherKey->pActiveVoices->end(); for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { - if (itVoiceToBeKilled->Type != Voice::type_release_trigger) + if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger)) itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList); } } @@ -1096,7 +1173,10 @@ pKey->pEvents->free(itNoteOnEventOnKeyList); if (!pChannel->SoloMode || pChannel->PortamentoPos < 0.0f) pChannel->PortamentoPos = (float) key; - pKey->RoundRobinIndex++; + if (pKey->pRoundRobinIndex) { + (*pKey->pRoundRobinIndex)++; // counter specific for the key or region + pChannel->RoundRobinIndex++; // common counter for the channel + } pChannel->listeners.PostProcessNoteOn(key, vel); } @@ -1198,7 +1278,7 @@ VoiceIterator itVoiceToBeKilled = pKey->pActiveVoices->first(); VoiceIterator end = pKey->pActiveVoices->end(); for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { - if (itVoiceToBeKilled->Type != Voice::type_release_trigger) + if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger)) itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList); } } @@ -1331,11 +1411,7 @@ pKey->itSelf = pChannel->pActiveKeys->allocAppend(); *pKey->itSelf = itNoteOnEvent->Param.Note.Key; } - if (itNewVoice->KeyGroup) { - uint** ppKeyGroup = &pChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; - *ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group - } - if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) + if (itNewVoice->Type & Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) return 0; // success } }