File indexing completed on 2025-01-12 04:26:31
0001 /* 0002 SPDX-FileCopyrightText: 2008 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 Based on code by Arendt David <admin@prnet.org> 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QEvent> 0011 #include <QMap> 0012 #include <QObject> 0013 #include <QThread> 0014 0015 #include <media_ctrl/mediactrl.h> 0016 0017 class MediaCtrlEvent : public QEvent 0018 { 0019 public: 0020 MediaCtrlEvent(QEvent::Type type, int value) 0021 : QEvent(type) 0022 , m_value(value) 0023 { 0024 } 0025 0026 int value() { return m_value; } 0027 0028 static const QEvent::Type Key; 0029 static const QEvent::Type Jog; 0030 static const QEvent::Type Shuttle; 0031 0032 private: 0033 int m_value; 0034 }; 0035 0036 class ShuttleThread : public QThread 0037 { 0038 0039 public: 0040 ShuttleThread(QString device, QObject *parent); 0041 ~ShuttleThread() override; 0042 void run() override; 0043 QString device(); 0044 void stop(); 0045 0046 private: 0047 enum { MaxShuttleRange = 7 }; 0048 0049 void handleEvent(const media_ctrl_event &ev); 0050 void jog(const media_ctrl_event &ev); 0051 void shuttle(const media_ctrl_event &ev); 0052 void key(const media_ctrl_event &ev); 0053 0054 QString m_device; 0055 QObject *m_parent; 0056 volatile bool m_isRunning; 0057 }; 0058 0059 typedef QMap<QString, QString> DeviceMap; 0060 typedef QMap<QString, QString>::iterator DeviceMapIter; 0061 0062 class JogShuttle : public QObject 0063 { 0064 Q_OBJECT 0065 public: 0066 explicit JogShuttle(const QString &device, QObject *parent = nullptr); 0067 ~JogShuttle() override; 0068 void stopDevice(); 0069 void initDevice(const QString &device); 0070 static QString canonicalDevice(const QString &device); 0071 static DeviceMap enumerateDevices(const QString &devPath); 0072 static int keysCount(const QString &devPath); 0073 0074 protected: 0075 void customEvent(QEvent *e) override; 0076 0077 private: 0078 ShuttleThread m_shuttleProcess; 0079 0080 Q_SIGNALS: 0081 void jogBack(); 0082 void jogForward(); 0083 void shuttlePos(int); 0084 void button(int); 0085 };