1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
3 * Based on code by Arendt David <admin@prnet.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
22 #include "jogshuttle.h"
27 #include <QApplication>
34 #include <linux/input.h>
60 #define JOG_BACK1 10001
61 #define JOG_FWD1 10002
63 #define JOG_FWD_SLOW 10004
64 #define JOG_FWD_FAST 10005
65 #define JOG_BACK 10006
66 #define JOG_BACK_SLOW 10007
67 #define JOG_BACK_FAST 10008
68 #define JOG_STOP 10009
71 void ShuttleThread::init(QObject *parent, QString device) {
76 shuttlevalue = 0xffff;
80 bool ShuttleThread::isWorking() {
84 void ShuttleThread::run() {
85 kDebug() << "------- STARTING SHUTTLE: " << m_device;
87 const int fd = KDE_open((char *) m_device.toUtf8().data(), O_RDONLY);
89 fprintf(stderr, "Can't open Jog Shuttle FILE DESCRIPTOR\n");
94 if (ioctl(fd, EVIOCGRAB, 1) < 0) {
95 fprintf(stderr, "Can't get exclusive access on Jog Shuttle FILE DESCRIPTOR\n");
100 read(fd, &ev, sizeof(ev));
107 void ShuttleThread::handle_event(EV ev) {
110 key(ev.code, ev.value);
113 jogshuttle(ev.code, ev.value);
118 void ShuttleThread::key(unsigned short code, unsigned int value) {
120 // Button release (ignored)
130 kDebug() << "Button PRESSED: " << code;
131 QApplication::postEvent(m_parent, new QEvent((QEvent::Type)(20000 + code)));
135 void ShuttleThread::shuttle(int value) {
136 //gettimeofday( &last_shuttle, 0 );
137 //need_synthetic_shuttle = value != 0;
139 if (value == shuttlevalue)
141 shuttlevalue = value;
148 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK_FAST));
149 break; // Reverse fast
151 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK));
154 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK_SLOW));
155 break; // Reverse slow
157 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_STOP));
160 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD_SLOW));
161 break; // Forward slow
163 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD));
164 break; // Normal play
170 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD_FAST));
171 break; // Fast forward
176 void ShuttleThread::jog(unsigned int value) {
177 // We should generate a synthetic event for the shuttle going
178 // to the home position if we have not seen one recently
181 if (jogvalue != 0xffff) {
182 if (value < jogvalue)
183 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK1));
184 else if (value > jogvalue)
185 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD1));
191 void ShuttleThread::jogshuttle(unsigned short code, unsigned int value) {
203 JogShuttle::JogShuttle(QString device, QObject *parent): QObject(parent) {
207 JogShuttle::~JogShuttle() {
208 if (m_shuttleProcess.isRunning()) m_shuttleProcess.exit();
211 void JogShuttle::initDevice(QString device) {
212 if (m_shuttleProcess.isRunning()) return;
213 m_shuttleProcess.init(this, device);
214 m_shuttleProcess.start(QThread::LowestPriority);
217 void JogShuttle::stopDevice() {
218 if (m_shuttleProcess.isRunning()) m_shuttleProcess.stop_me = true;
221 void JogShuttle::customEvent(QEvent* e) {
251 emit button(e->type() - 20000);
257 // #include "jogshuttle.moc"