From 92d7d0f49eca3378714670843f244a8d7ae8b05d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 9 Oct 2015 00:24:57 +0200 Subject: [PATCH] Wire the transition names through to the UI. --- glwidget.cpp | 5 +++++ glwidget.h | 1 + mainwindow.cpp | 34 +++++++++++++++++++++++++++++++++- mainwindow.h | 8 ++++++++ mixer.h | 5 +++++ theme.cpp | 19 +++++++++++++++++++ theme.h | 2 ++ theme.lua | 34 ++++++++++++++++++++++++++++++++-- 8 files changed, 105 insertions(+), 3 deletions(-) diff --git a/glwidget.cpp b/glwidget.cpp index 1e34a1c..3482a13 100644 --- a/glwidget.cpp +++ b/glwidget.cpp @@ -8,6 +8,7 @@ #include #include "glwidget.h" +#include "mainwindow.h" #include #include @@ -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 #include +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); diff --git a/glwidget.h b/glwidget.h index d397273..3641f66 100644 --- a/glwidget.h +++ b/glwidget.h @@ -37,6 +37,7 @@ protected: signals: void clicked(); + void transition_names_updated(std::vector transition_names); private: Mixer::Output output; diff --git a/mainwindow.cpp b/mainwindow.cpp index a373670..8872523 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,14 +1,19 @@ #include "mainwindow.h" #include "window.h" #include +#include +#include #include +#include #include "context.h" #include "mixer.h" #include "ui_mainwindow.cpp" -using std::thread; +using namespace std; + +Q_DECLARE_METATYPE(std::vector); 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"); + connect(ui->preview1, SIGNAL(transition_names_updated(std::vector)), + this, SLOT(set_transition_names(std::vector))); +} + +void MainWindow::set_transition_names(vector 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) diff --git a/mainwindow.h b/mainwindow.h index 6db9a09..daf48b3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,10 @@ #define MAINWINDOW_H #include +#include +#include + +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 transition_names); + +private: + QPushButton *transition_btn1, *transition_btn2, *transition_btn3; }; #endif diff --git a/mixer.h b/mixer.h index c6366fd..b2561d1 100644 --- a/mixer.h +++ b/mixer.h @@ -77,6 +77,11 @@ public: output_channel[output].set_frame_ready_callback(callback); } + std::vector 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, diff --git a/theme.cpp b/theme.cpp index 5a42dff..28218f6 100644 --- a/theme.cpp +++ b/theme.cpp @@ -396,6 +396,25 @@ Theme::get_chain(unsigned num, float t, unsigned width, unsigned height) }); } +std::vector Theme::get_transition_names(float t) +{ + unique_lock 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 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 f35c6d5..bb6ff9b 100644 --- a/theme.h +++ b/theme.h @@ -26,6 +26,8 @@ public: } int get_num_channels() { return num_channels; } + std::vector 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); diff --git a/theme.lua b/theme.lua index 67c80a3..c7ce264 100644 --- 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) -- 2.39.2