File indexing completed on 2024-04-14 04:47:02

0001 /*
0002     SPDX-FileCopyrightText: 2011 Simon Andreas Eugster <simon.eu@gmail.com>
0003     This file is part of kdenlive. See www.kdenlive.org.
0004 
0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include "audioscopes/abstractaudioscopewidget.h"
0011 #include "colorscopes/abstractgfxscopewidget.h"
0012 
0013 #include <QList>
0014 
0015 class QDockWidget;
0016 class AbstractMonitor;
0017 class QSignalMapper;
0018 
0019 /** @class ScopeManager
0020     @brief Manages communication between Scopes and Renderer.
0021   
0022     The scope manager handles the data transfer between the active Renderer and
0023     all scopes that have been registered via ScopeManager::addScope(AbstractAudioScopeWidget, QDockWidget)
0024     or ScopeManager::addScope(AbstractGfxScopeWidget, QDockWidget). It checks whether the renderer really
0025     needs to send data (it does not, for example, if no scopes are visible).
0026   */
0027 class ScopeManager : public QObject
0028 {
0029     Q_OBJECT
0030 
0031     struct GfxScopeData
0032     {
0033         AbstractGfxScopeWidget *scope;
0034         bool singleFrameRequested;
0035         GfxScopeData()
0036         {
0037             scope = nullptr;
0038             singleFrameRequested = false;
0039         }
0040     };
0041 
0042     struct AudioScopeData
0043     {
0044         AbstractAudioScopeWidget *scope;
0045         bool singleFrameRequested;
0046         AudioScopeData()
0047         {
0048             scope = nullptr;
0049             singleFrameRequested = false;
0050         }
0051     };
0052 
0053 public:
0054     explicit ScopeManager(QObject *parent = nullptr);
0055 
0056     /**
0057       Adds a scope and sets up signal/slot connections to ensure that the scope
0058       receives data when required.
0059       \see addScope(AbstractGfxScopeWidget, QDockWidget)
0060       */
0061     bool addScope(AbstractAudioScopeWidget *audioScope, QDockWidget *audioScopeWidget = nullptr);
0062     /**
0063       \see addScope(AbstractAudioScopeWidget, QDockWidget)
0064       */
0065     bool addScope(AbstractGfxScopeWidget *colorScope, QDockWidget *colorScopeWidget = nullptr);
0066 
0067 private:
0068     QList<AudioScopeData> m_audioScopes;
0069     QList<GfxScopeData> m_colorScopes;
0070 
0071     AbstractMonitor *m_lastConnectedRenderer{nullptr};
0072 
0073     QSignalMapper *m_signalMapper;
0074 
0075     /**
0076       Checks whether there is any scope accepting audio data, or if all of them are hidden
0077       or if auto refresh is disabled.
0078       \see imagesAcceptedByScopes(): Same for image data
0079       */
0080     bool audioAcceptedByScopes() const;
0081     /**
0082       \see audioAcceptedByScopes()
0083       */
0084     bool imagesAcceptedByScopes() const;
0085 
0086     /**
0087       Creates all the scopes in audioscopes/ and colorscopes/.
0088       New scopes are not detected automatically but have to be added.
0089      */
0090     void createScopes();
0091 
0092     /**
0093       Creates a dock for @param scopeWidget with the title @param title and
0094       adds it to the manager.
0095       @param scopeWidget has to be of type AbstractAudioScopeWidget or AbstractGfxScopeWidget (@see addScope).
0096      */
0097     template <class T> void createScopeDock(T *scopeWidget, const QString &title, const QString &name);
0098 
0099 public Q_SLOTS:
0100     void slotCheckActiveScopes();
0101 
0102 private Q_SLOTS:
0103     /**
0104       Updates the signal/slot connection since the active renderer has changed.
0105       */
0106     void slotUpdateActiveRenderer();
0107     /**
0108       The scope source was deleted, clear it.
0109       */
0110     void slotClearColorScopes();
0111     /**
0112       \see checkActiveAudioScopes()
0113       \see checkActiveColourScopes()
0114       */
0115 
0116     /**
0117     Checks whether audio data is required, and notifies the renderer (enable or disable data sending).
0118     \see checkActiveAudioScopes() for image data
0119     */
0120     void checkActiveAudioScopes();
0121     /**
0122       Checks whether any scope accepts frames, and notifies the renderer.
0123       \see checkActiveAudioScopes() for audio data
0124       */
0125     void checkActiveColourScopes();
0126 
0127     void slotDistributeFrame(const QImage &image);
0128     void slotDistributeAudio(const audioShortVector &sampleData, int freq, int num_channels, int num_samples);
0129     /**
0130       Allows a scope to explicitly request a new frame, even if the scope's autoRefresh is disabled.
0131       */
0132     void slotRequestFrame(const QString &widgetName);
0133     void slotScopeReady();
0134 };