]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Start adding some faders for the miniview (they don't do much yet).
[nageru] / mainwindow.cpp
index 9ed7d3e4ca7a3ea97cb084b5bb53a7d1077fb4c6..9ae13fb071a13681998ecb3035752cb46edb09bf 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <signal.h>
 #include <algorithm>
+#include <chrono>
 #include <string>
 #include <vector>
 #include <QBoxLayout>
 #include <QString>
 
 #include "aboutdialog.h"
+#include "disk_space_estimator.h"
 #include "flags.h"
 #include "glwidget.h"
 #include "lrameter.h"
 #include "mixer.h"
 #include "post_to_main_thread.h"
+#include "ui_audio_miniview.h"
 #include "ui_display.h"
 #include "ui_mainwindow.h"
 #include "vumeter.h"
@@ -30,6 +33,7 @@
 class QResizeEvent;
 
 using namespace std;
+using namespace std::chrono;
 using namespace std::placeholders;
 
 Q_DECLARE_METATYPE(std::string);
@@ -93,6 +97,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 +130,8 @@ MainWindow::MainWindow()
        qRegisterMetaType<vector<string>>("std::vector<std::string>");
        connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
        qRegisterMetaType<Mixer::Output>("Mixer::Output");
+
+       last_audio_level_callback = steady_clock::now() - seconds(1);
 }
 
 void MainWindow::resizeEvent(QResizeEvent* event)
@@ -164,6 +175,21 @@ void MainWindow::mixer_created(Mixer *mixer)
                connect(ui_display->wb_button, &QPushButton::clicked, bind(&MainWindow::wb_button_clicked, this, i));
        }
 
+       // Audio miniview: Make some channels!
+       for (unsigned i = 0; i < num_previews; ++i) {
+               Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
+
+               QWidget *channel = new QWidget(this);
+               Ui::AudioMiniView *ui_audio_miniview = new Ui::AudioMiniView;
+               ui_audio_miniview->setupUi(channel);
+               ui_audio_miniview->channel_desc_label->setFullText(
+                       QString::fromStdString(mixer->get_channel_name(output)));
+               ui->faders->addWidget(channel);
+
+               connect(ui_audio_miniview->fader, &QAbstractSlider::valueChanged,
+                       bind(&MainWindow::mini_fader_changed, this, ui_audio_miniview, i, _1));
+       }
+
        // TODO: Fetch all of the values these for completeness,
        // not just the enable knobs implied by flags.
        ui->locut_enabled->setChecked(global_mixer->get_locut_enabled());
@@ -283,6 +309,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, "<font color=\"red\">Less than a minute</font>");
+       } 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), "<font color=\"red\">%dm %ds</font>", 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;
@@ -299,6 +358,15 @@ void MainWindow::compressor_threshold_knob_changed(int value)
                QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
 }
 
+void MainWindow::mini_fader_changed(Ui::AudioMiniView *ui, int channel, int value)
+{
+       float volume_dbfs = value * 0.1f;
+
+       char buf[256];
+       snprintf(buf, sizeof(buf), "%+.1f dB", volume_dbfs);
+       ui->fader_label->setText(buf);
+}
+
 void MainWindow::reset_meters_button_clicked()
 {
        global_mixer->reset_meters();
@@ -311,13 +379,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<double>(now - last_audio_level_callback).count();
        if (last_update_age < 0.100) {
                return;
        }
@@ -366,8 +432,8 @@ void MainWindow::relayout()
        }
        remaining_height -= me_height + ui->vertical_layout->spacing();
 
-       double audiostrip_height = ui->audiostrip->geometry().height();
-       remaining_height -= audiostrip_height + ui->vertical_layout->spacing();
+       // Space between the M/E displays and the audio strip.
+       remaining_height -= ui->vertical_layout->spacing();
 
        // The previews will be constrained by the remaining height, and the width.
        double preview_label_height = previews[0]->title_bar->geometry().height() +
@@ -377,9 +443,8 @@ void MainWindow::relayout()
        remaining_height -= preview_height + preview_label_height + ui->vertical_layout->spacing();
 
        ui->vertical_layout->setStretch(0, lrintf(me_height));
-       ui->vertical_layout->setStretch(1, 0);  // Don't stretch the audiostrip.
-       ui->vertical_layout->setStretch(2, max<int>(1, remaining_height));  // Spacer.
-       ui->vertical_layout->setStretch(3, lrintf(preview_height + preview_label_height));
+       ui->vertical_layout->setStretch(1, lrintf(remaining_height));  // Audio strip.
+       ui->vertical_layout->setStretch(2, lrintf(preview_height + preview_label_height));
 
        // Set the widths for the previews.
        double preview_width = preview_height * 16.0 / 9.0;