xref: /haiku/src/kits/midi/SoftSynth.h (revision 94bfc1f561e5349d40af906de09c50efadabbc99)
1fbaf754aSmahlzeit /*
277f87987SJérôme Duval  * Copyright 2006, 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
12fbaf754aSmahlzeit  */
13fbaf754aSmahlzeit 
14fbaf754aSmahlzeit #ifndef _SOFT_SYNTH_H
15fbaf754aSmahlzeit #define _SOFT_SYNTH_H
16fbaf754aSmahlzeit 
17d1c4420eSmahlzeit /*
182df2b984SJérôme Duval 	This version of SoftSynth is a wrapper libfluidsynth.so.
19d1c4420eSmahlzeit  */
20d1c4420eSmahlzeit 
21e3a74a24SJérôme Duval #include <fluidsynth.h>
222df2b984SJérôme Duval #include <Midi.h>
232df2b984SJérôme Duval #include <SoundPlayer.h>
242df2b984SJérôme Duval #include <Synth.h>
25e3a74a24SJérôme Duval 
26d1c4420eSmahlzeit class BMidiConsumer;
2765f512e0SIngo Weinhold class BMidiSynth;
2865f512e0SIngo Weinhold class BSynth;
29d1c4420eSmahlzeit 
30fbaf754aSmahlzeit namespace BPrivate {
31fbaf754aSmahlzeit 
32*94bfc1f5SStefano Ceccherini class BSoftSynth {
33fbaf754aSmahlzeit public:
34bafde775SJérôme Duval 	bool InitCheck();
35d1c4420eSmahlzeit 
36e3a74a24SJérôme Duval 	void Unload();
37e3a74a24SJérôme Duval 	bool IsLoaded() const;
38fbaf754aSmahlzeit 
39fbaf754aSmahlzeit 	status_t SetDefaultInstrumentsFile();
40fbaf754aSmahlzeit 	status_t SetInstrumentsFile(const char* path);
41fbaf754aSmahlzeit 
42fbaf754aSmahlzeit 	status_t LoadAllInstruments();
43fbaf754aSmahlzeit 	status_t LoadInstrument(int16 instrument);
44fbaf754aSmahlzeit 	status_t UnloadInstrument(int16 instrument);
45fbaf754aSmahlzeit 	status_t RemapInstrument(int16 from, int16 to);
46fbaf754aSmahlzeit 	void FlushInstrumentCache(bool startStopCache);
47fbaf754aSmahlzeit 
48fbaf754aSmahlzeit 	void SetVolume(double volume);
49fbaf754aSmahlzeit 	double Volume(void) const;
50fbaf754aSmahlzeit 
51fbaf754aSmahlzeit 	status_t SetSamplingRate(int32 rate);
52fbaf754aSmahlzeit 	int32 SamplingRate() const;
53fbaf754aSmahlzeit 
54fbaf754aSmahlzeit 	status_t SetInterpolation(interpolation_mode mode);
55fbaf754aSmahlzeit 	interpolation_mode Interpolation() const;
56fbaf754aSmahlzeit 
57fbaf754aSmahlzeit 	status_t EnableReverb(bool enabled);
58fbaf754aSmahlzeit 	bool IsReverbEnabled() const;
59fbaf754aSmahlzeit 	void SetReverb(reverb_mode mode);
60fbaf754aSmahlzeit 	reverb_mode Reverb() const;
61fbaf754aSmahlzeit 
62fbaf754aSmahlzeit 	status_t SetMaxVoices(int32 max);
63fbaf754aSmahlzeit 	int16 MaxVoices(void) const;
64fbaf754aSmahlzeit 
65fbaf754aSmahlzeit 	status_t SetLimiterThreshold(int32 threshold);
66fbaf754aSmahlzeit 	int16 LimiterThreshold(void) const;
67fbaf754aSmahlzeit 
68fbaf754aSmahlzeit 	void Pause(void);
69fbaf754aSmahlzeit 	void Resume(void);
70fbaf754aSmahlzeit 
71fbaf754aSmahlzeit 	void NoteOff(uchar, uchar, uchar, uint32);
72fbaf754aSmahlzeit 	void NoteOn(uchar, uchar, uchar, uint32);
73fbaf754aSmahlzeit 	void KeyPressure(uchar, uchar, uchar, uint32);
74fbaf754aSmahlzeit 	void ControlChange(uchar, uchar, uchar, uint32);
75fbaf754aSmahlzeit 	void ProgramChange(uchar, uchar, uint32);
76fbaf754aSmahlzeit  	void ChannelPressure(uchar, uchar, uint32);
77fbaf754aSmahlzeit 	void PitchBend(uchar, uchar, uchar, uint32);
78fbaf754aSmahlzeit 	void SystemExclusive(void*, size_t, uint32);
79fbaf754aSmahlzeit 	void SystemCommon(uchar, uchar, uchar, uint32);
80fbaf754aSmahlzeit 	void SystemRealTime(uchar, uint32);
81fbaf754aSmahlzeit 	void TempoChange(int32, uint32);
82fbaf754aSmahlzeit 	void AllNotesOff(bool, uint32);
83fbaf754aSmahlzeit 
84fbaf754aSmahlzeit private:
85fbaf754aSmahlzeit 
8665f512e0SIngo Weinhold 	friend class ::BSynth;
8765f512e0SIngo Weinhold 	friend class ::BMidiSynth;
88fbaf754aSmahlzeit 
89fbaf754aSmahlzeit 	BSoftSynth();
90fbaf754aSmahlzeit 	~BSoftSynth();
91fbaf754aSmahlzeit 
924810cdcdSJérôme Duval 	void _Init();
934810cdcdSJérôme Duval 	void _Done();
94*94bfc1f5SStefano Ceccherini 	static void PlayBuffer(void* cookie, void* data, size_t size,
95*94bfc1f5SStefano Ceccherini 			const media_raw_audio_format& format);
96d1c4420eSmahlzeit 
97e3a74a24SJérôme Duval 	bool fInitCheck;
98e3a74a24SJérôme Duval 	char* fInstrumentsFile;
99e3a74a24SJérôme Duval 	int32 fSampleRate;
100e3a74a24SJérôme Duval 	interpolation_mode fInterpMode;
101e3a74a24SJérôme Duval 	int16 fMaxVoices;
102e3a74a24SJérôme Duval 	int16 fLimiterThreshold;
103e3a74a24SJérôme Duval 	reverb_mode fReverbMode;
104e3a74a24SJérôme Duval 	bool fReverbEnabled;
105d1c4420eSmahlzeit 
106e3a74a24SJérôme Duval 	fluid_synth_t* fSynth;
107e3a74a24SJérôme Duval 	fluid_settings_t* fSettings;
108d1c4420eSmahlzeit 
109e3a74a24SJérôme Duval 	BSoundPlayer* fSoundPlayer;
110fbaf754aSmahlzeit };
111fbaf754aSmahlzeit 
112fbaf754aSmahlzeit } // namespace BPrivate
113fbaf754aSmahlzeit 
1142df2b984SJérôme Duval #endif // _SOFT_SYNTH_H
115