xref: /haiku/src/kits/midi/SoftSynth.h (revision bc3955fea5b07e2e94a27fc05e4bb58fe6f0319b)
1 /*
2  * Copyright 2006, 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  */
13 
14 #ifndef _SOFT_SYNTH_H
15 #define _SOFT_SYNTH_H
16 
17 /*
18 	This version of SoftSynth is a wrapper libfluidsynth.so.
19  */
20 
21 #include <fluidsynth.h>
22 #include <Midi.h>
23 #include <SoundPlayer.h>
24 #include <Synth.h>
25 
26 class BMidiConsumer;
27 class BMidiSynth;
28 class BSynth;
29 
30 namespace BPrivate {
31 
32 class BSoftSynth
33 {
34 public:
35 
36 	bool InitCheck();
37 
38 	void Unload();
39 	bool IsLoaded() const;
40 
41 	status_t SetDefaultInstrumentsFile();
42 	status_t SetInstrumentsFile(const char* path);
43 
44 	status_t LoadAllInstruments();
45 	status_t LoadInstrument(int16 instrument);
46 	status_t UnloadInstrument(int16 instrument);
47 	status_t RemapInstrument(int16 from, int16 to);
48 	void FlushInstrumentCache(bool startStopCache);
49 
50 	void SetVolume(double volume);
51 	double Volume(void) const;
52 
53 	status_t SetSamplingRate(int32 rate);
54 	int32 SamplingRate() const;
55 
56 	status_t SetInterpolation(interpolation_mode mode);
57 	interpolation_mode Interpolation() const;
58 
59 	status_t EnableReverb(bool enabled);
60 	bool IsReverbEnabled() const;
61 	void SetReverb(reverb_mode mode);
62 	reverb_mode Reverb() const;
63 
64 	status_t SetMaxVoices(int32 max);
65 	int16 MaxVoices(void) const;
66 
67 	status_t SetLimiterThreshold(int32 threshold);
68 	int16 LimiterThreshold(void) const;
69 
70 	void Pause(void);
71 	void Resume(void);
72 
73 	void NoteOff(uchar, uchar, uchar, uint32);
74 	void NoteOn(uchar, uchar, uchar, uint32);
75 	void KeyPressure(uchar, uchar, uchar, uint32);
76 	void ControlChange(uchar, uchar, uchar, uint32);
77 	void ProgramChange(uchar, uchar, uint32);
78  	void ChannelPressure(uchar, uchar, uint32);
79 	void PitchBend(uchar, uchar, uchar, uint32);
80 	void SystemExclusive(void*, size_t, uint32);
81 	void SystemCommon(uchar, uchar, uchar, uint32);
82 	void SystemRealTime(uchar, uint32);
83 	void TempoChange(int32, uint32);
84 	void AllNotesOff(bool, uint32);
85 
86 private:
87 
88 	friend class ::BSynth;
89 	friend class ::BMidiSynth;
90 
91 	BSoftSynth();
92 	~BSoftSynth();
93 
94 	void _Init();
95 	void _Done();
96 	static void PlayBuffer(void * cookie, void * data, size_t size, 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 
113 } // namespace BPrivate
114 
115 #endif // _SOFT_SYNTH_H
116