Skip to content

Commit 30eed6e

Browse files
committed
Finalize runtime configuration support
1 parent b5196ac commit 30eed6e

File tree

7 files changed

+214
-40
lines changed

7 files changed

+214
-40
lines changed

src/device.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ device_add_common(const device_t *dev, const device_t *cd, void *p, void *params
192192
memcpy(&device_current, &device_prev, sizeof(device_context_t));
193193
device_priv[c] = priv;
194194
devices_instances[c] = inst;
195-
} else
195+
} else {
196196
device_priv[c] = p;
197+
devices_instances[c] = inst;
198+
}
197199

198200
return priv;
199201
}

src/qt/qt_deviceconfig.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ EnumerateSerialDevices()
108108
}
109109

110110
void
111-
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, QWidget *settings, bool atRuntime)
111+
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, QWidget *settings, void* devicePriv)
112112
{
113113
DeviceConfig dc(settings);
114114
dc.setWindowTitle(QString("%1 Device Configuration").arg(device->name));
115115
int p;
116116
int q;
117117
device_context_t device_context;
118118
device_set_context(&device_context, device, instance);
119+
if (devicePriv)
120+
startblit();
119121

120122
auto device_label = new QLabel(device->name);
121123
dc.ui->formLayout->addRow(device_label);
@@ -125,7 +127,7 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, QWidget *set
125127
dc.ui->formLayout->addRow(line);
126128
const auto *config = device->config;
127129
while (config->type != -1) {
128-
if (atRuntime && !(config->type & CONFIG_RUNTIME))
130+
if (devicePriv && !(config->type & CONFIG_RUNTIME))
129131
continue;
130132
switch (config->type & CONFIG_TYPE_MASK) {
131133
case CONFIG_BINARY:
@@ -298,17 +300,17 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, QWidget *set
298300
}
299301
++config;
300302
}
301-
if (atRuntime)
303+
if (devicePriv)
302304
endblit();
303305

304306
dc.setFixedSize(dc.minimumSizeHint());
305307
int res = dc.exec();
306308
if (res == QDialog::Accepted) {
307-
if (atRuntime)
309+
if (devicePriv)
308310
startblit();
309311
config = device->config;
310312
while (config->type != -1) {
311-
if (atRuntime && !(config->type & CONFIG_RUNTIME))
313+
if (devicePriv && !(config->type & CONFIG_RUNTIME))
312314
continue;
313315
switch (config->type & CONFIG_TYPE_MASK) {
314316
case CONFIG_BINARY:
@@ -375,7 +377,14 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, QWidget *set
375377
}
376378
config++;
377379
}
378-
// Endblit will be called in qt_mainwindow.cpp.
380+
381+
/* The :: prefix is intentional. */
382+
if (devicePriv) {
383+
::device_context(device);
384+
device->reload_config(devicePriv);
385+
::device_context_restore();
386+
endblit();
387+
}
379388
}
380389
}
381390

