Skip to content

Commit a650f92

Browse files
authored
Merge pull request EasyRPG#3168 from Ghabry/audio-cfg
Config for Soundfont, Font and "Focus Lost"
2 parents 6e33041 + 57cddd1 commit a650f92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1609
-439
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|SDL1|libretro|psvita|3ds|switch|wii|a
10711071
player_find_package(NAME FluidLite
10721072
CONDITION PLAYER_WITH_FLUIDLITE
10731073
DEFINITION HAVE_FLUIDLITE
1074-
TARGET FluidLite::fluidlite)
1074+
TARGET "fluidlite::fluidlite;fluidlite::fluidlite-static")
10751075
endif()
10761076

10771077
# xmp (lite)
@@ -1525,7 +1525,7 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|SDL1|libretro|psvita|3ds|switch|wii)$
15251525
if(TARGET FluidSynth::libfluidsynth)
15261526
list(APPEND MIDI_LIBS "FluidSynth")
15271527
endif()
1528-
if(TARGET FluidLite::fluidlite)
1528+
if(TARGET fluidlite::fluidlite OR TARGET fluidlite::fluidlite-static)
15291529
list(APPEND MIDI_LIBS "FluidLite")
15301530
endif()
15311531
if(TARGET WildMidi::libwildmidi OR TARGET WildMidi::libwildmidi-static)

builds/cmake/Modules/FindFluidLite.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# This module defines the following :prop_tgt:`IMPORTED` targets:
1111
#
12-
# ``FluidLite::fluidlite``
12+
# ``fluidlite::fluidlite``
1313
# The ``FluidLite`` library, if found.
1414
#
1515
# Result Variables
@@ -53,9 +53,9 @@ if(FLUIDLITE_FOUND)
5353
set(FLUIDLITE_LIBRARIES ${FLUIDLITE_LIBRARIES})
5454
endif()
5555

