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 * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2013 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 * |
31 |
#include "../common/ConditionServer.h" |
#include "../common/ConditionServer.h" |
32 |
#include "../common/Pool.h" |
#include "../common/Pool.h" |
33 |
#include "../common/RingBuffer.h" |
#include "../common/RingBuffer.h" |
34 |
|
#include "../common/ChangeFlagRelaxed.h" |
35 |
|
#include "../common/ResourceManager.h" |
36 |
#include "../drivers/audio/AudioOutputDevice.h" |
#include "../drivers/audio/AudioOutputDevice.h" |
37 |
#include "common/Event.h" |
#include "common/Event.h" |
38 |
|
#include "common/Note.h" |
39 |
#include "common/SignalUnitRack.h" |
#include "common/SignalUnitRack.h" |
40 |
|
#include "common/InstrumentScriptVM.h" |
41 |
|
|
42 |
namespace LinuxSampler { |
namespace LinuxSampler { |
43 |
|
|
55 |
virtual ~AbstractEngine(); |
virtual ~AbstractEngine(); |
56 |
|
|
57 |
// implementation of abstract methods derived from class 'LinuxSampler::Engine' |
// implementation of abstract methods derived from class 'LinuxSampler::Engine' |
58 |
virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender); |
virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender) OVERRIDE; |
59 |
virtual void Reset(); |
virtual void Reset() OVERRIDE; |
60 |
virtual void Enable(); |
virtual void Enable() OVERRIDE; |
61 |
virtual void Disable(); |
virtual void Disable() OVERRIDE; |
62 |
virtual uint VoiceCount(); |
virtual uint VoiceCount() OVERRIDE; |
63 |
virtual uint VoiceCountMax(); |
virtual uint VoiceCountMax() OVERRIDE; |
64 |
virtual String EngineName(); |
virtual String EngineName() OVERRIDE; |
65 |
|
virtual void AdjustScaleTuning(const int8_t ScaleTunes[12]) OVERRIDE; |
66 |
|
virtual void GetScaleTuning(int8_t* pScaleTunes) OVERRIDE; |
67 |
|
virtual void ResetScaleTuning() OVERRIDE; |
68 |
|
|
69 |
virtual Format GetEngineFormat() = 0; |
virtual Format GetEngineFormat() = 0; |
70 |
virtual void Connect(AudioOutputDevice* pAudioOut) = 0; |
virtual void Connect(AudioOutputDevice* pAudioOut) = 0; |
71 |
virtual void DisableAndLock(); |
virtual void DisableAndLock(); |
72 |
|
|
73 |
void SetVoiceCount(uint Count);// Simple array wrapper just to make sure memory is freed |
void SetVoiceCount(uint Count); |
74 |
// when liblinuxsampler is unloaded |
|
75 |
|
/** |
76 |
|
* Returns event with the given event ID. |
77 |
|
*/ |
78 |
|
RTList<Event>::Iterator EventByID(event_id_t id) { |
79 |
|
return pEventPool->fromID(id); |
80 |
|
} |
81 |
|
|
82 |
|
virtual NoteBase* NoteByID(note_id_t id) = 0; |
83 |
|
|
84 |
float Random() { |
float Random() { |
85 |
RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator |
RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator |
86 |
return RandomSeed / 4294967296.0f; |
return RandomSeed / 4294967296.0f; |
87 |
} |
} |
88 |
|
|
89 |
|
// Simple array wrapper just to make sure memory is freed |
90 |
|
// when liblinuxsampler is unloaded |
91 |
class FloatTable { |
class FloatTable { |
92 |
private: |
private: |
93 |
const float* array; |
const float* array; |
101 |
static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center). |
static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center). |
102 |
static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127. |
static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127. |
103 |
|
|
104 |
|
static float PanCurveValueNorm(float pan, int channel); |
105 |
|
|
106 |
AudioOutputDevice* pAudioOutputDevice; |
AudioOutputDevice* pAudioOutputDevice; |
107 |
|
|
108 |
//TODO: should be protected |
//TODO: should be protected |
114 |
template<class V, class R, class I> friend class EngineChannelBase; |
template<class V, class R, class I> friend class EngineChannelBase; |
115 |
template<class EC, class R, class S, class D> friend class VoiceBase; |
template<class EC, class R, class S, class D> friend class VoiceBase; |
116 |
|
|
117 |
protected: |
//protected: |
118 |
ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance. |
ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance. |
119 |
ConditionServer EngineDisabled; |
ConditionServer EngineDisabled; |
120 |
int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave |
int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave |
121 |
|
ChangeFlagRelaxed ScaleTuningChanged; ///< Boolean flag indicating whenever ScaleTuning has been modified by a foreign thread (i.e. by API). |
122 |
RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages). |
RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages). |
123 |
EventGenerator* pEventGenerator; |
EventGenerator* pEventGenerator; |
124 |
RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages). |
RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages). |
130 |
int ActiveVoiceCountMax; ///< the maximum voice usage since application start |
int ActiveVoiceCountMax; ///< the maximum voice usage since application start |
131 |
atomic_t ActiveVoiceCount; ///< number of currently active voices |
atomic_t ActiveVoiceCount; ///< number of currently active voices |
132 |
int VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit. |
int VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit. |
133 |
|
InstrumentScriptVM* pScriptVM; ///< Real-time instrument script virtual machine runner for this engine. |
134 |
|
|
135 |
void RouteAudio(EngineChannel* pEngineChannel, uint Samples); |
void RouteAudio(EngineChannel* pEngineChannel, uint Samples); |
136 |
void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples); |
void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples); |
137 |
void ClearEventLists(); |
void ClearEventLists(); |
138 |
void ImportEvents(uint Samples); |
void ImportEvents(uint Samples); |
139 |
void ProcessSysex(Pool<Event>::Iterator& itSysexEvent); |
void ProcessSysex(Pool<Event>::Iterator& itSysexEvent); |
|
void ResetScaleTuning(); |
|
140 |
void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent); |
void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent); |
141 |
|
|
142 |
void ProcessFxSendControllers ( |
void ProcessFxSendControllers ( |
151 |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0; |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0; |
152 |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0; |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0; |
153 |
virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0; |
virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0; |
154 |
|
virtual void ProcessChannelPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itChannelPressureEvent) = 0; |
155 |
|
virtual void ProcessPolyphonicKeyPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNotePressureEvent) = 0; |
156 |
|
virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) = 0; |
157 |
virtual int GetMinFadeOutSamples() = 0; |
virtual int GetMinFadeOutSamples() = 0; |
158 |
|
virtual note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) = 0; |
159 |
|
virtual void CreateInstrumentScriptVM(); |
160 |
|
|
161 |
private: |
private: |
162 |
static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines; |
static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines; |
167 |
static float* InitCrossfadeCurve(); |
static float* InitCrossfadeCurve(); |
168 |
static float* InitCurve(const float* segments, int size = 128); |
static float* InitCurve(const float* segments, int size = 128); |
169 |
|
|
|
void AdjustScale(int8_t ScaleTunes[12]); |
|
170 |
bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples); |
bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples); |
171 |
}; |
}; |
172 |
|
|