From 99af0ab365ab5ab7d2cb2b96d19377bfb117f662 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 13 Jan 2025 21:20:27 +0100 Subject: Switch between songs --- MIDIPlayer.cpp | 15 ++++++++++++++- html/index.html | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/MIDIPlayer.cpp b/MIDIPlayer.cpp index c7945d6..f2bba8c 100644 --- a/MIDIPlayer.cpp +++ b/MIDIPlayer.cpp @@ -1,12 +1,18 @@ #include "MIDIPlayer.h" #include +#include +#include +#include #include +#include namespace bp = boost::process; namespace fs = std::filesystem; +using namespace std::chrono_literals; + MIDIPlayer::MIDIPlayer(const std::filesystem::path& path): m_child{}, m_dir{path}, @@ -24,7 +30,7 @@ void MIDIPlayer::start() if (m_child.valid() && m_child.running()) { stop(); } else { - m_child = bp::child("aplaymidi -p24 locked_out_of_heaven.midi");//, bp::std_out > bp::null); + m_child = bp::child(fmt::format("aplaymidi -p24 \"{}\"", m_file).c_str());//, bp::std_out > bp::null); } } @@ -51,6 +57,12 @@ bool MIDIPlayer::is_playing() void MIDIPlayer::set_file(const std::string& filename) { m_file = filename; + + if (is_playing()) { + stop(); + std::this_thread::sleep_for(100ms); + start(); + } } std::string MIDIPlayer::get_file() @@ -71,6 +83,7 @@ std::vector MIDIPlayer::get_filelist() break; } } + std::sort(result.begin(), result.end()); return result; } diff --git a/html/index.html b/html/index.html index ac85aa1..b6daf8c 100644 --- a/html/index.html +++ b/html/index.html @@ -12,13 +12,28 @@ .selected{ color: #FF8080; + cursor: pointer; } .normal{ color: #000000; + cursor: pointer; } + +#songlist{ + height:400px; + overflow:auto; +} +