X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjogshuttle.cpp;h=f9049511dceefcc568ecf037e33c2fdec5b3ea0c;hb=2b4a438e09bf373960bcd127dcf6701a74b3ee22;hp=8446076e95da3e74a9186a29b5f0dd867ecabb1e;hpb=0ae1ad35ac158ca3a89de99c25dff38575ea1ae5;p=kdenlive diff --git a/src/jogshuttle.cpp b/src/jogshuttle.cpp index 8446076e..f9049511 100644 --- a/src/jogshuttle.cpp +++ b/src/jogshuttle.cpp @@ -73,7 +73,7 @@ void ShuttleThread::init(QObject *parent, QString device) stop_me = false; m_isWorking = false; shuttlevalue = 0xffff; - shuttlechange = false; + shuttlecounter = 0; jogvalue = 0xffff; } @@ -149,15 +149,17 @@ void ShuttleThread::shuttle(int value) //gettimeofday( &last_shuttle, 0 ); //need_synthetic_shuttle = value != 0; - if (value == shuttlevalue) + if (value == shuttlevalue) { + shuttlecounter = 1; return; + } if (value > MAX_SHUTTLE_RANGE || value < -MAX_SHUTTLE_RANGE) { fprintf(stderr, "Jog Shuttle returned value of %d (should be between -%d ad +%d)", value, MAX_SHUTTLE_RANGE, MAX_SHUTTLE_RANGE); return; } shuttlevalue = value; - shuttlechange = true; + shuttlecounter = 1; QApplication::postEvent(m_parent, new QEvent((QEvent::Type) (JOG_STOP + value))); } @@ -184,14 +186,16 @@ void ShuttleThread::jog(unsigned int value) QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_BACK1)); else if ((forward && !wrap) || (rewind && wrap)) QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_FWD1)); - else if (!forward && !rewind && !shuttlechange) + else if (!forward && !rewind && shuttlecounter > 2) { // An event without changing the jog value is sent after each shuttle change. // As the shuttle rest position does not get a shuttle event, only a non-position-changing jog event. // Hence we stop on this when we see 2 non-position-changing jog events in a row. + shuttlecounter = 0; QApplication::postEvent(m_parent, new QEvent((QEvent::Type) JOG_STOP)); + } } jogvalue = value; - shuttlechange = false; + if (shuttlecounter > 0) shuttlecounter++; } @@ -203,7 +207,7 @@ JogShuttle::JogShuttle(QString device, QObject *parent) : JogShuttle::~JogShuttle() { - if (m_shuttleProcess.isRunning()) m_shuttleProcess.exit(); + stopDevice(); } void JogShuttle::initDevice(QString device) @@ -218,8 +222,19 @@ void JogShuttle::initDevice(QString device) void JogShuttle::stopDevice() { - if (m_shuttleProcess.isRunning()) + if (m_shuttleProcess.isRunning()) { + /* the read fd is in blocking mode => stop_me is broken at the moment */ m_shuttleProcess.stop_me = true; + m_shuttleProcess.exit(); + /* give the thread some time to shutdown */ + m_shuttleProcess.wait(100); + + /* if still running - do it in the hardcore way */ + if (m_shuttleProcess.isRunning()) { + m_shuttleProcess.terminate(); + kDebug() << "/// terminate jogshuttle process\n"; + } + } } void JogShuttle::customEvent(QEvent* e)