]> git.sesse.net Git - nageru/commitdiff
Wire the transition names through to the UI.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 8 Oct 2015 22:24:57 +0000 (00:24 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 8 Oct 2015 22:24:57 +0000 (00:24 +0200)
glwidget.cpp
glwidget.h
mainwindow.cpp
mainwindow.h
mixer.h
theme.cpp
theme.h
theme.lua

index 1e34a1cb3290b6cd84099597a50ae53f8a4fa0bd..3482a13391609c049869650d7aadb32481cb94ec 100644 (file)
@@ -8,6 +8,7 @@
 #include <QSurfaceFormat>
 
 #include "glwidget.h"
+#include "mainwindow.h"
 
 #include <movit/resource_pool.h>
 #include <stdio.h>
@@ -17,6 +18,7 @@
 #include "mixer.h"
 #include "ref_counted_gl_sync.h"
 
+class MainWindow;
 class QSurface;
 class QWidget;
 
@@ -24,6 +26,8 @@ class QWidget;
 #include <movit/util.h>
 #include <string>
 
+using namespace std;
+
 GLWidget::GLWidget(QWidget *parent)
     : QGLWidget(parent, global_share_widget),
       resource_pool(new movit::ResourcePool)
@@ -46,6 +50,7 @@ void GLWidget::initializeGL()
        });
        global_mixer->set_frame_ready_callback(output, [this]{
                QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
+               emit transition_names_updated(global_mixer->get_transition_names());
        });
 
        glDisable(GL_BLEND);
index d3972739cff27de4550b462f5cc863617620ff49..3641f66a75f5fecfa317e1363c937c4dbce14bb3 100644 (file)
@@ -37,6 +37,7 @@ protected:
 
 signals:
        void clicked();
+       void transition_names_updated(std::vector<std::string> transition_names);
 
 private:
        Mixer::Output output;
index a3736709531c451b28c6bc7443774c4fb8795606..8872523e71d30fa6eb5cefa2d993ae73bdbedb78 100644 (file)
@@ -1,14 +1,19 @@
 #include "mainwindow.h"
 #include "window.h"
 #include <thread>
+#include <vector>
+#include <string>
 #include <QSignalMapper>
+#include <QMetaType>
 
 #include "context.h"
 #include "mixer.h"
 
 #include "ui_mainwindow.cpp"
 
-using std::thread;
+using namespace std;
+
+Q_DECLARE_METATYPE(std::vector<std::string>);
 
 MainWindow::MainWindow()
 {
@@ -47,6 +52,33 @@ MainWindow::MainWindow()
                connect(ui->transition_btn3, SIGNAL(clicked()), mapper, SLOT(map()));
                connect(mapper, SIGNAL(mapped(int)), this, SLOT(transition_clicked(int)));
        }
+
+       // Aiee...
+       transition_btn1 = ui->transition_btn1;
+       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>)),
+               this, SLOT(set_transition_names(std::vector<std::string>)));
+}
+
+void MainWindow::set_transition_names(vector<string> transition_names)
+{
+       if (transition_names.size() < 1) {
+               transition_btn1->setText(QString(""));
+       } else {
+               transition_btn1->setText(QString::fromStdString(transition_names[0]));
+       }
+       if (transition_names.size() < 2) {
+               transition_btn2->setText(QString(""));
+       } else {
+               transition_btn2->setText(QString::fromStdString(transition_names[1]));
+       }
+       if (transition_names.size() < 3) {
+               transition_btn3->setText(QString(""));
+       } else {
+               transition_btn3->setText(QString::fromStdString(transition_names[2]));
+       }
 }
 
 void MainWindow::transition_clicked(int transition_number)
index 6db9a09cdccc1e4f531dbd83a828933367f5f102..daf48b31794b49ea7a618920fcb0c67ab9bde7d4 100644 (file)
@@ -2,6 +2,10 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <vector>
+#include <string>
+
+class QPushButton;
 
 class MainWindow : public QMainWindow
 {
@@ -13,6 +17,10 @@ public:
 public slots:
        void transition_clicked(int transition_number);
        void channel_clicked(int channel_number);
+       void set_transition_names(std::vector<std::string> transition_names);
+
+private:
+       QPushButton *transition_btn1, *transition_btn2, *transition_btn3;
 };
 
 #endif
