--- linuxsampler/trunk/src/engines/gig/EngineChannel.cpp 2005/05/19 19:25:14 554 +++ linuxsampler/trunk/src/engines/gig/EngineChannel.cpp 2006/06/27 22:57:37 880 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 Christian Schoenebeck * + * Copyright (C) 2005, 2006 Christian Schoenebeck * * * * 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 * @@ -30,7 +30,6 @@ pEngine = NULL; pInstrument = NULL; pEvents = NULL; // we allocate when we retrieve the right Engine object - pCCEvents = NULL; // we allocate when we retrieve the right Engine object pEventQueue = new RingBuffer(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); pActiveKeys = new Pool(128); for (uint i = 0; i < 128; i++) { @@ -42,13 +41,16 @@ pMIDIKeyInfo[i].VoiceTheftsQueued = 0; pMIDIKeyInfo[i].RoundRobinIndex = 0; } - for (uint i = 0; i < Event::destination_count; i++) { - pSynthesisEvents[i] = NULL; // we allocate when we retrieve the right Engine object - } InstrumentIdx = -1; InstrumentStat = -1; AudioDeviceChannelLeft = -1; AudioDeviceChannelRight = -1; + pMidiInputPort = NULL; + midiChannel = midi_chan_all; + ResetControllers(); + SoloMode = false; + PortamentoMode = false; + PortamentoTime = CONFIG_PORTAMENTO_TIME_DEFAULT; } EngineChannel::~EngineChannel() { @@ -60,18 +62,43 @@ } /** + * Implementation of virtual method from abstract EngineChannel interface. + * This method will periodically be polled (e.g. by the LSCP server) to + * check if some engine channel parameter has changed since the last + * StatusChanged() call. + * + * This method can also be used to mark the engine channel as changed + * from outside, e.g. by a MIDI input device. The optional argument + * \a nNewStatus can be used for this. + * + * TODO: This "poll method" is just a lazy solution and might be + * replaced in future. + * @param bNewStatus - (optional, default: false) sets the new status flag + * @returns true if engine channel status has changed since last + * StatusChanged() call + */ + bool EngineChannel::StatusChanged(bool bNewStatus) { + bool b = bStatusChanged; + bStatusChanged = bNewStatus; + return b; + } + + void EngineChannel::Reset() { + if (pEngine) pEngine->DisableAndLock(); + ResetInternal(); + ResetControllers(); + if (pEngine) { + pEngine->Enable(); + pEngine->Reset(); + } + } + + /** * This method is not thread safe! */ void EngineChannel::ResetInternal() { - Pitch = 0; - SustainPedal = false; - GlobalVolume = 1.0; - GlobalPanLeft = 1.0f; - GlobalPanRight = 1.0f; CurrentKeyDimension = 0; - ResetControllers(); - // reset key info for (uint i = 0; i < 128; i++) { if (pMIDIKeyInfo[i].pActiveVoices) @@ -84,6 +111,8 @@ pMIDIKeyInfo[i].itSelf = Pool::Iterator(); pMIDIKeyInfo[i].VoiceTheftsQueued = 0; } + SoloKey = -1; // no solo key active yet + PortamentoPos = -1.0f; // no portamento active yet // reset all key groups std::map::iterator iter = ActiveKeyGroups.begin(); @@ -96,6 +125,9 @@ pEventQueue->init(); if (pEngine) pEngine->ResetInternal(); + + // status of engine channel has changed, so set notify flag + bStatusChanged = true; } LinuxSampler::Engine* EngineChannel::GetEngine() { @@ -157,16 +189,16 @@ catch (RIFF::Exception e) { InstrumentStat = -2; String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message; - throw LinuxSamplerException(msg); + throw Exception(msg); } catch (InstrumentResourceManagerException e) { InstrumentStat = -3; String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message(); - throw LinuxSamplerException(msg); + throw Exception(msg); } catch (...) { InstrumentStat = -4; - throw LinuxSamplerException("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file."); + throw Exception("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file."); } // rebuild ActiveKeyGroups map with key groups of current instrument @@ -183,7 +215,7 @@ } catch (AudioOutputException e) { String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message(); - throw LinuxSamplerException(msg); + throw Exception(msg); } if (pEngine) pEngine->Enable(); @@ -208,6 +240,7 @@ void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) { this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) if (pEngine) pEngine->Enable(); + bStatusChanged = true; // status of engine has changed, so set notify flag } /** @@ -219,6 +252,7 @@ void EngineChannel::OnResourceProgress(float fProgress) { this->InstrumentStat = int(fProgress * 100.0f); dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat)); + bStatusChanged = true; // status of engine has changed, so set notify flag } void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { @@ -228,11 +262,7 @@ } pEngine = Engine::AcquireEngine(this, pAudioOut); ResetInternal(); - pEvents = new RTList(pEngine->pEventPool); - pCCEvents = new RTList(pEngine->pEventPool); - for (uint i = 0; i < Event::destination_count; i++) { - pSynthesisEvents[i] = new RTList(pEngine->pEventPool); - } + pEvents = new RTList(pEngine->pEventPool); for (uint i = 0; i < 128; i++) { pMIDIKeyInfo[i].pActiveVoices = new RTList(pEngine->pVoicePool); pMIDIKeyInfo[i].pEvents = new RTList(pEngine->pEventPool); @@ -241,6 +271,7 @@ AudioDeviceChannelRight = 1; pOutputLeft = pAudioOut->Channel(0)->Buffer(); pOutputRight = pAudioOut->Channel(1)->Buffer(); + MidiInputPort::AddSysexListener(pEngine); } void EngineChannel::DisconnectAudioOutputDevice() { @@ -250,10 +281,6 @@ delete pEvents; pEvents = NULL; } - if (pCCEvents) { - delete pCCEvents; - pCCEvents = NULL; - } for (uint i = 0; i < 128; i++) { if (pMIDIKeyInfo[i].pActiveVoices) { delete pMIDIKeyInfo[i].pActiveVoices; @@ -264,12 +291,6 @@ pMIDIKeyInfo[i].pEvents = NULL; } } - for (uint i = 0; i < Event::destination_count; i++) { - if (pSynthesisEvents[i]) { - delete pSynthesisEvents[i]; - pSynthesisEvents[i] = NULL; - } - } Engine* oldEngine = pEngine; AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; pEngine = NULL; @@ -309,6 +330,28 @@ } } + void EngineChannel::Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) { + if (!pMidiPort || pMidiPort == this->pMidiInputPort) return; + DisconnectMidiInputPort(); + this->pMidiInputPort = pMidiPort; + this->midiChannel = MidiChannel; + pMidiPort->Connect(this, MidiChannel); + } + + void EngineChannel::DisconnectMidiInputPort() { + MidiInputPort* pOldPort = this->pMidiInputPort; + this->pMidiInputPort = NULL; + if (pOldPort) pOldPort->Disconnect(this); + } + + MidiInputPort* EngineChannel::GetMidiInputPort() { + return pMidiInputPort; + } + + midi_chan_t EngineChannel::MidiChannel() { + return midiChannel; + } + /** * Will be called by the MIDIIn Thread to let the audio thread trigger a new * voice for the given key. @@ -385,10 +428,6 @@ void EngineChannel::ClearEventLists() { pEvents->clear(); - pCCEvents->clear(); - for (uint i = 0; i < Event::destination_count; i++) { - pSynthesisEvents[i]->clear(); - } // empty MIDI key specific event lists { RTList::Iterator iuiKey = pActiveKeys->first(); @@ -400,6 +439,12 @@ } void EngineChannel::ResetControllers() { + Pitch = 0; + SustainPedal = false; + SostenutoPedal = false; + GlobalVolume = CONFIG_GLOBAL_ATTENUATION; + GlobalPanLeft = 1.0f; + GlobalPanRight = 1.0f; // set all MIDI controller values to zero memset(ControllerTable, 0x00, 128); } @@ -446,6 +491,7 @@ void EngineChannel::Volume(float f) { GlobalVolume = f; + bStatusChanged = true; // status of engine channel has changed, so set notify flag } uint EngineChannel::Channels() { @@ -471,5 +517,5 @@ String EngineChannel::EngineName() { return LS_GIG_ENGINE_NAME; } - + }} // namespace LinuxSampler::gig