Line 0
Link Here
|
|
|
1 |
From 1f7cd3ed5af6640c0e38a2dc2d9be5a9ae036dc8 Mon Sep 17 00:00:00 2001 |
2 |
From: Hyunjin Song <tteu.ingog@gmail.com> |
3 |
Date: Sun, 28 Oct 2018 10:31:33 +0900 |
4 |
Subject: [PATCH] Allow building SF2 player with FluidSynth 2.x (#4678) |
5 |
|
6 |
Resolves the incompatibility between FluidSynth 1.x and 2.x |
7 |
due to some API changes by shimming some functions. |
8 |
|
9 |
Note that 1.x and 2.x are not binary compatible. |
10 |
--- |
11 |
plugins/sf2_player/fluidsynthshims.h | 88 +++++++++++++++++++++++++++ |
12 |
plugins/sf2_player/patches_dialog.cpp | 44 ++++++++------ |
13 |
plugins/sf2_player/patches_dialog.h | 2 +- |
14 |
plugins/sf2_player/sf2_player.cpp | 43 ++++++++++--- |
15 |
plugins/sf2_player/sf2_player.h | 2 +- |
16 |
5 files changed, 152 insertions(+), 27 deletions(-) |
17 |
create mode 100644 plugins/sf2_player/fluidsynthshims.h |
18 |
|
19 |
diff --git plugins/sf2_player/fluidsynthshims.h plugins/sf2_player/fluidsynthshims.h |
20 |
new file mode 100644 |
21 |
index 0000000000..4302256ba3 |
22 |
--- /dev/null |
23 |
+++ plugins/sf2_player/fluidsynthshims.h |
24 |
@@ -0,0 +1,88 @@ |
25 |
+/* |
26 |
+ * fluidsynthshims.h - a shim header for FluidSynth 2.0 API changes |
27 |
+ * |
28 |
+ * Copyright (c) 2018 Hyunjin Song <tteu.ingog@gmail.com> |
29 |
+ * |
30 |
+ * This file is part of LMMS - https://lmms.io |
31 |
+ * |
32 |
+ * This program is free software; you can redistribute it and/or |
33 |
+ * modify it under the terms of the GNU General Public |
34 |
+ * License as published by the Free Software Foundation; either |
35 |
+ * version 2 of the License, or (at your option) any later version. |
36 |
+ * |
37 |
+ * This program is distributed in the hope that it will be useful, |
38 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
39 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
40 |
+ * General Public License for more details. |
41 |
+ * |
42 |
+ * You should have received a copy of the GNU General Public |
43 |
+ * License along with this program (see COPYING); if not, write to the |
44 |
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
45 |
+ * Boston, MA 02110-1301 USA. |
46 |
+ * |
47 |
+ */ |
48 |
+ |
49 |
+ |
50 |
+#ifndef FLUIDSYNTHSHIMS_H |
51 |
+#define FLUIDSYNTHSHIMS_H |
52 |
+ |
53 |
+#include <fluidsynth.h> |
54 |
+ |
55 |
+#if FLUIDSYNTH_VERSION_MAJOR < 2 |
56 |
+ |
57 |
+inline const char* fluid_preset_get_name(fluid_preset_t* preset) |
58 |
+{ |
59 |
+ return preset->get_name(preset); |
60 |
+} |
61 |
+ |
62 |
+inline int fluid_preset_get_banknum(fluid_preset_t* preset) |
63 |
+{ |
64 |
+ return preset->get_banknum(preset); |
65 |
+} |
66 |
+ |
67 |
+inline int fluid_preset_get_num(fluid_preset_t* preset) |
68 |
+{ |
69 |
+ return preset->get_num(preset); |
70 |
+} |
71 |
+ |
72 |
+inline fluid_sfont_t* fluid_preset_get_sfont(fluid_preset_t* preset) |
73 |
+{ |
74 |
+ return preset->sfont; |
75 |
+} |
76 |
+ |
77 |
+inline char* fluid_sfont_get_name(fluid_sfont_t* sfont) |
78 |
+{ |
79 |
+ return sfont->get_name(sfont); |
80 |
+} |
81 |
+ |
82 |
+inline void fluid_sfont_iteration_start(fluid_sfont_t* sfont) |
83 |
+{ |
84 |
+ sfont->iteration_start(sfont); |
85 |
+} |
86 |
+ |
87 |
+// Due to the API change, we can't simply shim the 'fluid_sfont_iteration_next' function |
88 |
+inline fluid_preset_t* fluid_sfont_iteration_next_wrapper(fluid_sfont_t* sfont, fluid_preset_t* preset) |
89 |
+{ |
90 |
+ return sfont->iteration_next(sfont, preset) ? preset : nullptr; |
91 |
+} |
92 |
+ |
93 |
+#else // FLUIDSYNTH_VERSION_MAJOR < 2 |
94 |
+ |
95 |
+#define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f |
96 |
+#define FLUID_REVERB_DEFAULT_DAMP 0.0f |
97 |
+#define FLUID_REVERB_DEFAULT_WIDTH 0.5f |
98 |
+#define FLUID_REVERB_DEFAULT_LEVEL 0.9f |
99 |
+ |
100 |
+#define FLUID_CHORUS_DEFAULT_N 3 |
101 |
+#define FLUID_CHORUS_DEFAULT_LEVEL 2.0f |
102 |
+#define FLUID_CHORUS_DEFAULT_SPEED 0.3f |
103 |
+#define FLUID_CHORUS_DEFAULT_DEPTH 8.0f |
104 |
+ |
105 |
+inline fluid_preset_t* fluid_sfont_iteration_next_wrapper(fluid_sfont_t* sfont, fluid_preset_t*) |
106 |
+{ |
107 |
+ return fluid_sfont_iteration_next(sfont); |
108 |
+} |
109 |
+ |
110 |
+#endif // FLUIDSYNTH_VERSION_MAJOR < 2 |
111 |
+ |
112 |
+#endif // FLUIDSYNTHSHIMS_H |
113 |
diff --git plugins/sf2_player/patches_dialog.cpp plugins/sf2_player/patches_dialog.cpp |
114 |
index 6ae791c155..189d996f30 100644 |
115 |
--- plugins/sf2_player/patches_dialog.cpp |
116 |
+++ plugins/sf2_player/patches_dialog.cpp |
117 |
@@ -143,7 +143,6 @@ void patchesDialog::setup ( fluid_synth_t * pSynth, int iChan, |
118 |
m_iChan = iChan; |
119 |
|
120 |
|
121 |
- fluid_preset_t preset; |
122 |
QTreeWidgetItem *pBankItem = NULL; |
123 |
// For all soundfonts (in reversed stack order) fill the available banks... |
124 |
int cSoundFonts = ::fluid_synth_sfcount(m_pSynth); |
125 |
@@ -151,11 +150,17 @@ void patchesDialog::setup ( fluid_synth_t * pSynth, int iChan, |
126 |
fluid_sfont_t *pSoundFont = ::fluid_synth_get_sfont(m_pSynth, i); |
127 |
if (pSoundFont) { |
128 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
129 |
- int iBankOffset = ::fluid_synth_get_bank_offset(m_pSynth, pSoundFont->id); |
130 |
+ int iBankOffset = ::fluid_synth_get_bank_offset(m_pSynth, fluid_sfont_get_id(pSoundFont)); |
131 |
#endif |
132 |
- pSoundFont->iteration_start(pSoundFont); |
133 |
- while (pSoundFont->iteration_next(pSoundFont, &preset)) { |
134 |
- int iBank = preset.get_banknum(&preset); |
135 |
+ fluid_sfont_iteration_start(pSoundFont); |
136 |
+#if FLUIDSYNTH_VERSION_MAJOR < 2 |
137 |
+ fluid_preset_t preset; |
138 |
+ fluid_preset_t *pCurPreset = &preset; |
139 |
+#else |
140 |
+ fluid_preset_t *pCurPreset; |
141 |
+#endif |
142 |
+ while ((pCurPreset = fluid_sfont_iteration_next_wrapper(pSoundFont, pCurPreset))) { |
143 |
+ int iBank = fluid_preset_get_banknum(pCurPreset); |
144 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
145 |
iBank += iBankOffset; |
146 |
#endif |
147 |
@@ -173,9 +178,9 @@ void patchesDialog::setup ( fluid_synth_t * pSynth, int iChan, |
148 |
m_iBank = 0; |
149 |
fluid_preset_t *pPreset = ::fluid_synth_get_channel_preset(m_pSynth, m_iChan); |
150 |
if (pPreset) { |
151 |
- m_iBank = pPreset->get_banknum(pPreset); |
152 |
+ m_iBank = fluid_preset_get_banknum(pPreset); |
153 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
154 |
- m_iBank += ::fluid_synth_get_bank_offset(m_pSynth, (pPreset->sfont)->id); |
155 |
+ m_iBank += ::fluid_synth_get_bank_offset(m_pSynth, fluid_sfont_get_id(fluid_preset_get_sfont(sfont))); |
156 |
#endif |
157 |
} |
158 |
|
159 |
@@ -186,7 +191,7 @@ void patchesDialog::setup ( fluid_synth_t * pSynth, int iChan, |
160 |
|
161 |
// Set the selected program. |
162 |
if (pPreset) |
163 |
- m_iProg = pPreset->get_num(pPreset); |
164 |
+ m_iProg = fluid_preset_get_num(pPreset); |
165 |
QTreeWidgetItem *pProgItem = findProgItem(m_iProg); |
166 |
m_progListView->setCurrentItem(pProgItem); |
167 |
m_progListView->scrollToItem(pProgItem); |
168 |
@@ -312,7 +317,6 @@ void patchesDialog::bankChanged (void) |
169 |
// Clear up the program listview. |
170 |
m_progListView->setSortingEnabled(false); |
171 |
m_progListView->clear(); |
172 |
- fluid_preset_t preset; |
173 |
QTreeWidgetItem *pProgItem = NULL; |
174 |
// For all soundfonts (in reversed stack order) fill the available programs... |
175 |
int cSoundFonts = ::fluid_synth_sfcount(m_pSynth); |
176 |
@@ -320,23 +324,29 @@ void patchesDialog::bankChanged (void) |
177 |
fluid_sfont_t *pSoundFont = ::fluid_synth_get_sfont(m_pSynth, i); |
178 |
if (pSoundFont) { |
179 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
180 |
- int iBankOffset = ::fluid_synth_get_bank_offset(m_pSynth, pSoundFont->id); |
181 |
+ int iBankOffset = ::fluid_synth_get_bank_offset(m_pSynth, fluid_sfont_get_id(pSoundFont)); |
182 |
+#endif |
183 |
+ fluid_sfont_iteration_start(pSoundFont); |
184 |
+#if FLUIDSYNTH_VERSION_MAJOR < 2 |
185 |
+ fluid_preset_t preset; |
186 |
+ fluid_preset_t *pCurPreset = &preset; |
187 |
+#else |
188 |
+ fluid_preset_t *pCurPreset; |
189 |
#endif |
190 |
- pSoundFont->iteration_start(pSoundFont); |
191 |
- while (pSoundFont->iteration_next(pSoundFont, &preset)) { |
192 |
- int iBank = preset.get_banknum(&preset); |
193 |
+ while ((pCurPreset = fluid_sfont_iteration_next_wrapper(pSoundFont, pCurPreset))) { |
194 |
+ int iBank = fluid_preset_get_banknum(pCurPreset); |
195 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
196 |
iBank += iBankOffset; |
197 |
#endif |
198 |
- int iProg = preset.get_num(&preset); |
199 |
+ int iProg = fluid_preset_get_num(pCurPreset); |
200 |
if (iBank == iBankSelected && !findProgItem(iProg)) { |
201 |
pProgItem = new patchItem(m_progListView, pProgItem); |
202 |
if (pProgItem) { |
203 |
pProgItem->setText(0, QString::number(iProg)); |
204 |
- pProgItem->setText(1, preset.get_name(&preset)); |
205 |
- //pProgItem->setText(2, QString::number(pSoundFont->id)); |
206 |
+ pProgItem->setText(1, fluid_preset_get_name(pCurPreset)); |
207 |
+ //pProgItem->setText(2, QString::number(fluid_sfont_get_id(pSoundFont))); |
208 |
//pProgItem->setText(3, QFileInfo( |
209 |
- // pSoundFont->get_name(pSoundFont)).baseName()); |
210 |
+ // fluid_sfont_get_name(pSoundFont).baseName()); |
211 |
} |
212 |
} |
213 |
} |
214 |
diff --git plugins/sf2_player/patches_dialog.h plugins/sf2_player/patches_dialog.h |
215 |
index f4523ff904..a2c88a79d1 100644 |
216 |
--- plugins/sf2_player/patches_dialog.h |
217 |
+++ plugins/sf2_player/patches_dialog.h |
218 |
@@ -29,7 +29,7 @@ |
219 |
#include "ui_patches_dialog.h" |
220 |
#include "LcdSpinBox.h" |
221 |
|
222 |
-#include <fluidsynth.h> |
223 |
+#include "fluidsynthshims.h" |
224 |
#include <QWidget> |
225 |
#include <QLabel> |
226 |
|
227 |
diff --git plugins/sf2_player/sf2_player.cpp plugins/sf2_player/sf2_player.cpp |
228 |
index 742f5fb8e1..f7a09f01e7 100644 |
229 |
--- plugins/sf2_player/sf2_player.cpp |
230 |
+++ plugins/sf2_player/sf2_player.cpp |
231 |
@@ -127,6 +127,29 @@ sf2Instrument::sf2Instrument( InstrumentTrack * _instrument_track ) : |
232 |
// everytime we load a new soundfont. |
233 |
m_synth = new_fluid_synth( m_settings ); |
234 |
|
235 |
+#if FLUIDSYNTH_VERSION_MAJOR >= 2 |
236 |
+ // Get the default values from the setting |
237 |
+ double settingVal; |
238 |
+ |
239 |
+ fluid_settings_getnum_default(m_settings, "synth.reverb.room-size", &settingVal); |
240 |
+ m_reverbRoomSize.setInitValue(settingVal); |
241 |
+ fluid_settings_getnum_default(m_settings, "synth.reverb.damping", &settingVal); |
242 |
+ m_reverbDamping.setInitValue(settingVal); |
243 |
+ fluid_settings_getnum_default(m_settings, "synth.reverb.width", &settingVal); |
244 |
+ m_reverbWidth.setInitValue(settingVal); |
245 |
+ fluid_settings_getnum_default(m_settings, "synth.reverb.level", &settingVal); |
246 |
+ m_reverbLevel.setInitValue(settingVal); |
247 |
+ |
248 |
+ fluid_settings_getnum_default(m_settings, "synth.chorus.nr", &settingVal); |
249 |
+ m_chorusNum.setInitValue(settingVal); |
250 |
+ fluid_settings_getnum_default(m_settings, "synth.chorus.level", &settingVal); |
251 |
+ m_chorusLevel.setInitValue(settingVal); |
252 |
+ fluid_settings_getnum_default(m_settings, "synth.chorus.speed", &settingVal); |
253 |
+ m_chorusSpeed.setInitValue(settingVal); |
254 |
+ fluid_settings_getnum_default(m_settings, "synth.chorus.depth", &settingVal); |
255 |
+ m_chorusDepth.setInitValue(settingVal); |
256 |
+#endif |
257 |
+ |
258 |
loadFile( ConfigManager::inst()->defaultSoundfont() ); |
259 |
|
260 |
updateSampleRate(); |
261 |
@@ -392,7 +415,6 @@ QString sf2Instrument::getCurrentPatchName() |
262 |
int iBankSelected = m_bankNum.value(); |
263 |
int iProgSelected = m_patchNum.value(); |
264 |
|
265 |
- fluid_preset_t preset; |
266 |
// For all soundfonts (in reversed stack order) fill the available programs... |
267 |
int cSoundFonts = ::fluid_synth_sfcount( m_synth ); |
268 |
for( int i = 0; i < cSoundFonts; i++ ) |
269 |
@@ -403,21 +425,26 @@ QString sf2Instrument::getCurrentPatchName() |
270 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
271 |
int iBankOffset = |
272 |
fluid_synth_get_bank_offset( |
273 |
- m_synth, pSoundFont->id ); |
274 |
+ m_synth, fluid_sfont_get_id(pSoundFont) ); |
275 |
+#endif |
276 |
+ fluid_sfont_iteration_start( pSoundFont ); |
277 |
+#if FLUIDSYNTH_VERSION_MAJOR < 2 |
278 |
+ fluid_preset_t preset; |
279 |
+ fluid_preset_t *pCurPreset = &preset; |
280 |
+#else |
281 |
+ fluid_preset_t *pCurPreset; |
282 |
#endif |
283 |
- pSoundFont->iteration_start( pSoundFont ); |
284 |
- while( pSoundFont->iteration_next( pSoundFont, |
285 |
- &preset ) ) |
286 |
+ while ((pCurPreset = fluid_sfont_iteration_next_wrapper(pSoundFont, pCurPreset))) |
287 |
{ |
288 |
- int iBank = preset.get_banknum( &preset ); |
289 |
+ int iBank = fluid_preset_get_banknum( pCurPreset ); |
290 |
#ifdef CONFIG_FLUID_BANK_OFFSET |
291 |
iBank += iBankOffset; |
292 |
#endif |
293 |
- int iProg = preset.get_num( &preset ); |
294 |
+ int iProg = fluid_preset_get_num( pCurPreset ); |
295 |
if( iBank == iBankSelected && iProg == |
296 |
iProgSelected ) |
297 |
{ |
298 |
- return preset.get_name( &preset ); |
299 |
+ return fluid_preset_get_name( pCurPreset ); |
300 |
} |
301 |
} |
302 |
} |
303 |
diff --git plugins/sf2_player/sf2_player.h plugins/sf2_player/sf2_player.h |
304 |
index 0d29c27e1f..eed7e24ab3 100644 |
305 |
--- plugins/sf2_player/sf2_player.h |
306 |
+++ plugins/sf2_player/sf2_player.h |
307 |
@@ -36,7 +36,7 @@ |
308 |
#include "Knob.h" |
309 |
#include "LcdSpinBox.h" |
310 |
#include "LedCheckbox.h" |
311 |
-#include "fluidsynth.h" |
312 |
+#include "fluidsynthshims.h" |
313 |
#include "MemoryManager.h" |
314 |
|
315 |
class sf2InstrumentView; |