Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "projectsession.h"
24 :
25 : #include "global/io/fileinfo.h"
26 :
27 : #include "notation/imasternotation.h"
28 : #include "notation/inotation.h"
29 : #include "project/inotationproject.h"
30 :
31 : using namespace mu::project;
32 : using namespace mu::notation;
33 : using namespace muse::async;
34 :
35 0 : ProjectSession::ProjectSession()
36 : {
37 0 : }
38 :
39 0 : void ProjectSession::setProject(const INotationProjectPtr& project)
40 : {
41 0 : if (m_currentProject == project) {
42 0 : return;
43 : }
44 :
45 : //! NOTE Hold the previous project (and its notation) until all the receivers
46 : //! have disconnected from it in the notifications below
47 0 : INotationProjectPtr prevProject = m_currentProject;
48 0 : INotationPtr prevNotation = m_currentNotation;
49 :
50 0 : if (m_currentProject) {
51 0 : fsRestriction()->removeAllowedPathBase("project");
52 : }
53 :
54 0 : m_currentProject = project;
55 :
56 0 : if (m_currentProject) {
57 0 : fsRestriction()->addAllowedPathBase("project", muse::io::dirpath(m_currentProject->path()));
58 :
59 0 : m_currentProject->pathChanged().onNotify(this, [this]() {
60 0 : fsRestriction()->addAllowedPathBase("project", muse::io::dirpath(m_currentProject->path()));
61 0 : });
62 : } else {
63 0 : fsRestriction()->removeAllowedPathBase("project");
64 : }
65 :
66 0 : INotationPtr notation = project ? project->masterNotation()->notation() : nullptr;
67 0 : doSetCurrentNotation(notation);
68 :
69 0 : m_currentProjectChanged.notify();
70 0 : m_currentNotationChanged.notify();
71 0 : }
72 :
73 0 : INotationProjectPtr ProjectSession::project() const
74 : {
75 0 : return m_currentProject;
76 : }
77 :
78 0 : Notification ProjectSession::projectChanged() const
79 : {
80 0 : return m_currentProjectChanged;
81 : }
82 :
83 0 : IMasterNotationPtr ProjectSession::masterNotation() const
84 : {
85 0 : return m_currentProject ? m_currentProject->masterNotation() : nullptr;
86 : }
87 :
88 0 : Notification ProjectSession::masterNotationChanged() const
89 : {
90 : //! NOTE Same as project
91 0 : return m_currentProjectChanged;
92 : }
93 :
94 0 : void ProjectSession::setCurrentNotation(const INotationPtr& notation)
95 : {
96 0 : if (m_currentNotation == notation) {
97 0 : return;
98 : }
99 :
100 : //! NOTE Hold the previous notation until all the receivers
101 : //! have disconnected from it in the notification below
102 0 : INotationPtr prevNotation = m_currentNotation;
103 :
104 0 : doSetCurrentNotation(notation);
105 0 : m_currentNotationChanged.notify();
106 0 : }
107 :
108 0 : INotationPtr ProjectSession::currentNotation() const
109 : {
110 0 : return m_currentNotation;
111 : }
112 :
113 0 : Notification ProjectSession::currentNotationChanged() const
114 : {
115 0 : return m_currentNotationChanged;
116 : }
117 :
118 0 : void ProjectSession::doSetCurrentNotation(const INotationPtr& notation)
119 : {
120 0 : if (m_currentNotation == notation) {
121 0 : return;
122 : }
123 :
124 0 : m_currentNotation = notation;
125 :
126 0 : if (m_currentNotation) {
127 0 : m_currentNotation->setIsOpen(true);
128 : }
129 : }
|