mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-27 17:38:01 +03:00
Add -mididevice option
This commit is contained in:
@@ -111,7 +111,12 @@ The first line is not used because track 1 on a game CD is usually a data
|
||||
track.
|
||||
|
||||
#### `-fm`
|
||||
By default, system3-sdl2 uses MIDI sound if available. This option forces FM tone generator emulation.
|
||||
By default, system3-sdl2 uses MIDI sound if available. This option forces FM
|
||||
tone generator emulation.
|
||||
|
||||
#### `-mididevice` _number_
|
||||
Specifies the MIDI device number to use. If not specified, the first available
|
||||
device is used.
|
||||
|
||||
#### `-game` _game_id_
|
||||
As System1-3 have slight variations depending on the game, `system3` uses the
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
@@ -26,6 +27,19 @@ bool to_bool(const char *s, int lineno)
|
||||
return true;
|
||||
}
|
||||
|
||||
int to_int(const char *s, int lineno = -1)
|
||||
{
|
||||
char *end;
|
||||
int n = strtol(s, &end, 10);
|
||||
if (*end) {
|
||||
if (lineno == -1)
|
||||
ERROR("Command line: Invalid integer value '%s'", s);
|
||||
else
|
||||
ERROR(INIFILENAME ":%d Invalid integer value '%s'", lineno, s);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
std::string normalize_path(std::string s)
|
||||
{
|
||||
for (char& c : s) {
|
||||
@@ -96,6 +110,8 @@ Config::Config(int argc, char *argv[])
|
||||
playlist = argv[++i];
|
||||
else if (strcmp(argv[i], "-fm") == 0)
|
||||
use_fm = true;
|
||||
else if (strcmp(argv[i], "-mididevice") == 0)
|
||||
midi_device = to_int(argv[++i]);
|
||||
else if (strcmp(argv[i], "-game") == 0)
|
||||
game_id = argv[++i];
|
||||
else if (strcmp(argv[i], "-encoding") == 0)
|
||||
@@ -152,6 +168,8 @@ void Config::load_ini()
|
||||
playlist = normalize_path(val);
|
||||
else if (!strcasecmp(key, "fm"))
|
||||
use_fm = to_bool(val, lineno);
|
||||
else if (!strcasecmp(key, "mididevice"))
|
||||
midi_device = to_int(val, lineno);
|
||||
else if (!strcasecmp(key, "game"))
|
||||
game_id = val;
|
||||
else if (!strcasecmp(key, "encoding"))
|
||||
|
||||
@@ -28,6 +28,7 @@ struct Config {
|
||||
std::string save_dir;
|
||||
std::string playlist;
|
||||
std::string title;
|
||||
int midi_device = -1;
|
||||
bool use_fm = false;
|
||||
bool no_antialias = false;
|
||||
bool scanline = false;
|
||||
|
||||
@@ -53,7 +53,7 @@ MAKO::MAKO(NACT* parent, const Config& config) :
|
||||
if (Mix_OpenAudio(SAMPLE_RATE, AUDIO_S16LSB, 2, 4096) < 0)
|
||||
WARNING("Mix_OpenAudio failed: %s", Mix_GetError());
|
||||
|
||||
midi = std::make_unique<MAKOMidi>();
|
||||
midi = std::make_unique<MAKOMidi>(config.midi_device);
|
||||
if (!midi->is_available())
|
||||
use_fm = true;
|
||||
}
|
||||
|
||||
+12
-5
@@ -21,7 +21,7 @@ namespace {
|
||||
|
||||
std::unique_ptr<RtMidiOut> midiout;
|
||||
|
||||
void initialize_midi()
|
||||
void initialize_midi(int device)
|
||||
{
|
||||
try {
|
||||
midiout = std::make_unique<RtMidiOut>();
|
||||
@@ -34,8 +34,15 @@ void initialize_midi()
|
||||
for (int i = 0; i < n; i++) {
|
||||
NOTICE("MIDI #%d: %s", i, midiout->getPortName(i).c_str());
|
||||
}
|
||||
// Open first available port.
|
||||
midiout->openPort(0);
|
||||
if (device < 0) {
|
||||
// not specified, use the first device
|
||||
device = 0;
|
||||
} else if (device >= n) {
|
||||
WARNING("Invalid MIDI device number: %d", device);
|
||||
midiout.reset();
|
||||
return;
|
||||
}
|
||||
midiout->openPort(device);
|
||||
} catch (RtMidiError &error) {
|
||||
WARNING("Cannot initialize MIDI: %s", error.getMessage().c_str());
|
||||
midiout.reset();
|
||||
@@ -627,9 +634,9 @@ struct MAKOMidi::Command {
|
||||
Command(Type t, std::unique_ptr<Playback> p = {}) : type(t), playback(std::move(p)) {}
|
||||
};
|
||||
|
||||
MAKOMidi::MAKOMidi()
|
||||
MAKOMidi::MAKOMidi(int device)
|
||||
{
|
||||
initialize_midi();
|
||||
initialize_midi(device);
|
||||
if (midiout) {
|
||||
thread = SDL_CreateThread(thread_main, "MAKOMidi", this);
|
||||
queue_mutex = SDL_CreateMutex();
|
||||
|
||||
+2
-1
@@ -12,7 +12,7 @@ class NACT;
|
||||
|
||||
class MAKOMidi {
|
||||
public:
|
||||
MAKOMidi();
|
||||
explicit MAKOMidi(int device);
|
||||
~MAKOMidi();
|
||||
bool is_available();
|
||||
bool play(NACT* nact, char* amus, int page, int loop);
|
||||
@@ -38,6 +38,7 @@ private:
|
||||
|
||||
class MAKOMidi {
|
||||
public:
|
||||
explicit MAKOMidi(int device) {}
|
||||
bool is_available() { return false; }
|
||||
bool play(NACT* nact, char* amus, int page, int loop) { return false; }
|
||||
void stop() {}
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ MAKO::MAKO(NACT* parent, const Config& config) :
|
||||
parent->fatal("SDL_GetWindowWMInfo failed: %s", SDL_GetError());
|
||||
mci_thread = new MCIThread(parent, info.info.win.window);
|
||||
|
||||
midi = std::make_unique<MAKOMidi>();
|
||||
midi = std::make_unique<MAKOMidi>(config.midi_device);
|
||||
if (!midi->is_available())
|
||||
use_fm = true;
|
||||
}
|
||||
|
||||
+4
-2
@@ -18,10 +18,12 @@ fontfile = custom_font.ttf
|
||||
; line.
|
||||
playlist = bgm/playlist.txt
|
||||
|
||||
; Enable FM tone generator emulation. If not specified, MIDI sound will be
|
||||
; used.
|
||||
; Force FM tone generator emulation even if MIDI is available.
|
||||
fm = true
|
||||
|
||||
; MIDI device number to use for music playback.
|
||||
mididevice = 0
|
||||
|
||||
; Game ID. No need to specify if using AliceSoft's original game data.
|
||||
; Refer to README.md for a list of possible values.
|
||||
game = rance41
|
||||
|
||||
Reference in New Issue
Block a user