diff --git a/mixer.h b/mixer.h
index c6366fdec1a65d5e8f7e909ed788e0c6119d8c73..b2561d15c0b395f2d82e2a5d92b682b7ab634942 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -77,6 +77,11 @@ public:
                output_channel[output].set_frame_ready_callback(callback);
        }
 
+       std::vector<std::string> get_transition_names()
+       {
+               return theme->get_transition_names(frame / 60.0);
+       }
+
 private:
        void bm_frame(int card_index, uint16_t timecode,
                FrameAllocator::Frame video_frame, size_t video_offset, uint16_t video_format,
index 5a42dff65e585e51e57d9083a8b3d52775d8a5d3..28218f6d5d1cb3cdd48f8fca84b34247369017b6 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -396,6 +396,25 @@ Theme::get_chain(unsigned num, float t, unsigned width, unsigned height)
        });
 }
 
+std::vector<std::string> Theme::get_transition_names(float t)
+{
+       unique_lock<mutex> lock(m);
+       lua_getglobal(L, "get_transitions");
+       lua_pushnumber(L, t);
+       if (lua_pcall(L, 1, 1, 0) != 0) {
+               fprintf(stderr, "error running function `get_transitions': %s\n", lua_tostring(L, -1));
+               exit(1);
+       }
+
+       std::vector<std::string> ret;
+       lua_pushnil(L);
+       while (lua_next(L, -2) != 0) {
+               ret.push_back(lua_tostring(L, -1));
+               lua_pop(L, 1);
+       }
+       return ret;
+}      
+
 void Theme::connect_signal(YCbCrInput *input, int signal_num)
 {
        input->set_texture_num(0, input_textures[signal_num].tex_y);
diff --git a/theme.h b/theme.h
index f35c6d5be472eddb3ad9b02b9864e2ab6687b963..bb6ff9bebd43ffc761c538739727800a8cc60a0c 100644 (file)
--- a/theme.h
+++ b/theme.h
@@ -26,6 +26,8 @@ public:
        }
        int get_num_channels() { return num_channels; }
 
+       std::vector<std::string> get_transition_names(float t);
+
        void connect_signal(movit::YCbCrInput *input, int signal_num);
        void transition_clicked(int transition_num, float t);
        void channel_clicked(int preview_num);
index 67c80a32a9166ea49d3cdeacea1ba9aaad0f2cba..c7ce264017cfd9bde2572bf74e9c9e8096898ecf 100644 (file)
--- a/theme.lua
+++ b/theme.lua
@@ -90,8 +90,38 @@ function num_channels()
 end
 
 -- Called every frame.
-function get_transitions()
-       return {"Cut", "Fade", "Zoom!"}
+function get_transitions(t)
+       -- If live is 2 (SBS) but de-facto single, make it so.
+       if live_signal_num == 2 and t >= zoom_end and zoom_dst == 1.0 then
+               live_signal_num = 0
+       end
+
+       if live_signal_num == preview_signal_num then
+               return {}
+       end
+
+       if live_signal_num == 2 and t >= zoom_start and t <= zoom_end then
+               -- Zoom in progress.
+               return {"Cut"}
+       end
+
+       if (live_signal_num == 0 and preview_signal_num == 1) or
+          (live_signal_num == 1 and preview_signal_num == 0) then
+               return {"Cut"}
+       end
+
+       if live_signal_num == 2 and preview_signal_num == 1 then
+               -- Zoom-out not supported here yet.
+               return {"Cut"}
+       end
+
+       if live_signal_num == 2 and preview_signal_num == 0 then
+               return {"Cut", "Zoom in"}
+       elseif live_signal_num == 0 and preview_signal_num == 2 then
+               return {"Cut", "Zoom out"}
+       end
+
+       return {"Cut"}
 end
 
 function transition_clicked(num, t)