src/qt/qt_deviceconfig.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DeviceConfig : public QDialog {
2323
explicit DeviceConfig(QWidget *parent = nullptr);
2424
~DeviceConfig();
2525

26-
static void ConfigureDevice(const _device_ *device, int instance = 0, QWidget *settings = nullptr, bool atRuntime = false);
26+
static void ConfigureDevice(const _device_ *device, int instance = 0, QWidget *settings = nullptr, void* devicePriv = nullptr);
2727
static QString DeviceName(const _device_ *device, const char *internalName, int bus);
2828

2929
private:

src/qt/qt_mainwindow.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,25 @@ MainWindow::MainWindow(QWidget *parent)
210210
this->setWindowTitle(QString("%1 - %2 %3").arg(vmname, EMU_NAME, EMU_VERSION_FULL));
211211

212212
connect(this, &MainWindow::hardResetCompleted, this, [this]() {
213+
int c = 0;
213214
ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA));
214215
ui->menuDevice_settings->clear();
215216
for (int i = 0; i < 256; i++) {
216217
device_context_t ctx;
217218
if (!devices[i] || (devices[i] && !(devices[i]->flags & DEVICE_RTCONFIG)))
218219
continue;
219220

221+
c++;
220222
device_set_context(&ctx, devices[i], devices_instances[i]);
221223

222-
auto action = ui->menuDevice_settings->addAction(QString(ctx.name), [this, ctx, i] {
223-
DeviceConfig::ConfigureDevice(devices[i], devices_instances[i], this, true);
224-
devices[i]->reload_config(device_priv[i]);
225-
endblit();
224+
QAction* action = new QAction(ui->menuDevice_settings);
225+
action->setText(QString(ctx.name));
226+
connect(action, &QAction::triggered, this, [this, ctx, i] {
227+
DeviceConfig::ConfigureDevice(devices[i], devices_instances[i], this, device_priv[i]);
226228
});
229+
ui->menuDevice_settings->addAction(action);
227230
}
231+
ui->menuDevice_settings->menuAction()->setVisible(!!c);
228232
QApplication::setOverrideCursor(Qt::ArrowCursor);
229233
#ifdef USE_WACOM
230234
ui->menuTablet_tool->menuAction()->setVisible(mouse_input_mode >= 1);

src/sound/midi_fluidsynth.c

Lines changed: 109 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,99 @@ fluidsynth_sysex(uint8_t *data, unsigned int len)
150150
fluid_synth_sysex(d->synth, (const char *) data, len, 0, 0, 0, 0);
151151
}
152152

153+
void
154+
fluidsynth_reload_config(UNUSED(void* priv))
155+
{
156+
fluidsynth_t *data = &fsdev;
157+
158+
fluid_synth_sfunload(data->synth, data->sound_font, 1);
159+
160+
fluid_settings_setnum(data->settings, "synth.gain", device_get_config_int("output_gain") / 100.0f);
161+
162+
const char *sound_font = device_get_config_string("sound_font");
163+
#ifdef __unix__
164+
if (!sound_font || sound_font[0] == 0)
165+
sound_font = (access("/usr/share/sounds/sf2/FluidR3_GM.sf2", F_OK) == 0 ? "/usr/share/sounds/sf2/FluidR3_GM.sf2" :
166+
(access("/usr/share/soundfonts/default.sf2", F_OK) == 0 ? "/usr/share/soundfonts/default.sf2" : ""));
167+
#endif
168+
data->sound_font = fluid_synth_sfload(data->synth, sound_font, 1);
169+
170+
if (device_get_config_int("chorus")) {
171+
#ifndef USE_OLD_FLUIDSYNTH_API
172+
fluid_synth_chorus_on(data->synth, -1, 1);
173+
#else
174+
fluid_synth_set_chorus_on(data->synth, 1);
175+
#endif
176+
177+
int chorus_voices = device_get_config_int("chorus_voices");
178+
double chorus_level = device_get_config_int("chorus_level") / 100.0;
179+
double chorus_speed = device_get_config_int("chorus_speed") / 100.0;
180+
double chorus_depth = device_get_config_int("chorus_depth") / 10.0;
181+
182+
int chorus_waveform = FLUID_CHORUS_MOD_SINE;
183+
if (device_get_config_int("chorus_waveform") == 0)
184+
chorus_waveform = FLUID_CHORUS_MOD_SINE;
185+
else
186+
chorus_waveform = FLUID_CHORUS_MOD_TRIANGLE;
187+
188+
#ifndef USE_OLD_FLUIDSYNTH_API
189+
fluid_synth_set_chorus_group_nr(data->synth, -1, chorus_voices);
190+
fluid_synth_set_chorus_group_level(data->synth, -1, chorus_level);
191+
fluid_synth_set_chorus_group_speed(data->synth, -1, chorus_speed);
192+
fluid_synth_set_chorus_group_depth(data->synth, -1, chorus_depth);
193+
fluid_synth_set_chorus_group_type(data->synth, -1, chorus_waveform);
194+
#else
195+
fluid_synth_set_chorus(data->synth, chorus_voices, chorus_level, chorus_speed, chorus_depth, chorus_waveform);
196+
#endif
197+
} else
198+
#ifndef USE_OLD_FLUIDSYNTH_API
199+
fluid_synth_chorus_on(data->synth, -1, 0);
200+
#else
201+
fluid_synth_set_chorus_on(data->synth, 0);
202+
#endif
203+
204+
if (device_get_config_int("reverb")) {
205+
#ifndef USE_OLD_FLUIDSYNTH_API
206+
fluid_synth_reverb_on(data->synth, -1, 1);
207+
#else
208+
fluid_synth_set_reverb_on(data->synth, 1);
209+
#endif
210+
211+
double reverb_room_size = device_get_config_int("reverb_room_size") / 100.0;
212+
double reverb_damping = device_get_config_int("reverb_damping") / 100.0;
213+
double reverb_width = device_get_config_int("reverb_width") / 10.0;
214+
double reverb_level = device_get_config_int("reverb_level") / 100.0;
215+
216+
#ifndef USE_OLD_FLUIDSYNTH_API
217+
fluid_synth_set_reverb_group_roomsize(data->synth, -1, reverb_room_size);
218+
fluid_synth_set_reverb_group_damp(data->synth, -1, reverb_damping);
219+
fluid_synth_set_reverb_group_width(data->synth, -1, reverb_width);
220+
fluid_synth_set_reverb_group_level(data->synth, -1, reverb_level);
221+
#else
222+
fluid_synth_set_reverb(data->synth, reverb_room_size, reverb_damping, reverb_width, reverb_level);
223+
#endif
224+
} else
225+
#ifndef USE_OLD_FLUIDSYNTH_API
226+
fluid_synth_reverb_on(data->synth, -1, 0);
227+
#else
228+
fluid_synth_set_reverb_on(data->synth, 0);
229+
#endif
230+
231+
int interpolation = device_get_config_int("interpolation");
232+
int fs_interpolation = FLUID_INTERP_4THORDER;
233+
234+
if (interpolation == 0)
235+
fs_interpolation = FLUID_INTERP_NONE;
236+
else if (interpolation == 1)
237+
fs_interpolation = FLUID_INTERP_LINEAR;
238+
else if (interpolation == 2)
239+
fs_interpolation = FLUID_INTERP_4THORDER;
240+
else if (interpolation == 3)
241+
fs_interpolation = FLUID_INTERP_7THORDER;
242+
243+
fluid_synth_set_interp_method(data->synth, -1, fs_interpolation);
244+
}
245+
153246
void *
154247
fluidsynth_init(UNUSED(const device_t *info))
155248
{
@@ -323,14 +416,14 @@ static const device_config_t fluidsynth_config[] = {
323416
{
324417
.name = "sound_font",
325418
.description = "Sound Font",
326-
.type = CONFIG_FNAME,
419+
.type = CONFIG_FNAME | CONFIG_RUNTIME,
327420
.default_string = "",
328421
.file_filter = "SF2 Sound Fonts (*.sf2)|*.sf2"
329422
},
330423
{
331424
.name = "output_gain",
332425
.description = "Output Gain",
333-
.type = CONFIG_SPINNER,
426+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
334427
.spinner =
335428
{
336429
.min = 0,
@@ -341,13 +434,13 @@ static const device_config_t fluidsynth_config[] = {
341434
{
342435
.name = "chorus",
343436
.description = "Chorus",
344-
.type = CONFIG_BINARY,
437+
.type = CONFIG_BINARY | CONFIG_RUNTIME,
345438
.default_int = 1
346439
},
347440
{
348441
.name = "chorus_voices",
349442
.description = "Chorus Voices",
350-
.type = CONFIG_SPINNER,
443+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
351444
.spinner =
352445
{
353446
.min = 0,
@@ -358,7 +451,7 @@ static const device_config_t fluidsynth_config[] = {
358451
{
359452
.name = "chorus_level",
360453
.description = "Chorus Level",
361-
.type = CONFIG_SPINNER,
454+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
362455
.spinner =
363456
{
364457
.min = 0,
@@ -369,7 +462,7 @@ static const device_config_t fluidsynth_config[] = {
369462
{
370463
.name = "chorus_speed",
371464
.description = "Chorus Speed",
372-
.type = CONFIG_SPINNER,
465+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
373466
.spinner =
374467
{
375468
.min = 10,
@@ -380,7 +473,7 @@ static const device_config_t fluidsynth_config[] = {
380473
{
381474
.name = "chorus_depth",
382475
.description = "Chorus Depth",
383-
.type = CONFIG_SPINNER,
476+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
384477
.spinner =
385478
{
386479
.min = 0,
@@ -391,7 +484,7 @@ static const device_config_t fluidsynth_config[] = {
391484
{
392485
.name = "chorus_waveform",
393486
.description = "Chorus Waveform",
394-
.type = CONFIG_SELECTION,
487+
.type = CONFIG_SELECTION | CONFIG_RUNTIME,
395488
.selection =
396489
{
397490
{
@@ -408,13 +501,13 @@ static const device_config_t fluidsynth_config[] = {
408501
{
409502
.name = "reverb",
410503
.description = "Reverb",
411-
.type = CONFIG_BINARY,
504+
.type = CONFIG_BINARY | CONFIG_RUNTIME,
412505
.default_int = 1
413506
},
414507
{
415508
.name = "reverb_room_size",
416509
.description = "Reverb Room Size",
417-
.type = CONFIG_SPINNER,
510+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
418511
.spinner =
419512
{
420513
.min = 0,
@@ -425,7 +518,7 @@ static const device_config_t fluidsynth_config[] = {
425518
{
426519
.name = "reverb_damping",
427520
.description = "Reverb Damping",
428-
.type = CONFIG_SPINNER,
521+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
429522
.spinner =
430523
{
431524
.min = 0,
@@ -436,7 +529,7 @@ static const device_config_t fluidsynth_config[] = {
436529
{
437530
.name = "reverb_width",
438531
.description = "Reverb Width",
439-
.type = CONFIG_SPINNER,
532+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
440533
.spinner =
441534
{
442535
.min = 0,
@@ -447,7 +540,7 @@ static const device_config_t fluidsynth_config[] = {
447540
{
448541
.name = "reverb_level",
449542
.description = "Reverb Level",
450-
.type = CONFIG_SPINNER,
543+
.type = CONFIG_SPINNER | CONFIG_RUNTIME,
451544
.spinner =
452545
{
453546
.min = 0,
@@ -458,7 +551,7 @@ static const device_config_t fluidsynth_config[] = {
458551
{
459552
.name = "interpolation",
460553
.description = "Interpolation Method",
461-
.type = CONFIG_SELECTION,
554+
.type = CONFIG_SELECTION | CONFIG_RUNTIME,
462555
.selection =
463556
{
464557
{
@@ -487,14 +580,15 @@ static const device_config_t fluidsynth_config[] = {
487580
const device_t fluidsynth_device = {
488581
.name = "FluidSynth",
489582
.internal_name = "fluidsynth",
490-
.flags = 0,
583+
.flags = DEVICE_RTCONFIG,
491584
.local = 0,
492585
.init = fluidsynth_init,
493586
.close = fluidsynth_close,
494587
.reset = NULL,
495588
{ .available = fluidsynth_available },
496589
.speed_changed = NULL,
497590
.force_redraw = NULL,
591+
.reload_config = fluidsynth_reload_config,
498592
.config = fluidsynth_config
499593
};
500594

0 commit comments

Comments
 (0)