]> git.sesse.net Git - kdenlive/blob - plugins/sampleplugin/sampleplugin.cpp
Add new clip generator: noise
[kdenlive] / plugins / sampleplugin / sampleplugin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include <QtGui>
22 #include <QDialog>
23 #include <QDomDocument>
24 #include <QInputDialog>
25
26 #include <KUrlRequester>
27 #include <KIntSpinBox>
28 #include <KDebug>
29 #include <KMessageBox>
30
31 #include "sampleplugin.h"
32 #include "ui_countdown_ui.h"
33
34 QStringList SamplePlugin::generators() const {
35     return QStringList() << i18n("Countdown") << i18n("Noise");
36 }
37
38
39 KUrl SamplePlugin::generatedClip(const QString &generator, const KUrl &projectFolder, const QStringList &lumaNames, const QStringList &lumaFiles, const double fps, const int width, const int height) {
40     QString prePath;
41     if (generator == i18n("Noise")) {
42         prePath = projectFolder.path() + "/noise";
43     } else prePath = projectFolder.path() + "/counter";
44     int ct = 0;
45     QString counter = QString::number(ct).rightJustified(5, '0', false);
46     while (QFile::exists(prePath + counter + ".westley")) {
47         ct++;
48         counter = QString::number(ct).rightJustified(5, '0', false);
49     }
50     QDialog d;
51     if (generator == i18n("Noise")) d.setWindowTitle(tr("Create Noise Clip"));
52     else d.setWindowTitle(tr("Create Countdown Clip"));
53     Ui::CountDown_UI view;
54     view.setupUi(&d);
55     QString clipFile = prePath + counter + ".westley";
56     view.path->setPath(clipFile);
57     if (d.exec() == QDialog::Accepted) {
58         QDomDocument doc;
59         QDomElement westley = doc.createElement("westley");
60         QDomElement playlist = doc.createElement("playlist");
61         if (generator == i18n("Noise")) {
62             QDomElement prod = doc.createElement("producer");
63             prod.setAttribute("mlt_service", "noise");
64             prod.setAttribute("in", "0");
65             prod.setAttribute("out", QString::number((int) fps * view.duration->value()));
66             playlist.appendChild(prod);
67         } else {
68             for (int i = 0; i < view.duration->value(); i++) {
69                 // Create the producers
70                 QDomElement prod = doc.createElement("producer");
71                 prod.setAttribute("mlt_service", "pango");
72                 prod.setAttribute("in", "0");
73                 prod.setAttribute("out", QString::number((int) fps));
74                 prod.setAttribute("markup", QString::number(view.duration->value() - i));
75                 playlist.appendChild(prod);
76             }
77         }
78         westley.appendChild(playlist);
79         doc.appendChild(westley);
80         QFile file(view.path->url().path());
81         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
82             kWarning() << "//////  ERROR writing to file: " << view.path->url().path();
83             KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
84             return KUrl();
85         }
86         QTextStream out(&file);
87         out << doc.toString();
88         file.close();
89         return view.path->url();
90     }
91     return KUrl();
92 }
93
94 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)