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 "modelwithvoiceandpositionoptions.h"
24 :
25 : #include "engraving/dom/part.h"
26 :
27 : #include "notationscene/notationcommands.h"
28 :
29 : using namespace mu::propertiespanel;
30 : using namespace mu::engraving;
31 : using namespace mu::notation;
32 :
33 0 : ModelWithVoiceAndPositionOptions::ModelWithVoiceAndPositionOptions(QObject* parent,
34 : const muse::modularity::ContextPtr& iocCtx,
35 : IElementRepositoryService* repository,
36 0 : ElementType elementType)
37 0 : : ModelWithStaveCenteringOptions(parent, iocCtx, repository, elementType)
38 : {
39 0 : createProperties();
40 0 : }
41 :
42 0 : void ModelWithVoiceAndPositionOptions::createProperties()
43 : {
44 0 : ModelWithStaveCenteringOptions::createProperties();
45 :
46 0 : m_voiceBasedPosition = buildPropertyItem(Pid::DIRECTION, [this](const mu::engraving::Pid pid, const QVariant& newValue) {
47 0 : onPropertyValueChanged(pid, newValue);
48 0 : updateStaveCenteringFlags();
49 0 : });
50 0 : m_voiceAssignment = buildPropertyItem(Pid::VOICE_ASSIGNMENT);
51 0 : m_voice = buildPropertyItem(Pid::VOICE);
52 0 : updateIsMultiStaffInstrument();
53 0 : }
54 :
55 0 : void ModelWithVoiceAndPositionOptions::loadProperties()
56 : {
57 0 : ModelWithStaveCenteringOptions::loadProperties();
58 :
59 0 : loadPropertyItem(m_voiceBasedPosition);
60 0 : loadPropertyItem(m_voiceAssignment);
61 0 : loadPropertyItem(m_voice);
62 0 : updateIsMultiStaffInstrument();
63 0 : }
64 :
65 0 : void ModelWithVoiceAndPositionOptions::updateIsMultiStaffInstrument()
66 : {
67 0 : bool isMultiStaffInstrument = true;
68 0 : for (EngravingItem* item : m_elementList) {
69 0 : if (item->part()->nstaves() <= 1) {
70 0 : isMultiStaffInstrument = false;
71 0 : break;
72 : }
73 : }
74 :
75 0 : setIsMultiStaffInstrument(isMultiStaffInstrument);
76 0 : }
77 :
78 0 : bool ModelWithVoiceAndPositionOptions::centeringSideIsRelevant(const EngravingItem* item, bool above) const
79 : {
80 : // These items may be placed automatically, in which case either side may end up being the one used
81 0 : const DirectionV itemDirection = item->getProperty(Pid::DIRECTION).value<DirectionV>();
82 0 : return above ? itemDirection != DirectionV::DOWN : itemDirection != DirectionV::UP;
83 : }
84 :
85 0 : PropertyItem* ModelWithVoiceAndPositionOptions::voiceBasedPosition() const
86 : {
87 0 : return m_voiceBasedPosition;
88 : }
89 :
90 0 : PropertyItem* ModelWithVoiceAndPositionOptions::voiceAssignment() const
91 : {
92 0 : return m_voiceAssignment;
93 : }
94 :
95 0 : PropertyItem* ModelWithVoiceAndPositionOptions::voice() const
96 : {
97 0 : return m_voice;
98 : }
99 :
100 0 : bool ModelWithVoiceAndPositionOptions::isMultiStaffInstrument() const
101 : {
102 0 : return m_isMultiStaffInstrument;
103 : }
104 :
105 0 : void ModelWithVoiceAndPositionOptions::setIsMultiStaffInstrument(bool v)
106 : {
107 0 : if (v == m_isMultiStaffInstrument) {
108 0 : return;
109 : }
110 :
111 0 : m_isMultiStaffInstrument = v;
112 0 : emit isMultiStaffInstrumentChanged(m_isMultiStaffInstrument);
113 : }
114 :
115 0 : void ModelWithVoiceAndPositionOptions::changeVoice(int voice)
116 : {
117 0 : if (m_elementList.empty()) {
118 0 : return;
119 : }
120 :
121 0 : beginCommand(TranslatableString("undoableAction", "Change voice"));
122 :
123 0 : for (EngravingItem* item : m_elementList) {
124 0 : IF_ASSERT_FAILED(item) {
125 0 : continue;
126 : }
127 :
128 0 : item->undoChangeProperty(Pid::VOICE_ASSIGNMENT, VoiceAssignment::CURRENT_VOICE_ONLY);
129 0 : item->undoChangeProperty(Pid::VOICE, static_cast<voice_idx_t>(voice));
130 : }
131 :
132 0 : loadPropertyItem(m_voiceAssignment);
133 0 : loadPropertyItem(m_voice);
134 :
135 0 : updateNotation();
136 0 : endCommand();
137 : }
138 :
139 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseVoice1() const
140 : {
141 0 : return shortcutsForCommand(USE_VOICE_1_COMMAND);
142 : }
143 :
144 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseVoice2() const
145 : {
146 0 : return shortcutsForCommand(USE_VOICE_2_COMMAND);
147 : }
148 :
149 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseVoice3() const
150 : {
151 0 : return shortcutsForCommand(USE_VOICE_3_COMMAND);
152 : }
153 :
154 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseVoice4() const
155 : {
156 0 : return shortcutsForCommand(USE_VOICE_4_COMMAND);
157 : }
158 :
159 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseAllVoicesInstrument() const
160 : {
161 0 : return shortcutsForCommand(VOICE_ASSIGNMENT_ALL_IN_INSTR_COMMAND);
162 : }
163 :
164 0 : QString ModelWithVoiceAndPositionOptions::shortcutUseAllVoicesStaff() const
165 : {
166 0 : return shortcutsForCommand(VOICE_ASSIGNMENT_ALL_IN_STAFF_COMMAND);
167 : }
|