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) 2026 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 : #include "notationcommandsstate.h"
23 :
24 : #include "global/containers.h"
25 :
26 : #include "../notationcommands.h"
27 : #include "rcommand/commandtypes.h"
28 :
29 : using namespace muse;
30 : using namespace muse::rcommand;
31 : using namespace mu::notation;
32 : using namespace mu::engraving;
33 :
34 : static const muse::Uri PROJECT_PAGE_URI("musescore://notation");
35 :
36 : template<typename Map>
37 0 : static inline auto commands(const Map& m) -> std::vector<typename Map::key_type>
38 : {
39 0 : std::vector<typename Map::key_type> result;
40 0 : result.reserve(m.size());
41 0 : for (const auto& p : m) {
42 0 : result.push_back(p.first);
43 : }
44 0 : return result;
45 0 : }
46 :
47 : static const std::vector<Command> HAS_SELECTION_REQUIRED_COMMANDS = {
48 : CutCommand::id,
49 : CopyCommand::id,
50 : CopyPasteSwapCommand::id,
51 : DeleteCommand::id,
52 : FlipCommand::id,
53 : FLIP_HORIZONTALLY_COMMAND,
54 : SelectNextSegmentCommand::id,
55 : SelectPrevSegmentCommand::id,
56 : SelectUpNoteInChordCommand::id,
57 : SelectDownNoteInChordCommand::id,
58 : SelectTopNoteInChordCommand::id,
59 : SelectBottomNoteInChordCommand::id,
60 : SelectSimilarCommand::id,
61 : SelectSimilarInStaffCommand::id,
62 : SelectSimilarInRangeCommand::id,
63 : SelectNotesInChordCommand::id,
64 : OpenSelectionOptionsCommand::id,
65 : ChangeDurationCommand::id,
66 : ChangeDurationDoubleCommand::id,
67 : ChangeDurationHalveCommand::id,
68 : ChangeDurationDoubleDottedCommand::id,
69 : ChangeDurationHalveDottedCommand::id,
70 : TOGGLE_SNAP_TO_PREV_COMMAND,
71 : TOGGLE_SNAP_TO_NEXT_COMMAND,
72 : MIRROR_NOTEHEAD_COMMAND,
73 : MOVE_UP_COMMAND,
74 : MOVE_DOWN_COMMAND,
75 : INCREASE_DYNAMIC_COMMAND,
76 : DECREASE_DYNAMIC_COMMAND
77 : };
78 :
79 : static const std::vector<Command> UNDO_REDO_COMMANDS = {
80 : UndoCommand::id,
81 : RedoCommand::id
82 : };
83 :
84 : static const std::vector<Command> TEXT_EDITING_COMMANDS = {
85 : EDITTEXT_TOGGLE_BOLD_COMMAND,
86 : EDITTEXT_TOGGLE_ITALIC_COMMAND,
87 : EDITTEXT_TOGGLE_UNDERLINE_COMMAND,
88 : EDITTEXT_TOGGLE_STRIKE_COMMAND,
89 : EDITTEXT_TOGGLE_SUBSCRIPT_COMMAND,
90 : EDITTEXT_TOGGLE_SUPERSCRIPT_COMMAND,
91 : EDITTEXT_NEXT_ELEMENT_COMMAND,
92 : EDITTEXT_PREV_ELEMENT_COMMAND,
93 : EDITTEXT_NEXT_WORD_COMMAND,
94 : EDITTEXT_NEXT_BEAT_COMMAND,
95 : EDITTEXT_PREV_BEAT_COMMAND,
96 : EditTextAdvanceLongaCommand::id,
97 : EditTextAdvanceBreveCommand::id,
98 : EditTextAdvance1Command::id,
99 : EditTextAdvance2Command::id,
100 : EditTextAdvance4Command::id,
101 : EditTextAdvance8Command::id,
102 : EditTextAdvance16Command::id,
103 : EditTextAdvance32Command::id,
104 : EditTextAdvance64Command::id,
105 : };
106 :
107 : static const std::vector<Command> LYRICS_EDITING_COMMANDS = {
108 : EDITLYRIC_NEXT_VERSE_COMMAND,
109 : EDITLYRIC_PREV_VERSE_COMMAND,
110 : EDITLYRIC_NEXT_SYLLABLE_COMMAND,
111 : EDITLYRIC_ADD_MELISMA_COMMAND,
112 : EDITLYRIC_ADD_VERSE_COMMAND
113 : };
114 :
115 : static const std::vector<Command> NOT_TEXT_EDITING_COMMANDS = {
116 : TOGGLE_MMREST_COMMAND,
117 : };
118 :
119 : static const std::vector<Command> NOTE_INPUT_COMMANDS = {
120 : ToggleNoteInputCommand::id,
121 : ToggleNoteInputDefaultCommand::id,
122 : ToggleNoteInputByNameCommand::id,
123 : ToggleNoteInputByDurationCommand::id,
124 : ToggleNoteInputRhythmCommand::id,
125 : ToggleNoteInputRepitchCommand::id,
126 : ToggleNoteInputRealtimeAutoCommand::id,
127 : ToggleNoteInputRealtimeManualCommand::id,
128 : ToggleNoteInputTimewiseCommand::id,
129 : ToggleInsertModeCommand::id
130 : };
131 :
132 : static const std::map<Command, NoteInputMethod> NOTE_INPUT_METHODS = {
133 : { ToggleNoteInputDefaultCommand::id, NoteInputMethod::DEFAULT },
134 : { ToggleNoteInputByNameCommand::id, NoteInputMethod::BY_NOTE_NAME },
135 : { ToggleNoteInputByDurationCommand::id, NoteInputMethod::BY_DURATION },
136 : { ToggleNoteInputRhythmCommand::id, NoteInputMethod::RHYTHM },
137 : { ToggleNoteInputRepitchCommand::id, NoteInputMethod::REPITCH },
138 : { ToggleNoteInputRealtimeAutoCommand::id, NoteInputMethod::REALTIME_AUTO },
139 : { ToggleNoteInputRealtimeManualCommand::id, NoteInputMethod::REALTIME_MANUAL },
140 : { ToggleNoteInputTimewiseCommand::id, NoteInputMethod::TIMEWISE }
141 : };
142 :
143 : static const std::map<Command, DurationType> DURATION_COMMANDS = {
144 : { SetDurationLongaCommand::id, DurationType::V_LONG },
145 : { SetDurationBreveCommand::id, DurationType::V_BREVE },
146 : { SetDurationWholeCommand::id, DurationType::V_WHOLE },
147 : { SetDurationHalfCommand::id, DurationType::V_HALF },
148 : { SetDurationQuarterCommand::id, DurationType::V_QUARTER },
149 : { SetDurationEighthCommand::id, DurationType::V_EIGHTH },
150 : { SetDuration16thCommand::id, DurationType::V_16TH },
151 : { SetDuration32ndCommand::id, DurationType::V_32ND },
152 : { SetDuration64thCommand::id, DurationType::V_64TH },
153 : { SetDuration128thCommand::id, DurationType::V_128TH },
154 : { SetDuration256thCommand::id, DurationType::V_256TH },
155 : { SetDuration512thCommand::id, DurationType::V_512TH },
156 : { SetDuration1024thCommand::id, DurationType::V_1024TH }
157 : };
158 :
159 : static const std::map<Command, int> DOT_COUNT_COMMANDS = {
160 : { ToggleDotCommand::id, 1 },
161 : { ToggleDot2Command::id, 2 },
162 : { ToggleDot3Command::id, 3 },
163 : { ToggleDot4Command::id, 4 }
164 : };
165 :
166 : static const std::map<Command, AccidentalType> ACCIDENTAL_COMMANDS = {
167 : { ToggleFlat2Command::id, AccidentalType::FLAT2 },
168 : { ToggleFlatCommand::id, AccidentalType::FLAT },
169 : { ToggleNaturalCommand::id, AccidentalType::NATURAL },
170 : { ToggleSharpCommand::id, AccidentalType::SHARP },
171 : { ToggleSharp2Command::id, AccidentalType::SHARP2 }
172 : };
173 :
174 : static const std::vector<Command> ADD_COMMANDS = {
175 : TOGGLE_TIE_COMMAND,
176 : ADD_SLUR_COMMAND,
177 : TOGGLE_LV_COMMAND
178 : };
179 :
180 : static const std::map<Command, SymId> ADD_ARTICULATION_COMMANDS = {
181 : { TOGGLE_MARCATO_COMMAND, SymId::articMarcatoAbove },
182 : { TOGGLE_SFORZATO_COMMAND, SymId::articAccentAbove },
183 : { TOGGLE_TENUTO_COMMAND, SymId::articTenutoAbove },
184 : { TOGGLE_STACCATO_COMMAND, SymId::articStaccatoAbove }
185 : };
186 :
187 : static const std::map<Command, voice_idx_t> VOICE_COMMANDS = {
188 : { UseVoice1Command::id, 0 },
189 : { UseVoice2Command::id, 1 },
190 : { UseVoice3Command::id, 2 },
191 : { UseVoice4Command::id, 3 }
192 : };
193 :
194 : static const std::vector<Command> NOTE_COMMANDS = {
195 : AddNoteCommand::id,
196 : AddNoteC_ToNextChordCommand::id,
197 : AddNoteD_ToNextChordCommand::id,
198 : AddNoteE_ToNextChordCommand::id,
199 : AddNoteF_ToNextChordCommand::id,
200 : AddNoteG_ToNextChordCommand::id,
201 : AddNoteA_ToNextChordCommand::id,
202 : AddNoteB_ToNextChordCommand::id,
203 : ENTER_REST_COMMAND,
204 : AddNoteC_ToCurrentChordCommand::id,
205 : AddNoteD_ToCurrentChordCommand::id,
206 : AddNoteE_ToCurrentChordCommand::id,
207 : AddNoteF_ToCurrentChordCommand::id,
208 : AddNoteG_ToCurrentChordCommand::id,
209 : AddNoteA_ToCurrentChordCommand::id,
210 : AddNoteB_ToCurrentChordCommand::id,
211 : AddNoteC_ToInsertChordCommand::id,
212 : AddNoteD_ToInsertChordCommand::id,
213 : AddNoteE_ToInsertChordCommand::id,
214 : AddNoteF_ToInsertChordCommand::id,
215 : AddNoteG_ToInsertChordCommand::id,
216 : AddNoteA_ToInsertChordCommand::id,
217 : AddNoteB_ToInsertChordCommand::id
218 : };
219 :
220 : static const std::vector<Command> TUPLET_COMMANDS = {
221 : OpenTupletConfigureCommand::id,
222 : AddTupletCommand::id,
223 : AddDupletCommand::id,
224 : AddTripletCommand::id,
225 : AddQuadrupletCommand::id,
226 : AddQuintupletCommand::id,
227 : AddSextupletCommand::id,
228 : AddSeptupletCommand::id,
229 : AddOctupletCommand::id,
230 : AddNonupletCommand::id,
231 : };
232 :
233 : static const std::vector<Command> NOTE_OR_REST_SELECTED_COMMANDS = {
234 : ADD_DYNAMIC_COMMAND,
235 : ADD_HAIRPIN_COMMAND,
236 : ADD_HAIRPIN_REVERSE_COMMAND
237 : };
238 :
239 : static const std::map<Command, MoveSelectionType> MOVE_SELECTION_COMMANDS = {
240 : { SelectFirstItemCommand::id, MoveSelectionType::EngravingItem },
241 : { SelectLastItemCommand::id, MoveSelectionType::EngravingItem },
242 : { SelectNextItemCommand::id, MoveSelectionType::EngravingItem },
243 : { SelectPrevItemCommand::id, MoveSelectionType::EngravingItem },
244 : { SelectNextTrackCommand::id, MoveSelectionType::Track },
245 : { SelectPrevTrackCommand::id, MoveSelectionType::Track },
246 : { SelectNextFrameCommand::id, MoveSelectionType::Frame },
247 : { SelectPrevFrameCommand::id, MoveSelectionType::Frame },
248 : { SelectNextSystemCommand::id, MoveSelectionType::System },
249 : { SelectPrevSystemCommand::id, MoveSelectionType::System }
250 : };
251 :
252 : static const std::vector<Command> LAYOUT_BREAK_COMMANDS = {
253 : TOGGLE_SYSTEM_BREAK_COMMAND,
254 : TOGGLE_PAGE_BREAK_COMMAND,
255 : TOGGLE_SECTION_BREAK_COMMAND
256 : };
257 :
258 : static const std::map<Command, ScoreConfigType> SCORE_CONFIG_COMMANDS = {
259 : { SHOW_INVISIBLE_COMMAND, ScoreConfigType::ShowInvisibleElements },
260 : { SHOW_UNPRINTABLE_COMMAND, ScoreConfigType::ShowUnprintableElements },
261 : { SHOW_FRAMES_COMMAND, ScoreConfigType::ShowFrames },
262 : { SHOW_PAGEBORDERS_COMMAND, ScoreConfigType::ShowPageMargins },
263 : { SHOW_SOUNDFLAGS_COMMAND, ScoreConfigType::ShowSoundFlags },
264 : { SHOW_IRREGULAR_COMMAND, ScoreConfigType::MarkIrregularMeasures }
265 : };
266 :
267 : static const std::vector<Command> STYLE_COMMANDS = {
268 : TOGGLE_CONCERT_PITCH_COMMAND
269 : };
270 :
271 : static const std::vector<Command> TAB_COMMANDS = {
272 : SET_DURATION_WHOLE_TAB_COMMAND,
273 : SET_DURATION_HALF_TAB_COMMAND,
274 : SET_DURATION_QUARTER_TAB_COMMAND,
275 : SET_DURATION_EIGHTH_TAB_COMMAND,
276 : SET_DURATION_16TH_TAB_COMMAND,
277 : SET_DURATION_32ND_TAB_COMMAND,
278 : SET_DURATION_64TH_TAB_COMMAND,
279 : SET_DURATION_128TH_TAB_COMMAND,
280 : SET_DURATION_256TH_TAB_COMMAND,
281 : SET_DURATION_512TH_TAB_COMMAND,
282 : SET_DURATION_1024TH_TAB_COMMAND,
283 : ENTER_REST_TAB_COMMAND,
284 : AddFret0Command::id,
285 : AddFret1Command::id,
286 : AddFret2Command::id,
287 : AddFret3Command::id,
288 : AddFret4Command::id,
289 : AddFret5Command::id,
290 : AddFret6Command::id,
291 : AddFret7Command::id,
292 : AddFret8Command::id,
293 : AddFret9Command::id,
294 : AddFret10Command::id,
295 : AddFret11Command::id,
296 : AddFret12Command::id,
297 : AddFret13Command::id,
298 : AddFret14Command::id,
299 : GOTO_STRING_ABOVE_COMMAND,
300 : GOTO_STRING_BELOW_COMMAND
301 : };
302 :
303 : static const std::vector<Command> DEBUG_COMMANDS = {
304 : SHOW_ELEMENT_BOUNDING_RECTS_COMMAND,
305 : COLOR_ELEMENT_SHAPES_COMMAND,
306 : SHOW_SEGMENT_SHAPES_COMMAND,
307 : COLOR_SEGMENT_SHAPES_COMMAND,
308 : SHOW_SKYLINES_COMMAND,
309 : SHOW_SYSTEM_BOUNDING_RECTS_COMMAND,
310 : SHOW_ELEMENT_MASKS_COMMAND,
311 : SHOW_LINE_ATTACH_POINTS_COMMAND,
312 : MARK_EMPTY_STAFF_COMMAND,
313 : MARK_CORRUPTED_MEASURES_COMMAND,
314 : SHOW_GAP_RESTS_COMMAND,
315 : SHOW_ORIGIN_AND_COMBINED_COMMAND,
316 : };
317 :
318 0 : std::string NotationCommandsState::moduleName() const
319 : {
320 0 : return "notation";
321 : }
322 :
323 0 : void NotationCommandsState::init()
324 : {
325 0 : m_moduleRegister = commandsRegister()->moduleRegister(moduleName());
326 0 : IF_ASSERT_FAILED(m_moduleRegister) {
327 0 : return;
328 : }
329 :
330 0 : projectSession()->projectChanged().onNotify(this, [this]() {
331 0 : updateCommandStates();
332 0 : });
333 :
334 0 : if (interactive()) {
335 0 : interactive()->opened().onReceive(this, [this](const muse::Uri&) {
336 0 : updateCommandStates();
337 0 : });
338 : }
339 :
340 0 : controller()->selectionChanged().onNotify(this, [this]() {
341 0 : updateCommandStates(HAS_SELECTION_REQUIRED_COMMANDS);
342 0 : updateCommandStates(ADD_COMMANDS);
343 0 : updateCommandStates({ ToggleRestCommand::id });
344 0 : updateCommandStates(commands(VOICE_COMMANDS));
345 0 : updateCommandStates(NOTE_OR_REST_SELECTED_COMMANDS);
346 0 : updateCommandStates(TUPLET_COMMANDS);
347 0 : updateCommandStates(commands(MOVE_SELECTION_COMMANDS));
348 0 : updateCommandStates(LAYOUT_BREAK_COMMANDS);
349 0 : updateCommandStates(TAB_COMMANDS);
350 0 : });
351 :
352 0 : controller()->stackChanged().onNotify(this, [this]() {
353 0 : updateCommandStates(UNDO_REDO_COMMANDS);
354 0 : });
355 :
356 0 : controller()->textEditingChanged().onReceive(this, [this](bool) {
357 0 : updateCommandStates(TEXT_EDITING_COMMANDS);
358 0 : updateCommandStates(LYRICS_EDITING_COMMANDS);
359 0 : updateCommandStates(LAYOUT_BREAK_COMMANDS);
360 0 : updateCommandStates(NOT_TEXT_EDITING_COMMANDS);
361 0 : });
362 :
363 0 : controller()->isNoteInputAllowedChanged().onReceive(this, [this](bool) {
364 0 : updateCommandStates(NOTE_INPUT_COMMANDS);
365 0 : });
366 :
367 0 : controller()->noteInputStateChanged().onNotify(this, [this]() {
368 0 : updateCommandStates(NOTE_INPUT_COMMANDS);
369 0 : updateCommandStates(commands(DURATION_COMMANDS));
370 0 : updateCommandStates(commands(DOT_COUNT_COMMANDS));
371 0 : updateCommandStates({ ToggleRestCommand::id });
372 0 : updateCommandStates(commands(ACCIDENTAL_COMMANDS));
373 0 : updateCommandStates({ REALTIME_ADVANCE_COMMAND });
374 0 : updateCommandStates(ADD_COMMANDS);
375 0 : updateCommandStates(commands(ADD_ARTICULATION_COMMANDS));
376 0 : updateCommandStates(commands(VOICE_COMMANDS));
377 0 : updateCommandStates(NOTE_COMMANDS);
378 0 : updateCommandStates(NOTE_OR_REST_SELECTED_COMMANDS);
379 0 : updateCommandStates(TUPLET_COMMANDS);
380 0 : updateCommandStates(TAB_COMMANDS);
381 0 : });
382 :
383 0 : controller()->scoreConfigChanged().onReceive(this, [this](ScoreConfigType configType) {
384 0 : updateCommandStates({ muse::key(SCORE_CONFIG_COMMANDS, configType) });
385 0 : });
386 :
387 0 : controller()->notationStyleChanged().onNotify(this, [this]() {
388 0 : updateCommandStates(STYLE_COMMANDS);
389 0 : });
390 :
391 0 : controller()->automationModeEnabledChanged().onNotify(this, [this]() {
392 0 : updateCommandStates({ TOGGLE_AUTOMATION_COMMAND });
393 0 : });
394 :
395 0 : controller()->debuggingOptionsChanged().onNotify(this, [this]() {
396 0 : updateCommandStates(DEBUG_COMMANDS);
397 0 : });
398 :
399 0 : updateCommandStates();
400 : }
401 :
402 0 : void NotationCommandsState::deinit()
403 : {
404 0 : projectSession()->projectChanged().disconnect(this);
405 0 : if (interactive()) {
406 0 : interactive()->opened().disconnect(this);
407 : }
408 0 : controller()->selectionChanged().disconnect(this);
409 0 : controller()->stackChanged().disconnect(this);
410 0 : controller()->textEditingChanged().disconnect(this);
411 0 : controller()->isNoteInputAllowedChanged().disconnect(this);
412 0 : controller()->noteInputStateChanged().disconnect(this);
413 0 : controller()->scoreConfigChanged().disconnect(this);
414 0 : controller()->notationStyleChanged().disconnect(this);
415 0 : controller()->automationModeEnabledChanged().disconnect(this);
416 0 : controller()->debuggingOptionsChanged().disconnect(this);
417 0 : }
418 :
419 0 : void NotationCommandsState::updateCommandStates(const std::vector<Command>& commands)
420 : {
421 0 : IF_ASSERT_FAILED(m_moduleRegister) {
422 0 : return;
423 : }
424 :
425 0 : const auto& commandList = commands.empty() ? m_moduleRegister->commandList() : commands;
426 :
427 0 : for (const auto& command : commandList) {
428 0 : CommandState newState = commandState(command);
429 0 : if (m_commandStates[command] != newState) {
430 0 : m_commandStates[command] = newState;
431 0 : m_commandStateChanged.send(command, newState);
432 : }
433 : }
434 : }
435 :
436 0 : CommandState NotationCommandsState::doCommandState(const Command& command) const
437 : {
438 0 : if (!isProjectOpened()) {
439 0 : return CommandState(false, false);
440 : }
441 :
442 0 : if (muse::contains(HAS_SELECTION_REQUIRED_COMMANDS, command)) {
443 0 : return CommandState(controller()->hasSelection(), false);
444 : }
445 :
446 0 : if (muse::contains(MOVE_SELECTION_COMMANDS, command)) {
447 0 : return CommandState(controller()->isMoveSelectionAvailable(MOVE_SELECTION_COMMANDS.at(command)), false);
448 : }
449 :
450 0 : if (command == UndoCommand::id) {
451 0 : return CommandState(controller()->canUndo(), false);
452 : }
453 0 : if (command == RedoCommand::id) {
454 0 : return CommandState(controller()->canRedo(), false);
455 : }
456 :
457 0 : if (muse::contains(NOTE_COMMANDS, command)) {
458 0 : return CommandState(controller()->isNoteInputActionAllowed(), false);
459 : }
460 :
461 0 : if (muse::contains(TEXT_EDITING_COMMANDS, command)) {
462 0 : return CommandState(controller()->isTextEditing(), false);
463 : }
464 :
465 0 : if (muse::contains(LYRICS_EDITING_COMMANDS, command)) {
466 0 : return CommandState(controller()->isLyricsEditing(), false);
467 : }
468 :
469 0 : if (muse::contains(NOT_TEXT_EDITING_COMMANDS, command)) {
470 0 : return CommandState(!controller()->isTextEditing(), false);
471 : }
472 :
473 0 : if (muse::contains(NOTE_INPUT_COMMANDS, command)) {
474 0 : if (muse::contains(NOTE_INPUT_METHODS, command)) {
475 0 : return CommandState(controller()->isNoteInputAllowed(),
476 0 : controller()->isNoteInputMode()
477 0 : && controller()->noteInputMethod() == NOTE_INPUT_METHODS.at(command));
478 : } else {
479 0 : return CommandState(controller()->isNoteInputAllowed(), false);
480 : }
481 : }
482 :
483 0 : if (muse::contains(DURATION_COMMANDS, command)) {
484 0 : return CommandState(true, controller()->currentDurationType() == DURATION_COMMANDS.at(command));
485 : }
486 :
487 0 : if (muse::contains(DOT_COUNT_COMMANDS, command)) {
488 0 : return CommandState(true, controller()->currentDotCount() == DOT_COUNT_COMMANDS.at(command));
489 : }
490 :
491 0 : if (command == ToggleRestCommand::id) {
492 0 : return CommandState(true, controller()->currentIsRest());
493 : }
494 :
495 0 : if (muse::contains(ACCIDENTAL_COMMANDS, command)) {
496 0 : return CommandState(true, controller()->currentAccidentalType() == ACCIDENTAL_COMMANDS.at(command));
497 : }
498 :
499 0 : if (command == TOGGLE_TIE_COMMAND) {
500 0 : return CommandState(true, controller()->selectionHasTie());
501 : }
502 0 : if (command == ADD_SLUR_COMMAND) {
503 0 : return CommandState(true, controller()->selectionHasSlur());
504 : }
505 0 : if (command == TOGGLE_LV_COMMAND) {
506 0 : return CommandState(true, controller()->selectionHasLaissezVib());
507 : }
508 :
509 0 : if (muse::contains(ADD_ARTICULATION_COMMANDS, command)) {
510 0 : return CommandState(true, controller()->currentArticulations().contains(ADD_ARTICULATION_COMMANDS.at(command)));
511 : }
512 :
513 0 : if (muse::contains(VOICE_COMMANDS, command)) {
514 0 : return CommandState(true, controller()->currentVoice() == VOICE_COMMANDS.at(command));
515 : }
516 :
517 0 : if (command == ADD_DYNAMIC_COMMAND) {
518 0 : return CommandState(controller()->isNoteOrRestSelected() || controller()->isHairpinSelected(), false);
519 : }
520 :
521 0 : if (muse::contains(NOTE_OR_REST_SELECTED_COMMANDS, command)) {
522 0 : return CommandState(controller()->isNoteOrRestSelected(), false);
523 : }
524 :
525 0 : if (muse::contains(TUPLET_COMMANDS, command)) {
526 : // Re-pitch must not change durations
527 0 : const bool isRepitch = controller()->isNoteInputMode() && controller()->noteInputMethod() == NoteInputMethod::REPITCH;
528 0 : return CommandState(controller()->isNoteOrRestSelected() && !isRepitch, false);
529 : }
530 :
531 0 : if (muse::contains(LAYOUT_BREAK_COMMANDS, command)) {
532 0 : return CommandState(controller()->isToggleLayoutBreakAvailable(), false);
533 : }
534 :
535 0 : if (muse::contains(SCORE_CONFIG_COMMANDS, command)) {
536 0 : return CommandState(true, controller()->scoreConfig().isShown(SCORE_CONFIG_COMMANDS.at(command)));
537 : }
538 :
539 0 : if (muse::contains(STYLE_COMMANDS, command)) {
540 0 : auto style = controller()->notationStyle();
541 0 : return CommandState(true, style ? style->styleValue(StyleId::concertPitch).toBool() : false);
542 0 : }
543 :
544 0 : if (muse::contains(TAB_COMMANDS, command)) {
545 0 : return CommandState(controller()->isTablatureStaff(), false);
546 : }
547 :
548 0 : if (command == TOGGLE_AUTOMATION_COMMAND) {
549 0 : return CommandState(true, controller()->isAutomationModeEnabled());
550 : }
551 :
552 0 : if (muse::contains(DEBUG_COMMANDS, command)) {
553 0 : return CommandState(true, controller()->isDebuggingCommandEnabled(command));
554 : }
555 :
556 0 : return CommandState(true, false);
557 : }
558 :
559 0 : CommandState NotationCommandsState::commandState(const Command& command) const
560 : {
561 0 : CommandState state = doCommandState(command);
562 : // LOGDA() << "command: " << command
563 : // << ", enabled: " << state.enabled
564 : // << ", checked: " << state.checked;
565 0 : return state;
566 : }
567 :
568 0 : async::Channel<Command, CommandState> NotationCommandsState::commandStateChanged() const
569 : {
570 0 : return m_commandStateChanged;
571 : }
572 :
573 0 : bool NotationCommandsState::isProjectOpened() const
574 : {
575 0 : if (!projectSession()->project()) {
576 0 : return false;
577 : }
578 :
579 0 : if (!interactive() || !interactive()->isOpened(PROJECT_PAGE_URI).val) {
580 0 : return false;
581 : }
582 :
583 0 : return true;
584 : }
|