2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
|
* Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
23 |
***************************************************************************/ |
***************************************************************************/ |
24 |
|
|
25 |
#ifndef __LS_GIG_ENGINE_H__ |
#ifndef __LS_GIG_ENGINE_H__ |
26 |
#define __LS_GIG_ENGINE_H__ |
#define __LS_GIG_ENGINE_H__ |
27 |
|
|
28 |
#include "../../common/global.h" |
#include "DiskThread.h" |
29 |
|
#include "../EngineBase.h" |
30 |
#if DEBUG_HEADERS |
#include "Voice.h" |
31 |
# warning Engine.h included |
#include <gig.h> |
|
#endif // DEBUG_HEADERS |
|
|
|
|
|
#include "../../common/RingBuffer.h" |
|
|
#include "../../common/RTELMemoryPool.h" |
|
|
#include "../../common/ConditionServer.h" |
|
|
#include "../common/Engine.h" |
|
|
#include "../common/Event.h" |
|
|
#include "../common/BiquadFilter.h" |
|
|
#include "../../lib/fileloader/libgig/gig.h" |
|
|
#include "InstrumentResourceManager.h" |
|
|
#include "../../network/lscp.h" |
|
|
|
|
|
#define PITCHBEND_SEMITONES 12 |
|
|
#define MAX_AUDIO_VOICES 128 |
|
32 |
|
|
33 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
34 |
|
|
35 |
// just symbol prototyping |
class Engine: public LinuxSampler::EngineBase<Voice, ::gig::Region, ::gig::DimensionRegion, DiskThread, InstrumentResourceManager, ::gig::Instrument> { |
|
class Voice; |
|
|
class DiskThread; |
|
|
class InstrumentResourceManager; |
|
|
|
|
|
/** |
|
|
* Sampler engine for the Gigasampler format. |
|
|
*/ |
|
|
class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer { |
|
36 |
public: |
public: |
37 |
// methods |
Engine() { } |
38 |
Engine(); |
virtual ~Engine() { } |
39 |
~Engine(); |
// implementation of abstract methods derived from class 'LinuxSampler::Engine' |
40 |
|
virtual bool DiskStreamSupported(); |
41 |
// abstract methods derived from class 'LinuxSampler::Engine' |
virtual String Description(); |
42 |
virtual void LoadInstrument(const char* FileName, uint Instrument); |
virtual String Version(); |
43 |
virtual void Reset(); |
|
44 |
virtual void Enable(); |
virtual Format GetEngineFormat(); |
45 |
virtual void Disable(); |
|
46 |
virtual void SendNoteOn(uint8_t Key, uint8_t Velocity); |
virtual void ProcessControlChange ( |
47 |
virtual void SendNoteOff(uint8_t Key, uint8_t Velocity); |
LinuxSampler::EngineChannel* pEngineChannel, |
48 |
virtual void SendPitchbend(int Pitch); |
Pool<Event>::Iterator& itControlChangeEvent |
49 |
virtual void SendControlChange(uint8_t Controller, uint8_t Value); |
); |
|
virtual float Volume(); |
|
|
virtual void Volume(float f); |
|
|
virtual void Connect(AudioOutputDevice* pAudioOut); |
|
|
virtual void DisconnectAudioOutputDevice(); |
|
|
virtual int RenderAudio(uint Samples); |
|
|
virtual uint VoiceCount(); |
|
|
virtual uint VoiceCountMax(); |
|
|
virtual bool DiskStreamSupported(); |
|
|
virtual uint DiskStreamCount(); |
|
|
virtual uint DiskStreamCountMax(); |
|
|
virtual String DiskStreamBufferFillBytes(); |
|
|
virtual String DiskStreamBufferFillPercentage(); |
|
|
virtual String Description(); |
|
|
virtual String Version(); |
|
|
|
|
|
// abstract methods derived from interface class 'InstrumentConsumer' |
|
|
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg); |
|
|
virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg); |
|
|
protected: |
|
|
struct midi_key_info_t { |
|
|
RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key. |
|
|
bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed. |
|
|
bool Active; ///< If the key contains active voices. |
|
|
uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys |
|
|
RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently) |
|
|
}; |
|
|
|
|
|
static InstrumentResourceManager Instruments; |
|
|
|
|
|
AudioOutputDevice* pAudioOutputDevice; |
|
|
DiskThread* pDiskThread; |
|
|
uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. |
|
|
RingBuffer<Event>* pEventQueue; ///< Input event queue. |
|
|
midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key |
|
|
RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated. |
|
|
RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
|
|
RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used. |
|
|
EventGenerator* pEventGenerator; |
|
|
RTEList<Event>* pEvents; ///< All events for the current audio fragment. |
|
|
RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment. |
|
|
RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). |
|
|
float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop. |
|
|
biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter. |
|
|
biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass). |
|
|
RIFF::File* pRIFF; |
|
|
::gig::File* pGig; |
|
|
::gig::Instrument* pInstrument; |
|
|
bool SustainPedal; ///< true if sustain pedal is down |
|
|
double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification) |
|
|
int Pitch; ///< Current (absolute) MIDI pitch value. |
|
|
int ActiveVoiceCount; ///< number of currently active voices |
|
|
int ActiveVoiceCountMax; ///< the maximum voice usage since application start |
|
|
bool SuspensionRequested; |
|
|
ConditionServer EngineDisabled; |
|
|
|
|
|
void ProcessNoteOn(Event* pNoteOnEvent); |
|
|
void ProcessNoteOff(Event* pNoteOffEvent); |
|
|
void ProcessPitchbend(Event* pPitchbendEvent); |
|
|
void ProcessControlChange(Event* pControlChangeEvent); |
|
|
void KillVoice(Voice* pVoice); |
|
|
void ResetSynthesisParameters(Event::destination_t dst, float val); |
|
|
void ResetInternal(); |
|
50 |
|
|
51 |
friend class Voice; |
friend class Voice; |
52 |
friend class EGADSR; |
|
53 |
friend class EGDecay; |
protected: |
54 |
friend class VCAManipulator; |
virtual DiskThread* CreateDiskThread(); |
55 |
friend class VCFCManipulator; |
|
56 |
friend class VCOManipulator; |
virtual Pool<Voice>::Iterator LaunchVoice ( |
57 |
friend class InstrumentResourceManager; |
LinuxSampler::EngineChannel* pEngineChannel, |
58 |
private: |
Pool<Event>::Iterator& itNoteOnEvent, |
59 |
void DisableAndLock(); |
int iLayer, |
60 |
|
bool ReleaseTriggerVoice, |
61 |
|
bool VoiceStealing, |
62 |
|
bool HandleKeyGroupConflicts |
63 |
|
); |
64 |
|
|
65 |
|
virtual void TriggerNewVoices ( |
66 |
|
LinuxSampler::EngineChannel* pEngineChannel, |
67 |
|
RTList<Event>::Iterator& itNoteOnEvent, |
68 |
|
bool HandleKeyGroupConflicts |
69 |
|
); |
70 |
|
|
71 |
|
void TriggerReleaseVoices ( |
72 |
|
LinuxSampler::EngineChannel* pEngineChannel, |
73 |
|
RTList<Event>::Iterator& itNoteOffEvent |
74 |
|
); |
75 |
}; |
}; |
76 |
|
|
77 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |
78 |
|
|
79 |
#endif // __LS_GIG_ENGINE_H__ |
#endif /* __LS_GIG_ENGINE_H__ */ |
80 |
|
|