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"
24 #include <KUrlRequester>
25 #include <KIntSpinBox>
27 #include <KMessageBox>
28 #include <KApplication>
31 #include <QDomDocument>
32 #include <QInputDialog>
35 QStringList SamplePlugin::generators(const QStringList &producers) const
38 if (producers.contains("pango")) result << i18n("Countdown");
39 if (producers.contains("noise")) result << i18n("Noise");
44 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)
47 if (generator == i18n("Noise")) {
48 prePath = projectFolder.path() + "/noise";
49 } else prePath = projectFolder.path() + "/counter";
51 QString counter = QString::number(ct).rightJustified(5, '0', false);
52 while (QFile::exists(prePath + counter + ".mlt")) {
54 counter = QString::number(ct).rightJustified(5, '0', false);
56 QPointer<QDialog> d = new QDialog;
57 Ui::CountDown_UI view;
59 if (generator == i18n("Noise")) {
60 d->setWindowTitle(i18n("Create Noise Clip"));
61 view.font_label->setHidden(true);
62 view.font->setHidden(true);
64 d->setWindowTitle(i18n("Create Countdown Clip"));
65 view.font->setValue(height);
68 // Set single file mode. Default seems to be File::ExistingOnly.
69 view.path->setMode(KFile::File);
71 QString clipFile = prePath + counter + ".mlt";
72 view.path->setUrl(KUrl(clipFile));
75 if (d->exec() == QDialog::Accepted) {
76 QProcess generatorProcess;
78 // Disable VDPAU so that rendering will work even if there is a Kdenlive instance using VDPAU
79 #if QT_VERSION >= 0x040600
80 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
81 env.insert("MLT_NO_VDPAU", "1");
82 generatorProcess.setProcessEnvironment(env);
84 QStringList env = QProcess::systemEnvironment();
85 env << "MLT_NO_VDPAU=1";
86 generatorProcess.setEnvironment(env);
89 if (generator == i18n("Noise")) {
90 args << "noise:" << "in=0" << QString("out=" + QString::number((int) fps * view.duration->value()));
94 for (int i = 0; i < view.duration->value(); i++) {
95 // Create the producers
96 args << "pango:" << "in=0" << QString("out=" + QString::number((int) fps * view.duration->value()));
97 args << QString("text=" + QString::number(view.duration->value() - i));
98 args << QString("font=" + QString::number(view.font->value()) + "px");
102 args << "-consumer"<<QString("xml:%1").arg(view.path->url().path());
103 generatorProcess.start(renderer, args);
104 if (generatorProcess.waitForFinished()) {
105 if (generatorProcess.exitStatus() == QProcess::CrashExit) {
106 kDebug() << "/// Generator failed: ";
107 QString error = generatorProcess.readAllStandardError();
108 KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
111 result = view.path->url();
114 kDebug() << "/// Generator failed: ";
115 QString error = generatorProcess.readAllStandardError();
116 KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
123 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)
125 #include "sampleplugin.moc"