1/*
2 * Copyright 2006-2014, Haiku.
3 *
4 * Copyright (c) 2004-2005 Matthijs Hollemans
5 * Copyright (c) 2003 Jerome Leveque
6 * Distributed under the terms of the MIT License.
7 *
8 * Authors:
9 * 		J��r��me Duval
10 *		J��r��me Leveque
11 *		Matthijs Hollemans
12 *		Pete Goodeve
13 */
14
15#ifndef _SOFT_SYNTH_H
16#define _SOFT_SYNTH_H
17
18/*
19	This version of SoftSynth is a wrapper libfluidsynth.so.
20 */
21
22#include <fluidlite.h>
23#include <Midi.h>
24#include <SoundPlayer.h>
25#include <Synth.h>
26
27class BMidiConsumer;
28class BMidiSynth;
29class BSynth;
30
31namespace BPrivate {
32
33class BSoftSynth {
34public:
35	bool InitCheck();
36
37	void Unload();
38	bool IsLoaded() const;
39
40	status_t SetDefaultInstrumentsFile();
41	status_t SetInstrumentsFile(const char* path);
42
43	status_t LoadAllInstruments();
44	status_t LoadInstrument(int16 instrument);
45	status_t UnloadInstrument(int16 instrument);
46	status_t RemapInstrument(int16 from, int16 to);
47	void FlushInstrumentCache(bool startStopCache);
48
49	void SetVolume(double volume);
50	double Volume(void) const;
51
52	status_t SetSamplingRate(int32 rate);
53	int32 SamplingRate() const;
54
55	status_t SetInterpolation(interpolation_mode mode);
56	interpolation_mode Interpolation() const;
57
58	status_t EnableReverb(bool enabled);
59	bool IsReverbEnabled() const;
60	void SetReverb(reverb_mode mode);
61	reverb_mode Reverb() const;
62
63	status_t SetMaxVoices(int32 max);
64	int16 MaxVoices(void) const;
65
66	status_t SetLimiterThreshold(int32 threshold);
67	int16 LimiterThreshold(void) const;
68
69	void Pause(void);
70	void Resume(void);
71
72	void NoteOff(uchar, uchar, uchar, uint32);
73	void NoteOn(uchar, uchar, uchar, uint32);
74	void KeyPressure(uchar, uchar, uchar, uint32);
75	void ControlChange(uchar, uchar, uchar, uint32);
76	void ProgramChange(uchar, uchar, uint32);
77 	void ChannelPressure(uchar, uchar, uint32);
78	void PitchBend(uchar, uchar, uchar, uint32);
79	void SystemExclusive(void*, size_t, uint32);
80	void SystemCommon(uchar, uchar, uchar, uint32);
81	void SystemRealTime(uchar, uint32);
82	void TempoChange(int32, uint32);
83	void AllNotesOff(bool, uint32);
84
85private:
86
87	friend class ::BSynth;
88	friend class ::BMidiSynth;
89
90	BSoftSynth();
91	~BSoftSynth();
92
93	void _Init();
94	void _Done();
95	static void PlayBuffer(void* cookie, void* data, size_t size,
96			const media_raw_audio_format& format);
97
98	bool fInitCheck;
99	char* fInstrumentsFile;
100	int32 fSampleRate;
101	interpolation_mode fInterpMode;
102	int16 fMaxVoices;
103	int16 fLimiterThreshold;
104	reverb_mode fReverbMode;
105	bool fReverbEnabled;
106
107	fluid_synth_t* fSynth;
108	fluid_settings_t* fSettings;
109
110	BSoundPlayer* fSoundPlayer;
111
112	float* fMonitor;
113	size_t fMonitorSize;
114	int16 fMonitorChans;
115};
116
117} // namespace BPrivate
118
119#endif // _SOFT_SYNTH_H
120