1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "sampleplugin.h"
22 #include "ui_countdown_ui.h"
25 #include <KMessageBox>
26 #include <KApplication>
31 QStringList SamplePlugin::generators(const QStringList &producers) const
34 if (producers.contains(QLatin1String("pango"))) result << i18n("Countdown");
35 if (producers.contains(QLatin1String("noise"))) result << i18n("Noise");
40 KUrl SamplePlugin::generatedClip(const QString &renderer, const QString &generator, const KUrl &projectFolder, const QStringList &/*lumaNames*/, const QStringList &/*lumaFiles*/, const double fps, const int /*width*/, const int height)
43 if (generator == i18n("Noise")) {
44 prePath = projectFolder.path() + QLatin1String("/noise");
45 } else prePath = projectFolder.path() + QLatin1String("/counter");
47 QString counter = QString::number(ct).rightJustified(5, QLatin1Char('0'), false);
48 while (QFile::exists(prePath + counter + QLatin1String(".mlt"))) {
50 counter = QString::number(ct).rightJustified(5, QLatin1Char('0'), false);
52 QPointer<QDialog> d = new QDialog;
53 Ui::CountDown_UI view;
55 if (generator == i18n("Noise")) {
56 d->setWindowTitle(i18n("Create Noise Clip"));
57 view.font_label->setHidden(true);
58 view.font->setHidden(true);
60 d->setWindowTitle(i18n("Create Countdown Clip"));
61 view.font->setValue(height);
64 // Set single file mode. Default seems to be File::ExistingOnly.
65 view.path->setMode(KFile::File);
67 QString clipFile = prePath + counter + QLatin1String(".mlt");
68 view.path->setUrl(KUrl(clipFile));
71 if (d->exec() == QDialog::Accepted) {
72 QProcess generatorProcess;
74 // Disable VDPAU so that rendering will work even if there is a Kdenlive instance using VDPAU
75 #if QT_VERSION >= 0x040600
76 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
77 env.insert(QLatin1String("MLT_NO_VDPAU"), QLatin1String("1"));
78 generatorProcess.setProcessEnvironment(env);
80 QStringList env = QProcess::systemEnvironment();
81 env << QLatin1String("MLT_NO_VDPAU=1");
82 generatorProcess.setEnvironment(env);
85 if (generator == i18n("Noise")) {
86 args << QLatin1String("noise:") << QLatin1String("in=0") << QLatin1String("out=") + QString::number((int) fps * view.duration->value());
90 for (int i = 0; i < view.duration->value(); i++) {
91 // Create the producers
92 args << QLatin1String("pango:") << QLatin1String("in=0") << QLatin1String("out=") + QString::number((int) fps * view.duration->value());
93 args << QLatin1String("text=") + QString::number(view.duration->value() - i);
94 args << QLatin1String("font=") + QString::number(view.font->value()) + QLatin1String("px");
98 args << QLatin1String("-consumer")<<QString::fromLatin1("xml:%1").arg(view.path->url().path());
99 generatorProcess.start(renderer, args);
100 if (generatorProcess.waitForFinished()) {
101 if (generatorProcess.exitStatus() == QProcess::CrashExit) {
102 kDebug() << "/// Generator failed: ";
103 QString error = QString::fromLocal8Bit(generatorProcess.readAllStandardError());
104 KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
107 result = view.path->url();
110 kDebug() << "/// Generator failed: ";
111 QString error = QString::fromLocal8Bit(generatorProcess.readAllStandardError());
112 KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
119 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)
121 #include "sampleplugin.moc"