Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project_manager.h
1// SPDX-FileCopyrightText: © 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "gui/backend/project_session.h"
7#include "gui/backend/recent_projects_model.h"
8#include "gui/qquick/qfuture_qml_wrapper.h"
9
10#include <QFutureWatcher>
11#include <QtQmlIntegration/qqmlintegration.h>
12
13// DEPRECATED - do not use in new code
14#define PROJECT \
15 (zrythm::gui::ProjectManager::get_instance ()->activeSession ()->project ())
16
17namespace zrythm::gui
18{
19
20class ProjectManager : public QObject
21{
22 Q_OBJECT
23 QML_ELEMENT
24 Q_PROPERTY (
25 zrythm::gui::RecentProjectsModel * recentProjects READ getRecentProjects
26 CONSTANT)
27 Q_PROPERTY (
28 zrythm::gui::ProjectSession * activeSession READ activeSession WRITE
29 setActiveSession NOTIFY activeSessionChanged)
30 QML_UNCREATABLE ("")
31
32public:
33 ProjectManager (utils::AppSettings &app_settings, QObject * parent = nullptr);
34
35 using Template = fs::path;
36 using TemplateList = std::vector<Template>;
37 using ProjectLoadResult =
38 std::variant<utils::QObjectUniquePtr<ProjectSession>, QString>;
39
40 static ProjectManager * get_instance ();
41
45 TemplateList get_templates () const;
46
52 Q_INVOKABLE static QString
53 getNextAvailableProjectName (const QUrl &directory, const QString &name);
54
55 Q_INVOKABLE void createNewProject (
56 const QUrl &directory,
57 const QString &name,
58 const QUrl &templateUrl = QUrl{});
59
67 Q_INVOKABLE qquick::QFutureQmlWrapper * loadProject (const QString &filepath);
68
69 RecentProjectsModel * getRecentProjects () const;
70
71 ProjectSession * activeSession () const;
72 void setActiveSession (ProjectSession * project);
73
74Q_SIGNALS:
75 void projectLoaded (ProjectSession * project);
76 void projectLoadingFailed (const QString &errorMessage);
77 void activeSessionChanged (ProjectSession * project);
78
79private:
83 void init_templates ();
84
85 // void create_or_load_project (const QString &filepath, bool is_template);
86
91 void load_from_file ();
92
105 const fs::path &prj_dir,
106 const utils::Utf8String &name,
107 bool with_engine);
108
114 std::unique_ptr<plugins::IPluginHostWindow>
115 create_window_for_plugin (plugins::Plugin &plugin) const;
116
117private:
118 utils::AppSettings &app_settings_;
119
121 TemplateList templates_;
122
128 Template demo_template_;
129
130 RecentProjectsModel * recent_projects_model_ = nullptr;
131
136
142 QFutureWatcher<ProjectLoadResult> project_watcher_;
143};
144
145}
TemplateList get_templates() const
Gets a copy of the list of project templates.
Q_INVOKABLE qquick::QFutureQmlWrapper * loadProject(const QString &filepath)
Loads a project from the specified directory.
static Q_INVOKABLE QString getNextAvailableProjectName(const QUrl &directory, const QString &name)
Get the next available untitled project name for the given directory.
Composition root for a project session.
QML-exposed wrapper over a QFuture that provides properties for binding.
DSP processing plugin.
Definition plugin.h:30
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38