]> git.sesse.net Git - kdenlive/commitdiff
Clean up timecode handling, improves:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Aug 2009 20:26:58 +0000 (20:26 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Aug 2009 20:26:58 +0000 (20:26 +0000)
http://www.kdenlive.org/mantis/view.php?id=1080

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

16 files changed:
src/clipdurationdialog.cpp
src/clipproperties.cpp
src/customruler.cpp
src/customtrackview.cpp
src/docclipbase.cpp
src/dvdwizardchapters.cpp
src/kdenlivedoc.cpp
src/keyframeedit.cpp
src/markerdialog.cpp
src/monitor.cpp
src/positionedit.cpp
src/slideshowclip.cpp
src/spacerdialog.cpp
src/timecode.cpp
src/timecode.h
src/titlewidget.cpp

index 453c9945e1588c143630d4338425ddfc25f41e8b..884a03188e4bc31ce81aa783d8b312ec2bbb9c82 100644 (file)
@@ -50,9 +50,9 @@ ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWid
         m_view.crop_label->hide();
     }
 
-    m_view.clip_position->setText(tc.getTimecode(m_clip->startPos(), m_fps));
-    m_view.crop_position->setText(tc.getTimecode(m_clip->cropStart(), m_fps));
-    m_view.clip_duration->setText(tc.getTimecode(m_clip->cropDuration(), m_fps));
+    m_view.clip_position->setText(tc.getTimecode(m_clip->startPos()));
+    m_view.crop_position->setText(tc.getTimecode(m_clip->cropStart()));
+    m_view.clip_duration->setText(tc.getTimecode(m_clip->cropDuration()));
     connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotPosUp()));
     connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotPosDown()));
     connect(m_view.crop_up, SIGNAL(clicked()), this, SLOT(slotCropUp()));
@@ -77,108 +77,108 @@ void ClipDurationDialog::setMargins(GenTime min, GenTime max)
 
 void ClipDurationDialog::slotCheckStart()
 {
-    int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
-    int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.clip_position->text());
+    int dur = m_tc.getFrameCount(m_view.clip_duration->text());
     GenTime start(pos, m_fps);
     GenTime duration(dur, m_fps);
     if (m_min != GenTime() && start < m_min) {
-        m_view.clip_position->setText(m_tc.getTimecode(m_min, m_fps));
+        m_view.clip_position->setText(m_tc.getTimecode(m_min));
     } else if (m_max != GenTime() && start + duration > m_max) {
-        m_view.clip_position->setText(m_tc.getTimecode(m_max - duration, m_fps));
+        m_view.clip_position->setText(m_tc.getTimecode(m_max - duration));
     }
 }
 
 void ClipDurationDialog::slotCheckDuration()
 {
-    int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
-    int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.clip_position->text());
+    int dur = m_tc.getFrameCount(m_view.clip_duration->text());
     GenTime start(pos, m_fps);
     GenTime duration(dur, m_fps);
     GenTime maxDuration;
     if (m_clip->maxDuration() == GenTime()) maxDuration = m_max;
     else maxDuration = m_max == GenTime() ? start + m_clip->maxDuration() : qMin(m_max, start + m_clip->maxDuration());
     if (maxDuration != GenTime() && start + duration > maxDuration) {
-        m_view.clip_duration->setText(m_tc.getTimecode(maxDuration - start, m_fps));
+        m_view.clip_duration->setText(m_tc.getTimecode(maxDuration - start));
     }
 }
 
 void ClipDurationDialog::slotCheckCrop()
 {
-    int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
-    int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
+    int dur = m_tc.getFrameCount(m_view.clip_duration->text());
+    int crop = m_tc.getFrameCount(m_view.crop_position->text());
     GenTime duration(dur, m_fps);
     GenTime cropStart(crop, m_fps);
     GenTime maxDuration = m_clip->maxDuration();
     if (maxDuration != GenTime() && cropStart + duration > maxDuration) {
-        m_view.crop_position->setText(m_tc.getTimecode(maxDuration - duration, m_fps));
+        m_view.crop_position->setText(m_tc.getTimecode(maxDuration - duration));
     }
 }
 
 void ClipDurationDialog::slotPosUp()
 {
-    int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
+    int position = m_tc.getFrameCount(m_view.clip_position->text());
     //if (duration >= m_clip->duration().frames(m_fps)) return;
     position ++;
-    m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
+    m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps)));
 }
 
 void ClipDurationDialog::slotPosDown()
 {
-    int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
+    int position = m_tc.getFrameCount(m_view.clip_position->text());
     //if (duration >= m_clip->duration().frames(m_fps)) return;
     position --;
-    m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
+    m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps)));
 }
 
 void ClipDurationDialog::slotDurUp()
 {
-    int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
-    int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.clip_duration->text());
+    int crop = m_tc.getFrameCount(m_view.crop_position->text());
     if (m_clip->maxDuration() != GenTime() && duration + crop > m_clip->maxDuration().frames(m_fps)) return;
     duration ++;
