Commit 0da92188 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Reindent code

parent 953eb351
......@@ -17,16 +17,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "bincontroller.h"
#include "clipcontroller.h"
#include "kdenlivesettings.h"
static const char* kPlaylistTrackId = "main bin";
static const char *kPlaylistTrackId = "main bin";
BinController::BinController(const QString &profileName) :
QObject()
QObject()
{
m_binPlaylist = Q_NULLPTR;
// Disable VDPAU that crashes in multithread environment.
......@@ -43,7 +41,7 @@ BinController::~BinController()
Mlt::Repository *BinController::mltRepository()
{
return m_repository;
return m_repository;
}
Mlt::Profile *BinController::profile()
......@@ -67,10 +65,11 @@ void BinController::destroyBin()
void BinController::setDocumentRoot(const QString &root)
{
if (root.isEmpty())
if (root.isEmpty()) {
m_documentRoot.clear();
else
} else {
m_documentRoot = root + QStringLiteral("/");
}
}
const QString BinController::documentRoot() const
......@@ -80,7 +79,9 @@ const QString BinController::documentRoot() const
void BinController::loadExtraProducer(const QString &id, Mlt::Producer *prod)
{
if (m_extraClipList.contains(id)) return;
if (m_extraClipList.contains(id)) {
return;
}
m_extraClipList.insert(id, prod);
}
......@@ -97,14 +98,13 @@ QStringList BinController::getProjectHashes()
return hashes;
}
void BinController::initializeBin(Mlt::Playlist playlist)
{
// Load folders
Mlt::Properties folderProperties;
Mlt::Properties playlistProps(playlist.get_properties());
folderProperties.pass_values(playlistProps, "kdenlive:folder.");
QMap <QString,QString> foldersData;
QMap <QString, QString> foldersData;
for (int i = 0; i < folderProperties.count(); i++) {
foldersData.insert(folderProperties.get_name(i), folderProperties.get(i));
}
......@@ -120,7 +120,9 @@ void BinController::initializeBin(Mlt::Playlist playlist)
int max = m_binPlaylist->count();
for (int i = 0; i < max; i++) {
Mlt::Producer *producer = m_binPlaylist->get_clip(i);
if (producer->is_blank() || !producer->is_valid()) continue;
if (producer->is_blank() || !producer->is_valid()) {
continue;
}
QString id = producer->parent().get("id");
if (id.contains(QStringLiteral("_"))) {
// This is a track producer
......@@ -128,31 +130,30 @@ void BinController::initializeBin(Mlt::Playlist playlist)
QString track = id.section(QStringLiteral("_"), 1, 1);
if (m_clipList.contains(mainId)) {
// The controller for this track producer already exists
}
else {
} else {
// Create empty controller for this track
ClipController *controller = new ClipController(this);
m_clipList.insert(mainId, controller);
}
delete producer;
}
else {
} else {
//Controller was already added by a track producer, add master now
if (m_clipList.contains(id)) {
ClipController *master = m_clipList.value(id);
if (master) master->addMasterProducer(producer->parent());
}
else {
if (master) {
master->addMasterProducer(producer->parent());
}
} else {
// Controller has not been created yet
ClipController *controller = new ClipController(this, producer->parent());
// fix MLT somehow adding root to color producer's resource (report upstream)
if (strcmp(producer->parent().get("mlt_service"), "color") == 0) {
QString color = producer->parent().get("resource");
if (color.contains(QStringLiteral("/"))) {
color = color.section(QStringLiteral("/"), -1, -1);
producer->parent().set("resource", color.toUtf8().constData());
}
}
// fix MLT somehow adding root to color producer's resource (report upstream)
if (strcmp(producer->parent().get("mlt_service"), "color") == 0) {
QString color = producer->parent().get("resource");
if (color.contains(QStringLiteral("/"))) {
color = color.section(QStringLiteral("/"), -1, -1);
producer->parent().set("resource", color.toUtf8().constData());
}
}
m_clipList.insert(id, controller);
}
}
......@@ -161,25 +162,27 @@ void BinController::initializeBin(Mlt::Playlist playlist)
// Load markers
Mlt::Properties markerProperties;
markerProperties.pass_values(playlistProps, "kdenlive:marker.");
QMap <QString,QString> markersData;
QMap <QString, QString> markersData;
for (int i = 0; i < markerProperties.count(); i++) {
QString markerId = markerProperties.get_name(i);
QString controllerId = markerId.section(QStringLiteral(":"), 0, 0);
ClipController *ctrl = m_clipList.value(controllerId);
if (!ctrl) continue;
if (!ctrl) {
continue;
}
ctrl->loadSnapMarker(markerId.section(QStringLiteral(":"), 1), markerProperties.get(i));
}
}
QMap<double,QString> BinController::takeGuidesData()
QMap<double, QString> BinController::takeGuidesData()
{
QLocale locale;
// Load guides
Mlt::Properties guidesProperties;
Mlt::Properties playlistProps(m_binPlaylist->get_properties());
guidesProperties.pass_values(playlistProps, "kdenlive:guide.");
qCDebug(KDENLIVE_LOG)<<"***********\nFOUND GUIDES: "<<guidesProperties.count()<<"\n**********";
QMap <double,QString> guidesData;
qCDebug(KDENLIVE_LOG) << "***********\nFOUND GUIDES: " << guidesProperties.count() << "\n**********";
QMap <double, QString> guidesData;
for (int i = 0; i < guidesProperties.count(); i++) {
double time = locale.toDouble(guidesProperties.get_name(i));
guidesData.insert(time, guidesProperties.get(i));
......@@ -192,7 +195,9 @@ QMap<double,QString> BinController::takeGuidesData()
void BinController::createIfNeeded(Mlt::Profile *profile)
{
if (m_binPlaylist) return;
if (m_binPlaylist) {
return;
}
m_binPlaylist = new Mlt::Playlist(*profile);
m_binPlaylist->set("id", kPlaylistTrackId);
}
......@@ -208,8 +213,7 @@ void BinController::slotStoreFolder(const QString &folderId, const QString &pare
if (folderName.isEmpty()) {
// Remove this folder info
m_binPlaylist->set(propertyName.toUtf8().constData(), (char *) Q_NULLPTR);
}
else {
} else {
m_binPlaylist->set(propertyName.toUtf8().constData(), folderName.toUtf8().constData());
}
}
......@@ -220,8 +224,7 @@ void BinController::storeMarker(const QString &markerId, const QString &markerHa
if (markerHash.isEmpty()) {
// Remove this marker
m_binPlaylist->set(propertyName.toUtf8().constData(), (char *) Q_NULLPTR);
}
else {
} else {
m_binPlaylist->set(propertyName.toUtf8().constData(), markerHash.toUtf8().constData());
}
}
......@@ -245,7 +248,7 @@ void BinController::replaceProducer(const QString &id, Mlt::Producer &producer)
{
ClipController *ctrl = m_clipList.value(id);
if (!ctrl) {
qCDebug(KDENLIVE_LOG)<<" / // error controller not found, crashing";
qCDebug(KDENLIVE_LOG) << " / // error controller not found, crashing";
return;
}
pasteEffects(id, producer);
......@@ -279,8 +282,9 @@ void BinController::addClipToBin(const QString &id, ClipController *controller)
c2->updateProducer(id, &controller->originalProducer());
controller->originalProducer().set("id", id.toUtf8().constData());*/
//removeBinClip(id);
} else {
m_clipList.insert(id, controller);
}
else m_clipList.insert(id, controller);
}
void BinController::replaceBinPlaylistClip(const QString &id, Mlt::Producer &producer)
......@@ -296,7 +300,7 @@ void BinController::pasteEffects(const QString &id, Mlt::Producer &producer)
QScopedPointer<Mlt::Producer> prod(m_binPlaylist->get_clip(i));
QString prodId = prod->parent().get("id");
if (prodId == id) {
duplicateFilters(prod->parent(), producer);
duplicateFilters(prod->parent(), producer);
break;
}
}
......@@ -320,17 +324,17 @@ bool BinController::hasClip(const QString &id)
return m_clipList.contains(id);
}
bool BinController::removeBinClip(const QString &id)
{
if (!m_clipList.contains(id)) return false;
if (!m_clipList.contains(id)) {
return false;
}
removeBinPlaylistClip(id);
ClipController *controller = m_clipList.take(id);
delete controller;
return true;
}
Mlt::Producer *BinController::cloneProducer(Mlt::Producer &original)
{
QString xml = getProducerXML(original);
......@@ -341,12 +345,15 @@ Mlt::Producer *BinController::cloneProducer(Mlt::Producer &original)
Mlt::Producer *BinController::getBinProducer(const QString &id)
{
// TODO: framebuffer speed clips
if (!m_clipList.contains(id)) return Q_NULLPTR;
if (!m_clipList.contains(id)) {
return Q_NULLPTR;
}
ClipController *controller = m_clipList.value(id);
if (controller)
if (controller) {
return &controller->originalProducer();
else
} else {
return Q_NULLPTR;
}
}
Mlt::Producer *BinController::getBinVideoProducer(const QString &id)
......@@ -384,15 +391,18 @@ void BinController::duplicateFilters(Mlt::Producer original, Mlt::Producer clone
// Only duplicate Kdenlive filters
if (filter->is_valid()) {
QString effectId = filter->get("kdenlive_id");
if (effectId.isEmpty()) continue;
if (effectId.isEmpty()) {
continue;
}
// looks like there is no easy way to duplicate a filter,
// so we will create a new one and duplicate its properties
Mlt::Filter *dup = new Mlt::Filter(*original.profile(), filter->get("mlt_service"));
if (dup && dup->is_valid()) {
for (int i = 0; i < filter->count(); ++i) {
QString paramName = filter->get_name(i);
if (paramName.at(0) != '_')
if (paramName.at(0) != '_') {
dup->set(filter->get_name(i), filter->get(i));
}
}
dupService.attach(*dup);
}
......@@ -406,10 +416,12 @@ QStringList BinController::getClipIds() const
return m_clipList.keys();
}
QString BinController::xmlFromId(const QString & id)
QString BinController::xmlFromId(const QString &id)
{
ClipController *controller = m_clipList.value(id);
if (!controller) return Q_NULLPTR;
if (!controller) {
return Q_NULLPTR;
}
Mlt::Producer original = controller->originalProducer();
QString xml = getProducerXML(original);
QDomDocument mltData;
......@@ -425,20 +437,25 @@ QString BinController::getProducerXML(Mlt::Producer &producer, bool includeMeta)
{
Mlt::Consumer c(*producer.profile(), "xml", "string");
Mlt::Service s(producer.get_service());
if (!s.is_valid())
if (!s.is_valid()) {
return QLatin1String("");
}
int ignore = s.get_int("ignore_points");
if (ignore)
if (ignore) {
s.set("ignore_points", 0);
}
c.set("time_format", "frames");
if (!includeMeta) c.set("no_meta", 1);
if (!includeMeta) {
c.set("no_meta", 1);
}
c.set("store", "kdenlive");
c.set("no_root", 1);
c.set("root", "/");
c.connect(s);
c.start();
if (ignore)
if (ignore) {
s.set("ignore_points", ignore);
}
return QString::fromUtf8(c.get("string"));
}
......@@ -571,7 +588,7 @@ void BinController::saveDocumentProperties(const QMap<QString, QString> &props,
}
}
void BinController::saveProperty(const QString &name, const QString & value)
void BinController::saveProperty(const QString &name, const QString &value)
{
m_binPlaylist->set(name.toUtf8().constData(), value.toUtf8().constData());
}
......@@ -587,9 +604,11 @@ QMap<QString, QString> BinController::getProxies()
int size = m_binPlaylist->count();
for (int i = 0; i < size; i++) {
QScopedPointer<Mlt::Producer> prod(m_binPlaylist->get_clip(i));
if (!prod->is_valid() || prod->is_blank()) continue;
if (!prod->is_valid() || prod->is_blank()) {
continue;
}
QString proxy = prod->parent().get("kdenlive:proxy");
if (proxy.length() > 2) {
if (proxy.length() > 2) {
if (!proxy.startsWith(QLatin1Char('/'))) {
proxy.prepend(m_documentRoot);
}
......@@ -597,8 +616,8 @@ QMap<QString, QString> BinController::getProxies()
if (!sourceUrl.startsWith(QLatin1Char('/'))) {
sourceUrl.prepend(m_documentRoot);
}
proxies.insert(proxy, sourceUrl);
}
proxies.insert(proxy, sourceUrl);
}
}
return proxies;
}
......
......@@ -39,7 +39,7 @@ class Profile;
/**
* @class BinController
* @brief This is where MLT's project clips (the bin clips) are managed
*
*
* This is also where the Mlt::Factory is first initialized.
* The project profile, used to build the monitors renderers is stored here
*/
......@@ -51,80 +51,80 @@ class BinController : public QObject
public:
explicit BinController(const QString &profileName = QString());
virtual ~BinController();
/** @brief Returns the MLT profile used everywhere in the project. */
Mlt::Profile *profile();
/** @brief Returns the project's fps. */
double fps() const;
/** @brief Returns the project's dar. */
double dar() const;
/** @brief Returns the service for the Bin's playlist, used to make sure MLT will save it correctly in its XML. */
mlt_service service();
/** @brief Add a new clip producer to the project.
* @param id The clip's id
* @param producer The MLT producer for this clip
* */
void addClipToBin(const QString &id, ClipController *controller);
/** @brief Store a timeline producer in clip list for later re-use
* @param id The clip's id
* @param producer The MLT producer for this clip
* */
void loadExtraProducer(const QString &id, Mlt::Producer *prod);
/** @brief Returns the name MLT will use to store our bin's playlist */
static const QString binPlaylistId();
/** @brief Clear the bin's playlist */
void destroyBin();
/** @brief Initialize the bin's playlist from MLT's data
* @param playlist The MLT playlist containing our bin's clips
*/
void initializeBin(Mlt::Playlist playlist);
/** @brief If our bin's playlist does not exist, create a new one */
void createIfNeeded(Mlt::Profile *profile);
/** @brief Returns true if a clip with that id is in our bin's playlist
* @param id The clip's id as stored in DocClipBase
*/
/** @brief Returns true if a clip with that id is in our bin's playlist
* @param id The clip's id as stored in DocClipBase
*/
bool hasClip(const QString &id);
QStringList getClipIds() const;
/** @brief Delete a clip from the bin from its id.
/** @brief Delete a clip from the bin from its id.
* @param id The clip's id as stored in DocClipBase
* @return true on success, false on error
*/
bool removeBinClip(const QString &id);
/** @brief Get the MLT Producer for a given id.
@param id The clip id as stored in the DocClipBase class */
// TODO? Since MLT requires 1 different producer for each track to correctly handle audio mix,
// we should specify on which track the clip should be.
// TODO? Since MLT requires 1 different producer for each track to correctly handle audio mix,
// we should specify on which track the clip should be.
// @param track The track on which the producer will be put. Setting a value of -1 will return the master clip contained in the bin playlist
// @param clipState The state of the clip (if we need an audio only or video only producer).
// @param speed If the clip has a speed effect (framebuffer producer), we indicate the speed here
Mlt::Producer *getBinProducer(const QString &id);
/** @brief returns a video only (no audio) version of this producer */
Mlt::Producer *getBinVideoProducer(const QString &id);
/** @brief Returns the clip data as rendered by MLT's XML consumer, used to duplicate a clip
* @param producer The clip's original producer
*/
QString getProducerXML(Mlt::Producer &producer, bool includeMeta = false);
/** @brief Returns the clip data as rendered by MLT's XML consumer
* @param id The clip's original id
* @returns An XML element containing the clip xml
*/
QString xmlFromId(const QString & id);
QString xmlFromId(const QString &id);
int clipCount() const;
Mlt::Producer *cloneProducer(Mlt::Producer &original);
......@@ -136,7 +136,7 @@ public:
const QStringList getBinIdsByResource(const QUrl &url) const;
void replaceProducer(const QString &id, Mlt::Producer &producer);
void storeMarker(const QString &markerId, const QString &markerHash);
QMap<double,QString> takeGuidesData();
QMap<double, QString> takeGuidesData();
/** @brief A Bin clip effect was changed, update track producers */
void updateTrackProducer(const QString &id);
......@@ -154,7 +154,7 @@ public:
void saveDocumentProperties(const QMap<QString, QString> &props, const QMap<QString, QString> &metadata, const QMap<double, QString> &guidesData);
/** @brief Save a property to main bin */
void saveProperty(const QString &name, const QString & value);
void saveProperty(const QString &name, const QString &value);
/** @brief Save a property from the main bin */
const QString getProperty(const QString &name);
......@@ -177,12 +177,12 @@ public slots:
private:
/** @brief The MLT playlist holding our Producers */
Mlt::Playlist * m_binPlaylist;
Mlt::Playlist *m_binPlaylist;
/** @brief The current MLT profile's filename */
QString m_activeProfile;
/** @brief The MLT repository, useful for filter/producer requests */
/** @brief The MLT repository, useful for filter/producer requests */
Mlt::Repository *m_repository;
/** @brief Can be used to copy filters from a clip to another */
......@@ -200,14 +200,14 @@ private:
/** @brief Remove a clip from MLT's special bin playlist */
void removeBinPlaylistClip(const QString &id);
/** @brief Duplicate effects from stored producer */
/** @brief Duplicate effects from stored producer */
void pasteEffects(const QString &id, Mlt::Producer &producer);
signals:
void loadFolders(QMap<QString,QString>);
void loadThumb(QString,QImage,bool);
void createThumb(const QDomElement&,const QString&,int);
void requestAudioThumb(const QString&);
void loadFolders(QMap<QString, QString>);
void loadThumb(QString, QImage, bool);
void createThumb(const QDomElement &, const QString &, int);
void requestAudioThumb(const QString &);
void abortAudioThumbs();
void replaceTimelineProducer(const QString &id);
void setDocumentNotes(const QString &);
......
This diff is collapsed.
......@@ -8,7 +8,7 @@ modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
......@@ -44,7 +44,6 @@ class AudioStreamInfo;
* need to update or replace them
*/
class ClipController : public QObject
{
public:
......@@ -55,23 +54,23 @@ public:
*/
explicit ClipController(BinController *bincontroller, Mlt::Producer &producer, QObject *parent = Q_NULLPTR);
/**
* @brief Constructor used when opening a document and encountering a
* @brief Constructor used when opening a document and encountering a
* track producer before the master producer. The masterProducer MUST be set afterwards
* @param bincontroller reference to the bincontroller
*/
explicit ClipController(BinController *bincontroller);
virtual ~ClipController();
/** @brief Returns true if the master producer is valid */
bool isValid();
/** @brief Stores the file's creation time */
QDateTime date;
/** @brief Replaces the master producer and (TODO) the track producers with an updated producer, for example a proxy */
void updateProducer(const QString &id, Mlt::Producer *producer);
void getProducerXML(QDomDocument& document, bool includeMeta = false);
void getProducerXML(QDomDocument &document, bool includeMeta = false);
/** @brief Returns a clone of our master producer. Delete after use! */
Mlt::Producer *masterProducer();
......@@ -99,16 +98,16 @@ public:
* @param value the new value
*/
void setProperty(const QString &name, const QString &value);
void setProperty(const QString& name, int value);
void setProperty(const QString& name, double value);
void resetProperty(const QString& name);
void setProperty(const QString &name, int value);
void setProperty(const QString &name, double value);
void resetProperty(const QString &name);
/**
* @brief Returns the list of all properties starting with prefix. For subclips, the list is of this type:
* { subclip name , subclip in/out } where the subclip in/ou value is a semi-colon separated in/out value, like "25;220"
*/
QMap<QString, QString> getPropertiesFromPrefix(const QString &prefix, bool withPrefix = false);
/**
* @brief Returns the value of a property.
* @param name name o the property
......@@ -137,27 +136,27 @@ public:
/** @brief Returns the MLT producer's service. */
QString serviceName() const;
/** @brief Returns the original master producer. */
Mlt::Producer &originalProducer();
/** @brief Returns the current profile's display aspect ratio. */
double dar() const;
/** @brief Holds index of currently selected master clip effect. */
int selectedEffectIndex;
/** @brief Get a clone of master producer for a specific track. Retrieve it if it already exists
* in our list, otherwise we create it.
* in our list, otherwise we create it.
* Deprecated, track logic should be handled in timeline/track.cpp */
Q_DECL_DEPRECATED Mlt::Producer *getTrackProducer(const QString & trackName, PlaylistState::ClipState clipState = PlaylistState::Original, double speed = 1.0);
Q_DECL_DEPRECATED Mlt::Producer *getTrackProducer(const QString &trackName, PlaylistState::ClipState clipState = PlaylistState::Original, double speed = 1.0);
/** @brief Sets the master producer for this clip when we build the controller without master clip. */
void addMasterProducer(Mlt::Producer &producer);
QList < CommentedTime > commentedSnapMarkers() const;
GenTime findNextSnapMarker(const GenTime & currTime);
GenTime findPreviousSnapMarker(const GenTime & currTime);
QString deleteSnapMarker(const GenTime & time);