From: Jean-Baptiste Mardelle Date: Sun, 8 Aug 2010 20:04:34 +0000 (+0000) Subject: Try to fix timecode error: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=405ebfa31dec2209eca7031b7ee781f5ca7be10d;p=kdenlive Try to fix timecode error: http://www.kdenlive.org/mantis/view.php?id=1730 svn path=/trunk/kdenlive/; revision=4688 --- diff --git a/src/dvdwizardchapters.cpp b/src/dvdwizardchapters.cpp index 2b4aa3bc..61055608 100644 --- a/src/dvdwizardchapters.cpp +++ b/src/dvdwizardchapters.cpp @@ -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"); diff --git a/src/geometryval.cpp b/src/geometryval.cpp index 981b537a..4c7e608e 100644 --- a/src/geometryval.cpp +++ b/src/geometryval.cpp @@ -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; } diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 80037d38..1e399f94 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -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); } diff --git a/src/markerdialog.cpp b/src/markerdialog.cpp index 0ee5657f..87e3f43a 100644 --- a/src/markerdialog.cpp +++ b/src/markerdialog.cpp @@ -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)); diff --git a/src/monitor.cpp b/src/monitor.cpp index a39e7911..89ebe859 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -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) diff --git a/src/positionedit.cpp b/src/positionedit.cpp index 7877f7e0..44d800f0 100644 --- a/src/positionedit.cpp +++ b/src/positionedit.cpp @@ -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(); } diff --git a/src/timecode.cpp b/src/timecode.cpp index 83ed7d77..8303c59c 100644 --- a/src/timecode.cpp +++ b/src/timecode.cpp @@ -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; diff --git a/src/timecode.h b/src/timecode.h index 764a58af..e1ae7cbf 100644 --- a/src/timecode.h +++ b/src/timecode.h @@ -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 diff --git a/src/timecodedisplay.cpp b/src/timecodedisplay.cpp index 8fce02ea..7916ebdd 100644 --- a/src/timecodedisplay.cpp +++ b/src/timecodedisplay.cpp @@ -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) diff --git a/src/timecodedisplay.h b/src/timecodedisplay.h index 4a4232ed..dc1b8f89 100644 --- a/src/timecodedisplay.h +++ b/src/timecodedisplay.h @@ -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;