X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mainwindow.cpp;h=841952f8b28eda6b2c83483aedf717e00ef6c834;hb=b561d43a60201395f1354a585aa37670eda45883;hp=9ed7d3e4ca7a3ea97cb084b5bb53a7d1077fb4c6;hpb=a67460db8ba2c3c50e75866fa85091fbebdc7386;p=nageru diff --git a/mainwindow.cpp b/mainwindow.cpp index 9ed7d3e..841952f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include "aboutdialog.h" +#include "disk_space_estimator.h" #include "flags.h" #include "glwidget.h" #include "lrameter.h" @@ -30,6 +32,7 @@ class QResizeEvent; using namespace std; +using namespace std::chrono; using namespace std::placeholders; Q_DECLARE_METATYPE(std::string); @@ -93,6 +96,11 @@ MainWindow::MainWindow() global_mainwindow = this; ui->setupUi(this); + global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2)); + disk_free_label = new QLabel(this); + disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}"); + ui->menuBar->setCornerWidget(disk_free_label); + ui->me_live->set_output(Mixer::OUTPUT_LIVE); ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW); @@ -121,6 +129,8 @@ MainWindow::MainWindow() qRegisterMetaType>("std::vector"); connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names); qRegisterMetaType("Mixer::Output"); + + last_audio_level_callback = steady_clock::now() - seconds(1); } void MainWindow::resizeEvent(QResizeEvent* event) @@ -283,6 +293,39 @@ void MainWindow::cutoff_knob_changed(int value) ui->locut_cutoff_display->setText(buf); } +void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left) +{ + char time_str[256]; + if (estimated_seconds_left < 60.0) { + strcpy(time_str, "Less than a minute"); + } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red). + int s = lrintf(estimated_seconds_left); + int m = s / 60; + s %= 60; + snprintf(time_str, sizeof(time_str), "%dm %ds", m, s); + } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm. + int m = lrintf(estimated_seconds_left / 60.0); + snprintf(time_str, sizeof(time_str), "%dm", m); + } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym. + int m = lrintf(estimated_seconds_left / 60.0); + int h = m / 60; + m %= 60; + snprintf(time_str, sizeof(time_str), "%dh %dm", h, m); + } else { // More than ten hours: Xh. + int h = lrintf(estimated_seconds_left / 3600.0); + snprintf(time_str, sizeof(time_str), "%dh", h); + } + char buf[256]; + snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str); + + std::string label = buf; + + post_to_main_thread([this, label]{ + disk_free_label->setText(QString::fromStdString(label)); + ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right. + }); +} + void MainWindow::limiter_threshold_knob_changed(int value) { float threshold_dbfs = value * 0.1f; @@ -311,13 +354,11 @@ void MainWindow::audio_level_callback(float level_lufs, float peak_db, float glo float gain_staging_db, float final_makeup_gain_db, float correlation) { - timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); + steady_clock::time_point now = steady_clock::now(); // The meters are somewhat inefficient to update. Only update them // every 100 ms or so (we get updates every 5–20 ms). - double last_update_age = now.tv_sec - last_audio_level_callback.tv_sec + - 1e-9 * (now.tv_nsec - last_audio_level_callback.tv_nsec); + double last_update_age = duration(now - last_audio_level_callback).count(); if (last_update_age < 0.100) { return; }