diff options
author | Cameron Youell <cameronyouell@gmail.com> | 2023-03-27 00:37:17 +0000 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-04-09 20:58:54 -0600 |
commit | 7734eba03f8ded9005d036f48e6a5f4cc99025e7 (patch) | |
tree | 53f0bea4b262761bb86c571e72ad52638b49ad35 /Userland/Applications | |
parent | fb8d4b703247a4edee13e8459caa7d1bd541deb1 (diff) | |
download | serenity-7734eba03f8ded9005d036f48e6a5f4cc99025e7.zip |
Piano+LibAudio: Port to `Core::File`
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Piano/AudioPlayerLoop.cpp | 18 | ||||
-rw-r--r-- | Userland/Applications/Piano/AudioPlayerLoop.h | 2 | ||||
-rw-r--r-- | Userland/Applications/Piano/main.cpp | 8 |
3 files changed, 15 insertions, 13 deletions
diff --git a/Userland/Applications/Piano/AudioPlayerLoop.cpp b/Userland/Applications/Piano/AudioPlayerLoop.cpp index 2a4d820410..82dd16edef 100644 --- a/Userland/Applications/Piano/AudioPlayerLoop.cpp +++ b/Userland/Applications/Piano/AudioPlayerLoop.cpp @@ -93,14 +93,14 @@ intptr_t AudioPlayerLoop::pipeline_thread_main() // The track manager guards against allocations itself. m_track_manager.fill_buffer(m_buffer); - auto result = send_audio_to_server(); // Tolerate errors in the audio pipeline; we don't want this thread to crash the program. This might likely happen with OOM. - if (result.is_error()) [[unlikely]] { + if (auto result = send_audio_to_server(); result.is_error()) [[unlikely]] { dbgln("Error in audio pipeline: {}", result.error()); m_track_manager.reset(); } - write_wav_if_needed(); + if (auto result = write_wav_if_needed(); result.is_error()) [[unlikely]] + dbgln("Error writing WAV: {}", result.error()); } m_audio_client->async_pause_playback(); return static_cast<intptr_t>(0); @@ -131,28 +131,32 @@ ErrorOr<void> AudioPlayerLoop::send_audio_to_server() return {}; } -void AudioPlayerLoop::write_wav_if_needed() +ErrorOr<void> AudioPlayerLoop::write_wav_if_needed() { bool _true = true; if (m_need_to_write_wav.compare_exchange_strong(_true, false)) { m_audio_client->async_pause_playback(); - m_wav_writer.with_locked([this](auto& wav_writer) { + TRY(m_wav_writer.with_locked([this](auto& wav_writer) -> ErrorOr<void> { m_track_manager.reset(); m_track_manager.set_should_loop(false); do { // FIXME: This progress detection is crude, but it works for now. m_wav_percent_written.store(static_cast<int>(static_cast<float>(m_track_manager.transport()->time()) / roll_length * 100.0f)); m_track_manager.fill_buffer(m_buffer); - wav_writer.write_samples(m_buffer.span()); + TRY(wav_writer.write_samples(m_buffer.span())); } while (m_track_manager.transport()->time()); // FIXME: Make sure that the new TrackManager APIs aren't as bad. m_wav_percent_written.store(100); m_track_manager.reset(); m_track_manager.set_should_loop(true); wav_writer.finalize(); - }); + + return {}; + })); m_audio_client->async_start_playback(); } + + return {}; } void AudioPlayerLoop::toggle_paused() diff --git a/Userland/Applications/Piano/AudioPlayerLoop.h b/Userland/Applications/Piano/AudioPlayerLoop.h index 3a6713d5d3..c037af218b 100644 --- a/Userland/Applications/Piano/AudioPlayerLoop.h +++ b/Userland/Applications/Piano/AudioPlayerLoop.h @@ -34,7 +34,7 @@ private: intptr_t pipeline_thread_main(); ErrorOr<void> send_audio_to_server(); - void write_wav_if_needed(); + ErrorOr<void> write_wav_if_needed(); TrackManager& m_track_manager; FixedArray<DSP::Sample> m_buffer; diff --git a/Userland/Applications/Piano/main.cpp b/Userland/Applications/Piano/main.cpp index 954d876a5a..ac15d9a81c 100644 --- a/Userland/Applications/Piano/main.cpp +++ b/Userland/Applications/Piano/main.cpp @@ -65,11 +65,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) return; DeprecatedString error; wav_writer.with_locked([&](auto& wav_writer) { - wav_writer.set_file(save_path.value()); - if (wav_writer.has_error()) { - error = DeprecatedString::formatted("Failed to export WAV file: {}", wav_writer.error_string()); - wav_writer.clear_error(); - } + auto error_or_void = wav_writer.set_file(save_path.value()); + if (error_or_void.is_error()) + error = DeprecatedString::formatted("Failed to export WAV file: {}", error_or_void.error()); }); if (!error.is_empty()) { GUI::MessageBox::show_error(window, error); |