summaryrefslogtreecommitdiffhomepage
path: root/MIDIPlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MIDIPlayer.cpp')
-rw-r--r--MIDIPlayer.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/MIDIPlayer.cpp b/MIDIPlayer.cpp
index cb6a6bf..6b07105 100644
--- a/MIDIPlayer.cpp
+++ b/MIDIPlayer.cpp
@@ -20,13 +20,23 @@ using namespace std::chrono_literals;
namespace {
std::unordered_set<std::string> supported_devices{"AudioBox 22 VSL", "CH345", "M2"};
+
+ fs::path wav_from_midi(const fs::path& midipath)
+ {
+ fs::path result{midipath};
+
+ result.replace_extension("wav");
+
+ return result;
+ }
}
MIDIPlayer::MIDIPlayer(Config& config):
m_config(config),
- m_child{},
+ m_child_midiplayer{},
m_dir{m_config.get_file_path()},
- m_file{}
+ m_file{},
+ m_audio_player{m_dir, m_file}
{
std::vector<std::string> list = get_filelist();
@@ -41,34 +51,37 @@ MIDIPlayer::MIDIPlayer(Config& config):
void MIDIPlayer::start()
{
- if (m_child.valid() && m_child.running()) {
+ if (m_child_midiplayer.valid() && m_child_midiplayer.running()) {
stop();
- } else {
- m_child = bp::child(fmt::format("aplaymidi-mp -c -p{} \"{}\"", m_client, (m_dir / m_file).string()).c_str());//, bp::std_out > bp::null);
- if (!m_child.valid() || !m_child.running()) {
- throw std::runtime_error("aplaymidi not started");
- }
}
+ m_child_midiplayer = bp::child(fmt::format("aplaymidi-mp -c -p{} \"{}\"", m_client, (m_dir / m_file).string()).c_str());//, bp::std_out > bp::null);
+ if (!m_child_midiplayer.valid() || !m_child_midiplayer.running()) {
+ throw std::runtime_error("aplaymidi not started");
+ }
+
+ m_audio_player.start();
}
void MIDIPlayer::stop()
{
- // note:: m_child.terminate() would kill via SIGKILL, preventing note offs
+ // note:: m_child_midiplayer.terminate() would kill via SIGKILL
- if (m_child.valid()) {
- int result = kill(m_child.native_handle(), SIGTERM);
+ if (m_child_midiplayer.valid()) {
+ int result = kill(m_child_midiplayer.native_handle(), SIGTERM);
if (result < 0) {
std::cerr << "Error in MIDIPlayer::stop(): kill() unsuccessful\n";
}
}
+
+ m_audio_player.stop();
}
bool MIDIPlayer::is_playing()
{
- if (!m_child.valid()) {
+ if (!m_child_midiplayer.valid()) {
return false;
}
- return m_child.running();
+ return m_child_midiplayer.running();
}
void MIDIPlayer::set_file(const std::string& filename)
@@ -80,6 +93,8 @@ void MIDIPlayer::set_file(const std::string& filename)
std::this_thread::sleep_for(100ms);
start();
}
+
+ m_audio_player.set_file(wav_from_midi(filename));
}
std::string MIDIPlayer::get_file()