File indexing completed on 2024-04-21 04:51:12

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "definitions.h"
0009 #include "undohelper.hpp"
0010 #include <QString>
0011 #include <memory>
0012 #include <unordered_map>
0013 
0014 class ProjectItemModel;
0015 namespace Mlt {
0016 class Producer;
0017 }
0018 
0019 /** @brief This namespace provides convenience functions to create clips based on various parameters
0020  */
0021 namespace ClipCreator {
0022 /** @brief Create and inserts a color clip
0023    @param color : a string of the form "0xff0000ff" (solid red in RGBA)
0024    @param duration : duration expressed in number of frames
0025    @param name: name of the clip
0026    @param parentFolder: the binId of the containing folder
0027    @param model: a shared pointer to the bin item model
0028    @return the binId of the created clip
0029 */
0030 QString createColorClip(const QString &color, int duration, const QString &name, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model);
0031 
0032 /** @brief Create a title clip
0033    @param properties : title properties (xmldata, etc)
0034    @param duration : duration of the clip
0035    @param name: name of the clip
0036    @param parentFolder: the binId of the containing folder
0037    @param model: a shared pointer to the bin item model
0038 */
0039 QString createTitleClip(const std::unordered_map<QString, QString> &properties, int duration, const QString &name, const QString &parentFolder,
0040                         const std::shared_ptr<ProjectItemModel> &model);
0041 
0042 /** @brief Create a title template
0043    @param path : path to the template
0044    @param text : text of the template (optional)
0045    @param name: name of the clip
0046    @param parentFolder: the binId of the containing folder
0047    @param model: a shared pointer to the bin item model
0048    @return the binId of the created clip
0049 */
0050 QString createTitleTemplate(const QString &path, const QString &text, const QString &name, const QString &parentFolder,
0051                             const std::shared_ptr<ProjectItemModel> &model);
0052 
0053 /** @brief Create and inserts a playlist clip
0054    @param name: name of the clip
0055    @param parentFolder: the binId of the containing folder
0056    @param model: a shared pointer to the bin item model
0057    @return the binId of the created clip
0058 */
0059 QString createPlaylistClip(const QString &name, std::pair<int, int> tracks, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model);
0060 QString createPlaylistClip(const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, std::shared_ptr<Mlt::Producer> producer,
0061                            const QMap<QString, QString> mainProperties);
0062 QString createPlaylistClipWithUndo(const QString &name, std::pair<int, int> tracks, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model,
0063                                    Fun &undo, Fun &redo);
0064 
0065 /** @brief Create a slideshow clip
0066    @param path : path to the selected folder
0067    @param duration: this should be nbr of images * duration of one image
0068    @param name: name of the clip
0069    @param parentFolder: the binId of the containing folder
0070    @param properties: description of the slideshow
0071    @param model: a shared pointer to the bin item model
0072    @return the binId of the created clip
0073 */
0074 QString createSlideshowClip(const QString &path, int duration, const QString &name, const QString &parentFolder,
0075                             const std::unordered_map<QString, QString> &properties, const std::shared_ptr<ProjectItemModel> &model);
0076 /** @brief Reads a file from disk and create the corresponding clip
0077    @param path : path to the file
0078    @param parentFolder: the binId of the containing folder
0079    @param model: a shared pointer to the bin item model
0080    @return the binId of the created clip
0081 */
0082 QString createClipFromFile(
0083     const QString &path, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, Fun &undo, Fun &redo,
0084     const std::function<void(const QString &)> &readyCallBack = [](const QString &) {});
0085 bool createClipFromFile(const QString &path, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
0086 
0087 /** @brief Iterates recursively through the given url list and add the files it finds, recreating a folder structure
0088    @param list: the list of items (can be folders)
0089    @param checkRemovable: if true, it will check if files are on removable devices, and warn the user if so
0090    @param parentFolder: the binId of the containing folder
0091    @param model: a shared pointer to the bin item model
0092    @param undo
0093    @param redo
0094    @param topLevel
0095  */
0096 const QString createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model,
0097                                   Fun &undo, Fun &redo, bool topLevel = true);
0098 const QString createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
0099 
0100 /** @brief Create minimal xml description from an url
0101  */
0102 QDomDocument getXmlFromUrl(const QString &path);
0103 } // namespace ClipCreator