-    m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 void ClipDurationDialog::slotDurDown()
 {
-    int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.clip_duration->text());
     if (duration <= 0) return;
     duration --;
-    m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 void ClipDurationDialog::slotCropUp()
 {
-    int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
-    int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int crop = m_tc.getFrameCount(m_view.crop_position->text());
+    int duration = m_tc.getFrameCount(m_view.clip_duration->text());
     if (m_clip->maxDuration() != GenTime() && duration + crop > m_clip->maxDuration().frames(m_fps)) return;
     crop ++;
-    m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
+    m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps)));
 }
 
 void ClipDurationDialog::slotCropDown()
 {
-    int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
+    int crop = m_tc.getFrameCount(m_view.crop_position->text());
     if (crop <= 0) return;
     crop --;
-    m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
+    m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps)));
 }
 
 GenTime ClipDurationDialog::startPos() const
 {
-    int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.clip_position->text());
     return GenTime(pos, m_fps);
 }
 
 GenTime ClipDurationDialog::cropStart() const
 {
-    int pos = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.crop_position->text());
     return GenTime(pos, m_fps);
 }
 
 GenTime ClipDurationDialog::duration() const
 {
-    int pos = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.clip_duration->text());
     return GenTime(pos, m_fps);
 }
 
index 6ff0060047109c705fd83fce457f1a3477f18634..a050aa76768d7c7d22eeba713fb3cbf029894ae6 100644 (file)
@@ -234,7 +234,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
 
     KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
     m_view.clip_filesize->setText(KIO::convertSize(f.size()));
-    m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
+    m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
 
@@ -283,7 +283,7 @@ void ClipProperties::slotFillMarkersList()
     m_view.markers_list->clear();
     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
     for (int count = 0; count < marks.count(); ++count) {
-        QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
+        QString time = m_tc.getTimecode(marks[count].time());
         QStringList itemtext;
         itemtext << time << marks[count].comment();
         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
@@ -381,7 +381,7 @@ QMap <QString, QString> ClipProperties::properties()
             m_clipNeedsRefresh = true;
             props["colour"] = "0x" + new_color.right(6) + "ff";
         }
-        int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+        int duration = m_tc.getFrameCount(m_view.clip_duration->text());
         if (duration != m_clip->duration().frames(m_fps)) {
             props["out"] = QString::number(duration);
         }
@@ -390,7 +390,7 @@ QMap <QString, QString> ClipProperties::properties()
             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
             m_clipNeedsRefresh = true;
         }
-        int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+        int duration = m_tc.getFrameCount(m_view.clip_duration->text());
         if (duration != m_clip->duration().frames(m_fps)) {
             props["out"] = QString::number(duration);
         }
@@ -427,7 +427,7 @@ QMap <QString, QString> ClipProperties::properties()
         if (m_view.slide_duration_format->currentIndex() == 1) {
             // we are in frames mode
             duration = m_view.slide_duration_frames->value();
-        } else duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
+        } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
         if (duration != old_props.value("ttl").toInt()) {
             m_clipNeedsRefresh = true;
             props["ttl"] = QString::number(duration);
@@ -442,7 +442,7 @@ QMap <QString, QString> ClipProperties::properties()
             if (m_view.slide_duration_format->currentIndex() == 1) {
                 // we are in frames mode
                 luma_duration = m_view.luma_duration_frames->value();
-            } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text(), m_fps);
+            } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
             if (luma_duration != old_props.value("luma_duration").toInt()) {
                 m_clipNeedsRefresh = true;
                 props["luma_duration"] = QString::number(luma_duration);
@@ -513,9 +513,9 @@ void ClipProperties::parseFolder()
 void ClipProperties::slotCheckMaxLength()
 {
     if (m_clip->maxDuration() == GenTime()) return;
-    int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.clip_duration->text());
     if (duration > m_clip->maxDuration().frames(m_fps)) {
-        m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration(), m_fps));
+        m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
     }
 }
 
