]> git.sesse.net Git - nageru/commitdiff
Create the previews dynamically, in a number determined by the theme.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 Nov 2015 00:40:58 +0000 (01:40 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 Nov 2015 00:40:58 +0000 (01:40 +0100)
mainwindow.cpp
mainwindow.h
mixer.h
ui_mainwindow.ui

index 3f0098be7a07d385e3326f1de0dbc184cf0e4dc6..430ec0f0a8b5af09231308451ec1e5a1f5b2eaf9 100644 (file)
@@ -39,40 +39,6 @@ MainWindow::MainWindow()
        ui->me_live->set_output(Mixer::OUTPUT_LIVE);
        ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
 
-       // TODO: Ask for the real number.
-       ui->preview1->set_output(Mixer::OUTPUT_INPUT0);
-       ui->preview2->set_output(Mixer::OUTPUT_INPUT1);
-       ui->preview3->set_output(Mixer::OUTPUT_INPUT2);
-
-       // Hook up the preview clicks.
-       {
-               QSignalMapper *mapper = new QSignalMapper(this);
-               mapper->setMapping(ui->preview1, 0),
-               mapper->setMapping(ui->preview2, 1);
-               mapper->setMapping(ui->preview3, 2);
-               connect(ui->preview1, SIGNAL(clicked()), mapper, SLOT(map()));
-               connect(ui->preview2, SIGNAL(clicked()), mapper, SLOT(map()));
-               connect(ui->preview3, SIGNAL(clicked()), mapper, SLOT(map()));
-
-               connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
-       }
-
-       // Hook up the preview keyboard keys.
-       {
-               QSignalMapper *mapper = new QSignalMapper(this);
-               QShortcut *shortcut1 = new QShortcut(QKeySequence(Qt::Key_1), this);
-               connect(shortcut1, SIGNAL(activated()), mapper, SLOT(map()));
-               QShortcut *shortcut2 = new QShortcut(QKeySequence(Qt::Key_2), this);
-               connect(shortcut2, SIGNAL(activated()), mapper, SLOT(map()));
-               QShortcut *shortcut3 = new QShortcut(QKeySequence(Qt::Key_3), this);
-               connect(shortcut3, SIGNAL(activated()), mapper, SLOT(map()));
-               mapper->setMapping(shortcut1, 0),
-               mapper->setMapping(shortcut2, 1);
-               mapper->setMapping(shortcut3, 2);
-
-               connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
-       }
-
        // Hook up the transition buttons.
        // TODO: Make them dynamic.
        {
@@ -91,7 +57,7 @@ MainWindow::MainWindow()
        transition_btn2 = ui->transition_btn2;
        transition_btn3 = ui->transition_btn3;
        qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
-       connect(ui->preview1, SIGNAL(transition_names_updated(std::vector<std::string>)),
+       connect(ui->me_preview, SIGNAL(transition_names_updated(std::vector<std::string>)),
                this, SLOT(set_transition_names(std::vector<std::string>)));
 }
 
@@ -106,6 +72,28 @@ void MainWindow::resizeEvent(QResizeEvent* event)
 
 void MainWindow::mixer_created(Mixer *mixer)
 {
+       // Make the previews.
+       unsigned num_previews = mixer->get_num_channels();
+       QSignalMapper *mapper = new QSignalMapper(this);
+
+       for (unsigned i = 0; i < num_previews; ++i) {
+               GLWidget *preview = new GLWidget(this);
+               preview->set_output(Mixer::Output(Mixer::OUTPUT_INPUT0 + i));
+               ui->preview_displays->insertWidget(previews.size(), preview, 1);
+               previews.push_back(preview);
+
+               // Hook up the click.
+               mapper->setMapping(preview, i);
+               connect(preview, SIGNAL(clicked()), mapper, SLOT(map()));
+
+               // Hook up the keyboard key.
+               QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
+               mapper->setMapping(shortcut, i);
+               connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
+       }
+
+       connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
+
        mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
                ui->vu_meter->set_level(level_lufs);
                ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
@@ -138,7 +126,7 @@ void MainWindow::relayout()
 
        // The previews will be constrained by the remaining height, and the width.
        // FIXME: spacing?
-       double preview_height = std::min(height - me_height, (width / 4.0) * 9.0 / 16.0);
+       double preview_height = std::min(height - me_height, (width / double(previews.size())) * 9.0 / 16.0);
 
        ui->vertical_layout->setStretch(0, lrintf(me_height));
        ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
@@ -147,11 +135,12 @@ void MainWindow::relayout()
        // Set the widths for the previews.
        double preview_width = preview_height * 16.0 / 9.0;  // FIXME: spacing?
 
-       ui->preview_displays->setStretch(0, lrintf(preview_width));
-       ui->preview_displays->setStretch(1, lrintf(preview_width));
-       ui->preview_displays->setStretch(2, lrintf(preview_width));
-       ui->preview_displays->setStretch(3, lrintf(preview_width));
-       ui->preview_displays->setStretch(4, lrintf(width - 4.0 * preview_width));
+       for (unsigned i = 0; i < previews.size(); ++i) {
+               ui->preview_displays->setStretch(i, lrintf(preview_width));
+       }
+
+       // The spacer.
+       ui->preview_displays->setStretch(previews.size(), lrintf(width - previews.size() * preview_width));
 }
 
 void MainWindow::set_transition_names(vector<string> transition_names)
index ef0b04ffec04b06d25d7b9cbfec5136eec4bc191..8d80aafebac955e25f67565f957232739e642f26 100644 (file)
@@ -5,6 +5,7 @@
 #include <string>
 #include <vector>
 
+class GLWidget;
 class QResizeEvent;
 
 namespace Ui {
@@ -32,6 +33,7 @@ public slots:
 private:
        Ui::MainWindow *ui;
        QPushButton *transition_btn1, *transition_btn2, *transition_btn3;
+       std::vector<GLWidget *> previews;
 };
 
 extern MainWindow *global_mainwindow;
diff --git a/mixer.h b/mixer.h
index bf53c2482e23362e0cba1ff589cbf72d76d78dd0..00c1e1519c7dddb2b648cc6ab952ee00d3e43cd6 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -109,6 +109,11 @@ public:
                return theme->get_transition_names(pts());
        }
 
+       unsigned get_num_channels() const
+       {
+               return theme->get_num_channels();
+       }
+
 private:
        void bm_frame(unsigned card_index, uint16_t timecode,
                FrameAllocator::Frame video_frame, size_t video_offset, uint16_t video_format,
index 63418676d33732e68a86e92ca1764b4d24366824..ad5fb9e244f10c3b843d87fac364de00c7edbf7a 100644 (file)
@@ -43,6 +43,9 @@
             </property>
            </widget>
           </item>
+          <item>
+           <layout class="QHBoxLayout" name="horizontalLayout_3"/>
+          </item>
           <item>
            <widget class="QLabel" name="label_preview">
             <property name="text">
               <property name="autoFillBackground">
                <bool>true</bool>
               </property>
-              <zorder>peak_display</zorder>
-              <zorder>peak_display</zorder>
              </widget>
             </item>
            </layout>
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Preferred</enum>
+        </property>
         <property name="sizeHint" stdset="0">
          <size>
           <width>20</width>
        </spacer>
       </item>
       <item>
-       <layout class="QHBoxLayout" name="preview_displays">
+       <layout class="QHBoxLayout" name="preview_displays" stretch="0">
         <property name="topMargin">
          <number>0</number>
         </property>
-        <item>
-         <widget class="GLWidget" name="preview1" native="true">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-            <horstretch>1</horstretch>
-            <verstretch>1</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="GLWidget" name="preview2" native="true">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-            <horstretch>1</horstretch>
-            <verstretch>1</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="GLWidget" name="preview3" native="true">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-            <horstretch>1</horstretch>
-            <verstretch>1</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QGLWidget" name="preview4" native="true">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-            <horstretch>1</horstretch>
-            <verstretch>1</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
         <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Preferred</enum>
+          </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>0</width>
-            <height>0</height>
+            <height>40</height>
            </size>
           </property>
          </spacer>
    <extends>QWidget</extends>
    <header>glwidget.h</header>
   </customwidget>
-  <customwidget>
-   <class>QGLWidget</class>
-   <extends>QWidget</extends>
-   <header>qglwidget.h</header>
-  </customwidget>
   <customwidget>
    <class>VUMeter</class>
    <extends>QWidget</extends>