Emscripten: MIDI support

This commit is contained in:
kichikuou
2020-02-16 11:09:32 +09:00
parent 4ede5b1b4c
commit 52313dd682
2 changed files with 33 additions and 8 deletions
+2
View File
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.13)
project(System3 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
# In msys, `pkg-config --libs` returns `-lmingw32` but find_library() cannot
# find it in default search paths.
@@ -23,6 +24,7 @@ if (ANDROID)
elseif (EMSCRIPTEN)
add_executable(system3)
set(SRC_MAKO sys/mako_midi.cpp)
set(SRC_PLATFORM
linux/nact_linux.cpp
emscripten/mako.cpp
+31 -8
View File
@@ -3,15 +3,19 @@
[ MAKO ]
*/
#include <memory>
#include <emscripten.h>
#include "mako.h"
#include "mako_midi.h"
MAKO::MAKO(NACT* parent, const char* playlist)
: current_music(0)
, next_loop(0)
MAKO::MAKO(NACT* parent, const char* playlist) :
current_music(0),
next_loop(0),
nact(parent)
{
strcpy(amus, "AMUS.DAT");
for (int i = 1; i <= 99; i++)
cd_track[i] = i;
cd_track[i] = 0;
}
void MAKO::play_music(int page)
@@ -19,8 +23,22 @@ void MAKO::play_music(int page)
if (current_music == page)
return;
EM_ASM_ARGS({ xsystem35.cdPlayer.play($0, $1); },
cd_track[page] + 1, next_loop ? 0 : 1);
int track = page < 100 ? cd_track[page] : 0;
if (track) {
EM_ASM_ARGS({ xsystem35.cdPlayer.play($0, $1); },
cd_track[page] + 1, next_loop ? 0 : 1);
} else {
auto midi = std::make_unique<MAKOMidi>(nact, amus);
if (!midi->load_mml(page)) {
WARNING("load_mml(%d) failed", page);
return;
}
midi->load_mda(page);
std::vector<uint8_t> smf = midi->generate_smf(next_loop);
EM_ASM_ARGS({ xsystem35.midiPlayer.play($0, $1, $2); },
next_loop, smf.data(), smf.size());
}
current_music = page;
next_loop = 0;
@@ -28,8 +46,13 @@ void MAKO::play_music(int page)
void MAKO::stop_music()
{
if (current_music)
EM_ASM( xsystem35.cdPlayer.stop(); );
if (!current_music)
return;
EM_ASM({
xsystem35.cdPlayer.stop();
xsystem35.midiPlayer.stop();
});
current_music = 0;
}