--- linuxsampler/trunk/src/engines/AbstractEngine.cpp 2010/09/14 17:09:08 2121 +++ linuxsampler/trunk/src/engines/AbstractEngine.cpp 2014/05/18 17:38:25 2559 @@ -4,7 +4,8 @@ * * * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * * Copyright (C) 2005-2008 Christian Schoenebeck * - * Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2013-2014 Christian Schoenebeck and Andreas Persson * * * * 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 * @@ -26,6 +27,7 @@ #include "AbstractEngineChannel.h" #include "EngineFactory.h" #include "../common/global_private.h" +#include "../effects/EffectFactory.h" namespace LinuxSampler { @@ -164,6 +166,7 @@ */ void AbstractEngine::ResetScaleTuning() { memset(&ScaleTuning[0], 0x00, 12); + ScaleTuningChanged.raise(); } /** @@ -305,21 +308,21 @@ return false; // error } AudioChannel* pDstChan = NULL; - if (pFxSend->DestinationMasterEffectChain() >= 0) { // fx send routed to an internal master effect + if (pFxSend->DestinationEffectChain() >= 0) { // fx send routed to an internal send effect EffectChain* pEffectChain = - pAudioOutputDevice->MasterEffectChain( - pFxSend->DestinationMasterEffectChain() + pAudioOutputDevice->SendEffectChainByID( + pFxSend->DestinationEffectChain() ); if (!pEffectChain) { - dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationMasterEffectChain())); + dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationEffectChain())); return false; // error } Effect* pEffect = pEffectChain->GetEffect( - pFxSend->DestinationMasterEffect() + pFxSend->DestinationEffectChainPosition() ); if (!pEffect) { - dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect %d of effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationMasterEffect(), pFxSend->DestinationMasterEffectChain())); + dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect %d of effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationEffectChainPosition(), pFxSend->DestinationEffectChain())); return false; // error } pDstChan = pEffect->InputChannel(iDstChan); @@ -345,11 +348,13 @@ */ uint8_t AbstractEngine::GSCheckSum(const RingBuffer::NonVolatileReader AddrReader, uint DataSize) { RingBuffer::NonVolatileReader reader = AddrReader; - uint bytes = 3 /*addr*/ + DataSize; - uint8_t addr_and_data[bytes]; - reader.read(&addr_and_data[0], bytes); + uint bytes = 3 /*addr*/ + DataSize; uint8_t sum = 0; - for (uint i = 0; i < bytes; i++) sum += addr_and_data[i]; + uint8_t c; + for (uint i = 0; i < bytes; ++i) { + if (!reader.pop(&c)) break; + sum += c; + } return 128 - sum % 128; } @@ -358,8 +363,13 @@ * * @param ScaleTunes - detuning of all twelve semitones (in cents) */ - void AbstractEngine::AdjustScale(int8_t ScaleTunes[12]) { - memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12); //TODO: currently not sample accurate + void AbstractEngine::AdjustScaleTuning(const int8_t ScaleTunes[12]) { + memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12); + ScaleTuningChanged.raise(); + } + + void AbstractEngine::GetScaleTuning(int8_t* pScaleTunes) { + memcpy(pScaleTunes, &this->ScaleTuning[0], 12); } uint AbstractEngine::VoiceCount() { @@ -375,9 +385,7 @@ } /** - * Moves pitchbend event from the general (input) event list to the engine - * channel's event list. It will actually processed later by the - * respective voice. + * Stores the latest pitchbend event as current pitchbend scalar value. * * @param pEngineChannel - engine channel on which this event occured on * @param itPitchbendEvent - absolute pitch value and time stamp of the event @@ -506,9 +514,13 @@ for (int i = 0; i < engineChannels.size(); ++i) { AbstractEngineChannel* pEngineChannel = static_cast(engineChannels[i]); - if (pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort) { - KillAllVoices(pEngineChannel, itSysexEvent); - pEngineChannel->ResetControllers(); + Sync< ArrayList > midiInputs = pEngineChannel->midiInputs.front(); + for (int k = 0; k < midiInputs->size(); ++k) { + if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) { + KillAllVoices(pEngineChannel, itSysexEvent); + pEngineChannel->ResetControllers(); + break; + } } } } @@ -529,7 +541,7 @@ if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; #endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; - AdjustScale((int8_t*) scale_tunes); + AdjustScaleTuning((int8_t*) scale_tunes); dmsg(3,("\t\t\tNew scale applied.\n")); break; } @@ -541,19 +553,23 @@ for (int i = 0; i < engineChannels.size(); ++i) { AbstractEngineChannel* pEngineChannel = static_cast(engineChannels[i]); - if ( - (pEngineChannel->midiChannel == part || - pEngineChannel->midiChannel == midi_chan_all) && - pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort - ) { - try { - pEngineChannel->SetMidiInstrumentMap(map); - } catch (Exception e) { - dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str())); - goto free_sysex_data; - } catch (...) { - dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part)); - goto free_sysex_data; + if (pEngineChannel->midiChannel == part || + pEngineChannel->midiChannel == midi_chan_all) + { + Sync< ArrayList > midiInputs = pEngineChannel->midiInputs.front(); + for (int k = 0; k < midiInputs->size(); ++k) { + if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) { + try { + pEngineChannel->SetMidiInstrumentMap(map); + } catch (Exception e) { + dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str())); + goto free_sysex_data; + } catch (...) { + dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part)); + goto free_sysex_data; + } + break; + } } } }