Fix LADSPA effects, should work now:

http://www.kdenlive.org:80/mantis/view.php?id=499

svn path=/branches/KDE4/; revision=2838
parent dc7c415e
......@@ -1126,6 +1126,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) {
EffectsParameterList parameters;
parameters.addParam("tag", effect.attribute("tag"));
parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
QString state = effect.attribute("disabled");
if (!state.isEmpty()) {
......@@ -1193,7 +1194,7 @@ EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) {
parameters.addParam("tag", effect.attribute("tag"));
parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
parameters.addParam("id", effect.attribute("id"));
if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
QString state = effect.attribute("disabled");
if (!state.isEmpty()) {
parameters.addParam("disabled", state);
......
......@@ -67,6 +67,7 @@
#include "changetrackcommand.h"
#include "movegroupcommand.h"
#include "ui_addtrack_ui.h"
#include "initeffects.h"
//TODO:
// disable animation if user asked it in KDE's global settings
......@@ -1007,6 +1008,11 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
if (itemList.at(i)->type() == AVWIDGET) {
ClipItem *item = (ClipItem *)itemList.at(i);
item->initEffect(effect);
if (effect.attribute("tag") == "ladspa") {
QString ladpsaFile = m_document->getLadspaFile();
initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
effect.setAttribute("src", ladpsaFile);
}
AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true);
m_commandStack->push(command);
}
......@@ -1024,6 +1030,10 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
if (clip) {
EffectsParameterList effectParams = clip->getEffectArgs(effect);
if (effect.attribute("tag") == "ladspa") {
// Update the ladspa affect file
initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
}
// check if we are trying to reset a keyframe effect
if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
clip->initEffect(effect);
......@@ -3286,4 +3296,22 @@ void CustomTrackView::autoTransition() {
m_document->renderer()->mltUpdateTransition(transition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), tr->startPos(), tr->endPos(), transition);
}
QStringList CustomTrackView::getLadspaParams(QDomElement effect) const {
QStringList result;
QDomNodeList params = effect.elementsByTagName("parameter");
for (int i = 0; i < params.count(); i++) {
QDomElement e = params.item(i).toElement();
if (!e.isNull() && e.attribute("type") == "constant") {
if (e.hasAttribute("factor")) {
double factor = e.attribute("factor").toDouble();
double value = e.attribute("value").toDouble();
value = value / factor;
result.append(QString::number(value));
} else result.append(e.attribute("value"));
}
}
return result;
}
#include "customtrackview.moc"
......@@ -106,6 +106,7 @@ public:
void changeTimelineTrack(int ix, TrackInfo trackinfo);
void saveThumbnails();
void autoTransition();
QStringList getLadspaParams(QDomElement effect) const;
public slots:
void setCursorPos(int pos, bool seek = true);
......
......@@ -417,7 +417,7 @@ void initEffects::ladspaEffectFile(const QString & fname, int ladspaId, QStringL
delete filterString;
}
QString jackString = "<?xml version=\"1.0\"?><!DOCTYPE jackrack SYSTEM \"http://purge.bash.sh/~rah/jack_rack_1.2.dtd\"><jackrack><channels>2</channels><samplerate>48000</samplerate><plugin><id>";
const QString jackString = "<?xml version=\"1.0\"?><!DOCTYPE jackrack SYSTEM \"http://purge.bash.sh/~rah/jack_rack_1.2.dtd\"><jackrack><channels>2</channels><samplerate>48000</samplerate><plugin><id>";
char* initEffects::ladspaDeclipEffectString(QStringList) {
......
......@@ -179,6 +179,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
// make sure that the necessary folders exist
KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
KStandardDirs::makeDir(m_projectFolder.path() + "/ladspa/");
m_scenelist = m_document.toString();
kDebug() << "KDEnnlive document, init timecode: " << m_fps;
......@@ -336,8 +337,10 @@ int KdenliveDoc::zoom() const {
bool KdenliveDoc::convertDocument(double version) {
kDebug() << "Opening a document with version " << version;
if (version == 0.81) return true;
// Opening a old Kdenlive document
if (version == 0.5 || version == 0.7) {
if (version == 0.5 || version == 0.7 || version > 0.81) {
kDebug() << "Unable to open document with version " << version;
// TODO: convert 0.7 (0.5?) files to the new document format.
return FALSE;
......@@ -901,6 +904,7 @@ void KdenliveDoc::setProjectFolder(KUrl url) {
void KdenliveDoc::moveProjectData(KUrl url) {
QList <DocClipBase*> list = m_clipManager->documentClipList();
//TODO: Also move ladspa effects files
for (int i = 0; i < list.count(); i++) {
DocClipBase *clip = list.at(i);
if (clip->clipType() == TEXT) {
......@@ -1078,7 +1082,7 @@ QDomDocument KdenliveDoc::generateSceneList() {
QDomElement prod = doc.createElement("producer");
}
QDomDocument KdenliveDoc::toXml() const {
QDomDocument KdenliveDoc::toXml() {
return m_document;
}
......@@ -1412,5 +1416,15 @@ void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
}
QString KdenliveDoc::getLadspaFile() const {
int ct = 0;
QString counter = QString::number(ct).rightJustified(5, '0', false);
while (QFile::exists(m_projectFolder.path() + "/ladspa/" + counter + ".ladspa")) {
ct++;
counter = QString::number(ct).rightJustified(5, '0', false);
}
return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
}
#include "kdenlivedoc.moc"
......@@ -58,7 +58,7 @@ Q_OBJECT public:
KAutoSaveFile *m_autosave;
void backupMltPlaylist();
Timecode timecode() const;
QDomDocument toXml() const;
QDomDocument toXml();
void setRenderer(Render *render);
QUndoStack *commandStack();
QString producerName(const QString &id);
......@@ -117,6 +117,7 @@ Q_OBJECT public:
void switchTrackAudio(int ix, bool hide);
void cachePixmap(const QString &fileId, const QPixmap &pix) const;
void setProjectFolder(KUrl url);
QString getLadspaFile() const;
private:
KUrl m_url;
......
......@@ -1711,7 +1711,10 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool do
if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
if (clipService.detach(*filter) == 0) success = true;
kDebug() << " / / / DLEETED EFFECT: " << ct;
} else ct++;
} else {
if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
ct++;
}
filter = clipService.filter(ct);
}
m_isBlocked = false;
......@@ -1834,7 +1837,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
for (int j = 0; j < params.count(); j++) {
effectArgs.append(' ' + params.at(j).value());
}
kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
//kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
char *value = decodedString(effectArgs.simplified());
filter->set("effect", value);
delete[] value;
......
......@@ -34,7 +34,7 @@
#include "kdenlivedoc.h"
#include "mainwindow.h"
#include "customtrackview.h"
#include "initeffects.h"
TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
: QWidget(parent), m_doc(doc), m_scale(1.0), m_projectTracks(0) {
......@@ -401,6 +401,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
QString effecttag;
QString effectid;
QString effectindex;
QString ladspaEffectFile;
// Get effect tag & index
for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
// parse effect parameters
......@@ -411,6 +412,15 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
effectid = effectparam.text();
} else if (effectparam.attribute("name") == "kdenlive_ix") {
effectindex = effectparam.text();
} else if (effectparam.attribute("name") == "src") {
ladspaEffectFile = effectparam.text();
if (!QFile::exists(ladspaEffectFile)) {
// If the ladspa effect file is missing, recreate it
kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
ladspaEffectFile = m_doc->getLadspaFile();
effectparam.firstChild().setNodeValue(ladspaEffectFile);
kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
}
}
}
//kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
......@@ -527,6 +537,15 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
}
}
}
if (effecttag == "ladspa") {
//QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
if (!QFile::exists(ladspaEffectFile)) {
// If the ladspa effect file is missing, recreate it
initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
}
currenteffect.setAttribute("src", ladspaEffectFile);
}
item->addEffect(currenteffect, false);
item->effectsCounter();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment