Document the different filter types, and combine some split lines
[openal-soft.git] / Alc / midi / base.h
blob42a4c2798f125f07916554ee8208d5c2bd0a5353
1 #ifndef AL_MIDI_BASE_H
2 #define AL_MIDI_BASE_H
4 #include "alMain.h"
5 #include "atomic.h"
6 #include "evtqueue.h"
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
12 struct ALsoundfont;
14 typedef size_t (*ReaderCb)(void *ptr, size_t size, void *stream);
15 typedef struct Reader {
16 ReaderCb cb;
17 void *ptr;
18 int error;
19 } Reader;
20 #define READ(x_, buf_, len_) ((x_)->cb((buf_), (len_), (x_)->ptr))
21 #define READERR(x_) ((x_)->error)
23 ALboolean loadSf2(Reader *stream, struct ALsoundfont *sfont, ALCcontext *context);
26 #define MIDI_CLOCK_RES U64(1000000000)
29 struct MidiSynthVtable;
31 typedef struct MidiSynth {
32 EvtQueue EventQueue;
34 ALuint64 ClockBase;
35 ALuint SamplesDone;
36 ALuint SampleRate;
38 /* NOTE: This rwlock is for the state and soundfont. The EventQueue and
39 * related must instead use the device lock as they're used in the mixer
40 * thread.
42 RWLock Lock;
44 struct ALsoundfont **Soundfonts;
45 ALsizei NumSoundfonts;
47 volatile ALfloat Gain;
48 volatile ALenum State;
50 const struct MidiSynthVtable *vtbl;
51 } MidiSynth;
53 void MidiSynth_Construct(MidiSynth *self, ALCdevice *device);
54 void MidiSynth_Destruct(MidiSynth *self);
55 ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids);
56 inline void MidiSynth_setGain(MidiSynth *self, ALfloat gain) { self->Gain = gain; }
57 inline ALfloat MidiSynth_getGain(const MidiSynth *self) { return self->Gain; }
58 inline void MidiSynth_setState(MidiSynth *self, ALenum state) { ExchangeInt(&self->State, state); }
59 inline ALenum MidiSynth_getState(const MidiSynth *self) { return self->State; }
60 void MidiSynth_stop(MidiSynth *self);
61 inline void MidiSynth_reset(MidiSynth *self) { MidiSynth_stop(self); }
62 inline ALuint64 MidiSynth_getTime(const MidiSynth *self)
63 { return self->ClockBase + (self->SamplesDone*MIDI_CLOCK_RES/self->SampleRate); }
64 inline ALuint64 MidiSynth_getNextEvtTime(const MidiSynth *self)
66 if(self->EventQueue.pos == self->EventQueue.size)
67 return UINT64_MAX;
68 return self->EventQueue.events[self->EventQueue.pos].time;
70 void MidiSynth_setSampleRate(MidiSynth *self, ALuint srate);
71 inline void MidiSynth_update(MidiSynth *self, ALCdevice *device)
72 { MidiSynth_setSampleRate(self, device->Frequency); }
73 ALenum MidiSynth_insertEvent(MidiSynth *self, ALuint64 time, ALuint event, ALsizei param1, ALsizei param2);
74 ALenum MidiSynth_insertSysExEvent(MidiSynth *self, ALuint64 time, const ALbyte *data, ALsizei size);
77 struct MidiSynthVtable {
78 void (*const Destruct)(MidiSynth *self);
80 ALenum (*const selectSoundfonts)(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids);
82 void (*const setGain)(MidiSynth *self, ALfloat gain);
84 void (*const stop)(MidiSynth *self);
85 void (*const reset)(MidiSynth *self);
87 void (*const update)(MidiSynth *self, ALCdevice *device);
88 void (*const process)(MidiSynth *self, ALuint samples, ALfloat (*restrict DryBuffer)[BUFFERSIZE]);
90 void (*const Delete)(void *ptr);
93 #define DEFINE_MIDISYNTH_VTABLE(T) \
94 DECLARE_THUNK(T, MidiSynth, void, Destruct) \
95 DECLARE_THUNK3(T, MidiSynth, ALenum, selectSoundfonts, ALCcontext*, ALsizei, const ALuint*) \
96 DECLARE_THUNK1(T, MidiSynth, void, setGain, ALfloat) \
97 DECLARE_THUNK(T, MidiSynth, void, stop) \
98 DECLARE_THUNK(T, MidiSynth, void, reset) \
99 DECLARE_THUNK1(T, MidiSynth, void, update, ALCdevice*) \
100 DECLARE_THUNK2(T, MidiSynth, void, process, ALuint, ALfloatBUFFERSIZE*restrict) \
101 static void T##_MidiSynth_Delete(void *ptr) \
102 { T##_Delete(STATIC_UPCAST(T, MidiSynth, (MidiSynth*)ptr)); } \
104 static const struct MidiSynthVtable T##_MidiSynth_vtable = { \
105 T##_MidiSynth_Destruct, \
107 T##_MidiSynth_selectSoundfonts, \
108 T##_MidiSynth_setGain, \
109 T##_MidiSynth_stop, \
110 T##_MidiSynth_reset, \
111 T##_MidiSynth_update, \
112 T##_MidiSynth_process, \
114 T##_MidiSynth_Delete, \
118 MidiSynth *SSynth_create(ALCdevice *device);
119 MidiSynth *FSynth_create(ALCdevice *device);
120 MidiSynth *DSynth_create(ALCdevice *device);
122 MidiSynth *SynthCreate(ALCdevice *device);
124 #ifdef __cplusplus
126 #endif
128 #endif /* AL_MIDI_BASE_H */