/[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 233 - (hide annotations) (download) (as text)
Tue Sep 7 09:32:21 2004 UTC (19 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9404 byte(s)
* added support for layers
* fixed initial pitch calculation which did not honor the sample's own
  sample rate

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     #include "../../common/RingBuffer.h"
33     #include "../../common/RTELMemoryPool.h"
34     #include "../../common/ConditionServer.h"
35     #include "../common/Engine.h"
36     #include "../common/Event.h"
37 schoenebeck 80 #include "../common/BiquadFilter.h"
38 schoenebeck 53 #include "../../lib/fileloader/libgig/gig.h"
39     #include "InstrumentResourceManager.h"
40     #include "../../network/lscp.h"
41    
42     #define PITCHBEND_SEMITONES 12
43 schoenebeck 80 #define MAX_AUDIO_VOICES 128
44 schoenebeck 53
45     namespace LinuxSampler { namespace gig {
46    
47     // just symbol prototyping
48     class Voice;
49     class DiskThread;
50     class InstrumentResourceManager;
51    
52     /**
53     * Sampler engine for the Gigasampler format.
54     */
55     class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer {
56     public:
57     // methods
58     Engine();
59     ~Engine();
60    
61     // abstract methods derived from class 'LinuxSampler::Engine'
62     virtual void LoadInstrument(const char* FileName, uint Instrument);
63     virtual void Reset();
64     virtual void Enable();
65     virtual void Disable();
66     virtual void SendNoteOn(uint8_t Key, uint8_t Velocity);
67     virtual void SendNoteOff(uint8_t Key, uint8_t Velocity);
68     virtual void SendPitchbend(int Pitch);
69     virtual void SendControlChange(uint8_t Controller, uint8_t Value);
70     virtual float Volume();
71     virtual void Volume(float f);
72 schoenebeck 225 virtual uint Channels();
73 schoenebeck 53 virtual void Connect(AudioOutputDevice* pAudioOut);
74     virtual void DisconnectAudioOutputDevice();
75 schoenebeck 225 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
76     virtual int OutputChannel(uint EngineAudioChannel);
77 schoenebeck 53 virtual int RenderAudio(uint Samples);
78     virtual uint VoiceCount();
79     virtual uint VoiceCountMax();
80     virtual bool DiskStreamSupported();
81     virtual uint DiskStreamCount();
82     virtual uint DiskStreamCountMax();
83     virtual String DiskStreamBufferFillBytes();
84     virtual String DiskStreamBufferFillPercentage();
85     virtual String Description();
86     virtual String Version();
87 senkov 112 virtual String EngineName();
88     virtual String InstrumentFileName();
89     virtual int InstrumentIndex();
90 capela 133 virtual int InstrumentStatus();
91 schoenebeck 53
92     // abstract methods derived from interface class 'InstrumentConsumer'
93     virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
94     virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
95     protected:
96     struct midi_key_info_t {
97     RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
98     bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
99     bool Active; ///< If the key contains active voices.
100     uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys
101     RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
102     };
103    
104     static InstrumentResourceManager Instruments;
105    
106     AudioOutputDevice* pAudioOutputDevice;
107 schoenebeck 225 float* pOutputLeft; ///< Audio output channel buffer (left)
108     float* pOutputRight; ///< Audio output channel buffer (right)
109     int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
110     int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
111     uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
112     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
113 schoenebeck 53 DiskThread* pDiskThread;
114     uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
115     RingBuffer<Event>* pEventQueue; ///< Input event queue.
116     midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
117     RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
118     RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices.
119     RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used.
120     EventGenerator* pEventGenerator;
121     RTEList<Event>* pEvents; ///< All events for the current audio fragment.
122     RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment.
123     RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
124     float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
125 schoenebeck 80 biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
126     biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
127 schoenebeck 53 RIFF::File* pRIFF;
128     ::gig::File* pGig;
129     ::gig::Instrument* pInstrument;
130     bool SustainPedal; ///< true if sustain pedal is down
131     double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
132     int Pitch; ///< Current (absolute) MIDI pitch value.
133     int ActiveVoiceCount; ///< number of currently active voices
134     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
135     bool SuspensionRequested;
136     ConditionServer EngineDisabled;
137 senkov 112 String InstrumentFile;
138     int InstrumentIdx;
139 capela 133 int InstrumentStat;
140 schoenebeck 53
141     void ProcessNoteOn(Event* pNoteOnEvent);
142     void ProcessNoteOff(Event* pNoteOffEvent);
143     void ProcessPitchbend(Event* pPitchbendEvent);
144     void ProcessControlChange(Event* pControlChangeEvent);
145 schoenebeck 233 void LaunchVoice(Event* pNoteOnEvent, int iLayer = 0);
146 schoenebeck 53 void KillVoice(Voice* pVoice);
147     void ResetSynthesisParameters(Event::destination_t dst, float val);
148     void ResetInternal();
149    
150     friend class Voice;
151     friend class EGADSR;
152     friend class EGDecay;
153     friend class VCAManipulator;
154     friend class VCFCManipulator;
155     friend class VCOManipulator;
156     friend class InstrumentResourceManager;
157     private:
158     void DisableAndLock();
159     };
160    
161     }} // namespace LinuxSampler::gig
162    
163     #endif // __LS_GIG_ENGINE_H__

  ViewVC Help
Powered by ViewVC