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