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 "noteinputpreferencesmodel.h"
24 :
25 : #include "notationscene/notationcommands.h"
26 :
27 : using namespace mu::preferences;
28 :
29 0 : NoteInputPreferencesModel::NoteInputPreferencesModel(QObject* parent)
30 0 : : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
31 : {
32 0 : }
33 :
34 0 : void NoteInputPreferencesModel::load()
35 : {
36 0 : notationConfiguration()->defaultNoteInputMethodChanged().onNotify(this, [this]() {
37 0 : emit defaultNoteInputMethodChanged(defaultNoteInputMethod());
38 0 : });
39 :
40 0 : notationConfiguration()->addAccidentalDotsArticulationsToNextNoteEnteredChanged().onNotify(this, [this]() {
41 0 : emit addAccidentalDotsArticulationsToNextNoteEnteredChanged(addAccidentalDotsArticulationsToNextNoteEntered());
42 0 : });
43 :
44 0 : notationConfiguration()->useNoteInputCursorInInputByDurationChanged().onNotify(this, [this]() {
45 0 : emit useNoteInputCursorInInputByDurationChanged(useNoteInputCursorInInputByDuration());
46 0 : });
47 :
48 0 : notationConfiguration()->isMidiInputEnabledChanged().onNotify(this, [this]() {
49 0 : emit midiInputEnabledChanged(midiInputEnabled());
50 0 : });
51 :
52 0 : notationConfiguration()->startNoteInputAtSelectedNoteRestWhenPressingMidiKeyChanged().onNotify(this, [this]() {
53 0 : emit startNoteInputAtSelectedNoteRestWhenPressingMidiKeyChanged(startNoteInputAtSelectedNoteRestWhenPressingMidiKey());
54 0 : });
55 :
56 0 : playbackConfiguration()->playNotesWhenEditingChanged().onNotify(this, [this]() {
57 0 : emit playNotesWhenEditingChanged(playNotesWhenEditing());
58 0 : });
59 :
60 0 : playbackConfiguration()->playChordWhenEditingChanged().onReceive(this, [this](bool value) {
61 0 : emit playChordWhenEditingChanged(value);
62 0 : });
63 :
64 0 : playbackConfiguration()->playHarmonyWhenEditingChanged().onReceive(this, [this](bool value) {
65 0 : emit playChordSymbolWhenEditingChanged(value);
66 0 : });
67 :
68 0 : playbackConfiguration()->playNotesOnMidiInputChanged().onReceive(this, [this](bool value) {
69 0 : emit playNotesOnMidiInputChanged(value);
70 0 : });
71 :
72 0 : notationConfiguration()->playPreviewNotesWithScoreDynamicsChanged().onNotify(this, [this]() {
73 0 : emit playPreviewNotesWithScoreDynamicsChanged(playPreviewNotesWithScoreDynamics());
74 0 : });
75 :
76 0 : notationConfiguration()->useMidiVelocityAndDurationDuringNoteInputChanged().onReceive(this, [this](bool value) {
77 0 : emit useMidiVelocityAndDurationDuringNoteInputChanged(value);
78 0 : });
79 :
80 0 : notationConfiguration()->isPlayPreviewNotesInInputByDurationChanged().onNotify(this, [this]() {
81 0 : emit playPreviewNotesInInputByDurationChanged(playPreviewNotesInInputByDuration());
82 0 : });
83 :
84 0 : midiRemoteConfiguration()->advanceToNextNoteOnKeyReleaseChanged().onReceive(this, [this](bool value) {
85 0 : emit advanceToNextNoteOnKeyReleaseChanged(value);
86 0 : });
87 :
88 0 : notationConfiguration()->delayBetweenNotesInRealTimeModeMillisecondsChanged().onReceive(this, [this](int value) {
89 0 : emit delayBetweenNotesInRealTimeModeMillisecondsChanged(value);
90 0 : });
91 :
92 0 : notationConfiguration()->notePlayDurationMillisecondsChanged().onReceive(this, [this](int value) {
93 0 : emit notePlayDurationMillisecondsChanged(value);
94 0 : });
95 :
96 0 : engravingConfiguration()->dynamicsApplyToAllVoicesChanged().onReceive(this, [this](bool value) {
97 0 : emit dynamicsApplyToAllVoicesChanged(value);
98 0 : });
99 :
100 0 : notationConfiguration()->colorNotesOutsideOfUsablePitchRangeChanged().onReceive(this, [this](bool value) {
101 0 : emit colorNotesOutsideOfUsablePitchRangeChanged(value);
102 0 : });
103 :
104 0 : notationConfiguration()->warnGuitarBendsChanged().onReceive(this, [this](bool value) {
105 0 : emit warnGuitarBendsChanged(value);
106 0 : });
107 :
108 0 : engravingConfiguration()->autoUpdateFretboardDiagramsChanged().onReceive(this, [this](bool value) {
109 0 : emit autoUpdateFretboardDiagramsChanged(value);
110 0 : });
111 0 : }
112 :
113 0 : QVariantList NoteInputPreferencesModel::noteInputMethods() const
114 : {
115 : using namespace mu::notation;
116 : using Method = mu::notation::NoteInputMethod;
117 :
118 : std::vector<std::pair<muse::rcommand::Command, Method > > noteInputCommands {
119 0 : { TOGGLE_NOTE_INPUT_BY_NOTE_NAME_COMMAND, Method::BY_NOTE_NAME },
120 0 : { TOGGLE_NOTE_INPUT_BY_DURATION_COMMAND, Method::BY_DURATION },
121 0 : };
122 :
123 0 : QVariantList methods;
124 :
125 0 : for (const auto& pair : noteInputCommands) {
126 0 : const muse::rcommand::CommandInfo& commandInfo = commandsRegister()->commandInfo(pair.first);
127 :
128 0 : QVariantMap method;
129 0 : method["value"] = static_cast<int>(pair.second);
130 0 : method["text"] = commandInfo.title.qTranslatedWithoutMnemonic();
131 :
132 0 : methods.emplace_back(std::move(method));
133 0 : }
134 :
135 0 : return methods;
136 0 : }
137 :
138 0 : int NoteInputPreferencesModel::defaultNoteInputMethod() const
139 : {
140 0 : return static_cast<int>(notationConfiguration()->defaultNoteInputMethod());
141 : }
142 :
143 0 : bool NoteInputPreferencesModel::addAccidentalDotsArticulationsToNextNoteEntered() const
144 : {
145 0 : return notationConfiguration()->addAccidentalDotsArticulationsToNextNoteEntered();
146 : }
147 :
148 0 : bool NoteInputPreferencesModel::useNoteInputCursorInInputByDuration() const
149 : {
150 0 : return notationConfiguration()->useNoteInputCursorInInputByDuration();
151 : }
152 :
153 0 : bool NoteInputPreferencesModel::midiInputEnabled() const
154 : {
155 0 : return notationConfiguration()->isMidiInputEnabled();
156 : }
157 :
158 0 : bool NoteInputPreferencesModel::startNoteInputAtSelectedNoteRestWhenPressingMidiKey() const
159 : {
160 0 : return notationConfiguration()->startNoteInputAtSelectedNoteRestWhenPressingMidiKey();
161 : }
162 :
163 0 : bool NoteInputPreferencesModel::advanceToNextNoteOnKeyRelease() const
164 : {
165 0 : return midiRemoteConfiguration()->advanceToNextNoteOnKeyRelease();
166 : }
167 :
168 0 : int NoteInputPreferencesModel::delayBetweenNotesInRealTimeModeMilliseconds() const
169 : {
170 0 : return notationConfiguration()->delayBetweenNotesInRealTimeModeMilliseconds();
171 : }
172 :
173 0 : bool NoteInputPreferencesModel::playNotesWhenEditing() const
174 : {
175 0 : return playbackConfiguration()->playNotesWhenEditing();
176 : }
177 :
178 0 : bool NoteInputPreferencesModel::playPreviewNotesInInputByDuration() const
179 : {
180 0 : return notationConfiguration()->isPlayPreviewNotesInInputByDuration();
181 : }
182 :
183 0 : int NoteInputPreferencesModel::notePlayDurationMilliseconds() const
184 : {
185 0 : return notationConfiguration()->notePlayDurationMilliseconds();
186 : }
187 :
188 0 : bool NoteInputPreferencesModel::playChordWhenEditing() const
189 : {
190 0 : return playbackConfiguration()->playChordWhenEditing();
191 : }
192 :
193 0 : bool NoteInputPreferencesModel::playChordSymbolWhenEditing() const
194 : {
195 0 : return playbackConfiguration()->playHarmonyWhenEditing();
196 : }
197 :
198 0 : bool NoteInputPreferencesModel::playPreviewNotesWithScoreDynamics() const
199 : {
200 0 : return notationConfiguration()->playPreviewNotesWithScoreDynamics();
201 : }
202 :
203 0 : bool NoteInputPreferencesModel::playNotesOnMidiInput() const
204 : {
205 0 : return playbackConfiguration()->playNotesOnMidiInput();
206 : }
207 :
208 0 : bool NoteInputPreferencesModel::useMidiVelocityAndDurationDuringNoteInput() const
209 : {
210 0 : return notationConfiguration()->useMidiVelocityAndDurationDuringNoteInput();
211 : }
212 :
213 0 : bool NoteInputPreferencesModel::dynamicsApplyToAllVoices() const
214 : {
215 0 : return engravingConfiguration()->dynamicsApplyToAllVoices();
216 : }
217 :
218 0 : bool NoteInputPreferencesModel::colorNotesOutsideOfUsablePitchRange() const
219 : {
220 0 : return notationConfiguration()->colorNotesOutsideOfUsablePitchRange();
221 : }
222 :
223 0 : bool NoteInputPreferencesModel::warnGuitarBends() const
224 : {
225 0 : return notationConfiguration()->warnGuitarBends();
226 : }
227 :
228 0 : void NoteInputPreferencesModel::setDefaultNoteInputMethod(int value)
229 : {
230 0 : if (value == defaultNoteInputMethod()) {
231 0 : return;
232 : }
233 :
234 0 : notationConfiguration()->setDefaultNoteInputMethod(static_cast<mu::notation::NoteInputMethod>(value));
235 : }
236 :
237 0 : void NoteInputPreferencesModel::setAddAccidentalDotsArticulationsToNextNoteEntered(bool value)
238 : {
239 0 : if (value == addAccidentalDotsArticulationsToNextNoteEntered()) {
240 0 : return;
241 : }
242 :
243 0 : notationConfiguration()->setAddAccidentalDotsArticulationsToNextNoteEntered(value);
244 : }
245 :
246 0 : void NoteInputPreferencesModel::setUseNoteInputCursorInInputByDuration(bool value)
247 : {
248 0 : if (value == useNoteInputCursorInInputByDuration()) {
249 0 : return;
250 : }
251 :
252 0 : notationConfiguration()->setUseNoteInputCursorInInputByDuration(value);
253 : }
254 :
255 0 : void NoteInputPreferencesModel::setMidiInputEnabled(bool value)
256 : {
257 0 : if (value == midiInputEnabled()) {
258 0 : return;
259 : }
260 :
261 0 : notationConfiguration()->setIsMidiInputEnabled(value);
262 : }
263 :
264 0 : void NoteInputPreferencesModel::setStartNoteInputAtSelectedNoteRestWhenPressingMidiKey(bool value)
265 : {
266 0 : if (value == startNoteInputAtSelectedNoteRestWhenPressingMidiKey()) {
267 0 : return;
268 : }
269 :
270 0 : notationConfiguration()->setStartNoteInputAtSelectedNoteRestWhenPressingMidiKey(value);
271 : }
272 :
273 0 : void NoteInputPreferencesModel::setAdvanceToNextNoteOnKeyRelease(bool value)
274 : {
275 0 : if (value == advanceToNextNoteOnKeyRelease()) {
276 0 : return;
277 : }
278 :
279 0 : midiRemoteConfiguration()->setAdvanceToNextNoteOnKeyRelease(value);
280 : }
281 :
282 0 : void NoteInputPreferencesModel::setDelayBetweenNotesInRealTimeModeMilliseconds(int delay)
283 : {
284 0 : if (delay == delayBetweenNotesInRealTimeModeMilliseconds()) {
285 0 : return;
286 : }
287 :
288 0 : notationConfiguration()->setDelayBetweenNotesInRealTimeModeMilliseconds(delay);
289 : }
290 :
291 0 : void NoteInputPreferencesModel::setPlayNotesWhenEditing(bool value)
292 : {
293 0 : if (value == playNotesWhenEditing()) {
294 0 : return;
295 : }
296 :
297 0 : playbackConfiguration()->setPlayNotesWhenEditing(value);
298 : }
299 :
300 0 : void NoteInputPreferencesModel::setPlayPreviewNotesInInputByDuration(bool value)
301 : {
302 0 : if (value == playPreviewNotesInInputByDuration()) {
303 0 : return;
304 : }
305 :
306 0 : notationConfiguration()->setIsPlayPreviewNotesInInputByDuration(value);
307 : }
308 :
309 0 : void NoteInputPreferencesModel::setNotePlayDurationMilliseconds(int duration)
310 : {
311 0 : if (duration == notePlayDurationMilliseconds()) {
312 0 : return;
313 : }
314 :
315 0 : notationConfiguration()->setNotePlayDurationMilliseconds(duration);
316 : }
317 :
318 0 : void NoteInputPreferencesModel::setPlayChordWhenEditing(bool value)
319 : {
320 0 : if (value == playChordWhenEditing()) {
321 0 : return;
322 : }
323 :
324 0 : playbackConfiguration()->setPlayChordWhenEditing(value);
325 : }
326 :
327 0 : void NoteInputPreferencesModel::setPlayChordSymbolWhenEditing(bool value)
328 : {
329 0 : if (value == playChordSymbolWhenEditing()) {
330 0 : return;
331 : }
332 :
333 0 : playbackConfiguration()->setPlayHarmonyWhenEditing(value);
334 : }
335 :
336 0 : void NoteInputPreferencesModel::setPlayPreviewNotesWithScoreDynamics(bool play)
337 : {
338 0 : if (play == playPreviewNotesWithScoreDynamics()) {
339 0 : return;
340 : }
341 :
342 0 : notationConfiguration()->setPlayPreviewNotesWithScoreDynamics(play);
343 : }
344 :
345 0 : void NoteInputPreferencesModel::setPlayNotesOnMidiInput(bool value)
346 : {
347 0 : if (value == playNotesOnMidiInput()) {
348 0 : return;
349 : }
350 :
351 0 : playbackConfiguration()->setPlayNotesOnMidiInput(value);
352 : }
353 :
354 0 : void NoteInputPreferencesModel::setUseMidiVelocityAndDurationDuringNoteInput(bool value)
355 : {
356 0 : if (value == useMidiVelocityAndDurationDuringNoteInput()) {
357 0 : return;
358 : }
359 :
360 0 : notationConfiguration()->setUseMidiVelocityAndDurationDuringNoteInput(value);
361 : }
362 :
363 0 : void NoteInputPreferencesModel::setDynamicsApplyToAllVoices(bool value)
364 : {
365 0 : if (value == dynamicsApplyToAllVoices()) {
366 0 : return;
367 : }
368 :
369 0 : engravingConfiguration()->setDynamicsApplyToAllVoices(value);
370 : }
371 :
372 0 : void NoteInputPreferencesModel::setColorNotesOutsideOfUsablePitchRange(bool value)
373 : {
374 0 : if (value == colorNotesOutsideOfUsablePitchRange()) {
375 0 : return;
376 : }
377 :
378 0 : notationConfiguration()->setColorNotesOutsideOfUsablePitchRange(value);
379 : }
380 :
381 0 : void NoteInputPreferencesModel::setWarnGuitarBends(bool value)
382 : {
383 0 : if (value == warnGuitarBends()) {
384 0 : return;
385 : }
386 :
387 0 : notationConfiguration()->setWarnGuitarBends(value);
388 : }
389 :
390 0 : bool NoteInputPreferencesModel::autoUpdateFretboardDiagrams() const
391 : {
392 0 : return engravingConfiguration()->autoUpdateFretboardDiagrams();
393 : }
394 :
395 0 : void NoteInputPreferencesModel::setAutoUpdateFretboardDiagrams(bool value)
396 : {
397 0 : if (value == autoUpdateFretboardDiagrams()) {
398 0 : return;
399 : }
400 :
401 0 : engravingConfiguration()->setAutoUpdateFretboardDiagrams(value);
402 : }
|