File indexing completed on 2024-04-14 04:46:35

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 "assets/abstractassetsrepository.hpp"
0009 #include "definitions.h"
0010 #include <memory>
0011 #include <mutex>
0012 #include <unordered_map>
0013 
0014 /** @class EffectsRepository
0015     @brief This class stores all the effects that can be added by the user.
0016     You can query any effect based on its name.
0017     Note that this class is a Singleton
0018  */
0019 class EffectsRepository : public AbstractAssetsRepository<AssetListType::AssetType>
0020 {
0021 
0022 public:
0023     /** @brief Returns the instance of the Singleton */
0024     static std::unique_ptr<EffectsRepository> &get();
0025 
0026     /** @brief returns a fresh instance of the given effect */
0027     std::unique_ptr<Mlt::Filter> getEffect(const QString &effectId) const;
0028     /** @brief returns true if an effect exists in MLT (bypasses the blacklist/metadata parsing) */
0029     bool hasInternalEffect(const QString &effectId) const;
0030     QPair<QString, QString> reloadCustom(const QString &path);
0031     QString getCustomPath(const QString &id);
0032 
0033     /** @brief Returns whether this belongs to main effects */
0034     bool isPreferred(const QString &effectId) const;
0035 
0036     /** @brief Check custom effects (older custom effects need an update to default and current values
0037      *  returns a list of effects that were incorrectly converted */
0038     QPair<QStringList, QStringList> fixDeprecatedEffects();
0039     /** @brief Returns true if this is an effect group */
0040     bool isGroup(const QString &assetId) const;
0041     void deleteEffect(const QString &id);
0042     /** @brief Returns true if effect is audio */
0043     bool isAudioEffect(const QString &assetId) const;
0044     /** @brief Returns true if effect is text */
0045     bool isTextEffect(const QString &assetId) const;
0046 
0047 protected:
0048     /** @brief Constructor is protected because class is a Singleton */
0049     EffectsRepository();
0050 
0051     /** @brief Retrieves the list of all available effects from Mlt */
0052     Mlt::Properties *retrieveListFromMlt() const override;
0053 
0054     /** @brief Retrieves additional info about effects from a custom XML file
0055        The resulting assets are stored in customAssets
0056     */
0057     void parseCustomAssetFile(const QString &file_name, std::unordered_map<QString, Info> &customAssets) const override;
0058 
0059     /** @brief Returns the path to the effects' blacklist*/
0060     QString assetBlackListPath() const override;
0061 
0062     /** @brief Returns the path to the effects' preferred list*/
0063     QString assetPreferredListPath() const override;
0064 
0065     QStringList assetDirs() const override;
0066 
0067     void parseType(Mlt::Properties *metadata, Info &res) override;
0068 
0069     /** @brief Returns the metadata associated with the given asset*/
0070     Mlt::Properties *getMetadata(const QString &assetId) const override;
0071 
0072     QPair<QString, QString> fixCustomAssetFile(const QString &path);
0073 
0074     static std::unique_ptr<EffectsRepository> instance;
0075 
0076     /** @brief flag to create the repository only once */
0077     static std::once_flag m_onceFlag;
0078 };