--- linuxsampler/trunk/src/engines/gig/EngineChannel.cpp 2006/06/27 22:57:37 880 +++ linuxsampler/trunk/src/engines/gig/EngineChannel.cpp 2008/04/20 08:53:39 1723 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005, 2006 Christian Schoenebeck * + * Copyright (C) 2005 - 2008 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 * @@ -23,14 +23,20 @@ #include "EngineChannel.h" +#include "../../common/global_private.h" + namespace LinuxSampler { namespace gig { - EngineChannel::EngineChannel() { + EngineChannel::EngineChannel() : + InstrumentChangeCommandReader(InstrumentChangeCommand), + virtualMidiDevicesReader_AudioThread(virtualMidiDevices), + virtualMidiDevicesReader_MidiThread(virtualMidiDevices) + { pMIDIKeyInfo = new midi_key_info_t[128]; pEngine = NULL; pInstrument = NULL; pEvents = NULL; // we allocate when we retrieve the right Engine object - pEventQueue = new RingBuffer(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); + pEventQueue = new RingBuffer(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); pActiveKeys = new Pool(128); for (uint i = 0; i < 128; i++) { pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object @@ -43,6 +49,8 @@ } InstrumentIdx = -1; InstrumentStat = -1; + pChannelLeft = NULL; + pChannelRight = NULL; AudioDeviceChannelLeft = -1; AudioDeviceChannelRight = -1; pMidiInputPort = NULL; @@ -55,10 +63,10 @@ EngineChannel::~EngineChannel() { DisconnectAudioOutputDevice(); - if (pInstrument) Engine::instruments.HandBack(pInstrument, this); if (pEventQueue) delete pEventQueue; if (pActiveKeys) delete pActiveKeys; if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; + RemoveAllFxSends(); } /** @@ -156,69 +164,78 @@ * This method will then actually start to load the instrument and block * the calling thread until loading was completed. * - * @returns detailed description of the method call result * @see PrepareLoadInstrument() */ void EngineChannel::LoadInstrument() { - - if (pEngine) pEngine->DisableAndLock(); - - ResetInternal(); - - // free old instrument - if (pInstrument) { - // give old instrument back to instrument manager - Engine::instruments.HandBack(pInstrument, this); + // make sure we don't trigger any new notes with an old + // instrument + instrument_change_command_t& cmd = ChangeInstrument(0); + if (cmd.pInstrument) { + // give old instrument back to instrument manager, but + // keep the dimension regions and samples that are in use + Engine::instruments.HandBackInstrument(cmd.pInstrument, this, cmd.pDimRegionsInUse); } + cmd.pDimRegionsInUse->clear(); // delete all key groups ActiveKeyGroups.clear(); // request gig instrument from instrument manager + ::gig::Instrument* newInstrument; try { - instrument_id_t instrid; - instrid.FileName = InstrumentFile; - instrid.iInstrument = InstrumentIdx; - pInstrument = Engine::instruments.Borrow(instrid, this); - if (!pInstrument) { - InstrumentStat = -1; - dmsg(1,("no instrument loaded!!!\n")); - exit(EXIT_FAILURE); + InstrumentManager::instrument_id_t instrid; + instrid.FileName = InstrumentFile; + instrid.Index = InstrumentIdx; + newInstrument = Engine::instruments.Borrow(instrid, this); + if (!newInstrument) { + throw InstrumentManagerException("resource was not created"); } } catch (RIFF::Exception e) { InstrumentStat = -2; + StatusChanged(true); String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message; throw Exception(msg); } - catch (InstrumentResourceManagerException e) { + catch (InstrumentManagerException e) { InstrumentStat = -3; + StatusChanged(true); String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message(); throw Exception(msg); } catch (...) { InstrumentStat = -4; + StatusChanged(true); 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 - for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion()) + for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion()) if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL; - InstrumentIdxName = pInstrument->pInfo->Name; + InstrumentIdxName = newInstrument->pInfo->Name; InstrumentStat = 100; - // inform audio driver for the need of two channels - try { - if (pEngine && pEngine->pAudioOutputDevice) - pEngine->pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo - } - catch (AudioOutputException e) { - String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message(); - throw Exception(msg); - } + ChangeInstrument(newInstrument); - if (pEngine) pEngine->Enable(); + StatusChanged(true); + } + + + /** + * Changes the instrument for an engine channel. + * + * @param pInstrument - new instrument + * @returns the resulting instrument change command after the + * command switch, containing the old instrument and + * the dimregions it is using + */ + EngineChannel::instrument_change_command_t& EngineChannel::ChangeInstrument(::gig::Instrument* pInstrument) { + instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); + cmd.pInstrument = pInstrument; + cmd.bChangeInstrument = true; + + return InstrumentChangeCommand.SwitchConfig(); } /** @@ -263,19 +280,72 @@ pEngine = Engine::AcquireEngine(this, pAudioOut); ResetInternal(); pEvents = new RTList(pEngine->pEventPool); + + // reset the instrument change command struct (need to be done + // twice, as it is double buffered) + { + instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); + cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[0]); + cmd.pInstrument = 0; + cmd.bChangeInstrument = false; + } + { + instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); + cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[1]); + cmd.pInstrument = 0; + cmd.bChangeInstrument = false; + } + for (uint i = 0; i < 128; i++) { pMIDIKeyInfo[i].pActiveVoices = new RTList(pEngine->pVoicePool); pMIDIKeyInfo[i].pEvents = new RTList(pEngine->pEventPool); } AudioDeviceChannelLeft = 0; AudioDeviceChannelRight = 1; - pOutputLeft = pAudioOut->Channel(0)->Buffer(); - pOutputRight = pAudioOut->Channel(1)->Buffer(); + if (fxSends.empty()) { // render directly into the AudioDevice's output buffers + pChannelLeft = pAudioOut->Channel(AudioDeviceChannelLeft); + pChannelRight = pAudioOut->Channel(AudioDeviceChannelRight); + } else { // use local buffers for rendering and copy later + // ensure the local buffers have the correct size + if (pChannelLeft) delete pChannelLeft; + if (pChannelRight) delete pChannelRight; + pChannelLeft = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle()); + pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle()); + } + if (pEngine->EngineDisabled.GetUnsafe()) pEngine->Enable(); MidiInputPort::AddSysexListener(pEngine); } void EngineChannel::DisconnectAudioOutputDevice() { if (pEngine) { // if clause to prevent disconnect loops + + // delete the structures used for instrument change + RTList< ::gig::DimensionRegion*>* d = InstrumentChangeCommand.GetConfigForUpdate().pDimRegionsInUse; + if (d) delete d; + EngineChannel::instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); + d = cmd.pDimRegionsInUse; + + if (cmd.pInstrument) { + // release the currently loaded instrument + Engine::instruments.HandBackInstrument(cmd.pInstrument, this, d); + } + if (d) delete d; + + // release all active dimension regions to resource + // manager + RTList::Iterator iuiKey = pActiveKeys->first(); + RTList::Iterator end = pActiveKeys->end(); + while (iuiKey != end) { // iterate through all active keys + midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey]; + ++iuiKey; + + RTList::Iterator itVoice = pKey->pActiveVoices->first(); + RTList::Iterator itVoicesEnd = pKey->pActiveVoices->end(); + for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key + Engine::instruments.HandBackDimReg(itVoice->pDimRgn); + } + } + ResetInternal(); if (pEvents) { delete pEvents; @@ -297,9 +367,19 @@ Engine::FreeEngine(this, oldAudioDevice); AudioDeviceChannelLeft = -1; AudioDeviceChannelRight = -1; + if (!fxSends.empty()) { // free the local rendering buffers + if (pChannelLeft) delete pChannelLeft; + if (pChannelRight) delete pChannelRight; + } + pChannelLeft = NULL; + pChannelRight = NULL; } } + AudioOutputDevice* EngineChannel::GetAudioOutputDevice() { + return (pEngine) ? pEngine->pAudioOutputDevice : NULL; + } + void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) { if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet."); @@ -307,16 +387,18 @@ if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel)); switch (EngineAudioChannel) { case 0: // left output channel - pOutputLeft = pChannel->Buffer(); + if (fxSends.empty()) pChannelLeft = pChannel; AudioDeviceChannelLeft = AudioDeviceChannel; break; case 1: // right output channel - pOutputRight = pChannel->Buffer(); + if (fxSends.empty()) pChannelRight = pChannel; AudioDeviceChannelRight = AudioDeviceChannel; break; default: throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel)); } + + bStatusChanged = true; } int EngineChannel::OutputChannel(uint EngineAudioChannel) { @@ -352,9 +434,70 @@ return midiChannel; } + FxSend* EngineChannel::AddFxSend(uint8_t MidiCtrl, String Name) throw (Exception) { + if (pEngine) pEngine->DisableAndLock(); + FxSend* pFxSend = new FxSend(this, MidiCtrl, Name); + if (fxSends.empty()) { + if (pEngine && pEngine->pAudioOutputDevice) { + AudioOutputDevice* pDevice = pEngine->pAudioOutputDevice; + // create local render buffers + pChannelLeft = new AudioChannel(0, pDevice->MaxSamplesPerCycle()); + pChannelRight = new AudioChannel(1, pDevice->MaxSamplesPerCycle()); + } else { + // postpone local render buffer creation until audio device is assigned + pChannelLeft = NULL; + pChannelRight = NULL; + } + } + fxSends.push_back(pFxSend); + if (pEngine) pEngine->Enable(); + fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); + + return pFxSend; + } + + FxSend* EngineChannel::GetFxSend(uint FxSendIndex) { + return (FxSendIndex < fxSends.size()) ? fxSends[FxSendIndex] : NULL; + } + + uint EngineChannel::GetFxSendCount() { + return fxSends.size(); + } + + void EngineChannel::RemoveFxSend(FxSend* pFxSend) { + if (pEngine) pEngine->DisableAndLock(); + for ( + std::vector::iterator iter = fxSends.begin(); + iter != fxSends.end(); iter++ + ) { + if (*iter == pFxSend) { + delete pFxSend; + fxSends.erase(iter); + if (fxSends.empty()) { + // destroy local render buffers + if (pChannelLeft) delete pChannelLeft; + if (pChannelRight) delete pChannelRight; + // fallback to render directly into AudioOutputDevice's buffers + if (pEngine && pEngine->pAudioOutputDevice) { + pChannelLeft = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft); + pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); + } else { // we update the pointers later + pChannelLeft = NULL; + pChannelRight = NULL; + } + } + break; + } + } + if (pEngine) pEngine->Enable(); + fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); + } + /** * Will be called by the MIDIIn Thread to let the audio thread trigger a new - * voice for the given key. + * voice for the given key. This method is meant for real time rendering, + * that is an event will immediately be created with the current system + * time as time stamp. * * @param Key - MIDI key number of the triggered key * @param Velocity - MIDI velocity value of the triggered key @@ -368,12 +511,60 @@ event.pEngineChannel = this; if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); else dmsg(1,("EngineChannel: Input event queue full!")); + // inform connected virtual MIDI devices if any ... + // (e.g. virtual MIDI keyboard in instrument editor(s)) + ArrayList& devices = + const_cast&>( + virtualMidiDevicesReader_MidiThread.Lock() + ); + for (int i = 0; i < devices.size(); i++) { + devices[i]->SendNoteOnToDevice(Key, Velocity); + } + virtualMidiDevicesReader_MidiThread.Unlock(); + } + } + + /** + * Will be called by the MIDIIn Thread to let the audio thread trigger a new + * voice for the given key. This method is meant for offline rendering + * and / or for cases where the exact position of the event in the current + * audio fragment is already known. + * + * @param Key - MIDI key number of the triggered key + * @param Velocity - MIDI velocity value of the triggered key + * @param FragmentPos - sample point position in the current audio + * fragment to which this event belongs to + */ + void EngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { + if (FragmentPos < 0) { + dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); + } + else if (pEngine) { + Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); + event.Type = Event::type_note_on; + event.Param.Note.Key = Key; + event.Param.Note.Velocity = Velocity; + event.pEngineChannel = this; + if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); + else dmsg(1,("EngineChannel: Input event queue full!")); + // inform connected virtual MIDI devices if any ... + // (e.g. virtual MIDI keyboard in instrument editor(s)) + ArrayList& devices = + const_cast&>( + virtualMidiDevicesReader_MidiThread.Lock() + ); + for (int i = 0; i < devices.size(); i++) { + devices[i]->SendNoteOnToDevice(Key, Velocity); + } + virtualMidiDevicesReader_MidiThread.Unlock(); } } /** * Will be called by the MIDIIn Thread to signal the audio thread to release - * voice(s) on the given key. + * voice(s) on the given key. This method is meant for real time rendering, + * that is an event will immediately be created with the current system + * time as time stamp. * * @param Key - MIDI key number of the released key * @param Velocity - MIDI release velocity value of the released key @@ -387,12 +578,60 @@ event.pEngineChannel = this; if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); else dmsg(1,("EngineChannel: Input event queue full!")); + // inform connected virtual MIDI devices if any ... + // (e.g. virtual MIDI keyboard in instrument editor(s)) + ArrayList& devices = + const_cast&>( + virtualMidiDevicesReader_MidiThread.Lock() + ); + for (int i = 0; i < devices.size(); i++) { + devices[i]->SendNoteOffToDevice(Key, Velocity); + } + virtualMidiDevicesReader_MidiThread.Unlock(); + } + } + + /** + * Will be called by the MIDIIn Thread to signal the audio thread to release + * voice(s) on the given key. This method is meant for offline rendering + * and / or for cases where the exact position of the event in the current + * audio fragment is already known. + * + * @param Key - MIDI key number of the released key + * @param Velocity - MIDI release velocity value of the released key + * @param FragmentPos - sample point position in the current audio + * fragment to which this event belongs to + */ + void EngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { + if (FragmentPos < 0) { + dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); + } + else if (pEngine) { + Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); + event.Type = Event::type_note_off; + event.Param.Note.Key = Key; + event.Param.Note.Velocity = Velocity; + event.pEngineChannel = this; + if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); + else dmsg(1,("EngineChannel: Input event queue full!")); + // inform connected virtual MIDI devices if any ... + // (e.g. virtual MIDI keyboard in instrument editor(s)) + ArrayList& devices = + const_cast&>( + virtualMidiDevicesReader_MidiThread.Lock() + ); + for (int i = 0; i < devices.size(); i++) { + devices[i]->SendNoteOffToDevice(Key, Velocity); + } + virtualMidiDevicesReader_MidiThread.Unlock(); } } /** * Will be called by the MIDIIn Thread to signal the audio thread to change - * the pitch value for all voices. + * the pitch value for all voices. This method is meant for real time + * rendering, that is an event will immediately be created with the + * current system time as time stamp. * * @param Pitch - MIDI pitch value (-8192 ... +8191) */ @@ -408,8 +647,34 @@ } /** + * Will be called by the MIDIIn Thread to signal the audio thread to change + * the pitch value for all voices. This method is meant for offline + * rendering and / or for cases where the exact position of the event in + * the current audio fragment is already known. + * + * @param Pitch - MIDI pitch value (-8192 ... +8191) + * @param FragmentPos - sample point position in the current audio + * fragment to which this event belongs to + */ + void EngineChannel::SendPitchbend(int Pitch, int32_t FragmentPos) { + if (FragmentPos < 0) { + dmsg(1,("EngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); + } + else if (pEngine) { + Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); + event.Type = Event::type_pitchbend; + event.Param.Pitch.Pitch = Pitch; + event.pEngineChannel = this; + if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); + else dmsg(1,("EngineChannel: Input event queue full!")); + } + } + + /** * Will be called by the MIDIIn Thread to signal the audio thread that a - * continuous controller value has changed. + * continuous controller value has changed. This method is meant for real + * time rendering, that is an event will immediately be created with the + * current system time as time stamp. * * @param Controller - MIDI controller number of the occured control change * @param Value - value of the control change @@ -426,6 +691,32 @@ } } + /** + * Will be called by the MIDIIn Thread to signal the audio thread that a + * continuous controller value has changed. This method is meant for + * offline rendering and / or for cases where the exact position of the + * event in the current audio fragment is already known. + * + * @param Controller - MIDI controller number of the occured control change + * @param Value - value of the control change + * @param FragmentPos - sample point position in the current audio + * fragment to which this event belongs to + */ + void EngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos) { + if (FragmentPos < 0) { + dmsg(1,("EngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); + } + else if (pEngine) { + Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); + event.Type = Event::type_control_change; + event.Param.CC.Controller = Controller; + event.Param.CC.Value = Value; + event.pEngineChannel = this; + if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); + else dmsg(1,("EngineChannel: Input event queue full!")); + } + } + void EngineChannel::ClearEventLists() { pEvents->clear(); // empty MIDI key specific event lists @@ -442,11 +733,21 @@ Pitch = 0; SustainPedal = false; SostenutoPedal = false; - GlobalVolume = CONFIG_GLOBAL_ATTENUATION; + GlobalVolume = 1.0f; + MidiVolume = 1.0; GlobalPanLeft = 1.0f; GlobalPanRight = 1.0f; + iLastPanRequest = 64; + GlobalTranspose = 0; // set all MIDI controller values to zero - memset(ControllerTable, 0x00, 128); + memset(ControllerTable, 0x00, 129); + // reset all FX Send levels + for ( + std::vector::iterator iter = fxSends.begin(); + iter != fxSends.end(); iter++ + ) { + (*iter)->Reset(); + } } /** @@ -463,7 +764,41 @@ * current audio cycle */ void EngineChannel::ImportEvents(uint Samples) { - RingBuffer::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); + // import events from pure software MIDI "devices" + // (e.g. virtual keyboard in instrument editor) + { + const int FragmentPos = 0; // randomly chosen, we don't care about jitter for virtual MIDI devices + Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); + VirtualMidiDevice::event_t devEvent; // the event format we get from the virtual MIDI device + // as we're going to (carefully) write some status to the + // synchronized struct, we cast away the const + ArrayList& devices = + const_cast&>(virtualMidiDevicesReader_AudioThread.Lock()); + // iterate through all virtual MIDI devices + for (int i = 0; i < devices.size(); i++) { + VirtualMidiDevice* pDev = devices[i]; + // I think we can simply flush the whole FIFO(s), the user shouldn't be so fast ;-) + while (pDev->GetMidiEventFromDevice(devEvent)) { + event.Type = + (devEvent.Type == VirtualMidiDevice::EVENT_TYPE_NOTEON) ? + Event::type_note_on : Event::type_note_off; + event.Param.Note.Key = devEvent.Key; + event.Param.Note.Velocity = devEvent.Velocity; + event.pEngineChannel = this; + // copy event to internal event list + if (pEvents->poolIsEmpty()) { + dmsg(1,("Event pool emtpy!\n")); + goto exitVirtualDevicesLoop; + } + *pEvents->allocAppend() = event; + } + } + } + exitVirtualDevicesLoop: + virtualMidiDevicesReader_AudioThread.Unlock(); + + // import events from the regular MIDI devices + RingBuffer::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); Event* pEvent; while (true) { // get next event from input event queue @@ -485,6 +820,53 @@ eventQueueReader.free(); // free all copied events from input queue } + void EngineChannel::RemoveAllFxSends() { + if (pEngine) pEngine->DisableAndLock(); + if (!fxSends.empty()) { // free local render buffers + if (pChannelLeft) { + delete pChannelLeft; + if (pEngine && pEngine->pAudioOutputDevice) { + // fallback to render directly to the AudioOutputDevice's buffer + pChannelLeft = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft); + } else pChannelLeft = NULL; + } + if (pChannelRight) { + delete pChannelRight; + if (pEngine && pEngine->pAudioOutputDevice) { + // fallback to render directly to the AudioOutputDevice's buffer + pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); + } else pChannelRight = NULL; + } + } + for (int i = 0; i < fxSends.size(); i++) delete fxSends[i]; + fxSends.clear(); + if (pEngine) pEngine->Enable(); + } + + void EngineChannel::Connect(VirtualMidiDevice* pDevice) { + // double buffer ... double work ... + { + ArrayList& devices = virtualMidiDevices.GetConfigForUpdate(); + devices.add(pDevice); + } + { + ArrayList& devices = virtualMidiDevices.SwitchConfig(); + devices.add(pDevice); + } + } + + void EngineChannel::Disconnect(VirtualMidiDevice* pDevice) { + // double buffer ... double work ... + { + ArrayList& devices = virtualMidiDevices.GetConfigForUpdate(); + devices.remove(pDevice); + } + { + ArrayList& devices = virtualMidiDevices.SwitchConfig(); + devices.remove(pDevice); + } + } + float EngineChannel::Volume() { return GlobalVolume; } @@ -494,6 +876,19 @@ bStatusChanged = true; // status of engine channel has changed, so set notify flag } + float EngineChannel::Pan() { + return float(iLastPanRequest - 64) / 64.0f; + } + + void EngineChannel::Pan(float f) { + int iMidiPan = int(f * 64.0f) + 64; + if (iMidiPan > 127) iMidiPan = 127; + else if (iMidiPan < 0) iMidiPan = 0; + GlobalPanLeft = Engine::PanCurve[128 - iMidiPan]; + GlobalPanRight = Engine::PanCurve[iMidiPan]; + iLastPanRequest = iMidiPan; + } + uint EngineChannel::Channels() { return 2; }