@@ -524,8 +524,8 @@ void ClipProperties::slotUpdateDurationFormat(int ix)
     bool framesFormat = ix == 1;
     if (framesFormat) {
         // switching to frames count, update widget
-        m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text(), m_tc.fps()));
-        m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text(), m_tc.fps()));
+        m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
+        m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
         m_view.slide_duration->setHidden(true);
         m_view.luma_duration->setHidden(true);
         m_view.slide_duration_frames->setHidden(false);
index 60f34102124e0287b1daa2c974fc464d78df6603..fd9786e645a36dfd5fb1b26847ec52db8d201a41 100644 (file)
@@ -301,7 +301,6 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     offsetmin = offsetmin * m_textSpacing;
     for (f = offsetmin; f < offsetmax; f += m_textSpacing) {
         QString lab = m_timecode.getTimecodeFromFrames((int)(f / m_factor + 0.5));
-
         p.drawText(f - m_offset + 2, LABEL_SIZE, lab);
     }
 
index d3476517c1bbf9e333cb5b8a1204d0048add3e58..30247dbb7e3b9923a755077a9d1d054fbaeaa74e 100644 (file)
@@ -1033,11 +1033,11 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
             QDialog d(parentWidget());
             Ui::KeyFrameDialog_UI view;
             view.setupUi(&d);
-            view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
+            view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart()));
             view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
             view.kfr_value->setFocus();
             if (d.exec() == QDialog::Accepted) {
-                int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
+                int pos = m_document->timecode().getFrameCount(view.kfr_position->text());
                 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
                 ClipItem *item = (ClipItem *)m_dragItem;
                 QString previous = item->keyframes(item->selectedEffectIndex());
index ddea87e9104295e8d409a35fdbf5acdfcf17dac8..f22410f1d237f091fea6640e1f10407919507f5d 100644 (file)
@@ -258,7 +258,7 @@ QDomElement DocClipBase::toXML() const
         if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
     }
     doc.appendChild(clip);
-    //kDebug()<<"/// CLIP XML: "<<doc.toString();
+    //kDebug() << "/// CLIP XML: " << doc.toString();
     return doc.documentElement();
 }
 
index 4460ab818661f2760e564762f92df777cbb807e9..f35ffe7f0080775d584fa00d85c38c03e4f457c1 100644 (file)
@@ -37,7 +37,7 @@ DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
     // Build monitor for chapters
 
     if (m_isPal) m_tc.setFormat(25);
-    else m_tc.setFormat(30, true);
+    else m_tc.setFormat(30000.0/1001, true);
 
     m_manager = new MonitorManager(this);
     m_manager->resetProfiles(m_tc);