56-
if(NOT TARGET FluidLite::fluidlite)
57-
add_library(FluidLite::fluidlite UNKNOWN IMPORTED)
58-
set_target_properties(FluidLite::fluidlite PROPERTIES
56+
if(NOT TARGET fluidlite::fluidlite)
57+
add_library(fluidlite::fluidlite UNKNOWN IMPORTED)
58+
set_target_properties(fluidlite::fluidlite PROPERTIES
5959
INTERFACE_INCLUDE_DIRECTORIES "${FLUIDLITE_INCLUDE_DIRS}"
6060
IMPORTED_LOCATION "${FLUIDLITE_LIBRARY}")
6161
endif()

resources/emscripten/emscripten-post.js

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (Module.saveFs === undefined) {
1414
}
1515

1616
Module.initApi = function() {
17-
Module.api_private.download_js = function(buffer, size, filename) {
17+
Module.api_private.download_js = function (buffer, size, filename) {
1818
const blob = new Blob([Module.HEAPU8.slice(buffer, buffer + size)]);
1919
const link = document.createElement('a');
2020
link.href = window.URL.createObjectURL(blob);
@@ -23,28 +23,62 @@ Module.initApi = function() {
2323
link.remove();
2424
}
2525

26-
Module.api_private.uploadSavegame_js = function(slot) {
27-
let saveFile = document.getElementById('easyrpg_saveFile');
28-
if (saveFile == null) {
29-
saveFile = document.createElement('input');
30-
saveFile.type = 'file';
31-
saveFile.id = 'easyrpg_saveFile';
32-
saveFile.style.display = 'none';
33-
saveFile.addEventListener('change', function(evt) {
34-
const save = evt.target.files[0];
26+
Module.api_private.createInputElement_js = function (id, event) {
27+
let file = document.getElementById(id);
28+
if (file == null) {
29+
file = document.createElement('input');
30+
file.type = 'file';
31+
file.id = id;
32+
file.style.display = 'none';
33+
file.addEventListener('change', function (evt) {
34+
const selected_file = evt.target.files[0];
3535
const reader = new FileReader();
36-
reader.onload = function (file) {
37-
const result = new Uint8Array(file.currentTarget.result);
38-
var buf = Module._malloc(result.length);
39-
Module.HEAPU8.set(result, buf);
40-
Module.api_private.uploadSavegameStep2(slot, buf, result.length);
41-
Module._free(buf);
42-
Module.api.refreshScene();
43-
};
44-
reader.readAsArrayBuffer(save);
36+
reader.onload = function(file) {
37+
event(file, selected_file.name);
38+
}
39+
reader.readAsArrayBuffer(selected_file);
4540
});
4641
}
47-
saveFile.click();
42+
file.click();
43+
}
44+
45+
Module.api_private.uploadSavegame_js = function (slot) {
46+
Module.api_private.createInputElement_js('easyrpg_saveFile', function (file) {
47+
const result = new Uint8Array(file.currentTarget.result);
48+
var buf = Module._malloc(result.length);
49+
Module.HEAPU8.set(result, buf);
50+
Module.api_private.uploadSavegameStep2(slot, buf, result.length);
51+
Module._free(buf);
52+
Module.api.refreshScene();
53+
});
54+
}
55+
56+
Module.api_private.uploadSoundfont_js = function () {
57+
Module.api_private.createInputElement_js('easyrpg_sfFile', function (file, name) {
58+
const result = new Uint8Array(file.currentTarget.result);
59+
//const name_buf = Module._malloc(name.length + 1);
60+
//stringToUTF8(name, name_buf, name.length + 1);
61+
const content_buf = Module._malloc(result.length);
62+
Module.HEAPU8.set(result, content_buf);
63+
Module.api_private.uploadSoundfontStep2(name, content_buf, result.length);
64+
//Module._free(name_buf);
65+
Module._free(content_buf);
66+
Module.api.refreshScene();
67+
});
68+
}
69+
70+
Module.api_private.uploadFont_js = function () {
71+
Module.api_private.createInputElement_js('easyrpg_sfFile', function (file, name) {
72+
const result = new Uint8Array(file.currentTarget.result);
73+
//const name_buf = Module._malloc(name.length + 1);
74+
//stringToUTF8(name, name_buf, name.length + 1);
75+
const content_buf = Module._malloc(result.length);
76+
Module.HEAPU8.set(result, content_buf);
77+
Module.api_private.uploadFontStep2(name, content_buf, result.length);
78+
//Module._free(name_buf);
79+
Module._free(content_buf);
80+
Module.api.refreshScene();
81+
});
4882
}
4983
}
5084

resources/unix/bash-completion/easyrpg-player

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _easyrpg-player ()
1414

1515
# all possible options
1616
ouropts='--autobattle-algo --battle-test --disable-audio --disable-rtp \
17-
--encoding --enemyai-algo --engine --fps-limit --fps-render-window --fullscreen -h --help \
17+
--encoding --enemyai-algo --engine --fps-limit --fullscreen -h --help \
1818
--hide-title --load-game-id --new-game --no-vsync --project-path --rtp-path --record-input \
1919
--replay-input --save-path --seed --show-fps --start-map-id --start-party --no-log-color \
2020
--start-position --test-play --window -v --version'

resources/unix/easyrpg-player.6.adoc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ NOTE: For games that only use ASCII (English games) use '1252'.
6262
- 'rpg2k3v105' - RPG Maker 2003 (v1.05 - v1.09a)
6363
- 'rpg2k3e' - RPG Maker 2003 RPG Maker 2003 (English release, v1.12)
6464

65+
*--font1* _FILE_::
66+
Path to a font to use for the first font. The system graphic of the game
67+
determines whether font 1 or 2 is used. When no font is selected or the
68+
selected font lacks certain glyphs the built-in pixel font is used.
69+
70+
*--font1-size* _PX_::
71+
Size of font 1 in pixel. The default value is 12.
72+
73+
*--font2* _FILE_::
74+
Path to a font to use for the second font. See font 1 for further information.
75+
76+
*--font2-size* _PX_::
77+
Size of font 2 in pixel. The default value is 12.
78+
79+
*--font-path* _PATH_::
80+
Configures the path where the settings scene looks for fonts. The user can
81+
choose from any font in the directory. This is more flexible than using
82+
*--font1* or *--font2* directly. The default path is 'config-path/Font'.
83+
6584
*--language* _LANG_::
6685
Loads the game translation in language/'LANG' folder.
6786

@@ -171,6 +190,10 @@ NOTE: When using the game browser all games will share the same save directory!
171190
- 'widescreen' - 416x240 (16:9)
172191
- 'ultrawide' - 560x240 (21:9)
173192

193+
*--pause-focus-lost*::
194+
Pause the game when the window has no focus. Can be disabled with
195+
*--no-pause-focus-lost*.
196+
174197
*--scaling* _MODE_::
175198
How the video output is scaled. Possible options:
176199
- 'nearest' - Scale to screen size using nearest neighbour algorithm.
@@ -180,8 +203,10 @@ NOTE: When using the game browser all games will share the same save directory!
180203
- 'bilinear' - Like 'nearest' but apply a bilinear filter to avoid the
181204
artifacts.
182205
*--show-fps*::
183-
Enable display of the frames per second counter. Can be disabled with
184-
*--no-show-fps*.
206+
Enable display of the frames per second counter. When in windowed mode it is
207+
shown inside the window. When in fullscreen mode it is shown in the titlebar.
208+
Use *--fps-render-window* to always show the counter inside the window. Can be
209+
disabled with *--no-show-fps*.
185210

186211
*--stretch*::
187212
Ignore the aspect ratio and stretch video output to the entire width of the
@@ -211,6 +236,10 @@ NOTE: When using the game browser all games will share the same save directory!
211236
Adds 'FILE' to the list of soundfonts used for playing MIDI files and use
212237
this one with highest precedence. The soundfont must be in SF2 format.
213238

239+
*--soundfont-path* _P_::
240+
Configures the path where the settings scene looks for soundfonts. The user
241+
can choose from any soundfont in the directory. This is more flexible than
242+
using *--soundfont* directly. The default path is 'config-path/Soundfont'.
214243

215244
=== Debug options
216245

src/audio.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
// Headers
1919
#include "audio.h"
20+
#include "audio_midi.h"
2021
#include "system.h"
2122
#include "baseui.h"
2223
#include "player.h"
@@ -70,6 +71,21 @@ AudioInterface::AudioInterface(const Game_ConfigAudio& cfg) : cfg(cfg) {
7071
Game_ConfigAudio AudioInterface::GetConfig() const {
7172
auto acfg = cfg;
7273
acfg.Hide();
74+
75+
#if !defined(HAVE_FLUIDSYNTH) && !defined(HAVE_FLUIDLITE)
76+
acfg.fluidsynth_midi.SetOptionVisible(false);
77+
acfg.soundfont.SetOptionVisible(false);
78+
#endif
79+
#ifndef HAVE_LIBWILDMIDI
80+
acfg.wildmidi_midi.SetOptionVisible(false);
81+
#endif
82+
#ifndef HAVE_NATIVE_MIDI
83+
acfg.native_midi.SetOptionVisible(false);
84+
#endif
85+
#ifndef WANT_FMMIDI
86+
acfg.fmmidi_midi.SetOptionVisible(false);
87+
#endif
88+
7389
vGetConfig(acfg);
7490
return acfg;
7591
}
@@ -89,3 +105,36 @@ int AudioInterface::SE_GetGlobalVolume() const {
89105
void AudioInterface::SE_SetGlobalVolume(int volume) {
90106
cfg.sound_volume.Set(volume);
91107
}
108+
109+
bool AudioInterface::GetFluidsynthEnabled() const {
110+
return cfg.fluidsynth_midi.Get();
111+
}
112+
113+
void AudioInterface::SetFluidsynthEnabled(bool enable) {
114+
cfg.fluidsynth_midi.Set(enable);
115+
}
116+
117+
bool AudioInterface::GetWildMidiEnabled() const {
118+
return cfg.wildmidi_midi.Get();
119+
}
120+
121+
void AudioInterface::SetWildMidiEnabled(bool enable) {
122+
cfg.wildmidi_midi.Set(enable);
123+
}
124+
125+
bool AudioInterface::GetNativeMidiEnabled() const {
126+
return cfg.native_midi.Get();
127+
}
128+
129+
void AudioInterface::SetNativeMidiEnabled(bool enable) {
130+
cfg.native_midi.Set(enable);
131+
}
132+
133+
std::string AudioInterface::GetFluidsynthSoundfont() const {
134+
return cfg.soundfont.Get();
135+
}
136+
137+
void AudioInterface::SetFluidsynthSoundfont(StringView sf) {
138+
cfg.soundfont.Set(ToString(sf));
139+
MidiDecoder::ChangeFluidsynthSoundfont(sf);
140+
}

src/audio.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// Headers
2222
#include <string>
23+
#include "audio_generic_midiout.h"
2324
#include "filesystem_stream.h"
2425
#include "audio_secache.h"
2526
#include "game_config.h"
@@ -39,6 +40,15 @@ struct AudioInterface {
3940

4041
virtual void vGetConfig(Game_ConfigAudio& cfg) const = 0;
4142

43+
/**
44+
* Instantiates and returns the Native Midi Out device.
45+
* The Midi Out device is usually an exclusive resource.
46+
* Implementing classes should only create one Midi Out and return the
47+
* shared instance.
48+
* @return Native Midi Out Device or nullptr on error
49+
*/
50+
virtual GenericAudioMidiOut* CreateAndGetMidiOut() { return nullptr; }
51+
4252
/**
4353
* Update audio. Must be called each frame.
4454
*/
@@ -133,6 +143,18 @@ struct AudioInterface {
133143
int SE_GetGlobalVolume() const;
134144
void SE_SetGlobalVolume(int volume);
135145

146+
bool GetFluidsynthEnabled() const;
147+
void SetFluidsynthEnabled(bool enable);
148+
149+
bool GetWildMidiEnabled() const;
150+
void SetWildMidiEnabled(bool enable);
151+
152+
bool GetNativeMidiEnabled() const;
153+
void SetNativeMidiEnabled(bool enable);
154+
155+
std::string GetFluidsynthSoundfont() const;
156+
void SetFluidsynthSoundfont(StringView sf);
157+
136158
protected:
137159
Game_ConfigAudio cfg;
138160
};

0 commit comments

Comments
 (0)