24 |
#include "EngineChannel.h" |
#include "EngineChannel.h" |
25 |
|
|
26 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
27 |
|
#include "../../Sampler.h" |
28 |
|
|
29 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
30 |
|
|
31 |
EngineChannel::EngineChannel() : |
EngineChannel::EngineChannel() : |
32 |
InstrumentChangeCommandReader(InstrumentChangeCommand), |
InstrumentChangeCommandReader(InstrumentChangeCommand), |
33 |
virtualMidiDevicesReader(virtualMidiDevices) |
virtualMidiDevicesReader_AudioThread(virtualMidiDevices), |
34 |
|
virtualMidiDevicesReader_MidiThread(virtualMidiDevices) |
35 |
{ |
{ |
36 |
pMIDIKeyInfo = new midi_key_info_t[128]; |
pMIDIKeyInfo = new midi_key_info_t[128]; |
37 |
pEngine = NULL; |
pEngine = NULL; |
64 |
|
|
65 |
EngineChannel::~EngineChannel() { |
EngineChannel::~EngineChannel() { |
66 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
67 |
|
|
68 |
|
// In case the channel was removed before the instrument was |
69 |
|
// fully loaded, try to give back instrument again (see bug #113) |
70 |
|
instrument_change_command_t& cmd = ChangeInstrument(NULL); |
71 |
|
if (cmd.pInstrument) { |
72 |
|
Engine::instruments.HandBack(cmd.pInstrument, this); |
73 |
|
} |
74 |
|
/////// |
75 |
|
|
76 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
77 |
if (pActiveKeys) delete pActiveKeys; |
if (pActiveKeys) delete pActiveKeys; |
78 |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
339 |
// release the currently loaded instrument |
// release the currently loaded instrument |
340 |
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, d); |
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, d); |
341 |
} |
} |
342 |
|
|
343 |
if (d) delete d; |
if (d) delete d; |
344 |
|
|
345 |
// release all active dimension regions to resource |
// release all active dimension regions to resource |
462 |
} |
} |
463 |
fxSends.push_back(pFxSend); |
fxSends.push_back(pFxSend); |
464 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
465 |
fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); |
fireFxSendCountChanged(GetSamplerChannel()->Index(), GetFxSendCount()); |
466 |
|
|
467 |
return pFxSend; |
return pFxSend; |
468 |
} |
} |
501 |
} |
} |
502 |
} |
} |
503 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
504 |
fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); |
fireFxSendCountChanged(GetSamplerChannel()->Index(), GetFxSendCount()); |
505 |
} |
} |
506 |
|
|
507 |
/** |
/** |
522 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
523 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
524 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
525 |
// inform instrument editor(s), if any ... |
// inform connected virtual MIDI devices if any ... |
526 |
pEngine->instruments.TrySendNoteOnToEditors(Key, Velocity, pInstrument); |
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
527 |
|
ArrayList<VirtualMidiDevice*>& devices = |
528 |
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
529 |
|
virtualMidiDevicesReader_MidiThread.Lock() |
530 |
|
); |
531 |
|
for (int i = 0; i < devices.size(); i++) { |
532 |
|
devices[i]->SendNoteOnToDevice(Key, Velocity); |
533 |
|
} |
534 |
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
535 |
} |
} |
536 |
} |
} |
537 |
|
|
558 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
559 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
560 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
561 |
// inform instrument editor(s), if any ... |
// inform connected virtual MIDI devices if any ... |
562 |
pEngine->instruments.TrySendNoteOnToEditors(Key, Velocity, pInstrument); |
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
563 |
|
ArrayList<VirtualMidiDevice*>& devices = |
564 |
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
565 |
|
virtualMidiDevicesReader_MidiThread.Lock() |
566 |
|
); |
567 |
|
for (int i = 0; i < devices.size(); i++) { |
568 |
|
devices[i]->SendNoteOnToDevice(Key, Velocity); |
569 |
|
} |
570 |
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
571 |
} |
} |
572 |
} |
} |
573 |
|
|
589 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
590 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
591 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
592 |
// inform instrument editor(s), if any ... |
// inform connected virtual MIDI devices if any ... |
593 |
pEngine->instruments.TrySendNoteOffToEditors(Key, Velocity, pInstrument); |
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
594 |
|
ArrayList<VirtualMidiDevice*>& devices = |
595 |
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
596 |
|
virtualMidiDevicesReader_MidiThread.Lock() |
597 |
|
); |
598 |
|
for (int i = 0; i < devices.size(); i++) { |
599 |
|
devices[i]->SendNoteOffToDevice(Key, Velocity); |
600 |
|
} |
601 |
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
602 |
} |
} |
603 |
} |
} |
604 |
|
|
625 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
626 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
627 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
628 |
// inform instrument editor(s), if any ... |
// inform connected virtual MIDI devices if any ... |
629 |
pEngine->instruments.TrySendNoteOffToEditors(Key, Velocity, pInstrument); |
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
630 |
|
ArrayList<VirtualMidiDevice*>& devices = |
631 |
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
632 |
|
virtualMidiDevicesReader_MidiThread.Lock() |
633 |
|
); |
634 |
|
for (int i = 0; i < devices.size(); i++) { |
635 |
|
devices[i]->SendNoteOffToDevice(Key, Velocity); |
636 |
|
} |
637 |
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
638 |
} |
} |
639 |
} |
} |
640 |
|
|
748 |
MidiVolume = 1.0; |
MidiVolume = 1.0; |
749 |
GlobalPanLeft = 1.0f; |
GlobalPanLeft = 1.0f; |
750 |
GlobalPanRight = 1.0f; |
GlobalPanRight = 1.0f; |
751 |
|
iLastPanRequest = 64; |
752 |
GlobalTranspose = 0; |
GlobalTranspose = 0; |
753 |
// set all MIDI controller values to zero |
// set all MIDI controller values to zero |
754 |
memset(ControllerTable, 0x00, 129); |
memset(ControllerTable, 0x00, 129); |
784 |
// as we're going to (carefully) write some status to the |
// as we're going to (carefully) write some status to the |
785 |
// synchronized struct, we cast away the const |
// synchronized struct, we cast away the const |
786 |
ArrayList<VirtualMidiDevice*>& devices = |
ArrayList<VirtualMidiDevice*>& devices = |
787 |
const_cast<ArrayList<VirtualMidiDevice*>&>(virtualMidiDevicesReader.Lock()); |
const_cast<ArrayList<VirtualMidiDevice*>&>(virtualMidiDevicesReader_AudioThread.Lock()); |
788 |
// iterate through all virtual MIDI devices |
// iterate through all virtual MIDI devices |
789 |
for (int i = 0; i < devices.size(); i++) { |
for (int i = 0; i < devices.size(); i++) { |
790 |
VirtualMidiDevice* pDev = devices[i]; |
VirtualMidiDevice* pDev = devices[i]; |
806 |
} |
} |
807 |
} |
} |
808 |
exitVirtualDevicesLoop: |
exitVirtualDevicesLoop: |
809 |
virtualMidiDevicesReader.Unlock(); |
virtualMidiDevicesReader_AudioThread.Unlock(); |
810 |
|
|
811 |
// import events from the regular MIDI devices |
// import events from the regular MIDI devices |
812 |
RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
887 |
bStatusChanged = true; // status of engine channel has changed, so set notify flag |
bStatusChanged = true; // status of engine channel has changed, so set notify flag |
888 |
} |
} |
889 |
|
|
890 |
|
float EngineChannel::Pan() { |
891 |
|
return float(iLastPanRequest - 64) / 64.0f; |
892 |
|
} |
893 |
|
|
894 |
|
void EngineChannel::Pan(float f) { |
895 |
|
int iMidiPan = int(f * 64.0f) + 64; |
896 |
|
if (iMidiPan > 127) iMidiPan = 127; |
897 |
|
else if (iMidiPan < 0) iMidiPan = 0; |
898 |
|
GlobalPanLeft = Engine::PanCurve[128 - iMidiPan]; |
899 |
|
GlobalPanRight = Engine::PanCurve[iMidiPan]; |
900 |
|
iLastPanRequest = iMidiPan; |
901 |
|
} |
902 |
|
|
903 |
uint EngineChannel::Channels() { |
uint EngineChannel::Channels() { |
904 |
return 2; |
return 2; |
905 |
} |
} |