]> git.sesse.net Git - nageru/commitdiff
Make it possible for the theme to override the status line.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 24 Jul 2019 13:06:29 +0000 (15:06 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 24 Jul 2019 13:06:29 +0000 (15:06 +0200)
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
nageru/mainwindow.h
nageru/mixer.h
nageru/theme.cpp
nageru/theme.h
shared/disk_space_estimator.cpp
shared/disk_space_estimator.h

index f2adbf240c94a6e42afe8a2238553075f7cfcc38..66a11441d5883a2e6aa758f5b280c68b277eee92 100644 (file)
@@ -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));
index a0c090fcd86a138e8c230708061bf126d172274e..b6a053bd0f68ded9cc7d9d851d597bb8ebad4ff0 100644 (file)
@@ -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<AudioMixer::BusLevel> bus_levels, float global_level_lufs, float range_low_lufs, float range_high_lufs, float final_makeup_gain_db, float correlation);
index 69b28f58826bb7c4603107d3f7efa668b97e196c..9aa375636722d0e6d06be47bc8ca90c232b04d9b 100644 (file)
@@ -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(); }
index c6cf4515805ad83be506f783d26df92b30ebc103..9506294dcea2c11c3d5367a1bed4bd3c7fba45fc 100644 (file)
@@ -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<mutex> 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;
+}
index b4e8d8c406bcd612637eb662882d04798a115f2d..37113b2b954d88a607087ca8e691df1aa082a8fd 100644 (file)
@@ -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);
index da55ee1e46b5018a0f8e381752bf661e55c11cc1..5cdc264652415bbbe9f8a5a7be7de7d929432544 100644 (file)
@@ -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;
                }
        }
index 163b7efd555dd81ac2df84a5fc8591f63b393673..dfbb4a4cc788ca8bf8bd34b1bef57daad58f5ec1 100644 (file)
@@ -20,7 +20,7 @@
 
 class DiskSpaceEstimator {
 public:
-       typedef std::function<void(off_t free_bytes, double estimated_seconds_left)> callback_t;
+       typedef std::function<void(off_t free_bytes, double estimated_seconds_left, double file_length_seconds)> 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<MeasurePoint> 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().