@@ -136,7 +136,7 @@ void DvdWizardChapters::setVobFiles(bool isPal, const QStringList movies, const
 {
     m_isPal = isPal;
     if (m_isPal) m_tc.setFormat(25);
-    else m_tc.setFormat(30, true);
+    else m_tc.setFormat(30000.0/1001, true);
     m_manager->resetProfiles(m_tc);
     m_monitor->resetProfile();
 
index c6fdf30bed88fa4f0ddcdae6b8c7576616877fbd..b109c9d72668ac1817315910a28e6bef7169dac2 100644 (file)
@@ -224,8 +224,8 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
 
     kDebug() << "Kdenlive document, init timecode: " << m_fps;
-    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
-    else m_timecode.setFormat((int)(m_fps + 0.5));
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(m_fps, true);
+    else m_timecode.setFormat(m_fps);
 
     //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
@@ -693,8 +693,8 @@ void 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 == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
-    else m_timecode.setFormat((int)(m_fps + 0.5));
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(m_fps, true);
+    else m_timecode.setFormat(m_fps);
 }
 
 double KdenliveDoc::dar()
@@ -759,7 +759,7 @@ void KdenliveDoc::updateClip(const QString &id)
 
 int KdenliveDoc::getFramePos(QString duration)
 {
-    return m_timecode.getFrameCount(duration, m_fps);
+    return m_timecode.getFrameCount(duration);
 }
 
 QString KdenliveDoc::producerName(const QString &id)
index 66604ae98f867e9b6f54f3e1501be76132dff978..9931381c8cfa8af293d05acacf81984818c6ab34 100644 (file)
@@ -86,14 +86,14 @@ void KeyframeEdit::slotAddKeyframe()
     QTreeWidgetItem *item = m_ui.keyframe_list->currentItem();
     if (item == NULL) return;
     int ix = m_ui.keyframe_list->indexOfTopLevelItem(item);
-    int pos1 = m_timecode.getFrameCount(item->text(0), m_timecode.fps());
+    int pos1 = m_timecode.getFrameCount(item->text(0));
     QTreeWidgetItem *below = m_ui.keyframe_list->topLevelItem(ix + 1);
     if (below == NULL) below = m_ui.keyframe_list->topLevelItem(ix - 1);
     if (below == NULL) {
         if (pos1 == 0) pos2 = m_max;
         else pos2 = 0;
     } else {
-        pos2 = m_timecode.getFrameCount(below->text(0), m_timecode.fps());
+        pos2 = m_timecode.getFrameCount(below->text(0));
     }
 
     int result = (pos1 + pos2) / 2;
@@ -113,7 +113,7 @@ void KeyframeEdit::slotGenerateParams(QTreeWidgetItem *item, int column)
     if (item) {
         if (column == 0) {
             QString val = item->text(0);
-            int pos = m_timecode.getFrameCount(val, m_timecode.fps());
+            int pos = m_timecode.getFrameCount(val);
             if (pos <= 0) {
                 pos = 0;
                 val = m_timecode.getTimecodeFromFrames(pos);
@@ -138,7 +138,7 @@ void KeyframeEdit::slotGenerateParams(QTreeWidgetItem *item, int column)
     QString keyframes;
     for (int i = 0; i < m_ui.keyframe_list->topLevelItemCount(); i++) {
         QTreeWidgetItem *item = m_ui.keyframe_list->topLevelItem(i);
-        keyframes.append(QString::number(m_timecode.getFrameCount(item->text(0), m_timecode.fps())) + ':' + item->text(1) + ';');
+        keyframes.append(QString::number(m_timecode.getFrameCount(item->text(0))) + ':' + item->text(1) + ';');
     }
     m_param.setAttribute("keyframes", keyframes);
     emit parameterChanged();
@@ -152,11 +152,11 @@ void KeyframeEdit::slotAdjustKeyframeInfo()
     int max = m_max;
     QTreeWidgetItem *above = m_ui.keyframe_list->itemAbove(item);
     QTreeWidgetItem *below = m_ui.keyframe_list->itemBelow(item);
-    if (above) min = m_timecode.getFrameCount(above->text(0), m_timecode.fps()) + 1;
-    if (below) max = m_timecode.getFrameCount(below->text(0), m_timecode.fps()) - 1;
+    if (above) min = m_timecode.getFrameCount(above->text(0)) + 1;
+    if (below) max = m_timecode.getFrameCount(below->text(0)) - 1;
     m_ui.keyframe_pos->blockSignals(true);
     m_ui.keyframe_pos->setRange(min, max);
-    m_ui.keyframe_pos->setValue(m_timecode.getFrameCount(item->text(0), m_timecode.fps()));
+    m_ui.keyframe_pos->setValue(m_timecode.getFrameCount(item->text(0)));
     m_ui.keyframe_pos->blockSignals(false);
 }
 
@@ -168,6 +168,6 @@ void KeyframeEdit::slotAdjustKeyframeValue(int value)
 
 void KeyframeEdit::slotSaveCurrentParam(QTreeWidgetItem *item, int column)
 {
-    if (item && column == 0) m_previousPos = m_timecode.getFrameCount(item->text(0), m_timecode.fps());
+    if (item && column == 0) m_previousPos = m_timecode.getFrameCount(item->text(0));
 }
 
index 7fd788439be7808e0b8e8f1ba32df06908c7e445..90969a47ca8a467263d60d2cafba21d1886287ce 100644 (file)
@@ -82,7 +82,7 @@ MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, cons
         connect(m_view.marker_position, SIGNAL(textChanged(const QString &)), this, SIGNAL(updateThumb()));
     } else m_view.clip_thumb->setHidden(true);
 
-    m_view.marker_position->setText(tc.getTimecode(t.time(), m_fps));
+    m_view.marker_position->setText(tc.getTimecode(t.time()));
 
     m_view.marker_comment->setText(t.comment());
     m_view.marker_comment->selectAll();
@@ -104,7 +104,7 @@ MarkerDialog::~MarkerDialog()
 void MarkerDialog::slotUpdateThumb()
 {
     m_previewTimer->stop();
-    int pos = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
+    int pos = m_tc.getFrameCount(m_view.marker_position->text());
     int width = 100.0 * m_dar;
     if (width % 2 == 1) width++;
     QPixmap p = KThumb::getFrame(m_producer, pos, width, 100);
@@ -114,23 +114,23 @@ void MarkerDialog::slotUpdateThumb()
 
 void MarkerDialog::slotTimeUp()
 {
-    int duration = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.marker_position->text());
     if (m_clip && duration >= m_clip->duration().frames(m_fps)) return;
     duration ++;
-    m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 void MarkerDialog::slotTimeDown()
 {
-    int duration = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.marker_position->text());
     if (duration <= 0) return;
     duration --;
-    m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 CommentedTime MarkerDialog::newMarker()
 {
-    return CommentedTime(GenTime(m_tc.getFrameCount(m_view.marker_position->text(), m_fps), m_fps), m_view.marker_comment->text());
+    return CommentedTime(GenTime(m_tc.getFrameCount(m_view.marker_position->text()), m_fps), m_view.marker_comment->text());
 }
 
 void MarkerDialog::wheelEvent(QWheelEvent * event)
index 85f52c5940b8e6d9399bb153bcad472488efde4d..ea0478e0731913124e64790c123ed4ff4491b0f4 100644 (file)
@@ -453,7 +453,7 @@ void Monitor::activateMonitor()
 void Monitor::setTimePos(const QString &pos)
 {
     if (m_frametimecode) {
-        int frames = m_monitorManager->timecode().getFrameCount(pos, m_monitorManager->timecode().fps());
+        int frames = m_monitorManager->timecode().getFrameCount(pos);
         m_timePos->setText(QString::number(frames));
     } else m_timePos->setText(pos);
     slotSeek();
@@ -463,7 +463,7 @@ void Monitor::slotSeek()
 {
     int frames;
     if (m_frametimecode) frames = m_timePos->text().toInt();
-    else frames = m_monitorManager->timecode().getFrameCount(m_timePos->text(), m_monitorManager->timecode().fps());
+    else frames = m_monitorManager->timecode().getFrameCount(m_timePos->text());
     slotSeek(frames);
 }
 
@@ -766,7 +766,7 @@ void Monitor::updateTimecodeFormat()
 {
     m_frametimecode = KdenliveSettings::frametimecode();
     if (m_frametimecode) {
-        int frames = m_monitorManager->timecode().getFrameCount(m_timePos->text(), m_monitorManager->timecode().fps());
+        int frames = m_monitorManager->timecode().getFrameCount(m_timePos->text());
         m_timePos->setInputMask("999999999");
         m_timePos->setText(QString::number(frames));
     } else {
index 88ccd6629f0720644b77fe5117c9a1a609f2dccb..02f6253695633cc9ecfc30dc546d344dab8233b3 100644 (file)
@@ -53,7 +53,7 @@ void PositionEdit::slotUpdateTimecode()
 void PositionEdit::slotUpdatePosition()
 {
     m_ui.horizontalSlider->blockSignals(true);
-    int pos = m_tc.getFrameCount(m_ui.krestrictedline->text(), KdenliveSettings::project_fps());
+    int pos = m_tc.getFrameCount(m_ui.krestrictedline->text());
     m_ui.horizontalSlider->setValue(pos);
     if (pos != m_ui.horizontalSlider->value()) {
         // Value out of range
index e0870cfa501b3590da54db75593cc0eea89cf2dd..6a674af2bf2b3af9ccc9809dac115251191d7e0a 100644 (file)
@@ -220,8 +220,8 @@ void SlideshowClip::slotUpdateDurationFormat(int ix)
     bool framesFormat = ix == 1;
     if (framesFormat) {
         // switching to frames count, update widget
-        m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text(), m_timecode.fps()));
-        m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text(), m_timecode.fps()));
+        m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
+        m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
     } else {
         // switching to timecode format
         m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
index c0756fc7d18386618ba0f2f00848bea32c3ae7f7..b9f20e78e76597c8e14e9a408022c6fd009708e8 100644 (file)
@@ -33,7 +33,7 @@ SpacerDialog::SpacerDialog(const GenTime duration, Timecode tc, int track, int t
     setFont(KGlobalSettings::toolBarFont());
     m_fps = m_tc.fps();
     m_view.setupUi(this);
-    m_view.space_duration->setText(tc.getTimecode(duration, m_fps));
+    m_view.space_duration->setText(tc.getTimecode(duration));
     QStringList tracks;
     tracks << i18n("All tracks");
     for (int i = 0; i < trackNumber - 1; i++) {
@@ -54,22 +54,22 @@ SpacerDialog::~SpacerDialog()
 
 void SpacerDialog::slotTimeUp()
 {
-    int duration = m_tc.getFrameCount(m_view.space_duration->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.space_duration->text());
     duration ++;
-    m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 void SpacerDialog::slotTimeDown()
 {
-    int duration = m_tc.getFrameCount(m_view.space_duration->text(), m_fps);
+    int duration = m_tc.getFrameCount(m_view.space_duration->text());
     if (duration <= 0) return;
     duration --;
-    m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
+    m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
 }
 
 GenTime SpacerDialog::selectedDuration()
 {
-    return GenTime(m_tc.getFrameCount(m_view.space_duration->text(), m_fps), m_fps);
+    return GenTime(m_tc.getFrameCount(m_view.space_duration->text()), m_fps);
 }
 
 void SpacerDialog::wheelEvent(QWheelEvent * event)
index 244079a0790c834e7fa874d31babcad447da8b27..28b75c91d3db436e5c91efe4c5e7d64be15482c3 100644 (file)
 #include <kdebug.h>
 #include <klocale.h>
 
-Timecode::Timecode(Formats format, int framesPerSecond, bool dropFrame) :
+Timecode::Timecode(Formats format, double framesPerSecond, bool dropFrame) :
         m_format(format),
         m_dropFrame(dropFrame),
-        m_displayedFramesPerSecond(framesPerSecond + 0.5)
+        m_displayedFramesPerSecond(framesPerSecond + 0.5),
+       m_realFps(framesPerSecond)
 {
 }
 
@@ -36,12 +37,12 @@ int Timecode::fps() const
 }
 
 
-int Timecode::getFrameCount(const QString duration, double fps) const
+int Timecode::getFrameCount(const QString duration) const
 {
     if (m_dropFrame) {
         // calculate how many frames need to be dropped every minute.
         int frames;
-        int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - fps)  + 0.5);
+        int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - m_realFps)  + 0.5);
 
         int perMinute = toDrop / 9;
         int tenthMinute = toDrop % 9;
@@ -65,20 +66,20 @@ int Timecode::getFrameCount(const QString duration, double fps) const
         frames += duration.section(':', 2, 2).toInt() * m_displayedFramesPerSecond + duration.section(':', 3, 3).toInt();
         return frames;
     }
-    return (int)((duration.section(':', 0, 0).toInt()*3600.0 + duration.section(':', 1, 1).toInt()*60.0 + duration.section(':', 2, 2).toInt()) * fps + duration.section(':', 3, 3).toInt());
+    return (int)((duration.section(':', 0, 0).toInt()*3600.0 + duration.section(':', 1, 1).toInt()*60.0 + duration.section(':', 2, 2).toInt()) * m_realFps + duration.section(':', 3, 3).toInt());
 }
 
-QString Timecode::getTimecode(const GenTime & time, double fps) const
+QString Timecode::getTimecode(const GenTime & time) const
 {
     switch (m_format) {
     case HH_MM_SS_FF:
-        return getTimecodeHH_MM_SS_FF(time, fps);
+        return getTimecodeHH_MM_SS_FF(time);
         break;
     case HH_MM_SS_HH:
         return getTimecodeHH_MM_SS_HH(time);
         break;
     case Frames:
-        return getTimecodeFrames(time, fps);
+        return getTimecodeFrames(time);
         break;
     case Seconds:
         return getTimecodeSeconds(time);
@@ -87,7 +88,7 @@ QString Timecode::getTimecode(const GenTime & time, double fps) const
         kWarning() <<
         "Unknown timecode format specified, defaulting to HH_MM_SS_FF"
         << endl;
-        return getTimecodeHH_MM_SS_FF(time, fps);
+        return getTimecodeHH_MM_SS_FF(time);
     }
 }
 
@@ -162,16 +163,19 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps)
 }
 
 
-QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const
+QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const
 {
     if (m_dropFrame)
-        return getTimecodeDropFrame(time, fps);
+        return getTimecodeDropFrame(time);
 
-    return getTimecodeHH_MM_SS_FF((int)(time.frames(fps) + 0.5));
+    return getTimecodeHH_MM_SS_FF((int) time.frames(m_realFps));
 }
 
 QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const
 {
+    if (m_dropFrame) {
+       return getTimecodeDropFrame(frames);
+    }
     int seconds = frames / m_displayedFramesPerSecond;
     frames = frames % m_displayedFramesPerSecond;
 
@@ -215,9 +219,9 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
     return text;
 }
 
-QString Timecode::getTimecodeFrames(const GenTime & time, double fps) const
+QString Timecode::getTimecodeFrames(const GenTime & time) const
 {
-    return QString::number(time.frames(fps));
+    return QString::number(time.frames(m_realFps));
 }
 
 QString Timecode::getTimecodeSeconds(const GenTime & time) const
@@ -225,15 +229,19 @@ QString Timecode::getTimecodeSeconds(const GenTime & time) const
     return QString::number(time.seconds());
 }
 
-QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const
+QString Timecode::getTimecodeDropFrame(const GenTime & time) const
+{
+    return getTimecodeDropFrame((int)time.frames(m_realFps));
+}
+
+QString Timecode::getTimecodeDropFrame(int frames) const
 {
     // Calculate the timecode using dropframes to remove the difference in fps. Note that this algorithm should work
     // for NTSC times, but is untested for any others - it is in no way an "official" algorithm, unless it's by fluke.
-    int frames = (int)time.frames(fps);
 
     // calculate how many frames need to be dropped every minute.
-    int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - fps)  + 0.5);
-
+    int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - m_realFps)  + 0.5);
+    
     int perMinute = toDrop / 9;
     int tenthMinute = toDrop % 9;
 
index e4b32548e275886573e9d7025000df5e70e20fe3..3d310eb6df7e37a1e67528d971bd1a30e010be66 100644 (file)
@@ -31,14 +31,15 @@ class Timecode
 public:
     enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds };
 
-    explicit Timecode(Formats format = HH_MM_SS_FF, int framesPerSecond =
+    explicit Timecode(Formats format = HH_MM_SS_FF, double framesPerSecond =
                           25, bool dropFrame = false);
 
     /** Set the current timecode format; this is the output format for this timecode. */
-    void setFormat(int framesPerSecond, bool dropFrame = false, Formats format = HH_MM_SS_FF) {
-        m_displayedFramesPerSecond = framesPerSecond;
+    void setFormat(double framesPerSecond, bool dropFrame = false, Formats format = HH_MM_SS_FF) {
+        m_displayedFramesPerSecond = (int) (framesPerSecond + 0.5);
         m_dropFrame = dropFrame;
         m_format = format;
+       m_realFps = framesPerSecond;
     }
 
     Formats format() const {
@@ -48,8 +49,8 @@ public:
     ~Timecode();
 
     /** Returns the timecode for a given time */
-    QString getTimecode(const GenTime & time, double fps) const;
-    int getFrameCount(const QString duration, double fps) const;
+    QString getTimecode(const GenTime & time) const;
+    int getFrameCount(const QString duration) const;
     static QString getEasyTimecode(const GenTime & time, const double &fps);
     static QString getStringTimecode(int frames, const double &fps);
     QString getTimecodeFromFrames(int frames) const;
@@ -59,13 +60,16 @@ private:
     Formats m_format;
     bool m_dropFrame;
     int m_displayedFramesPerSecond;
+    double m_realFps;
 
-    QString getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const;
+    QString getTimecodeHH_MM_SS_FF(const GenTime & time) const;
     QString getTimecodeHH_MM_SS_FF(int frames) const;
+    
     QString getTimecodeHH_MM_SS_HH(const GenTime & time) const;
-    QString getTimecodeFrames(const GenTime & time, double fps) const;
+    QString getTimecodeFrames(const GenTime & time) const;
     QString getTimecodeSeconds(const GenTime & time) const;
-    QString getTimecodeDropFrame(const GenTime & time, double fps) const;
+    QString getTimecodeDropFrame(const GenTime & time) const;
+    QString getTimecodeDropFrame(int frames) const;
 };
 
 #endif
index dec833f3b0fbb10eea2b9d624dce1db4868833b2..028f1a73cad946e9d9e1131e407064c8e31fbf33 100644 (file)
@@ -68,7 +68,7 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     showToolbars(TITLE_NONE);
 
     //TODO: get default title duration instead of hardcoded one
-    title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0), m_render->fps()));
+    title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
 
     connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
