Skip to content
Extraits de code Groupes Projets
Valider 16319f15 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Add basic missing events handlers and functions

parent bd7653eb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #2632 en échec
......@@ -198,7 +198,7 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d
(*win)->queue = queue;
(*win)->db = db;
(*win)->is_in_preparation = true;
(*win)->reg = qt_window_reg;
arg = LKT_ALLOC_STRUCT(poller_thread_arg);
RETURN_UNLESS(arg, "Out of memory", false);
......
......@@ -10,11 +10,8 @@ struct module_qt_window_s {
MainWindow *main_window;
MpvWidget *mpv_widget;
/* Thread related */
struct poller_thread self;
volatile int launched; /* SDL you sucks */
volatile bool is_in_preparation; /* Inside the MPV & SDL init */
volatile bool has_preparation_failed; /* The init failed */
struct module_reg *reg;
/* Things from the server */
struct queue *queue;
......
......@@ -3,7 +3,7 @@
MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent)
{
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this);
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, qt_window->reg, this);
connect(qt_window->mpv_widget, &MpvWidget::titleChanged, this, &MainWindow::updateWindowTitle);
setCentralWidget(qt_window->mpv_widget);
setFocusPolicy(Qt::StrongFocus);
......
......@@ -28,10 +28,11 @@ get_proc_address(void *ctx, const char *name)
return reinterpret_cast<void *>(glctx->getProcAddress(QByteArray(name)));
}
MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent)
MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, struct module_reg *reg, QWidget *parent)
: QOpenGLWidget(parent)
, m_queue(queue)
, m_db(db)
, m_reg(reg)
{
mpv = mpv_create();
if (!mpv)
......@@ -41,6 +42,7 @@ MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent)
mpv_set_option_string(mpv, "terminal", "yes");
mpv_set_option_string(mpv, "msg-level", "all=v");
mpv_set_option_string(mpv, "osc", "yes");
if (mpv_initialize(mpv) < 0)
throw std::runtime_error("could not initialize mpv context");
......@@ -129,6 +131,41 @@ MpvWidget::handle_mpv_event(mpv_event *event)
(void)prop;
switch (event->event_id) {
case MPV_EVENT_PAUSE:
lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PAUSE);
break;
case MPV_EVENT_UNPAUSE:
lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY);
break;
case MPV_EVENT_SHUTDOWN:
lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_STOP);
reg_call(m_reg, "close", 1);
break;
case MPV_EVENT_START_FILE:
//SET_STATE_FLAG(*(arg->state), PLAY);
//*(arg->hinib) = false;
LOG_DEBUG("WINDOW", "Start of file!");
break;
case MPV_EVENT_END_FILE:
//LOG_DEBUG("WINDOW", "End of file!");
//if (((*(arg->state)) != STATE_STOP) && !(*(arg->hinib))) {
// LOG_DEBUG("WINDOW", "Send play_next event");
// lkt_queue_send(queue, LKT_EVENT_PLAY_NEXT, NULL);
//} else
// LOG_DEBUG("WINDOW", "Don't send play_next event, hinib is %d and state is %s",
// *(arg->hinib),
// (*(arg->state) == STATE_STOP) ? "STOP"
// : (*(arg->state) == STATE_PLAY) ? "PLAY"
// : (*(arg->state) == STATE_PAUSE) ? "PAUSE"
// : "UNKNOWN");
LOG_DEBUG("WINDOW", "End of file!");
//lkt_queue_send(m_queue, LKT_EVENT_PLAY_NEXT, NULL);
break;
case MPV_EVENT_PROPERTY_CHANGE: {
prop = static_cast<mpv_event_property *>(event->data);
if (strcmp(prop->name, "time-pos") == 0) {
......@@ -146,22 +183,19 @@ MpvWidget::handle_mpv_event(mpv_event *event)
}
case MPV_EVENT_IDLE:
lkt_queue_make_available(m_queue, (LKT_EVENT_TYPE)LKT_EVENT_PLAY);
lkt_queue_make_available(m_queue, (LKT_EVENT_TYPE)LKT_EVENT_PROP);
titleChanged("[Lektord] Stopped");
break;
case MPV_EVENT_SHUTDOWN:
case MPV_EVENT_LOG_MESSAGE:
case MPV_EVENT_GET_PROPERTY_REPLY:
case MPV_EVENT_SET_PROPERTY_REPLY:
case MPV_EVENT_NONE:
case MPV_EVENT_COMMAND_REPLY:
case MPV_EVENT_START_FILE:
case MPV_EVENT_END_FILE:
case MPV_EVENT_FILE_LOADED:
case MPV_EVENT_TRACKS_CHANGED:
case MPV_EVENT_TRACK_SWITCHED:
case MPV_EVENT_PAUSE:
case MPV_EVENT_UNPAUSE:
case MPV_EVENT_TICK:
case MPV_EVENT_SCRIPT_INPUT_DISPATCH:
case MPV_EVENT_CLIENT_MESSAGE:
......@@ -207,18 +241,22 @@ MpvWidget::on_update(void *ctx)
bool
MpvWidget::get_elapsed(int UNUSED *elapsed_sec)
{
*elapsed_sec = 5;
return true;
}
bool
MpvWidget::get_duration(int UNUSED *dur_sec)
{
*dur_sec = 90;
return true;
}
bool
MpvWidget::set_paussed(int UNUSED paused)
MpvWidget::set_paussed(int paused)
{
const char *cmd[] = {"set", "pause", paused == 1 ? "yes" : "no", NULL};
mpv_command_async(mpv, 0, cmd);
return true;
}
......@@ -229,9 +267,9 @@ MpvWidget::set_volume(int UNUSED vol)
}
bool
MpvWidget::set_position(int UNUSED sec)
MpvWidget::set_position(int sec)
{
return true;
return lmpv_set_position(mpv, sec);
}
bool
......@@ -274,20 +312,22 @@ MpvWidget::update_window_title()
bool
MpvWidget::toggle_pause()
{
const char *cmd[] = {"cycle", "pause", NULL};
mpv_command_async(mpv, 0, cmd);
return true;
}
#define MPV_SEND_COMMAND_ASYNC( ... ) \
{ \
const char *cmd_seek[] = { __VA_ARGS__ }; \
mpv_command_async(mpv, 0, cmd_seek); \
const char *cmd[] = { __VA_ARGS__ }; \
mpv_command_async(mpv, 0, cmd); \
break; \
}
void
MpvWidget::keyPressEvent(QKeyEvent* event)
{
switch(event->modifiers()){
/* SHIFTED */
case Qt::ShiftModifier:
switch(event->key()){
case Qt::Key_J:
......@@ -296,11 +336,20 @@ MpvWidget::keyPressEvent(QKeyEvent* event)
}
break;
/* UN-SHIFTED */
default:
switch(event->key()){
/* Playback */
case Qt::Key_Space:
lmpv_toggle_pause(mpv);
//lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_TOGGLE);
break;
case Qt::Key_Enter:
lkt_queue_send(m_queue, LKT_EVENT_PLAY_NEXT, NULL);
break;
case Qt::Key_Less:
lkt_queue_send(m_queue, LKT_EVENT_PLAY_PREV, NULL);
break;
case Qt::Key_Left:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "seek", "-5", "relative", NULL);
......@@ -326,6 +375,8 @@ MpvWidget::keyPressEvent(QKeyEvent* event)
/* Misc */
case Qt::Key_I:
MPV_SEND_COMMAND_ASYNC("script-binding", "stats/display-stats", NULL);
case Qt::Key_Delete:
MPV_SEND_COMMAND_ASYNC("script-binding", "osc/visibility", NULL);
default:
break;
......
......@@ -9,7 +9,7 @@
class MpvWidget Q_DECL_FINAL : public QOpenGLWidget {
Q_OBJECT
public:
MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent);
MpvWidget(struct queue *queue, lkt_db *db, struct module_reg *reg, QWidget *parent);
virtual ~MpvWidget() override;
void command(const QVariant &params);
void setProperty(const QString &name, const QVariant &value);
......@@ -36,6 +36,7 @@ public:
private:
struct queue *m_queue;
lkt_db *m_db;
struct module_reg *m_reg;
protected:
void keyPressEvent(QKeyEvent* event);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter