core.h 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
Copyright (C) 2014  Till Theato <root@ttill.de>
This file is part of kdenlive. See www.kdenlive.org.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/

#ifndef CORE_H
#define CORE_H

Nicolas Carion's avatar
linting    
Nicolas Carion committed
14
#include "definitions.h"
Nicolas Carion's avatar
Nicolas Carion committed
15
#include "kdenlivecore_export.h"
16
#include "undohelper.hpp"
17
#include <QMutex>
18
#include <QObject>
19
#include <QUrl>
Nicolas Carion's avatar
Nicolas Carion committed
20
#include <memory>
Laurent Montel's avatar
Laurent Montel committed
21
#include <QPoint>
22
class Bin;
23
24
class DocUndoStack;
class EffectStackModel;
25
class JobManager;
26
class KdenliveDoc;
27
class LibraryWidget;
28
class MainWindow;
29
class MediaCapture;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
30
class MixerManager;
31
class Monitor;
32
class MonitorManager;
33
class ProfileModel;
34
class ProjectItemModel;
35
class ProjectManager;
36

Nicolas Carion's avatar
Nicolas Carion committed
37
namespace Mlt {
38
39
    class Repository;
    class Profile;
Nicolas Carion's avatar
Nicolas Carion committed
40
} // namespace Mlt
41

42
#define EXIT_RESTART (42)
43
#define EXIT_CLEAN_RESTART (43)
44
45
46
47
48
#define pCore Core::self()

/**
 * @class Core
 * @brief Singleton that provides access to the different parts of Kdenlive
Laurent Montel's avatar
Laurent Montel committed
49
 *
50
51
52
53
 * Needs to be initialize before any widgets are created in MainWindow.
 * Plugins should be loaded after the widget setup.
 */

