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 ***************************************************************************/
46 #define JOG_BACK1 10001
47 #define JOG_FWD1 10002
49 #define JOG_FWD_SLOW 10004
50 #define JOG_FWD_FAST 10005
51 #define JOG_BACK 10006
52 #define JOG_BACK_SLOW 10007
53 #define JOG_BACK_FAST 10008
54 #define JOG_STOP 10009
57 #include <QApplication>
67 #include <linux/input.h>
71 #include "jogshuttle.h"
74 void ShuttleThread::init(QObject *parent, QString device) {
79 shuttlevalue = 0xffff;
83 bool ShuttleThread::isWorking() {
87 void ShuttleThread::run() {
88 kDebug() << "------- STARTING SHUTTLE: " << m_device;
90 const int fd = open((char *) m_device.toUtf8().data(), O_RDONLY);
92 fprintf(stderr, "Can't open Jog Shuttle FILE DESCRIPTOR\n");
97 if (ioctl(fd, EVIOCGRAB, 1) < 0) {
98 fprintf(stderr, "Can't get exclusive access on Jog Shuttle FILE DESCRIPTOR\n");
103 read(fd, &ev, sizeof(ev));
110 void ShuttleThread::handle_event(EV ev) {
113 key(ev.code, ev.value);
116 jogshuttle(ev.code, ev.value);
121 void ShuttleThread::key(unsigned short code, unsigned int value) {
123 // Button release (ignored)
133 kDebug() << "Button PRESSED: " << code;
134 QApplication::postEvent(m_parent, new QEvent((QEvent::Type)(20000 + code)));
138 void ShuttleThread::shuttle(int value) {
139 //gettimeofday( &last_shuttle, 0 );
140 //need_synthetic_shuttle = value != 0;
142 if (value == shuttlevalue)
144 shuttlevalue = value;
151 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK_FAST));
152 break; // Reverse fast
154 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK));
157 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK_SLOW));
158 break; // Reverse slow
160 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_STOP));
163 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD_SLOW));
164 break; // Forward slow
166 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD));
167 break; // Normal play
173 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD_FAST));
174 break; // Fast forward
179 void ShuttleThread::jog(unsigned int value) {
180 // We should generate a synthetic event for the shuttle going
181 // to the home position if we have not seen one recently
184 if (jogvalue != 0xffff) {
185 if (value < jogvalue)
186 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK1));
187 else if (value > jogvalue)
188 QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD1));
194 void ShuttleThread::jogshuttle(unsigned short code, unsigned int value) {
206 JogShuttle::JogShuttle(QString device, QObject *parent): QObject(parent) {
210 JogShuttle::~JogShuttle() {
211 if (m_shuttleProcess.isRunning()) m_shuttleProcess.exit();
214 void JogShuttle::initDevice(QString device) {
215 if (m_shuttleProcess.isRunning()) return;
216 m_shuttleProcess.init(this, device);
217 m_shuttleProcess.start(QThread::LowestPriority);
220 void JogShuttle::stopDevice() {
221 if (m_shuttleProcess.isRunning()) m_shuttleProcess.stop_me = true;
224 void JogShuttle::customEvent(QEvent* e) {
254 emit button(e->type() - 20000);
260 // #include "jogshuttle.moc"