summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-01-14 12:45:33 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-14 21:37:23 +0100
commit4d3a5c21b0d04fa58b330d91ba4fa06e91108d3e (patch)
tree230b7b19e7738b5f3187b2c32c4ad002152a2456
parent84673278073a79ec83d367395c32396e6da6e537 (diff)
downloadserenity-4d3a5c21b0d04fa58b330d91ba4fa06e91108d3e.zip
Utilities/aplay: Print progress in seconds and minutes by default
By default, aplay now prints the played time, the remaining time and the total duration of the file in seconds and minutes. This is much more intuitive. The old sample-based format is kept and hidden behind the -s flag.
-rw-r--r--Userland/Utilities/aplay.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/Userland/Utilities/aplay.cpp b/Userland/Utilities/aplay.cpp
index 72c26397f2..ce8bb75a1e 100644
--- a/Userland/Utilities/aplay.cpp
+++ b/Userland/Utilities/aplay.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -10,6 +11,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibMain/Main.h>
+#include <math.h>
#include <stdio.h>
// The Kernel has issues with very large anonymous buffers.
@@ -20,10 +22,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
const char* path = nullptr;
bool should_loop = false;
+ bool show_sample_progress = false;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(path, "Path to audio file", "path");
args_parser.add_option(should_loop, "Loop playback", "loop", 'l');
+ args_parser.add_option(show_sample_progress, "Show playback progress in samples", "sample-progress", 's');
args_parser.parse(arguments);
Core::EventLoop loop;
@@ -59,7 +63,27 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (samples.value()->sample_count() > 0) {
// We can read and enqueue more samples
out("\033[u");
- out("{}/{}", loader->loaded_samples(), loader->total_samples());
+ if (show_sample_progress) {
+ out("{}/{}", loader->loaded_samples(), loader->total_samples());
+ } else {
+ auto playing_seconds = static_cast<int>(floor(static_cast<double>(loader->loaded_samples()) / static_cast<double>(loader->sample_rate())));
+ auto playing_minutes = playing_seconds / 60;
+ auto playing_seconds_of_minute = playing_seconds % 60;
+
+ auto total_seconds = static_cast<int>(floor(static_cast<double>(loader->total_samples()) / static_cast<double>(loader->sample_rate())));
+ auto total_minutes = total_seconds / 60;
+ auto total_seconds_of_minute = total_seconds % 60;
+
+ auto remaining_seconds = total_seconds - playing_seconds;
+ auto remaining_minutes = remaining_seconds / 60;
+ auto remaining_seconds_of_minute = remaining_seconds % 60;
+
+ out("\033[1m{:02d}:{:02d}\033[0m [{}{:02d}:{:02d}] -- {:02d}:{:02d}",
+ playing_minutes, playing_seconds_of_minute,
+ remaining_seconds == 0 ? " " : "-",
+ remaining_minutes, remaining_seconds_of_minute,
+ total_minutes, total_seconds_of_minute);
+ }
fflush(stdout);
resampler.reset();
auto resampled_samples = TRY(Audio::resample_buffer(resampler, *samples.value()));