54
class /*KDENLIVECORE_EXPORT*/ Core : public QObject
55
56
57
58
{
    Q_OBJECT

public:
Nicolas Carion's avatar
Nicolas Carion committed
59
60
61
62
    Core(const Core &) = delete;
    Core &operator=(const Core &) = delete;
    Core(Core &&) = delete;
    Core &operator=(Core &&) = delete;
63

Nicolas Carion's avatar
Nicolas Carion committed
64
    ~Core() override;
65
66

    /**
67
68
     * @brief Setup the basics of the application, in particular the connection
     * with Mlt
69
70
     * @param isAppImage do we expect an AppImage (if yes, we use App path to deduce 
     * other binaries paths (melt, ffmpeg, etc)
71
     * @param MltPath (optional) path to MLT environment
72
     */
73
    static void build(bool isAppImage, const QString &MltPath = QString());
74
75
76

    /**
     * @brief Init the GUI part of the app and show the main window
77
     * @param Url (optional) file to open
78
     * If Url is present, it will be opened, otherwise, if openlastproject is
79
80
     * set, latest project will be opened. If no file is open after trying this,
     * a default new file will be created. */
81
    void initGUI(const QUrl &Url, const QString &clipsToLoad = QString());
82
83

    /** @brief Returns a pointer to the singleton object. */
Nicolas Carion's avatar
Nicolas Carion committed
84
    static std::unique_ptr<Core> &self();
85

86
87
88
    /** @brief Delete the global core instance */
    static void clean();

89
90
    /** @brief Returns a pointer to the main window. */
    MainWindow *window();
Till Theato's avatar
Till Theato committed
91
92
93

    /** @brief Returns a pointer to the project manager. */
    ProjectManager *projectManager();
94
    /** @brief Returns a pointer to the current project. */
95
    KdenliveDoc *currentDoc();
96
97
    /** @brief Set current project modified. */
    void setDocumentModified();
98
99
    /** @brief Returns a pointer to the monitor manager. */
    MonitorManager *monitorManager();
100
    /** @brief Returns a pointer to the view of the project bin. */
101
    Bin *bin();
102
103
    /** @brief Select a clip in the Bin from its id. */
    void selectBinClip(const QString &id, int frame = -1, const QPoint &zone = QPoint());
104
105
    /** @brief Returns a pointer to the model of the project bin. */
    std::shared_ptr<ProjectItemModel> projectItemModel();
106
107
    /** @brief Returns a pointer to the job manager. Please do not store it. */
    std::shared_ptr<JobManager> jobManager();
108
109
    /** @brief Returns a pointer to the library. */
    LibraryWidget *library();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
110
111
    /** @brief Returns a pointer to the audio mixer. */
    MixerManager *mixer();
112

113
    /** @brief Returns a pointer to MLT's repository */
Nicolas Carion's avatar
Nicolas Carion committed
114
    std::unique_ptr<Mlt::Repository> &getMltRepository();
115
116

    /** @brief Returns a pointer to the current profile */
Nicolas Carion's avatar
Nicolas Carion committed
117
    std::unique_ptr<ProfileModel> &getCurrentProfile() const;
118
119
    const QString &getCurrentProfilePath() const;

Nicolas Carion's avatar
linting    
Nicolas Carion committed
120
    /** @brief Define the active profile
121
122
123
     *  @returns true if profile exists, false if not found
     */
    bool setCurrentProfile(const QString &profilePath);
124
125
    /** @brief Returns Sample Aspect Ratio of current profile */
    double getCurrentSar() const;
126
    /** @brief Returns Display Aspect Ratio of current profile */
127
    double getCurrentDar() const;
128
129

    /** @brief Returns frame rate of current profile */
130
131
132
133
134
135
    double getCurrentFps() const;

    /** @brief Returns the frame size (width x height) of current profile */
    QSize getCurrentFrameSize() const;
    /** @brief Returns the frame display size (width x height) of current profile */
    QSize getCurrentFrameDisplaySize() const;
136
137
    /** @brief Request project monitor refresh */
    void requestMonitorRefresh();
138
139
    /** @brief Request project monitor refresh if current position is inside range*/
    void refreshProjectRange(QSize range);
140
    /** @brief Request project monitor refresh if referenced item is under cursor */
141
    void refreshProjectItem(const ObjectId &id);
142
143
    /** @brief Returns a reference to a monitor (clip or project monitor) */
    Monitor *getMonitor(int id);
144

145
146
147
    /** @brief This function must be called whenever the profile used changes */
    void profileChanged();

148
149
150
    /** @brief Create and push and undo object based on the corresponding functions
        Note that if you class permits and requires it, you should use the macro PUSH_UNDO instead*/
    void pushUndo(const Fun &undo, const Fun &redo, const QString &text);
151
    void pushUndo(QUndoCommand *command);
152
    /** @brief display a user info/warning message in statusbar */
153
    void displayMessage(const QString &message, MessageType type, int timeout = -1);
154
155
    /** @brief Clear asset view if itemId is displayed. */
    void clearAssetPanel(int itemId);
156
157
    /** @brief Returns the effectstack of a given bin clip. */
    std::shared_ptr<EffectStackModel> getItemEffectStack(int itemType, int itemId);
158
    int getItemPosition(const ObjectId &id);
159
    int getItemIn(const ObjectId &id);
160
    int getItemTrack(const ObjectId &id);
161
    int getItemDuration(const ObjectId &id);
162
163
    /** @brief Returns the capabilities of a clip: AudioOnly, VideoOnly or Disabled if both are allowed */
    PlaylistState::ClipState getItemState(const ObjectId &id);
164
    /** @brief Get a list of video track names with indexes */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
165
    QMap<int, QString> getTrackNames(bool videoOnly);
166
    /** @brief Returns the composition A track (MLT index / Track id) */
Nicolas Carion's avatar
Nicolas Carion committed
167
    QPair<int, int> getCompositionATrack(int cid) const;
168
    void setCompositionATrack(int cid, int aTrack);
169
170
171
    /* @brief Return true if composition's a_track is automatic (no forced track)
     */
    bool compositionAutoTrack(int cid) const;
172
    std::shared_ptr<DocUndoStack> undoStack();
173
    double getClipSpeed(int id) const;
174
    /** @brief Mark an item as invalid for timeline preview */
175
    void invalidateItem(ObjectId itemId);
176
    void invalidateRange(QSize range);
177
    void prepareShutdown();
178
179
    /** the keyframe model changed (effect added, deleted, active effect changed), inform timeline */
    void updateItemKeyframes(ObjectId id);
180
181
    /** A fade for clip id changed, update timeline */
    void updateItemModel(ObjectId id, const QString &service);
182
183
    /** Show / hide keyframes for a timeline clip */
    void showClipKeyframes(ObjectId id, bool enable);
184
    Mlt::Profile *thumbProfile();
185
186
    /** @brief Returns the current project duration */
    int projectDuration() const;
187
188
    /** @brief Returns true if current project has some rendered timeline preview  */
    bool hasTimelinePreview() const;
189
190
    /** @brief Returns current timeline cursor position  */
    int getTimelinePosition() const;
191
    /** @brief Handles audio and video capture **/
192
193
    void startMediaCapture(int tid, bool, bool);
    void stopMediaCapture(int tid, bool, bool);
194
195
    QStringList getAudioCaptureDevices();
    int getMediaCaptureState();
196
    bool isMediaCapturing();
197
    MediaCapture *getAudioDevice();
198
    /** @brief Returns Project Folder name for capture output location */
199
    QString getProjectFolderName();
200
201
    /** @brief Returns a timeline clip's bin id */
    QString getTimelineClipBinId(int cid);
202
203
    /** @brief Returns a frame duration from a timecode */
    int getDurationFromString(const QString &time);
204
205
    /** @brief An error occured within a filter, inform user */
    void processInvalidFilter(const QString service, const QString id, const QString message);
206
207
    /** @brief Update current project's tags */
    void updateProjectTags(QMap <QString, QString> tags);
208
209
    /** @brief Returns the consumer profile, that will be scaled 
     *  according to preview settings. Should only be used on the consumer */
210
    Mlt::Profile *getProjectProfile();
211

212
private:
213
    explicit Core();
214
    static std::unique_ptr<Core> m_self;
215

216
217
218
    /** @brief Makes sure Qt's locale and system locale settings match. */
    void initLocale();

Nicolas Carion's avatar
Nicolas Carion committed
219
220
221
    MainWindow *m_mainWindow{nullptr};
    ProjectManager *m_projectManager{nullptr};
    MonitorManager *m_monitorManager{nullptr};
222
    std::shared_ptr<ProjectItemModel> m_projectItemModel;
223
    std::shared_ptr<JobManager> m_jobManager;
Nicolas Carion's avatar
Nicolas Carion committed
224
225
    Bin *m_binWidget{nullptr};
    LibraryWidget *m_library{nullptr};
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
226
    MixerManager *m_mixerWidget{nullptr};
227
228
    /** @brief Current project's profile path */
    QString m_currentProfile;
229

230
    QString m_profile;
231
    std::unique_ptr<Mlt::Profile> m_thumbProfile;
232
233
    /** @brief Mlt profile used in the consumer 's monitors */
    std::unique_ptr<Mlt::Profile> m_projectProfile;
234
    bool m_guiConstructed = false;
235
    /** @brief Check that the profile is valid (width is a multiple of 8 and height a multiple of 2 */
236
    void checkProfileValidity();
237
    std::unique_ptr<MediaCapture> m_capture;
238
    QUrl m_mediaCaptureFile;
239
240
    QMutex m_thumbProfileMutex;

241
242
public slots:
    void triggerAction(const QString &name);
243
244
    /** @brief display a user info/warning message in the project bin */
    void displayBinMessage(const QString &text, int type, const QList<QAction *> &actions = QList<QAction *>());
245
    void displayBinLogMessage(const QString &text, int type, const QString &logInfo);
246
247
    /** @brief Create small thumbnails for luma used in compositions */
    void buildLumaThumbs(const QStringList &values);
248

249
250
signals:
    void coreIsReady();
251
    void updateLibraryPath();
252
    void updateMonitorProfile();
253
254
    /** @brief Call config dialog on a selected page / tab */
    void showConfigDialog(int, int);
255
    void finalizeRecording(const QString &captureFile);
256
    void autoScrollChanged();
257
258
259
};

#endif