]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Fix a couple of compile warnings because of unused and uninitialized variables.
[kdenlive] / src / renderwidget.cpp
index 429ffd5cc69ffee4b0f968b65045682e981bda60..a654bc6038870e6f8ca979de5a7c07541110b661 100644 (file)
@@ -45,6 +45,7 @@
 #include <QDBusConnectionInterface>
 #include <QDBusInterface>
 #include <QThread>
+#include <QScriptEngine>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -54,9 +55,8 @@ const int ParamsRole = GroupRole + 4;
 const int EditableRole = GroupRole + 5;
 const int MetaGroupRole = GroupRole + 6;
 const int ExtraRole = GroupRole + 7;
-const int TwoPassRole = GroupRole + 8;
-const int BitratesRole = GroupRole + 9;
-const int DefaultBitrateRole = GroupRole + 10;
+const int BitratesRole = GroupRole + 8;
+const int DefaultBitrateRole = GroupRole + 9;
 
 // Running job status
 const int WAITINGJOB = 0;
@@ -739,7 +739,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
         guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
         guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
-        render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
+        render_process_args << "in=" + QString::number((int) GenTime(guideStart).frames(fps)) << "out=" + QString::number((int) GenTime(guideEnd).frames(fps));
     }
 
     if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");
@@ -760,7 +760,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         width = m_profile.width;
         height = m_profile.height;
     }
-    renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
+
     //renderArgs.replace("%width", QString::number((int)(m_profile.height * m_profile.display_aspect_num / (double) m_profile.display_aspect_den + 0.5)));
     //renderArgs.replace("%height", QString::number((int)m_profile.height));
 
@@ -775,14 +775,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     renderArgs.append(QString(" threads=%1").arg(KdenliveSettings::encodethreads()));
     renderArgs.append(QString(" real_time=-%1").arg(KdenliveSettings::mltthreads()));
 
-    // 2 pass
-    if (m_view.checkTwoPass->isEnabled() && m_view.checkTwoPass->isChecked())
-        renderArgs.append(" pass=2");
-
-    // bitrate
-    if (m_view.comboBitrates->isEnabled())
-        renderArgs.replace("%bitrate", m_view.comboBitrates->currentText());
-
     // Check if the rendering profile is different from project profile,
     // in which case we need to use the producer_comsumer from MLT
     QString std = renderArgs;
@@ -802,13 +794,27 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     }
     bool resizeProfile = (subsize != currentSize);
     QStringList paramsList = renderArgs.split(" ", QString::SkipEmptyParts);
-    for (int i = 0; i < paramsList.count(); i++) {
-        if (paramsList.at(i).startsWith("mlt_profile=")) {
-            if (paramsList.at(i).section('=', 1) != m_profile.path) resizeProfile = true;
-            break;
+
+    QScriptEngine sEngine;
+    sEngine.globalObject().setProperty("bitrate", m_view.comboBitrates->currentText());
+    sEngine.globalObject().setProperty("dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
+    sEngine.globalObject().setProperty("passes", static_cast<int>(m_view.checkTwoPass->isChecked()) + 1);
+
+    for (int i = 0; i < paramsList.count(); ++i) {
+        QString paramName = paramsList.at(i).section('=', 0, 0);
+        QString paramValue = paramsList.at(i).section('=', 1, 1);
+        // If the profiles do not match we need to use the consumer tag
+        if (paramName == "mlt_profile=" && paramValue != m_profile.path) {
+            resizeProfile = true;
+        }
+        // evaluate expression
+        if (paramValue.startsWith('%')) {
+            paramValue = sEngine.evaluate(paramValue.remove(0, 1)).toString();
+            paramsList[i] = paramName + '=' + paramValue;
         }
+        sEngine.globalObject().setProperty(paramName.toUtf8().constData(), paramValue);
     }
-       
+
     if (resizeProfile)
         render_process_args << "consumer:" + (scriptExport ? "$SOURCE" : playlistPath);
     else
@@ -1065,11 +1071,6 @@ void RenderWidget::refreshView()
     KIcon brokenIcon("dialog-close");
     KIcon warningIcon("dialog-warning");
 
-    if (m_view.format_list->currentItem()->data(TwoPassRole).canConvert(QVariant::Bool))
-        m_view.checkTwoPass->setEnabled(m_view.format_list->currentItem()->data(TwoPassRole).toBool());
-    else
-        m_view.checkTwoPass->setEnabled(true);
-
     const QStringList formatsList = KdenliveSettings::supportedformats();
     const QStringList vcodecsList = KdenliveSettings::videocodecs();
     const QStringList acodecsList = KdenliveSettings::audiocodecs();
@@ -1254,6 +1255,8 @@ void RenderWidget::refreshParams()
         m_view.comboBitrates->setEnabled(false);
     }
 
+    m_view.checkTwoPass->setEnabled(params.contains("passes"));
+
     m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
     m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
 }
@@ -1457,7 +1460,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
     QString renderer;
     QString params;
     QString standard;
-    QString twoPass;
     QString bitrates, defaultBitrate;
     KIcon icon;
 
@@ -1483,7 +1485,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
         groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
         extension = documentElement.attribute("extension", QString());
         renderer = documentElement.attribute("renderer", QString());
-        twoPass = documentElement.attribute("twopass", "true");
         bool exists = false;
         for (int j = 0; j < m_renderCategory.count(); j++) {
             if (m_renderCategory.at(j)->text() == groupName && m_renderCategory.at(j)->data(MetaGroupRole) == metagroupId) {
@@ -1494,7 +1495,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
         if (!exists) {
             QListWidgetItem *itemcat = new QListWidgetItem(groupName); //, m_view.format_list);
             itemcat->setData(MetaGroupRole, metagroupId);
-            itemcat->setData(TwoPassRole, twoPass == "false" ? false : true);
             m_renderCategory.append(itemcat);
         }
 
@@ -1720,12 +1720,12 @@ void RenderWidget::parseScriptFiles()
         item->setData(1, Qt::UserRole, KUrl(target).path());
         item->setData(1, Qt::UserRole + 1, scriptpath.path());
     }
-    bool activate = false;
+//     bool activate = false;
     QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
     if (script) {
         m_view.scripts_list->setCurrentItem(script);
         script->setSelected(true);
-        activate = true;
+//         activate = true;
     }
 //    m_view.start_script->setEnabled(activate);
 //    m_view.delete_script->setEnabled(activate);