From 948d715655a84b93d8292e64731ea3c32b45deb7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 24 Jul 2019 15:06:29 +0200 Subject: [PATCH] Make it possible for the theme to override the status line. This is done by declaring a function format_status_line, which receives the text that would normally be there (disk space left), as well as the length of the current recording file in seconds. It can then return whatever it would like. My own code, but inspired by a C++ patch by Alex Thomazo in the Breizhcamp repository (which did it by hardcoding a different status line in C++). --- nageru/mainwindow.cpp | 8 +++++--- nageru/mainwindow.h | 2 +- nageru/mixer.h | 5 +++++ nageru/theme.cpp | 21 +++++++++++++++++++++ nageru/theme.h | 2 ++ shared/disk_space_estimator.cpp | 6 +++++- shared/disk_space_estimator.h | 3 ++- 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/nageru/mainwindow.cpp b/nageru/mainwindow.cpp index f2adbf2..66a1144 100644 --- a/nageru/mainwindow.cpp +++ b/nageru/mainwindow.cpp @@ -198,7 +198,7 @@ MainWindow::MainWindow() global_mainwindow = this; ui->setupUi(this); - global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2)); + global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2, _3)); disk_free_label = new QLabel(this); disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}"); ui->menuBar->setCornerWidget(disk_free_label); @@ -786,7 +786,7 @@ void MainWindow::update_cutoff_labels(float cutoff_hz) } } -void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left) +void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left, double file_length_seconds) { char time_str[256]; if (estimated_seconds_left < 60.0) { @@ -811,7 +811,9 @@ void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_le char buf[256]; snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str); - std::string label = buf; + // NOTE: The default formatter does not use file_length_seconds for anything, + // but the theme might want to do so. + std::string label = global_mixer->format_status_line(buf, file_length_seconds); post_to_main_thread([this, label]{ disk_free_label->setText(QString::fromStdString(label)); diff --git a/nageru/mainwindow.h b/nageru/mainwindow.h index a0c090f..b6a053b 100644 --- a/nageru/mainwindow.h +++ b/nageru/mainwindow.h @@ -145,7 +145,7 @@ private: void next_page(); // Called from DiskSpaceEstimator. - void report_disk_space(off_t free_bytes, double estimated_seconds_left); + void report_disk_space(off_t free_bytes, double estimated_seconds_left, double file_length_seconds); // Called from the mixer. void audio_level_callback(float level_lufs, float peak_db, std::vector bus_levels, float global_level_lufs, float range_low_lufs, float range_high_lufs, float final_makeup_gain_db, float correlation); diff --git a/nageru/mixer.h b/nageru/mixer.h index 69b28f5..9aa3756 100644 --- a/nageru/mixer.h +++ b/nageru/mixer.h @@ -288,6 +288,11 @@ public: theme->set_wb(channel, r, g, b); } + std::string format_status_line(const std::string &disk_space_left_text, double file_length_seconds) + { + return theme->format_status_line(disk_space_left_text, file_length_seconds); + } + // Note: You can also get this through the global variable global_audio_mixer. AudioMixer *get_audio_mixer() { return audio_mixer.get(); } const AudioMixer *get_audio_mixer() const { return audio_mixer.get(); } diff --git a/nageru/theme.cpp b/nageru/theme.cpp index c6cf451..9506294 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -1878,3 +1878,24 @@ void Theme::theme_menu_entry_clicked(int lua_ref) abort(); } } + +string Theme::format_status_line(const string &disk_space_left_text, double file_length_seconds) +{ + lock_guard lock(m); + lua_getglobal(L, "format_status_line"); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + return disk_space_left_text; + } + + lua_pushstring(L, disk_space_left_text.c_str()); + lua_pushnumber(L, file_length_seconds); + if (lua_pcall(L, 2, 1, 0) != 0) { + fprintf(stderr, "error running function format_status_line(): %s\n", lua_tostring(L, -1)); + abort(); + } + string text = checkstdstring(L, 1); + lua_pop(L, 1); + assert(lua_gettop(L) == 0); + return text; +} diff --git a/nageru/theme.h b/nageru/theme.h index b4e8d8c..37113b2 100644 --- a/nageru/theme.h +++ b/nageru/theme.h @@ -183,6 +183,8 @@ public: theme_menu_callback = callback; } + std::string format_status_line(const std::string &disk_space_left_text, double file_length_seconds); + private: void register_globals(); void register_class(const char *class_name, const luaL_Reg *funcs, EffectType effect_type = NO_EFFECT_TYPE); diff --git a/shared/disk_space_estimator.cpp b/shared/disk_space_estimator.cpp index da55ee1..5cdc264 100644 --- a/shared/disk_space_estimator.cpp +++ b/shared/disk_space_estimator.cpp @@ -40,6 +40,10 @@ void DiskSpaceEstimator::report_append(const string &filename, uint64_t pts) void DiskSpaceEstimator::report_write_internal(const string &filename, off_t file_size, uint64_t pts) { + if (measure_points.empty()) { + first_pts_this_file = pts; + } + // Reject points that are out-of-order (happens with B-frames). if (!measure_points.empty() && pts <= measure_points.back().pts) { return; @@ -66,7 +70,7 @@ void DiskSpaceEstimator::report_write_internal(const string &filename, off_t fil // Only report every second, since updating the UI can be expensive. if (last_pts_reported == 0 || pts - last_pts_reported >= TIMEBASE) { - callback(free_bytes, seconds_left); + callback(free_bytes, seconds_left, double(pts - first_pts_this_file) / TIMEBASE); last_pts_reported = pts; } } diff --git a/shared/disk_space_estimator.h b/shared/disk_space_estimator.h index 163b7ef..dfbb4a4 100644 --- a/shared/disk_space_estimator.h +++ b/shared/disk_space_estimator.h @@ -20,7 +20,7 @@ class DiskSpaceEstimator { public: - typedef std::function callback_t; + typedef std::function callback_t; DiskSpaceEstimator(callback_t callback); // Report that a video frame with the given pts and size has just been @@ -56,6 +56,7 @@ private: }; std::deque measure_points; uint64_t last_pts_reported = 0; + uint64_t first_pts_this_file = 0; off_t total_size = 0; // For report_write(). std::string last_filename; // For report_append(). -- 2.39.2