diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c08433..eabc1e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/emscripten/mako.cpp b/src/emscripten/mako.cpp index f81dc2a..4e000c3 100644 --- a/src/emscripten/mako.cpp +++ b/src/emscripten/mako.cpp @@ -3,15 +3,19 @@ [ MAKO ] */ +#include #include #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(nact, amus); + if (!midi->load_mml(page)) { + WARNING("load_mml(%d) failed", page); + return; + } + midi->load_mda(page); + std::vector 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; }