File indexing completed on 2024-04-28 08:44:47

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jean-Baptiste Mardelle
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 "lib/audio/audioCorrelation.h"
0010 #include "timeline2/model/timelineitemmodel.hpp"
0011 
0012 #include <KActionCollection>
0013 #include <QApplication>
0014 #include <QDir>
0015 
0016 class QAction;
0017 class QQuickItem;
0018 
0019 // see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
0020 class TimelineController : public QObject
0021 {
0022     Q_OBJECT
0023     /** @brief holds a list of currently selected clips (list of clipId's)
0024      */
0025     Q_PROPERTY(QList<int> selection READ selection NOTIFY selectionChanged)
0026     Q_PROPERTY(int selectedMix READ selectedMix NOTIFY selectedMixChanged)
0027     /** @brief holds the timeline zoom factor
0028      */
0029     Q_PROPERTY(double scaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged)
0030     /** @brief holds the current project duration
0031      */
0032     Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
0033     Q_PROPERTY(int fullDuration READ fullDuration NOTIFY durationChanged)
0034     Q_PROPERTY(bool audioThumbFormat READ audioThumbFormat NOTIFY audioThumbFormatChanged)
0035     Q_PROPERTY(bool audioThumbNormalize READ audioThumbNormalize NOTIFY audioThumbNormalizeChanged)
0036     Q_PROPERTY(int zoneIn READ zoneIn WRITE setZoneIn NOTIFY zoneChanged)
0037     Q_PROPERTY(int zoneOut READ zoneOut WRITE setZoneOut NOTIFY zoneChanged)
0038     Q_PROPERTY(bool ripple READ ripple NOTIFY rippleChanged)
0039     Q_PROPERTY(bool scrub READ scrub NOTIFY scrubChanged)
0040     Q_PROPERTY(bool snap READ snap NOTIFY snapChanged)
0041     Q_PROPERTY(bool showThumbnails READ showThumbnails NOTIFY showThumbnailsChanged)
0042     Q_PROPERTY(bool showMarkers READ showMarkers NOTIFY showMarkersChanged)
0043     Q_PROPERTY(bool showAudioThumbnails READ showAudioThumbnails NOTIFY showAudioThumbnailsChanged)
0044     Q_PROPERTY(QVariantList dirtyChunks READ dirtyChunks NOTIFY dirtyChunksChanged)
0045     Q_PROPERTY(QVariantList renderedChunks READ renderedChunks NOTIFY renderedChunksChanged)
0046     Q_PROPERTY(QVariantList masterEffectZones MEMBER m_masterEffectZones NOTIFY masterZonesChanged)
0047     Q_PROPERTY(int workingPreview READ workingPreview NOTIFY workingPreviewChanged)
0048     Q_PROPERTY(bool useRuler READ useRuler NOTIFY useRulerChanged)
0049     Q_PROPERTY(bool scrollVertically READ scrollVertically NOTIFY scrollVerticallyChanged)
0050     Q_PROPERTY(int activeTrack READ activeTrack WRITE setActiveTrack NOTIFY activeTrackChanged)
0051     Q_PROPERTY(QVariantList subtitlesList READ subtitlesList NOTIFY subtitlesListChanged)
0052     Q_PROPERTY(QVariantList audioTarget READ audioTarget NOTIFY audioTargetChanged)
0053     Q_PROPERTY(int videoTarget READ videoTarget WRITE setVideoTarget NOTIFY videoTargetChanged)
0054 
0055     Q_PROPERTY(QVariantList lastAudioTarget READ lastAudioTarget  NOTIFY lastAudioTargetChanged)
0056     Q_PROPERTY(int lastVideoTarget MEMBER m_lastVideoTarget NOTIFY lastVideoTargetChanged)
0057 
0058     Q_PROPERTY(int hasAudioTarget READ hasAudioTarget NOTIFY hasAudioTargetChanged)
0059     Q_PROPERTY(bool hasVideoTarget READ hasVideoTarget NOTIFY hasVideoTargetChanged)
0060     Q_PROPERTY(int clipTargets READ clipTargets NOTIFY hasAudioTargetChanged)
0061     Q_PROPERTY(bool autoScroll READ autoScroll NOTIFY autoScrollChanged)
0062     Q_PROPERTY(QColor videoColor READ videoColor NOTIFY colorsChanged)
0063     Q_PROPERTY(QColor audioColor READ audioColor NOTIFY colorsChanged)
0064     Q_PROPERTY(QColor titleColor READ titleColor NOTIFY colorsChanged)
0065     Q_PROPERTY(QColor imageColor READ imageColor NOTIFY colorsChanged)
0066     Q_PROPERTY(QColor thumbColor1 READ thumbColor1 NOTIFY colorsChanged)
0067     Q_PROPERTY(QColor thumbColor2 READ thumbColor2 NOTIFY colorsChanged)
0068     Q_PROPERTY(QColor slideshowColor READ slideshowColor NOTIFY colorsChanged)
0069     Q_PROPERTY(QColor targetColor READ targetColor NOTIFY colorsChanged)
0070     Q_PROPERTY(QColor targetTextColor READ targetTextColor NOTIFY colorsChanged)
0071     Q_PROPERTY(QColor lockedColor READ lockedColor NOTIFY colorsChanged)
0072     Q_PROPERTY(QColor selectionColor READ selectionColor NOTIFY colorsChanged)
0073     Q_PROPERTY(QColor groupColor READ groupColor NOTIFY colorsChanged)
0074     Q_PROPERTY(bool subtitlesWarning READ subtitlesWarning NOTIFY subtitlesWarningChanged)
0075     Q_PROPERTY(bool subtitlesDisabled READ subtitlesDisabled NOTIFY subtitlesDisabledChanged)
0076     Q_PROPERTY(bool subtitlesLocked READ subtitlesLocked NOTIFY subtitlesLockedChanged)
0077     Q_PROPERTY(int activeSubPosition MEMBER m_activeSubPosition NOTIFY activeSubtitlePositionChanged)
0078     Q_PROPERTY(bool guidesLocked READ guidesLocked NOTIFY guidesLockedChanged)
0079     Q_PROPERTY(bool autotrackHeight MEMBER m_autotrackHeight NOTIFY autotrackHeightChanged)
0080     Q_PROPERTY(QPoint effectZone MEMBER m_effectZone NOTIFY effectZoneChanged)
0081     Q_PROPERTY(int trimmingMainClip READ trimmingMainClip NOTIFY trimmingMainClipChanged)
0082     Q_PROPERTY(int multicamIn MEMBER multicamIn NOTIFY multicamInChanged)
0083 
0084 public:
0085     TimelineController(QObject *parent);
0086     ~TimelineController() override;
0087     /** @brief Sets the model that this widgets displays */
0088     void setModel(std::shared_ptr<TimelineItemModel> model);
0089     std::shared_ptr<TimelineItemModel> getModel() const;
0090     void setRoot(QQuickItem *root);
0091     /** @brief Edit an item's in/out points with a dialog
0092      */
0093     Q_INVOKABLE void editItemDuration(int itemId = -1);
0094     /** @brief Edit a title clip with a title widget
0095      */
0096     Q_INVOKABLE void editTitleClip(int itemId = -1);
0097     /** @brief Open a sequence timeline
0098      */
0099     Q_INVOKABLE void focusTimelineSequence(int id);
0100     /** @brief Edit an animation with Glaxnimate
0101      */
0102     Q_INVOKABLE void editAnimationClip(int itemId = -1);
0103 
0104     /** @brief Returns the topmost track containing a selected item (-1 if selection is embty) */
0105     Q_INVOKABLE int selectedTrack() const;
0106 
0107     /** @brief Select the clip in active track under cursor
0108         @param type is the type of the object (clip or composition)
0109         @param select: true if the object should be selected and false if it should be deselected
0110         @param addToCurrent: if true, the object will be added to the new selection
0111         @param showErrorMsg inform the user that no item was selected
0112         @return false if no item was found under timeline cursor in active track
0113     */
0114     bool selectCurrentItem(KdenliveObjectType type, bool select, bool addToCurrent = false, bool showErrorMsg = true);
0115 
0116     /** @brief Select all timeline items
0117      */
0118     void selectAll();
0119     /** @brief Select all items in one track
0120      */
0121     void selectCurrentTrack();
0122     /** @brief Select multiple objects on the timeline
0123         @param tracks List of ids of tracks from which to select
0124         @param start/endFrame Interval from which to select the items
0125         @param addToSelect if true, the old selection is retained
0126     */
0127     Q_INVOKABLE void selectItems(const QVariantList &tracks, int startFrame, int endFrame, bool addToSelect, bool selectBottomCompositions, bool selectSubTitles);
0128 
0129     /** @brief request a selection with a list of ids*/
0130     Q_INVOKABLE void selectItems(const QList<int> &ids);
0131 
0132     /** @brief Returns true is item is selected as well as other items */
0133     Q_INVOKABLE bool isInSelection(int itemId);
0134 
0135     /** @brief Show/hide audio record controls on a track
0136      */
0137     Q_INVOKABLE void switchRecording(int trackId, bool record);
0138     /** @brief Add recorded file to timeline
0139      */
0140     void finishRecording(const QString &recordedFile);
0141     /** @brief Open Kdenlive's config diablog on a defined page and tab
0142      */
0143     Q_INVOKABLE void showConfig(int page, int tab);
0144 
0145     /** @brief Returns true if we have at least one active track
0146      */
0147     Q_INVOKABLE bool hasActiveTracks() const;
0148 
0149     /** @brief returns current timeline's zoom factor
0150      */
0151     Q_INVOKABLE double scaleFactor() const;
0152     /** @brief set current timeline's zoom factor
0153      */
0154     void setScaleFactorOnMouse(double scale, bool zoomOnMouse);
0155     void setScaleFactor(double scale);
0156     /** @brief Returns the project's duration (tractor)
0157      */
0158     Q_INVOKABLE int duration() const;
0159     Q_INVOKABLE int fullDuration() const;
0160     /** @brief Returns the current cursor position (frame currently displayed by MLT)
0161      */
0162     /** @brief Returns the seek request position (-1 = no seek pending)
0163      */
0164     Q_INVOKABLE QVariantList audioTarget() const;
0165     Q_INVOKABLE QVariantList lastAudioTarget() const;
0166     Q_INVOKABLE const QString audioTargetName(int tid) const;
0167     Q_INVOKABLE int videoTarget() const;
0168     Q_INVOKABLE int hasAudioTarget() const;
0169     Q_INVOKABLE int clipTargets() const;
0170     Q_INVOKABLE bool hasVideoTarget() const;
0171     bool autoScroll() const;
0172     Q_INVOKABLE int activeTrack() const { return m_activeTrack; }
0173     Q_INVOKABLE int trimmingMainClip() const { return m_trimmingMainClip; }
0174     Q_INVOKABLE QColor videoColor() const;
0175     Q_INVOKABLE QColor audioColor() const;
0176     Q_INVOKABLE QColor titleColor() const;
0177     Q_INVOKABLE QColor imageColor() const;
0178     Q_INVOKABLE QColor thumbColor1() const;
0179     Q_INVOKABLE QColor thumbColor2() const;
0180     Q_INVOKABLE QColor slideshowColor() const;
0181     Q_INVOKABLE QColor targetColor() const;
0182     Q_INVOKABLE QColor targetTextColor() const;
0183     Q_INVOKABLE QColor lockedColor() const;
0184     Q_INVOKABLE QColor selectionColor() const;
0185     Q_INVOKABLE QColor groupColor() const;
0186     Q_INVOKABLE int doubleClickInterval() const { return QApplication::doubleClickInterval(); }
0187     Q_INVOKABLE void showToolTip(const QString &info = QString()) const;
0188     Q_INVOKABLE void showKeyBinding(const QString &info = QString()) const;
0189     Q_INVOKABLE void showTimelineToolInfo(bool show) const;
0190     /** @brief The model list for this timeline's subtitles */
0191     Q_INVOKABLE QVariantList subtitlesList() const;
0192     /** @brief Returns true if the avfilter.subtiles filter is not found */
0193     bool subtitlesWarning() const;
0194     Q_INVOKABLE void subtitlesWarningDetails();
0195     void switchSubtitleDisable();
0196     bool subtitlesDisabled() const;
0197     void switchSubtitleLock();
0198     bool subtitlesLocked() const;
0199     bool guidesLocked() const;
0200     int zoneIn() const { return m_zone.x(); }
0201     int zoneOut() const { return m_zone.y(); }
0202     void setZoneIn(int inPoint);
0203     void setZoneOut(int outPoint);
0204     void setZone(const QPoint &zone, bool withUndo = true);
0205     /** @brief Adjust timeline zone to current selection */
0206     void setZoneToSelection();
0207     /** @brief Request a seek operation
0208        @param position is the desired new timeline position
0209      */
0210     Q_INVOKABLE void setPosition(int position);
0211     Q_INVOKABLE bool snap();
0212     Q_INVOKABLE bool ripple();
0213     Q_INVOKABLE bool scrub();
0214     Q_INVOKABLE QString timecode(int frames) const;
0215     QString framesToClock(int frames) const;
0216     Q_INVOKABLE QString simplifiedTC(int frames) const;
0217     /** @brief Request inserting a new clip in timeline (dragged from bin or monitor)
0218        @param tid is the destination track
0219        @param position is the timeline position
0220        @param xml is the data describing the dropped clip
0221        @param logUndo if set to false, no undo object is stored
0222        @return the id of the inserted clip
0223      */
0224     Q_INVOKABLE int insertClip(int tid, int position, const QString &xml, bool logUndo, bool refreshView, bool useTargets);
0225     /** @brief Request inserting multiple clips into the timeline (dragged from bin or monitor)
0226      * @param tid is the destination track
0227      * @param position is the timeline position
0228      * @param binIds the IDs of the bins being dropped
0229      * @param logUndo if set to false, no undo object is stored
0230      * @return the ids of the inserted clips
0231      */
0232     Q_INVOKABLE QList<int> insertClips(int tid, int position, const QStringList &binIds, bool logUndo, bool refreshView);
0233     Q_INVOKABLE int copyItem();
0234     std::pair<int, QString> getCopyItemData();
0235     Q_INVOKABLE bool pasteItem(int position = -1, int tid = -1);
0236     /** @brief Request inserting a new composition in timeline (dragged from compositions list)
0237        @param tid is the destination track
0238        @param position is the timeline position
0239        @param transitionId is the data describing the dropped composition
0240        @param logUndo if set to false, no undo object is stored
0241        @return the id of the inserted composition
0242     */
0243     Q_INVOKABLE int insertComposition(int tid, int position, const QString &transitionId, bool logUndo);
0244     /** @brief Request inserting a new mix in timeline (dragged from compositions list)
0245        @param tid is the destination track
0246        @param position is the timeline position (clip start of the second clip)
0247        @param transitionId is the data describing the dropped composition
0248     */
0249     Q_INVOKABLE void insertNewMix(int tid, int position, const QString &transitionId);
0250     /** @brief Returns the cut position if the composition is over a cut between 2 clips, -1 otherwise
0251     */
0252     Q_INVOKABLE int isOnCut(int cid) const;
0253     /** @brief Request inserting a new composition in timeline (dragged from compositions list)
0254        this function will check if there is a clip at insert point and
0255        adjust the composition length accordingly
0256        @param tid is the destination track
0257        @param position is the timeline position
0258        @param transitionId is the data describing the dropped composition
0259        @param logUndo if set to false, no undo object is stored
0260        @return the id of the inserted composition
0261     */
0262     Q_INVOKABLE int insertNewCompositionAtPos(int tid, int position, const QString &transitionId);
0263     Q_INVOKABLE int insertNewComposition(int tid, int clipId, int offset, const QString &transitionId, bool logUndo);
0264 
0265     /** @brief Request deletion of the currently selected clips
0266      */
0267     Q_INVOKABLE void deleteSelectedClips();
0268 
0269     Q_INVOKABLE void triggerAction(const QString &name);
0270     Q_INVOKABLE const QString actionText(const QString &name);
0271 
0272     /** @brief Returns id of the timeline selected clip if there is only 1 clip selected
0273      * or an AVSplit group. If allowComposition is true, returns composition id if
0274      * only 1 is selected, otherwise returns -1. If restrictToCurrentPos is true, it will
0275      * only return the id if timeline cursor is inside item
0276      */
0277     int getMainSelectedItem(bool restrictToCurrentPos = true, bool allowComposition = false);
0278     int getMainSelectedClip();
0279     /** @brief Return the {position, track id} of current selection. Operates only on video items (or audio if audioPart is true)
0280      */
0281     std::pair<int, int> selectionPosition(int *aTracks, int *vTracks);
0282 
0283     /** @brief Do we want to display video thumbnails
0284      */
0285     bool showThumbnails() const;
0286     bool showAudioThumbnails() const;
0287     bool showMarkers() const;
0288     bool audioThumbFormat() const;
0289     bool audioThumbNormalize() const;
0290     /** @brief Do we want to display audio thumbnails
0291      */
0292     Q_INVOKABLE bool showWaveforms() const;
0293     /** @brief Invoke the GUI to add new timeline tracks
0294      */
0295     Q_INVOKABLE void beginAddTrack(int tid);
0296     /** @brief Remove multiple(or single) timeline tracks
0297      */
0298     Q_INVOKABLE void deleteMultipleTracks(int tid);
0299     /** @brief Show / hide audio rec controls in active track
0300      */
0301     void switchTrackRecord(int tid = -1, bool monitor = false);
0302     /** @brief Group selected items in timeline
0303      */
0304     Q_INVOKABLE void groupSelection();
0305     /** @brief Ungroup selected items in timeline
0306      */
0307     Q_INVOKABLE void unGroupSelection(int cid = -1);
0308     /** @brief Ask for edit marker dialog
0309      */
0310     Q_INVOKABLE void editMarker(int cid = -1, int position = -1);
0311     /** @brief Ask for marker add dialog
0312      */
0313     Q_INVOKABLE void addMarker(int cid = -1, int position = -1);
0314     /** @brief Ask for quick marker add (without dialog)
0315      */
0316     Q_INVOKABLE void addQuickMarker(int cid = -1, int position = -1);
0317     /** @brief Ask for marker delete
0318      */
0319     Q_INVOKABLE void deleteMarker(int cid = -1, int position = -1);
0320     /** @brief Ask for all markers delete
0321      */
0322     Q_INVOKABLE void deleteAllMarkers(int cid = -1);
0323     /** @brief Ask for edit timeline guide dialog
0324      */
0325     Q_INVOKABLE void editGuide(int frame = -1);
0326     Q_INVOKABLE void moveGuideById(int id, int newFrame);
0327     Q_INVOKABLE int moveGuideWithoutUndo(int mid, int newFrame);
0328     /** @brief Move all guides in the given range
0329      * @param start the start point of the range in frames
0330      * @param end the end point of the range in frames
0331      * @param offset how many frames the guides are moved
0332      */
0333     Q_INVOKABLE bool moveGuidesInRange(int start, int end, int offset);
0334     /** @brief Move all guides in the given range (same as above but with undo/redo)
0335      * @param start the start point of the range in frames
0336      * @param end the end point of the range in frames
0337      * @param offset how many frames the guides are moved
0338      * @param undo
0339      * @param redo
0340      */
0341     Q_INVOKABLE bool moveGuidesInRange(int start, int end, int offset, Fun &undo, Fun &redo);
0342 
0343     /** @brief Add a timeline guide
0344      */
0345     Q_INVOKABLE void switchGuide(int frame = -1, bool deleteOnly = false, bool showGui = false);
0346     /** @brief Request monitor refresh
0347      */
0348     Q_INVOKABLE void requestRefresh();
0349 
0350     /** @brief Show the asset of the given item in the AssetPanel
0351        If the id corresponds to a clip, we show the corresponding effect stack
0352        If the id corresponds to a composition, we show its properties
0353     */
0354     Q_INVOKABLE void showAsset(int id);
0355     Q_INVOKABLE void showTrackAsset(int trackId);
0356     /** @brief Adjust height of all similar (audio or video) tracks
0357     */
0358     Q_INVOKABLE void adjustTrackHeight(int trackId, int height);
0359     Q_INVOKABLE void adjustAllTrackHeight(int trackId, int height);
0360     Q_INVOKABLE void collapseAllTrackHeight(int trackId, bool collapse, int collapsedHeight);
0361 
0362     /** @brief Reset track \@trackId height to default track height. Adjusts all tracks if \@trackId == -1
0363     */
0364     Q_INVOKABLE void defaultTrackHeight(int trackId);
0365 
0366     Q_INVOKABLE bool exists(int itemId);
0367 
0368     Q_INVOKABLE int headerWidth() const;
0369     Q_INVOKABLE void setHeaderWidth(int width);
0370     /** @brief Hide / show a timeline track
0371      */
0372     Q_INVOKABLE void hideTrack(int trackId, bool hide);
0373 
0374     /** @brief Seek to next snap point
0375      */
0376     void gotoNextSnap();
0377     /** @brief Seek to previous snap point
0378      */
0379     void gotoPreviousSnap();
0380     /** @brief Seek to previous guide
0381      */
0382     void gotoPreviousGuide();
0383     /** @brief Seek to next guide
0384      */
0385     void gotoNextGuide();
0386 
0387     /** @brief Set current item's start point to cursor position
0388      */
0389     void setInPoint(bool ripple = false);
0390     /** @brief Set current item's end point to cursor position
0391      */
0392     void setOutPoint(bool ripple = false);
0393     /** @brief Return the project's tractor
0394      */
0395     Mlt::Tractor *tractor();
0396     /** @brief Return a track's producer
0397      */
0398     Mlt::Producer trackProducer(int tid);
0399     /** @brief Get the list of currently selected clip id's
0400      */
0401     QList<int> selection() const;
0402     /** @brief Returns the id of the currently selected mix's clip, -1 if no mix selected
0403      */
0404     int selectedMix() const;
0405 
0406     /** @brief Add an asset (effect, composition)
0407      */
0408     void addAsset(const QVariantMap &data);
0409 
0410     /** @brief Cuts the clip on current track at timeline position
0411      */
0412     Q_INVOKABLE void cutClipUnderCursor(int position = -1, int track = -1);
0413     /** @brief Cuts all clips at timeline position
0414      */
0415     Q_INVOKABLE void cutAllClipsUnderCursor(int position = -1);
0416     /** @brief Request a spacer operation
0417      */
0418     Q_INVOKABLE int requestSpacerStartOperation(int trackId, int position);
0419     /** @brief Returns the minimum available position for a spacer operation
0420      */
0421     Q_INVOKABLE int spacerMinPos() const;
0422     /** @brief Get a list of guides Id after a given frame
0423      */
0424     Q_INVOKABLE QVector<int> spacerSelection(int startFrame);
0425     /** @brief Move a list of guides from a given offset
0426      */
0427     Q_INVOKABLE void spacerMoveGuides(const QVector<int> &ids, int offset);
0428     /** @brief Get the position of the first marker in the list
0429      */
0430     Q_INVOKABLE int getGuidePosition(int ids);
0431     /** @brief Request a spacer operation
0432      */
0433     Q_INVOKABLE bool requestSpacerEndOperation(int clipId, int startPosition, int endPosition, int affectedTrack, const QVector<int> &selectedGuides = QVector<int>(), int guideStart = -1);
0434     /** @brief Request a Fade in effect for clip
0435      */
0436     Q_INVOKABLE void adjustFade(int cid, const QString &effectId, int duration, int initialDuration);
0437 
0438     Q_INVOKABLE const QString getTrackNameFromMltIndex(int trackPos);
0439     /** @brief Request inserting space in a track
0440      */
0441     Q_INVOKABLE void insertSpace(int trackId = -1, int frame = -1);
0442     Q_INVOKABLE void removeSpace(int trackId = -1, int frame = -1, bool affectAllTracks = false);
0443     /** @brief Remove all spaces in a @trackId track after @frame position
0444      */
0445     void removeTrackSpaces(int trackId, int frame);
0446     /** @brief Remove all clips in a @trackId track after @frame position
0447      */
0448     void removeTrackClips(int trackId, int frame);
0449     /** @brief If clip is enabled, disable, otherwise enable
0450      */
0451     Q_INVOKABLE void switchEnableState(std::unordered_set<int> selection = {});
0452     Q_INVOKABLE void addCompositionToClip(const QString &assetId, int clipId = -1, int offset = -1);
0453     Q_INVOKABLE void addEffectToClip(const QString &assetId, int clipId = -1);
0454     Q_INVOKABLE void setEffectsEnabled(int clipId, bool enabled);
0455 
0456     Q_INVOKABLE void requestClipCut(int clipId, int position);
0457 
0458     /** @brief Extract (delete + remove space) current clip
0459      */
0460     void extract(int clipId = -1, bool singleSelectionMode = false);
0461     /** @brief Save current clip cut as bin subclip
0462      */
0463     void saveZone(int clipId = -1);
0464 
0465     Q_INVOKABLE void splitAudio(int clipId);
0466     Q_INVOKABLE void splitVideo(int clipId);
0467     Q_INVOKABLE void setAudioRef(int clipId = -1);
0468     Q_INVOKABLE void alignAudio(int clipId = -1);
0469     Q_INVOKABLE void urlDropped(QStringList droppedFile, int frame, int tid);
0470 
0471     Q_INVOKABLE bool endFakeMove(int clipId, int position, bool updateView, bool logUndo, bool invalidateTimeline);
0472     Q_INVOKABLE int getItemMovingTrack(int itemId) const;
0473     bool endFakeGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool logUndo);
0474     bool endFakeGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo);
0475 
0476     bool splitAV();
0477 
0478     /** @brief Seeks to selected clip start / end
0479      */
0480     Q_INVOKABLE void pasteEffects(int targetId = -1);
0481     Q_INVOKABLE void deleteEffects(int targetId = -1);
0482     Q_INVOKABLE double fps() const;
0483     Q_INVOKABLE void addEffectKeyframe(int cid, int frame, double val);
0484     Q_INVOKABLE void removeEffectKeyframe(int cid, int frame);
0485     Q_INVOKABLE void updateEffectKeyframe(int cid, int oldFrame, int newFrame, const QVariant &normalizedValue = QVariant());
0486     Q_INVOKABLE bool hasKeyframeAt(int cid, int frame);
0487 
0488     /** @brief Make current timeline track active/inactive*/
0489     Q_INVOKABLE void switchTrackActive(int trackId = -1);
0490     /** @brief Toggle the active/inactive state of all tracks*/
0491     void switchAllTrackActive();
0492     /** @brief Make all tracks active or inactive */
0493     void makeAllTrackActive();
0494     void switchTrackDisabled();
0495     void switchTrackLock(bool applyToAll = false);
0496     void switchTargetTrack();
0497 
0498     const QString getTrackNameFromIndex(int trackIndex);
0499     /** @brief Seeks to selected clip start / end or, if none is selected, to the start / end of the clip under the cursor
0500      */
0501     void seekCurrentClip(bool seekToEnd = false);
0502     /** @brief Seeks to a clip start (or end) based on it's clip id
0503      */
0504     void seekToClip(int cid, bool seekToEnd);
0505     /** @brief Returns true if timeline cursor is inside the item
0506      */
0507     bool positionIsInItem(int id);
0508     /** @brief Returns the number of tracks (audioTrakcs, videoTracks)
0509      */
0510     QPair<int, int> getAvTracksCount() const;
0511     /** @brief Request monitor refresh if item (clip or composition) is under timeline cursor
0512      */
0513     void refreshItem(int id);
0514     /** @brief Seek timeline to mouse position
0515      */
0516     void seekToMouse();
0517 
0518     /** @brief Set a property on the active track
0519      */
0520     void setActiveTrackProperty(const QString &name, const QString &value);
0521     /** @brief Get a property on the active track
0522      */
0523     const QVariant getActiveTrackProperty(const QString &name) const;
0524     /** @brief Is the active track audio
0525      */
0526     bool isActiveTrackAudio() const;
0527 
0528     /** @brief Returns a list of all luma files used in the project
0529      */
0530     QStringList extractCompositionLumas() const;
0531     /** @brief Returns a list of all external files used by effects in the timeline
0532      */
0533     QStringList extractExternalEffectFiles() const;
0534     /** @brief Get the frame where mouse is positioned
0535      */
0536     int getMousePos();
0537     /** @brief Get the frame where mouse is positioned
0538      */
0539     int getMouseTrack();
0540     /** @brief Returns a map of track ids/track names
0541      */
0542     QMap<int, QString> getTrackNames(bool videoOnly);
0543     /** @brief Returns the transition a track index for a composition (MLT index / Track id)
0544      */
0545     QPair<int, int> getCompositionATrack(int cid) const;
0546     void setCompositionATrack(int cid, int aTrack);
0547     /** @brief Return true if composition's a_track is automatic (no forced track)
0548      */
0549     bool compositionAutoTrack(int cid) const;
0550     const QString getClipBinId(int clipId) const;
0551     void focusItem(int itemId);
0552     /** @brief Create and display a split clip view to compare effect
0553      */
0554     bool createSplitOverlay(int clipId, std::shared_ptr<Mlt::Filter> filter);
0555     /** @brief Delete the split clip view to compare effect
0556      */
0557     void removeSplitOverlay();
0558 
0559     /** @brief Limit the given offset to the max/min possible offset of the main trimming clip
0560      *  @returns The bounded offset
0561      */
0562     int trimmingBoundOffset(int offset);
0563     /** @brief @todo TODO */
0564     bool slipProcessSelection(int mainClipId, bool addToSelection);
0565     Q_INVOKABLE bool requestStartTrimmingMode(int clipId = -1, bool addToSelection = false, bool right = false);
0566     Q_INVOKABLE void requestEndTrimmingMode();
0567     Q_INVOKABLE void slipPosChanged(int offset);
0568     Q_INVOKABLE void ripplePosChanged(int pos, bool right);
0569 
0570     /** @brief @todo TODO */
0571     Q_INVOKABLE int requestItemRippleResize(int itemId, int size, bool right, bool logUndo = true, int snapDistance = -1, bool allowSingleResize = false);
0572 
0573     /** @brief Add current timeline zone to preview rendering
0574      */
0575     void addPreviewRange(bool add);
0576     /** @brief Clear current timeline zone from preview rendering
0577      */
0578     void clearPreviewRange(bool resetZones);
0579     void startPreviewRender();
0580     void stopPreviewRender();
0581     QVariantList dirtyChunks() const;
0582     QVariantList renderedChunks() const;
0583     /** @brief returns the frame currently processed by timeline preview, -1 if none
0584      */
0585     int workingPreview() const;
0586 
0587     /** @brief Return true if we want to use timeline ruler zone for editing */
0588     bool useRuler() const;
0589 
0590     /** @brief Return true if the scroll wheel should scroll vertically (Shift key for horizontal); false if it should scroll horizontally (Shift for vertical) */
0591     bool scrollVertically() const;
0592 
0593     /** @brief Load timeline preview from saved doc
0594      */
0595     void loadPreview(const QString &chunks, const QString &dirty, bool enable, Mlt::Playlist &playlist);
0596     /** @brief Return document properties with added settings from timeline
0597      */
0598     QMap<QString, QString> documentProperties();
0599 
0600     /** @brief Change track compsiting mode */
0601     void switchCompositing(bool enable);
0602 
0603     /** @brief Change a clip item's speed in timeline */
0604     Q_INVOKABLE void changeItemSpeed(int clipId, double speed);
0605     /** @brief Activate time remap on the clip */
0606     void remapItemTime(int clipId);
0607     /** @brief Delete selected zone and fill gap by moving following clips
0608      *  @param lift if true, the zone will simply be deleted but clips won't be moved
0609      */
0610     void extractZone(QPoint zone, bool liftOnly = false);
0611     /** @brief Insert clip monitor into timeline
0612      *  @returns the zone end position or -1 on fail
0613      */
0614     Q_INVOKABLE bool insertClipZone(const QString &binId, int tid, int pos);
0615     int insertZone(const QString &binId, QPoint zone, bool overwrite, Fun &undo, Fun &redo);
0616     void updateClip(int clipId, const QVector<int> &roles);
0617     void showClipKeyframes(int clipId, bool value);
0618     void showCompositionKeyframes(int clipId, bool value);
0619     /** @brief Adjust all timeline tracks height */
0620     void resetTrackHeight();
0621     /** @brief timeline preview params changed, reset */
0622     void resetPreview();
0623     /** @brief Set target tracks (video, audio) */
0624     void setTargetTracks(bool hasVideo, const QMap <int, QString> &audioTargets);
0625     /** @brief Restore Bin Clip original target tracks (video, audio) */
0626     void restoreTargetTracks();
0627     /** @brief Return asset's display name from it's id (effect or composition) */
0628     Q_INVOKABLE const QString getAssetName(const QString &assetId, bool isTransition);
0629     /** @brief Set keyboard grabbing on current selection */
0630     Q_INVOKABLE void grabCurrent();
0631     /** @brief Returns keys for all used thumbnails */
0632     const std::unordered_map<QString, std::vector<int>> getThumbKeys();
0633     /** @brief Returns true if a drag operation is currently running in timeline */
0634     bool dragOperationRunning();
0635     /** @brief Returns true if the timeline is in trimming mode (slip, slide, ripple, rolle) */
0636     bool trimmingActive();
0637     /** @brief Disconnect some stuff before closing project */
0638     void prepareClose();
0639     /** @brief Check that we don't keep a deleted track id */
0640     void checkTrackDeletion(int selectedTrackIx);
0641     /** @brief Return true if an overlay track is used */
0642     bool hasPreviewTrack() const;
0643     /** @brief Display project master effects */
0644     Q_INVOKABLE void showMasterEffects();
0645     /** @brief Return true if an instance of this bin clip is currently under timeline cursor */
0646     bool refreshIfVisible(int cid);
0647     /** @brief Collapse / expand active track */
0648     void collapseActiveTrack();
0649     /** @brief Expand MLT playlist to its contained clips/compositions */
0650     void expandActiveClip();
0651     /** @brief Retrieve a list of possible audio stream targets */
0652     QMap <int, QString> getCurrentTargets(int trackId, int &activeTargetStream);
0653     /** @brief Define audio stream target for a track index */
0654     void assignAudioTarget(int trackId, int stream);
0655     /** @brief Define a stream target for current track from the stream index */
0656     void assignCurrentTarget(int index);
0657     /** @brief Get the first unassigned target audio stream. */
0658     int getFirstUnassignedStream() const;
0659 
0660     /** @brief Add tracks to project */
0661     void addTracks(int videoTracks, int audioTracks);
0662     /** @brief Get in/out of currently selected items */
0663     QPoint selectionInOut() const;
0664     /** @brief Create a mix transition with currently selected clip. If delta = -1, mix with previous clip, +1 with next clip and 0 will check cursor position*/
0665     Q_INVOKABLE void mixClip(int cid = -1, int delta = 0);
0666     /** @brief Temporarily un/plug a list of clips in timeline. */
0667     void temporaryUnplug(const QList<int> &clipIds, bool hide);
0668     /** @brief Import a subtitle file*/
0669     void importSubtitle(const QString &path = QString());
0670     /** @brief Export a subtitle file*/
0671     void exportSubtitle();
0672     /** @brief Launch speech recognition on timeline zone*/
0673     void subtitleSpeechRecognition();
0674     /** @brief Show active effect zone for current effect*/
0675     void showRulerEffectZone(QPair <int, int>inOut, bool checked);
0676     /** @brief Set the list of master effect zones */
0677     void updateMasterZones(const QVariantList &zones);
0678     /** @brief get Maximum duration of a clip */
0679     int clipMaxDuration(int cid);
0680     /** @brief Get Mix cut pos (the duration of the mix on the right clip) */
0681     int getMixCutPos(int cid) const;
0682     /** @brief Get align info for a mix. */
0683     MixAlignment getMixAlign(int cid) const;
0684     /** @brief Process a lift operation for multitrack operation. */
0685     void processMultitrackOperation(int tid, int in);
0686     /** @brief Save all sequence properties (timeline position, guides, groups, ..) to the timeline tractor. */
0687     void saveSequenceProperties();
0688     /** @brief Trigger refresh of subtitles combo menu. */
0689     void refreshSubtitlesComboIndex();
0690 
0691 public Q_SLOTS:
0692     void updateClipActions();
0693     void resetView();
0694     void setAudioTarget(const QMap<int, int> &tracks);
0695     Q_INVOKABLE void switchAudioTarget(int trackId);
0696     Q_INVOKABLE void setVideoTarget(int track);
0697     Q_INVOKABLE void setActiveTrack(int track);
0698     void addEffectToCurrentClip(const QStringList &effectData);
0699     /** @brief Dis / enable timeline preview. */
0700     void disablePreview(bool disable);
0701     void invalidateItem(int cid);
0702     void invalidateTrack(int tid);
0703     void checkDuration();
0704     /** @brief Dis / enable multi track view. */
0705     void slotMultitrackView(bool enable = true, bool refresh = true);
0706     /** @brief Activate a video track by its position (0 = topmost). */
0707     void activateTrackAndSelect(int trackPosition, bool notesMode = false);
0708     /** @brief Save timeline selected clips to target folder. */
0709     void saveTimelineSelection(const QDir &targetDir);
0710     /** @brief Restore timeline scroll pos on open. */
0711     void setScrollPos(int pos);
0712     /** @brief Request resizing currently selected mix. */
0713     void resizeMix(int cid, int duration, MixAlignment align, int leftFrames = -1);
0714     /** @brief change zone info with undo. */
0715     Q_INVOKABLE void updateZone(const QPoint oldZone, const QPoint newZone, bool withUndo = true);
0716     Q_INVOKABLE void updateEffectZone(const QPoint oldZone, const QPoint newZone, bool withUndo = true);
0717     void updateTrimmingMode();
0718     /** @brief When a clip or composition is moved, inform asset panel to update cursor position in keyframe views. */
0719     void checkClipPosition(const QModelIndex &topLeft, const QModelIndex &, const QVector<int> &roles);
0720     /** @brief Adjust all tracks height to fit in view. */
0721     Q_INVOKABLE void autofitTrackHeight(int timelineHeight, int collapsedHeight);
0722     Q_INVOKABLE void subtitlesMenuActivatedAsync(int ix);
0723     /** @brief Switch the active subtitle in the list. */
0724     void subtitlesMenuActivated(int ix);
0725 
0726 private Q_SLOTS:
0727     void updateVideoTarget();
0728     void updateAudioTarget();
0729     /** @brief Dis / enable multi track view. */
0730     void updateMultiTrack();
0731     /** @brief An operation was attempted on a locked track, animate lock icon to make user aware */
0732     void slotFlashLock(int trackId);
0733     void initializePreview();
0734     /** @brief Display the active subtitle mode in subtitle track combobox. */
0735     void loadSubtitleIndex();
0736 
0737 public:
0738     /** @brief a list of actions that have to be enabled/disabled depending on the timeline selection */
0739     QList<QAction *> clipActions;
0740     /** @brief The in point for a multicam operation */
0741     int multicamIn;
0742     /** @brief Set the in point for a multicam operation and trigger necessary signals */
0743     void setMulticamIn(int pos);
0744 
0745 private:
0746     int m_duration;
0747     QQuickItem *m_root;
0748     KActionCollection *m_actionCollection;
0749     std::shared_ptr<TimelineItemModel> m_model;
0750     bool m_usePreview;
0751     int m_audioTarget;
0752     int m_videoTarget;
0753     int m_audioRef;
0754     int m_hasAudioTarget {0};
0755     bool m_hasVideoTarget {false};
0756     int m_lastVideoTarget {-1};
0757     /** @brief The last combination of audio targets in the form: {timeline track id, bin stream index} */
0758     QMap <int, int> m_lastAudioTarget;
0759     bool m_videoTargetActive {true};
0760     bool m_audioTargetActive {true};
0761     QPair<int, int> m_recordStart;
0762     int m_recordTrack;
0763     QPoint m_zone;
0764     int m_activeTrack;
0765     double m_scale;
0766     QAction *m_disablePreview;
0767     std::shared_ptr<AudioCorrelation> m_audioCorrelator;
0768     QMutex m_metaMutex;
0769     bool m_ready;
0770     std::vector<int> m_activeSnaps;
0771     int m_snapStackIndex;
0772     QMetaObject::Connection m_connection;
0773     QMetaObject::Connection m_deleteConnection;
0774     QPoint m_effectZone;
0775     bool m_autotrackHeight;
0776     QVariantList m_masterEffectZones;
0777     /** @brief The clip that is displayed in the preview monitor during a trimming operation*/
0778     int m_trimmingMainClip;
0779     /** @brief The position of the active subtitle in the menu list*/
0780     int m_activeSubPosition{-1};
0781 
0782     int getMenuOrTimelinePos() const;
0783     /** @brief Prepare the preview manager */
0784     void connectPreviewManager();
0785 
0786 Q_SIGNALS:
0787     void selected(Mlt::Producer *producer);
0788     void selectionChanged();
0789     void selectedMixChanged();
0790     void frameFormatChanged();
0791     void trackHeightChanged();
0792     void scaleFactorChanged();
0793     void audioThumbFormatChanged();
0794     void audioThumbNormalizeChanged();
0795     void durationChanged(int duration);
0796     void audioTargetChanged();
0797     void videoTargetChanged();
0798     void hasAudioTargetChanged();
0799     void hasVideoTargetChanged();
0800     void lastAudioTargetChanged();
0801     void autoScrollChanged();
0802     void lastVideoTargetChanged();
0803     void activeTrackChanged();
0804     void trimmingMainClipChanged();
0805     void colorsChanged();
0806     void showThumbnailsChanged();
0807     void showAudioThumbnailsChanged();
0808     void showMarkersChanged();
0809     void rippleChanged();
0810     void scrubChanged();
0811     void subtitlesWarningChanged();
0812     void multicamInChanged();
0813     void autotrackHeightChanged();
0814     void seeked(int position);
0815     void zoneChanged();
0816     void subtitlesListChanged();
0817     void zoneMoved(const QPoint &zone);
0818     /** @brief Requests that a given parameter model is displayed in the asset panel */
0819     void showTransitionModel(int tid, std::shared_ptr<AssetParameterModel>);
0820     /** @brief Requests that a given mix is displayed in the asset panel */
0821     void showMixModel(int cid, const std::shared_ptr<AssetParameterModel> &asset, bool refreshOnly);
0822     void showItemEffectStack(const QString &clipName, std::shared_ptr<EffectStackModel>, QSize frameSize, bool showKeyframes);
0823     void showSubtitle(int id);
0824     /** @brief notify of chunks change
0825      */
0826     void dirtyChunksChanged();
0827     void renderedChunksChanged();
0828     void workingPreviewChanged();
0829     void subtitlesDisabledChanged();
0830     void subtitlesLockedChanged();
0831     void useRulerChanged();
0832     void scrollVerticallyChanged();
0833     void updateZoom(double);
0834     /** @brief emitted when timeline selection changes, true if a clip is selected
0835      */
0836     void timelineClipSelected(bool);
0837     /** @brief User enabled / disabled snapping, update timeline behavior
0838      */
0839     void snapChanged();
0840     /** @brief Center timeline view on current position
0841      */
0842     void centerView();
0843     void guidesLockedChanged();
0844     void effectZoneChanged();
0845     void masterZonesChanged();
0846     Q_INVOKABLE void ungrabHack();
0847     void regainFocus();
0848     void updateAssetPosition(int itemId, const QUuid uuid);
0849     void stopAudioRecord();
0850     void activeSubtitlePositionChanged();
0851 };