From b37d59473f5b30c22df7720f0cf192c383b3be07 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 19 Jul 2009 18:54:53 +0000 Subject: [PATCH] Allow effects to have parameters depending on the project's profile properties (width, height) svn path=/trunk/kdenlive/; revision=3735 --- src/clipitem.cpp | 29 +++++++++++++++++++++++------ src/customtrackscene.cpp | 5 +++++ src/customtrackscene.h | 2 ++ src/effectstackedit.cpp | 15 +++++++++++++-- src/mainwindow.cpp | 7 +++++++ src/profilesdialog.cpp | 14 ++++++++++++++ src/profilesdialog.h | 1 + src/trackview.cpp | 35 +++++++++++++++++++++++++---------- 8 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 9a92cbd3..75c5ca22 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -26,6 +26,7 @@ #include "transition.h" #include "kdenlivesettings.h" #include "kthumb.h" +#include "profilesdialog.h" #include #include @@ -170,6 +171,16 @@ void ClipItem::initEffect(QDomElement effect) for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); kDebug() << "// init eff: " << e.attribute("name"); + + // Check if this effect has a variable parameter + if (e.attribute("default").startsWith('%')) { + double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default")); + e.setAttribute("default", evaluatedValue); + if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) { + e.setAttribute("value", evaluatedValue); + } + } + if (!e.isNull() && e.attribute("type") == "keyframe") { QString def = e.attribute("default"); // Effect has a keyframe type parameter, we need to set the values @@ -1275,7 +1286,7 @@ void ClipItem::setEffectAt(int ix, QDomElement effect) kDebug() << "Invalid effect index: " << ix; return; } - kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag"); + //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag"); effect.setAttribute("kdenlive_ix", ix + 1); m_effectList.insert(ix, effect); m_effectList.removeAt(ix + 1); @@ -1327,9 +1338,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) parameters.addParam("endtag", e.attribute("endtag", "end")); } - double f = e.attribute("factor", "1").toDouble(); - - if (f == 1) { + if (e.attribute("factor", "1") == "1") { parameters.addParam(e.attribute("name"), e.attribute("value")); // check if it is a fade effect @@ -1375,7 +1384,11 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) } } } else { - parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f)); + double fact; + if (e.attribute("factor").startsWith('%')) { + fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor")); + } else fact = e.attribute("factor", "1").toDouble(); + parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact)); } } } @@ -1435,7 +1448,11 @@ EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) parameters.addParam("start", neu); } else { if (e.attribute("factor", "1") != "1") { - parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble())); + double fact; + if (e.attribute("factor").startsWith('%')) { + fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor")); + } else fact = e.attribute("factor", "1").toDouble(); + parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact)); } else { parameters.addParam(e.attribute("name"), e.attribute("value")); } diff --git a/src/customtrackscene.cpp b/src/customtrackscene.cpp index 7a3209e4..eaacb63a 100644 --- a/src/customtrackscene.cpp +++ b/src/customtrackscene.cpp @@ -92,4 +92,9 @@ int CustomTrackScene::tracksCount() const return m_document->tracksCount(); } +MltVideoProfile CustomTrackScene::profile() const +{ + return m_document->mltProfile(); +} + #include "customtrackscene.moc" diff --git a/src/customtrackscene.h b/src/customtrackscene.h index eb22ec90..32224b20 100644 --- a/src/customtrackscene.h +++ b/src/customtrackscene.h @@ -28,6 +28,7 @@ #include "gentime.h" class KdenliveDoc; +class MltVideoProfile; /** This class holds all properties that need to be used by clip items */ @@ -46,6 +47,7 @@ public: QPointF scale() const; int tracksCount() const; QPixmap m_transitionPixmap; + MltVideoProfile profile() const; private: KdenliveDoc *m_document; diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 6edc6145..d8db6610 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -28,6 +28,7 @@ #include "keyframeedit.h" #include "effectslist.h" #include "kdenlivesettings.h" +#include "profilesdialog.h" #include #include @@ -158,6 +159,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out) QWidget * toFillin = new QWidget; QString value = pa.attribute("value").isNull() ? pa.attribute("default") : pa.attribute("value"); + if (type == "geometry") { /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency"); pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d"); @@ -171,7 +173,17 @@ void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out) //TODO constant, list, bool, complex , color, geometry, position if (type == "double" || type == "constant") { - createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt()); + int min; + int max; + if (pa.attribute("min").startsWith('%')) { + min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min")); + } + else min = pa.attribute("min").toInt(); + if (pa.attribute("max").startsWith('%')) { + max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max")); + } + else max = pa.attribute("max").toInt(); + createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max); delete toFillin; toFillin = NULL; } else if (type == "list") { @@ -501,7 +513,6 @@ void EffectStackEdit::createSliderItem(const QString& name, int val , int min, i QWidget* toFillin = new QWidget; Constval *ctval = new Constval; ctval->setupUi(toFillin); - ctval->horizontalSlider->setMinimum(min); ctval->horizontalSlider->setMaximum(max); ctval->spinBox->setMinimum(min); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8f940fff..106851e4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1612,11 +1612,18 @@ void MainWindow::slotEditProjectSettings() if (m_activeDocument->profilePath() != profile) { // Profile was changed double dar = m_activeDocument->dar(); + + // Deselect current effect / transition + m_effectStack->slotClipItemSelected(NULL, 0); + m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false); + m_activeDocument->setProfilePath(profile); KdenliveSettings::setCurrent_profile(profile); KdenliveSettings::setProject_fps(m_activeDocument->fps()); setCaption(m_activeDocument->description(), m_activeDocument->isModified()); m_monitorManager->resetProfiles(m_activeDocument->timecode()); + m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeTimeline->tracksNumber()); + m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode()); if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile()); m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description()); m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList()); diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index d86ee605..fc2a6421 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -228,6 +228,20 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) return result; } +// static +double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval) +{ + double result; + eval.replace("%width", QString::number(profile.width)); + eval.replace("%height", QString::number(profile.height)); + if (eval.contains('/')) result = (double) eval.section('/', 0, 0).toInt() / eval.section('/', 1, 1).toInt(); + else if (eval.contains('*')) result = (double) eval.section('*', 0, 0).toInt() * eval.section('*', 1, 1).toInt(); + else if (eval.contains('+')) result = (double) eval.section('+', 0, 0).toInt() + eval.section('+', 1, 1).toInt(); + else if (eval.contains('-')) result = (double) eval.section('-', 0, 0).toInt() - eval.section('-', 1, 1).toInt(); + else result = eval.toDouble(); + return result; +} + // static bool ProfilesDialog::existingProfileDescription(const QString &desc) diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 9f5e78f6..1bac83d3 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -41,6 +41,7 @@ public: static void saveProfile(MltVideoProfile &profile); static QString existingProfile(MltVideoProfile profile); static bool existingProfileDescription(const QString &desc); + static double getStringEval(const MltVideoProfile &profile, QString eval); protected: virtual void closeEvent(QCloseEvent *event); diff --git a/src/trackview.cpp b/src/trackview.cpp index a78c7bf1..d8a45938 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -30,6 +30,7 @@ #include "mainwindow.h" #include "customtrackview.h" #include "initeffects.h" +#include "profilesdialog.h" #include #include @@ -323,9 +324,14 @@ void TrackView::parseDocument(QDomDocument doc) QDomElement e = params.item(i).toElement(); if (!e.isNull() && e.attribute("tag") == paramName) { if (e.attribute("type") == "double") { - QString factor = e.attribute("factor", "1"); + QString factor = e.attribute("factor", "1"); if (factor != "1") { - double val = paramValue.toDouble() * factor.toDouble(); + double fact; + if (factor.startsWith('%')) { + fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); + } + else fact = factor.toDouble(); + double val = paramValue.toDouble() * fact; paramValue = QString::number(val); } } @@ -597,7 +603,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) { //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *"; // effect is key-framable, read all effects to retrieve keyframes - double factor = 0; + QString factor; QString starttag; QString endtag; QDomNodeList params = currenteffect.elementsByTagName("parameter"); @@ -606,7 +612,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) if (e.attribute("type") == "keyframe") { starttag = e.attribute("starttag", "start"); endtag = e.attribute("endtag", "end"); - factor = e.attribute("factor", "1").toDouble(); + factor = e.attribute("factor", "1"); break; } } @@ -615,13 +621,18 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) int effectout = effect.attribute("out").toInt(); double startvalue = 0; double endvalue = 0; + double fact; + if (factor.isEmpty()) fact = 1; + else if (factor.startsWith('%')) { + fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); + } else fact = factor.toDouble(); for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) { // parse effect parameters QDomElement effectparam = n3.toElement(); if (effectparam.attribute("name") == starttag) - startvalue = effectparam.text().toDouble() * factor; + startvalue = effectparam.text().toDouble() * fact; if (effectparam.attribute("name") == endtag) - endvalue = effectparam.text().toDouble() * factor; + endvalue = effectparam.text().toDouble() * fact; } // add first keyframe keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';'); @@ -644,7 +655,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) continueParsing = false; break; } else if (subeffectparam.attribute("name") == endtag) { - endvalue = subeffectparam.text().toDouble() * factor; + endvalue = subeffectparam.text().toDouble() * fact; break; } } @@ -685,9 +696,13 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) for (int k = 0; k < clipeffectparams.count(); k++) { e = clipeffectparams.item(k).toElement(); if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) { - double factor = e.attribute("factor", "1").toDouble(); - if (factor != 1) { - e.setAttribute("value", paramvalue.toDouble() * factor); + if (e.attribute("factor", "1") != "1") { + QString factor = e.attribute("factor", "1"); + double fact; + if (factor.startsWith('%')) { + fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); + } else fact = factor.toDouble(); + e.setAttribute("value", paramvalue.toDouble() * fact); } else e.setAttribute("value", paramvalue); break; } -- 2.39.2