]> git.sesse.net Git - kdenlive/commitdiff
Try to fix timecode error:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 8 Aug 2010 20:04:34 +0000 (20:04 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 8 Aug 2010 20:04:34 +0000 (20:04 +0000)
http://www.kdenlive.org/mantis/view.php?id=1730

svn path=/trunk/kdenlive/; revision=4688

src/dvdwizardchapters.cpp
src/geometryval.cpp
src/kdenlivedoc.cpp
src/markerdialog.cpp
src/monitor.cpp
src/positionedit.cpp
src/timecode.cpp
src/timecode.h
src/timecodedisplay.cpp
src/timecodedisplay.h

index 2b4aa3bc76f0103098343ce981a54e59cd88d50f..6105560832ba0ce92ed7ed857b71774e0301b91e 100644 (file)
@@ -38,7 +38,7 @@ DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
     // Build monitor for chapters
 
     if (m_isPal) m_tc.setFormat(25);
-    else m_tc.setFormat(30000.0 / 1001, true);
+    else m_tc.setFormat(30000.0 / 1001);
 
     m_manager = new MonitorManager(this);
     m_manager->resetProfiles(m_tc);
@@ -142,7 +142,7 @@ void DvdWizardChapters::setVobFiles(bool isPal, bool isWide, const QStringList m
         m_tc.setFormat(25);
         profile = "dv_pal";
     } else {
-        m_tc.setFormat(30000.0 / 1001, true);
+        m_tc.setFormat(30000.0 / 1001);
         profile = "dv_ntsc";
     }
     if (isWide) profile.append("_wide");
index 981b537a34b1431e0195441f67eac3519279ccd0..4c7e608ee7c63dd53540a7e3a59cfada14072793 100644 (file)
@@ -109,7 +109,6 @@ Geometryval::Geometryval(const MltVideoProfile profile, Timecode t, QPoint frame
     connect(buttonDelete , SIGNAL(clicked()) , this , SLOT(slotDeleteFrame()));
     connect(buttonAdd , SIGNAL(clicked()) , this , SLOT(slotAddFrame()));
     connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateTransitionProperties()));
-    connect(m_scene, SIGNAL(doubleClickEvent()), this, SLOT(slotGeometry()));
 
     buttonhcenter->setIcon(KIcon("kdenlive-align-hor"));
     buttonhcenter->setToolTip(i18n("Align item horizontally"));
@@ -225,7 +224,7 @@ void Geometryval::slotResizeCustom()
 
 void Geometryval::slotTransparencyChanged(int transp)
 {
-    int pos = m_timePos.value();
+    int pos = m_timePos.getValue();
     Mlt::GeometryItem item;
     int error = m_geom->fetch(&item, pos);
     if (error || item.key() == false) {
@@ -251,12 +250,15 @@ void Geometryval::updateTimecodeFormat()
 void Geometryval::slotPositionChanged(int pos, bool seek)
 {
     if (pos == -1) {
-        pos = m_timePos.value();
+        pos = m_timePos.getValue();
     }
+    kDebug() << "// POS CHANGED: " << pos << ", SEK: " << seek;
     if (seek && KdenliveSettings::transitionfollowcursor()) emit seekToPos(pos + m_startPoint);
     m_timePos.setValue(pos);
     //spinPos->setValue(pos);
+    m_helper->blockSignals(true);
     m_helper->setValue(pos);
+    m_helper->blockSignals(false);
     Mlt::GeometryItem item;
     int error = m_geom->fetch(&item, pos);
     if (error || item.key() == false) {
@@ -287,7 +289,7 @@ void Geometryval::slotDeleteFrame(int pos)
 {
     // check there is more than one keyframe
     Mlt::GeometryItem item;
-    int frame = m_timePos.value();
+    int frame = m_timePos.getValue();
 
     if (pos == -1) pos = frame;
     int error = m_geom->next_key(&item, pos + 1);
@@ -311,7 +313,7 @@ void Geometryval::slotDeleteFrame(int pos)
 
 void Geometryval::slotAddFrame(int pos)
 {
-    int frame = m_timePos.value();
+    int frame = m_timePos.getValue();
     if (pos == -1) pos = frame;
     Mlt::GeometryItem item;
     item.frame(pos);
@@ -445,7 +447,7 @@ void Geometryval::updateTransitionPath()
 
 void Geometryval::slotUpdateTransitionProperties()
 {
-    int pos = m_timePos.value();
+    int pos = m_timePos.getValue();
     Mlt::GeometryItem item;
     int error = m_geom->next_key(&item, pos);
     if (error || item.frame() != pos) {
@@ -559,7 +561,7 @@ void Geometryval::slotUpdateGeometry()
 bool Geometryval::keyframeSelected()
 {
     Mlt::GeometryItem item;
-    int pos = m_timePos.value();
+    int pos = m_timePos.getValue();
     if (m_geom->fetch(&item, pos) || item.key() == false) return false;
     return true;
 }
index 80037d38630e2d232e175a43e74cc7229ecb1e0b..1e399f94a039f373d7bb2bcdd3c149ad924df3ab 100644 (file)
@@ -716,8 +716,7 @@ bool KdenliveDoc::setProfilePath(QString path)
     m_width = m_profile.width;
     m_height = m_profile.height;
     kDebug() << "Kdenlive document, init timecode from path: " << path << ",  " << m_fps;
-    if (m_fps / 1.00 == (int)m_fps) m_timecode.setFormat(m_fps);
-    else m_timecode.setFormat(m_fps, true);
+    m_timecode.setFormat(m_fps);
     return (current_fps != m_fps);
 }
 
index 0ee5657f72685a0fb9d3e8f338798e75cda5832b..87e3f43ae03e00327eae103bf7138afdd43e4ce6 100644 (file)
@@ -70,7 +70,7 @@ MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, cons
             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
         case IMAGE:
         case TEXT:
-            p = QPixmap::fromImage(KThumb::getFrame(m_producer, m_in->value(), width, 100));
+            p = QPixmap::fromImage(KThumb::getFrame(m_producer, m_in->getValue(), width, 100));
             break;
         case COLOR:
             colour = colour.replace(0, 2, "#");
@@ -107,7 +107,7 @@ MarkerDialog::~MarkerDialog()
 void MarkerDialog::slotUpdateThumb()
 {
     m_previewTimer->stop();
-    int pos = m_in->value();
+    int pos = m_in->getValue();
     int width = 100.0 * m_dar;
     if (width % 2 == 1) width++;
     QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, width, 100));
index a39e79111d938320d239e7f42dcbb8182daea71d..89ebe859009ae15f201e88e1b791e4a651662c01 100644 (file)
@@ -523,7 +523,7 @@ void Monitor::setTimePos(const QString &pos)
 
 void Monitor::slotSeek()
 {
-    slotSeek(m_timePos->value());
+    slotSeek(m_timePos->getValue());
 }
 
 void Monitor::slotSeek(int pos)
index 7877f7e0f7d42f49b4b2b3927a943d8ce2284920..44d800f05f60711702a8e94439793c2f3c0da37a 100644 (file)
@@ -75,7 +75,7 @@ void PositionEdit::setPosition(int pos)
 void PositionEdit::slotUpdatePosition()
 {
     m_slider->blockSignals(true);
-    m_slider->setValue(m_display->value());
+    m_slider->setValue(m_display->getValue());
     m_slider->blockSignals(false);
     emit parameterChanged();
 }
index 83ed7d77044a36ba05cdd90e4e2977516d387bb1..8303c59c740a8faf58508fb83af75c14e23399ad 100644 (file)
@@ -87,23 +87,23 @@ return frameNumber;
 
 #include "timecode.h"
 
-Timecode::Timecode(Formats format, double framesPerSecond, bool dropFrame)
+Timecode::Timecode(Formats format, double framesPerSecond)
 {
     m_validator = new QRegExpValidator(0);
-    setFormat(framesPerSecond, dropFrame, format);
+    setFormat(framesPerSecond, format);
 }
 
 Timecode::~Timecode()
 {
 }
 
-void Timecode::setFormat(double framesPerSecond, bool dropFrame, Formats format)
+void Timecode::setFormat(double framesPerSecond, Formats format)
 {
     m_displayedFramesPerSecond = (int)(framesPerSecond + 0.5);
-    m_dropFrameTimecode = dropFrame;
+    m_dropFrameTimecode = (framesPerSecond / 1.00 != (int)framesPerSecond) ;
     m_format = format;
     m_realFps = framesPerSecond;
-    if (dropFrame) {
+    if (m_dropFrameTimecode) {
         m_dropFrames = round(m_realFps * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
         m_framesPer10Minutes = round(m_realFps * 600); //Number of frames per ten minutes
     }
@@ -280,9 +280,9 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps)
 
 const QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const
 {
-    if (m_dropFrameTimecode)
+    if (m_dropFrameTimecode) {
         return getTimecodeDropFrame(time);
-
+    }
     return getTimecodeHH_MM_SS_FF((int) time.frames(m_realFps));
 }
 
@@ -311,7 +311,7 @@ const QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const
     return text;
 }
 
-QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
+const QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
 {
     int hundredths = (int)(time.seconds() * 100);
     int seconds = hundredths / 100;
@@ -337,22 +337,22 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
     return text;
 }
 
-QString Timecode::getTimecodeFrames(const GenTime & time) const
+const QString Timecode::getTimecodeFrames(const GenTime & time) const
 {
     return QString::number(time.frames(m_realFps));
 }
 
-QString Timecode::getTimecodeSeconds(const GenTime & time) const
+const QString Timecode::getTimecodeSeconds(const GenTime & time) const
 {
     return QString::number(time.seconds());
 }
 
-QString Timecode::getTimecodeDropFrame(const GenTime & time) const
+const QString Timecode::getTimecodeDropFrame(const GenTime & time) const
 {
     return getTimecodeDropFrame((int)time.frames(m_realFps));
 }
 
-QString Timecode::getTimecodeDropFrame(int framenumber) const
+const QString Timecode::getTimecodeDropFrame(int framenumber) const
 {
     //CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE
     //Based on code by David Heidelberger, adapted from Andrew Duncan
@@ -362,10 +362,12 @@ QString Timecode::getTimecodeDropFrame(int framenumber) const
     int d = floor(framenumber / m_framesPer10Minutes);
     int m = framenumber % m_framesPer10Minutes;
 
-    if (m > 1) {
-        framenumber = framenumber + (m_dropFrames * 9 * d) + m_dropFrames * (floor((m - m_dropFrames) / (round(m_realFps * 60) - m_dropFrames)));
+    int framesPerMinute = round(m_realFps * 60) -  m_dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
+
+    if (m > m_dropFrames) {
+        framenumber += (m_dropFrames * 9 * d) + m_dropFrames * (floor((m - m_dropFrames) / (round(m_realFps * 60) - m_dropFrames)));
     } else {
-        framenumber = framenumber + m_dropFrames * 9 * d;
+        framenumber += m_dropFrames * 9 * d;
     }
 
     int frames = framenumber % m_displayedFramesPerSecond;
index 764a58af62567cf9a36066f813296555256a1190..e1ae7cbf40ddc60d1091c1b20bc6d92b4da575ca 100644 (file)
@@ -34,14 +34,12 @@ class Timecode
 public:
     enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds };
 
-    explicit Timecode(Formats format = HH_MM_SS_FF, double framesPerSecond = 25,
-                      bool dropFrame = false);
+    explicit Timecode(Formats format = HH_MM_SS_FF, double framesPerSecond = 25);
 
     /**
      * Set the current timecode format; this is the output format for this timecode.
      */
-    void setFormat(double framesPerSecond, bool dropFrame = false,
-                   Formats format = HH_MM_SS_FF);
+    void setFormat(double framesPerSecond, Formats format = HH_MM_SS_FF);
 
     Formats format() const {
         return m_format;
@@ -75,11 +73,11 @@ private:
     const QString getTimecodeHH_MM_SS_FF(const GenTime & time) const;
     const QString getTimecodeHH_MM_SS_FF(int frames) const;
 
-    QString getTimecodeHH_MM_SS_HH(const GenTime & time) const;
-    QString getTimecodeFrames(const GenTime & time) const;
-    QString getTimecodeSeconds(const GenTime & time) const;
-    QString getTimecodeDropFrame(const GenTime & time) const;
-    QString getTimecodeDropFrame(int framenumber) const;
+    const QString getTimecodeHH_MM_SS_HH(const GenTime & time) const;
+    const QString getTimecodeFrames(const GenTime & time) const;
+    const QString getTimecodeSeconds(const GenTime & time) const;
+    const QString getTimecodeDropFrame(const GenTime & time) const;
+    const QString getTimecodeDropFrame(int framenumber) const;
 };
 
 #endif
index 8fce02eab3f83016a7c5adc64e960795c9c3e6e7..7916ebdd784bdad15986e460a8bcb47e7d6bca05 100644 (file)
@@ -40,7 +40,7 @@ TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
     QFontMetrics fm = lineedit->fontMetrics();
     lineedit->setMaximumWidth(fm.width("88:88:88:888"));
     setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
-    
+
     setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
 
     connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp()));
@@ -50,7 +50,7 @@ TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
 
 void TimecodeDisplay::slotValueUp()
 {
-    int val = value();
+    int val = getValue();
     val++;
     setValue(val);
     lineedit->clearFocus();
@@ -59,7 +59,7 @@ void TimecodeDisplay::slotValueUp()
 
 void TimecodeDisplay::slotValueDown()
 {
-    int val = value();
+    int val = getValue();
     val--;
     setValue(val);
     lineedit->clearFocus();
@@ -69,7 +69,7 @@ void TimecodeDisplay::slotValueDown()
 void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init)
 {
     if (!init && m_frametimecode == frametimecode) return;
-    int val = value();
+    int val = getValue();
     m_frametimecode = frametimecode;
     if (m_frametimecode) {
         QIntValidator *valid = new QIntValidator(lineedit);
@@ -121,7 +121,7 @@ int TimecodeDisplay::minimum() const
     return m_minimum;
 }
 
-int TimecodeDisplay::value() const
+int TimecodeDisplay::getValue() const
 {
     if (m_frametimecode) return lineedit->text().toInt();
     else return m_timecode.getFrameCount(lineedit->text());
@@ -129,7 +129,7 @@ int TimecodeDisplay::value() const
 
 GenTime TimecodeDisplay::gentime() const
 {
-    return GenTime(value(), m_timecode.fps());
+    return GenTime(getValue(), m_timecode.fps());
 }
 
 Timecode TimecodeDisplay::timecode() const
@@ -155,13 +155,17 @@ void TimecodeDisplay::setValue(int value)
     if (m_maximum > m_minimum && value > m_maximum)
         value = m_maximum;
 
+    if (value == getValue()) return;
     downarrow->setEnabled(value > m_minimum);
     uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
 
     if (m_frametimecode)
         lineedit->setText(QString::number(value));
-    else
-        lineedit->setText(m_timecode.getTimecodeFromFrames(value));
+    else {
+        QString v = m_timecode.getTimecodeFromFrames(value);
+        kDebug() << "// SETTING TO: " << value << " = " << v << "( " << m_timecode.fps();
+        lineedit->setText(v);
+    }
 }
 
 void TimecodeDisplay::setValue(GenTime value)
index 4a4232ed7798d4180bd1616f88dfb4df30c6230f..dc1b8f8961607e688c7661c0db448290eee6f919 100644 (file)
@@ -57,7 +57,7 @@ public:
     void setRange(int min, int max);
 
     /** @brief Returns the current input in frames. */
-    int value() const;
+    int getValue() const;
 
     /** @brief Returns the current input as a GenTime object. */
     GenTime gentime() const;