diff options
Diffstat (limited to 'MIDIPlayer.cpp')
-rw-r--r-- | MIDIPlayer.cpp | 15 |
1 files changed, 14 insertions, 1 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 <signal.h> +#include <fmt/format.h> +#include <algorithm> +#include <chrono> #include <iostream> +#include <thread> 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<std::string> MIDIPlayer::get_filelist() break; } } + std::sort(result.begin(), result.end()); return result; } |