@@ -271,7 +271,7 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
         double out;
         m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
         adjustFrameSize();
-        title_duration->setText(m_tc.getTimecode(GenTime(out), m_render->fps()));
+        title_duration->setText(m_tc.getTimecode(GenTime(out)));
         slotSelectTool();
     } else {
         slotTextTool();
@@ -1316,7 +1316,7 @@ void TitleWidget::loadTitle()
         double out;
         m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
         adjustFrameSize();
-        title_duration->setText(m_tc.getTimecode(GenTime(out / 1000.0), m_render->fps()));
+        title_duration->setText(m_tc.getTimecode(GenTime(out / 1000.0)));
         insertingValues = true;
         startViewportX->setValue(m_startViewport->data(0).toInt());
         startViewportY->setValue(m_startViewport->data(1).toInt());
@@ -1334,7 +1334,7 @@ void TitleWidget::saveTitle(KUrl url)
 {
     if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Save Title"));
     if (!url.isEmpty()) {
-        if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, GenTime(m_tc.getFrameCount(title_duration->text(), m_render->fps()), m_render->fps()).ms()) == false)
+        if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, GenTime(m_tc.getFrameCount(title_duration->text()), m_render->fps()).ms()) == false)
             KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
     }
 }
@@ -1342,7 +1342,7 @@ void TitleWidget::saveTitle(KUrl url)
 QDomDocument TitleWidget::xml()
 {
     QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
-    doc.documentElement().setAttribute("out", GenTime(m_tc.getFrameCount(title_duration->text(), m_render->fps()), m_render->fps()).ms());
+    doc.documentElement().setAttribute("out", GenTime(m_tc.getFrameCount(title_duration->text())).ms());
     if (cropImage->isChecked()) {
         doc.documentElement().setAttribute("crop", 1);
     }
@@ -1351,7 +1351,7 @@ QDomDocument TitleWidget::xml()
 
 int TitleWidget::duration() const
 {
-    return GenTime(m_tc.getFrameCount(title_duration->text(), m_render->fps()), m_render->fps()).frames(m_render->fps());
+    return GenTime(m_tc.getFrameCount(title_duration->text())).frames(m_render->fps());
 }
 
 void TitleWidget::setXml(QDomDocument doc)
@@ -1359,12 +1359,12 @@ void TitleWidget::setXml(QDomDocument doc)
     double out;
     m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
     adjustFrameSize();
-    title_duration->setText(m_tc.getTimecode(GenTime(out / 1000.0), m_render->fps()));
+    title_duration->setText(m_tc.getTimecode(GenTime(out / 1000.0)));
     /*if (doc.documentElement().hasAttribute("out")) {
     GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
-    title_duration->setText(m_tc.getTimecode(duration, m_render->fps()));
+    title_duration->setText(m_tc.getTimecode(duration));
     }
-    else title_duration->setText(m_tc.getTimecode(GenTime(5000), m_render->fps()));*/
+    else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
 
     QDomElement e = doc.documentElement();
     cropImage->setChecked(e.hasAttribute("crop"));