/[svn]/linuxsampler/trunk/src/engines/gig/Engine.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/gig/Engine.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 244 - (hide annotations) (download) (as text)
Fri Sep 17 01:01:11 2004 UTC (19 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10342 byte(s)
* added support for scale tuning via MIDI GS system exclusive message

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 53 * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #ifndef __LS_GIG_ENGINE_H__
24     #define __LS_GIG_ENGINE_H__
25    
26     #include "../../common/global.h"
27    
28     #if DEBUG_HEADERS
29     # warning Engine.h included
30     #endif // DEBUG_HEADERS
31    
32 schoenebeck 239 #include <map>
33    
34 schoenebeck 53 #include "../../common/RingBuffer.h"
35     #include "../../common/RTELMemoryPool.h"
36     #include "../../common/ConditionServer.h"
37     #include "../common/Engine.h"
38     #include "../common/Event.h"
39 schoenebeck 80 #include "../common/BiquadFilter.h"
40 schoenebeck 53 #include "../../lib/fileloader/libgig/gig.h"
41     #include "InstrumentResourceManager.h"
42     #include "../../network/lscp.h"
43    
44     #define PITCHBEND_SEMITONES 12
45 schoenebeck 80 #define MAX_AUDIO_VOICES 128
46 schoenebeck 244 #define SYSEX_BUFFER_SIZE 2048 // 2kB
47 schoenebeck 53
48     namespace LinuxSampler { namespace gig {
49    
50 schoenebeck 239 using std::map;
51    
52 schoenebeck 53 // just symbol prototyping
53     class Voice;
54     class DiskThread;
55     class InstrumentResourceManager;
56    
57     /**
58     * Sampler engine for the Gigasampler format.
59     */
60     class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer {
61     public:
62     // methods
63     Engine();
64     ~Engine();
65    
66     // abstract methods derived from class 'LinuxSampler::Engine'
67     virtual void LoadInstrument(const char* FileName, uint Instrument);
68     virtual void Reset();
69     virtual void Enable();
70     virtual void Disable();
71     virtual void SendNoteOn(uint8_t Key, uint8_t Velocity);
72     virtual void SendNoteOff(uint8_t Key, uint8_t Velocity);
73     virtual void SendPitchbend(int Pitch);
74     virtual void SendControlChange(uint8_t Controller, uint8_t Value);
75 schoenebeck 244 virtual void SendSysex(void* pData, uint Size);
76 schoenebeck 53 virtual float Volume();
77     virtual void Volume(float f);
78 schoenebeck 225 virtual uint Channels();
79 schoenebeck 53 virtual void Connect(AudioOutputDevice* pAudioOut);
80     virtual void DisconnectAudioOutputDevice();
81 schoenebeck 225 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
82     virtual int OutputChannel(uint EngineAudioChannel);
83 schoenebeck 53 virtual int RenderAudio(uint Samples);
84     virtual uint VoiceCount();
85     virtual uint VoiceCountMax();
86     virtual bool DiskStreamSupported();
87     virtual uint DiskStreamCount();
88     virtual uint DiskStreamCountMax();
89     virtual String DiskStreamBufferFillBytes();
90     virtual String DiskStreamBufferFillPercentage();
91     virtual String Description();
92     virtual String Version();
93 senkov 112 virtual String EngineName();
94     virtual String InstrumentFileName();
95     virtual int InstrumentIndex();
96 capela 133 virtual int InstrumentStatus();
97 schoenebeck 53
98     // abstract methods derived from interface class 'InstrumentConsumer'
99     virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
100     virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
101     protected:
102     struct midi_key_info_t {
103 schoenebeck 242 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
104     bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
105     bool Active; ///< If the key contains active voices.
106     bool ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released
107     uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys
108     RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
109 schoenebeck 53 };
110    
111     static InstrumentResourceManager Instruments;
112    
113     AudioOutputDevice* pAudioOutputDevice;
114 schoenebeck 225 float* pOutputLeft; ///< Audio output channel buffer (left)
115     float* pOutputRight; ///< Audio output channel buffer (right)
116     int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
117     int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
118     uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
119     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
120 schoenebeck 53 DiskThread* pDiskThread;
121     uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
122     RingBuffer<Event>* pEventQueue; ///< Input event queue.
123 schoenebeck 244 RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
124 schoenebeck 53 midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
125     RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
126     RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices.
127     RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used.
128     EventGenerator* pEventGenerator;
129     RTEList<Event>* pEvents; ///< All events for the current audio fragment.
130     RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment.
131     RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
132     float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
133 schoenebeck 80 biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
134     biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
135 schoenebeck 239 map<uint,uint*> ActiveKeyGroups; ///< Contains active keys (in case they belong to a key group) ordered by key group ID.
136 schoenebeck 53 RIFF::File* pRIFF;
137     ::gig::File* pGig;
138     ::gig::Instrument* pInstrument;
139     bool SustainPedal; ///< true if sustain pedal is down
140     double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
141     int Pitch; ///< Current (absolute) MIDI pitch value.
142     int ActiveVoiceCount; ///< number of currently active voices
143     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
144     bool SuspensionRequested;
145     ConditionServer EngineDisabled;
146 senkov 112 String InstrumentFile;
147     int InstrumentIdx;
148 capela 133 int InstrumentStat;
149 schoenebeck 244 int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
150 schoenebeck 53
151     void ProcessNoteOn(Event* pNoteOnEvent);
152     void ProcessNoteOff(Event* pNoteOffEvent);
153     void ProcessPitchbend(Event* pPitchbendEvent);
154     void ProcessControlChange(Event* pControlChangeEvent);
155 schoenebeck 244 void ProcessSysex(Event* pSysexEvent);
156 schoenebeck 242 void LaunchVoice(Event* pNoteOnEvent, int iLayer = 0, bool ReleaseTriggerVoice = false);
157 schoenebeck 239 void KillVoiceImmediately(Voice* pVoice);
158 schoenebeck 53 void ResetSynthesisParameters(Event::destination_t dst, float val);
159     void ResetInternal();
160    
161     friend class Voice;
162     friend class EGADSR;
163     friend class EGDecay;
164     friend class VCAManipulator;
165     friend class VCFCManipulator;
166     friend class VCOManipulator;
167     friend class InstrumentResourceManager;
168     private:
169 schoenebeck 244 void DisableAndLock();
170     uint8_t GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize);
171     void AdjustScale(int8_t ScaleTunes[12]);
172 schoenebeck 53 };
173    
174     }} // namespace LinuxSampler::gig
175    
176     #endif // __LS_GIG_ENGINE_H__

  ViewVC Help
Powered by ViewVC