LCOV - code coverage report
Current view: top level - src/notationscene/internal - notationactioncontroller.h Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 2 0
Test Date: 2026-11-19 04:14:36

            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) 2025 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              : #pragma once
      23              : 
      24              : #include "../inotationcommandscontroller.h"
      25              : 
      26              : #include "types/ret.h"
      27              : #include "async/asyncable.h"
      28              : #include "rcommand/commandable.h"
      29              : 
      30              : #include "modularity/ioc.h"
      31              : #include "interactive/iinteractive.h"
      32              : #include "rcommand/commandtypes.h"
      33              : #include "rcommand/icommandsstate.h"
      34              : #include "rcommand/icommanddispatcher.h"
      35              : #include "project/iprojectsession.h"
      36              : #include "playback/iplaybackcontroller.h"
      37              : #include "engraving/iengravingconfiguration.h"
      38              : #include "notation/inotationconfiguration.h"
      39              : #include "notationscene/inotationsceneconfiguration.h"
      40              : 
      41              : #include "notation/inotation_fwd.h"
      42              : #include "notation/notationtypes.h"
      43              : 
      44              : #include "inotationviewcontroller.h"
      45              : #include "notationcommands.h"
      46              : 
      47              : namespace mu::notation {
      48              : class NotationActionController : public INotationCommandsController, public muse::rcommand::Commandable, public muse::async::Asyncable,
      49              :     public muse::Contextable
      50              : {
      51              :     muse::GlobalInject<INotationConfiguration> configuration;
      52              :     muse::GlobalInject<INotationSceneConfiguration> sceneConfiguration;
      53              :     muse::GlobalInject<engraving::IEngravingConfiguration> engravingConfiguration;
      54              :     muse::ContextInject<muse::rcommand::ICommandDispatcher> commandDispatcher = { this };
      55              :     muse::ContextInject<muse::rcommand::ICommandsState> commandsState = { this };
      56              :     muse::ContextInject<project::IProjectSession> projectSession = { this };
      57              :     muse::ContextInject<muse::IInteractive> interactive = { this };
      58              :     muse::ContextInject<playback::IPlaybackController> playbackController = { this };
      59              : 
      60              : public:
      61              : 
      62            0 :     NotationActionController(const muse::modularity::ContextPtr& iocCtx)
      63            0 :         : muse::Contextable(iocCtx) {}
      64              : 
      65              :     void init();
      66              : 
      67              :     void setViewController(INotationViewController* controller) override;
      68              :     INotationViewController* viewController() const override;
      69              : 
      70              :     bool hasSelection() const override;
      71              :     bool isSingleSelection() const override;
      72              :     bool isRangeSelection() const override;
      73              :     muse::async::Notification selectionChanged() const override;
      74              :     bool selectionHasTie() const override;
      75              :     bool selectionHasLaissezVib() const override;
      76              :     bool selectionHasSlur() const override;
      77              : 
      78              :     bool canUndo() const override;
      79              :     bool canRedo() const override;
      80              :     muse::async::Notification stackChanged() const override;
      81              : 
      82              :     bool isTextEditing() const override;
      83              :     bool isLyricsEditing() const override;
      84              :     muse::async::Channel<bool> textEditingChanged() const override;
      85              : 
      86              :     bool isNoteInputAllowed() const override;
      87              :     muse::async::Channel<bool> isNoteInputAllowedChanged() const override;
      88              : 
      89              :     muse::async::Notification noteInputStateChanged() const override;
      90              :     bool isNoteInputMode() const override;
      91              :     NoteInputMethod noteInputMethod() const override;
      92              :     engraving::DurationType currentDurationType() const override;
      93              :     int currentDotCount() const override;
      94              :     bool currentIsRest() const override;
      95              :     engraving::AccidentalType currentAccidentalType() const override;
      96              :     std::set<engraving::SymId> currentArticulations() const override;
      97              :     engraving::voice_idx_t currentVoice() const override;
      98              : 
      99              :     bool isNoteInputActionAllowed() const override;
     100              :     bool isNoteOrRestSelected() const override;
     101              :     bool isHairpinSelected() const override;
     102              :     bool isMoveSelectionAvailable(MoveSelectionType type) const override;
     103              : 
     104              :     bool isToggleLayoutBreakAvailable() const override;
     105              : 
     106              :     ScoreConfig scoreConfig() const override;
     107              :     muse::async::Channel<ScoreConfigType> scoreConfigChanged() const override;
     108              : 
     109              :     INotationStylePtr notationStyle() const override;
     110              :     muse::async::Notification notationStyleChanged() const override;
     111              : 
     112              :     bool isTablatureStaff() const override;
     113              : 
     114              :     INotationAutomationPtr automation() const;
     115              : 
     116              :     bool isAutomationModeEnabled() const override;
     117              :     muse::async::Notification automationModeEnabledChanged() const override;
     118              : 
     119              :     bool isDebuggingCommandEnabled(const muse::rcommand::Command& command) const override;
     120              :     muse::async::Notification debuggingOptionsChanged() const override;
     121              : 
     122              :     muse::async::Notification currentNotationChanged() const;
     123              : 
     124              :     INotationNoteInputPtr currentNotationNoteInput() const;
     125              :     INotationInteractionPtr currentNotationInteraction() const;
     126              :     INotationUndoStackPtr currentNotationUndoStack() const;
     127              : 
     128              :     IMasterNotationPtr currentMasterNotation() const;
     129              :     muse::async::Notification currentMasterNotationChanged() const;
     130              : 
     131              : private:
     132              :     INotationPtr currentNotation() const;
     133              :     INotationElementsPtr currentNotationElements() const;
     134              :     INotationSelectionPtr currentNotationSelection() const;
     135              :     INotationMidiInputPtr currentNotationMidiInput() const;
     136              : 
     137              :     mu::engraving::Score* currentNotationScore() const;
     138              : 
     139              :     muse::Ret resetState();
     140              :     muse::Ret undo();
     141              :     muse::Ret redo();
     142              :     muse::Ret copySelection();
     143              :     muse::Ret cutSelection();
     144              :     muse::Ret copyPasteSwap();
     145              :     muse::Ret copyLyrics();
     146              :     muse::Ret deleteSelection();
     147              : 
     148              :     muse::Ret select(const SelectCommand& command);
     149              :     muse::Ret select(SelectionTarget target, PlayMode playMode = PlayMode::NoPlay);
     150              :     muse::Ret addToSelection(const AddToSelectionCommand& command);
     151              :     muse::Ret addToSelection(SelectionTarget target);
     152              :     muse::Ret openSelectionMoreOptions();
     153              :     muse::Ret showLocation();
     154              : 
     155              :     muse::Ret toggleNoteInput(const ToggleNoteInputCommand& command);
     156              :     muse::Ret toggleNoteInput(NoteInputMethod method);
     157              :     muse::Ret toggleNoteInputInsert();
     158              : 
     159              :     muse::Ret setDuration(const SetDurationCommand& command);
     160              :     muse::Ret setDuration(engraving::DurationType duration);
     161              :     muse::Ret changeDuration(const ChangeDurationCommand& command);
     162              :     muse::Ret changeDuration(ChangeDurationMode mode);
     163              :     muse::Ret toggleDots(const ToggleDotsCommand& command);
     164              :     muse::Ret toggleDots(uint dots);
     165              : 
     166              :     muse::Ret toggleRest();
     167              : 
     168              :     muse::RetVal<RequestNoteInputStateCommand::Output> requestNoteInputState() const;
     169              : 
     170              :     muse::Ret addNote(const AddNoteCommand& command);
     171              :     muse::Ret addNote(NoteName noteName, NoteAddingMode addingMode);
     172              :     muse::Ret addDrumNote(const muse::rcommand::Params& params);
     173              :     void doAddNote(const NoteInputParams& params, const NoteAddingMode& addingMode);
     174              : 
     175              :     muse::Ret toggleAccidental(const ToggleAccidentalCommand& command);
     176              :     muse::Ret changeVoice(const UseVoiceCommand& command);
     177              :     muse::Ret swapVoices(const SwapVoicesCommand& command);
     178              : 
     179              :     muse::Ret putTuplet(const AddTupletCommand& command);
     180              :     muse::Ret openTupletOtherDialog();
     181              : 
     182              :     muse::Ret addBoxes(const AddBoxesCommand& command);
     183              :     muse::Ret addGraceNotes(const AddGraceNoteCommand& command);
     184              :     muse::Ret addInterval(const AddIntervalCommand& command);
     185              :     muse::Ret addText(const AddTextCommand& command);
     186              :     muse::Ret addBeam(const AddBeamCommand& command);
     187              :     muse::Ret addOrnament(const AddOrnamentCommand& command);
     188              :     muse::Ret flipSelection();
     189              : 
     190              :     // Tab
     191              :     muse::Ret addFret(const AddFretCommand& command);
     192              : 
     193              :     muse::Ret putNote(const muse::rcommand::Params& params);
     194              :     muse::Ret removeNote(const muse::rcommand::Params& params);
     195              : 
     196              :     void realtimeAdvance();
     197              : 
     198              :     void toggleArticulation(SymbolId articulationSymbolId);
     199              : 
     200              :     muse::Ret moveWithRet(MoveDirection direction, bool quickly = false);
     201              :     void move(MoveDirection direction, bool quickly = false);
     202              :     void moveInputNotes(bool up, PitchMode mode);
     203              :     void movePitchDiatonic(MoveDirection direction, bool);
     204              : 
     205              :     void repeatSelection();
     206              :     void addTie();
     207              :     void addLaissezVib();
     208              :     void addSlur();
     209              :     void addHammerOnPullOff();
     210              : 
     211              :     void insertClef(mu::engraving::ClefType type);
     212              : 
     213              :     void addDynamic();
     214              :     void addImage();
     215              :     void addFiguredBass();
     216              :     void addGuitarBend(GuitarBendType bendType);
     217              :     void addFretboardDiagram();
     218              : 
     219              :     muse::Ret startEditSelectedElement(const muse::rcommand::Params& params);
     220              :     muse::Ret startEditSelectedText(const muse::rcommand::Params& params);
     221              : 
     222              :     void addStretch(qreal value);
     223              : 
     224              :     void unrollRepeats();
     225              : 
     226              :     void toggleMmrest();
     227              :     void toggleHideEmpty();
     228              :     void addFullMeasureRest();
     229              : 
     230              :     void resetStretch();
     231              :     void resetBeamMode();
     232              : 
     233              :     muse::Ret openEditStyleDialog(const muse::rcommand::Params& params);
     234              :     void openPageSettingsDialog();
     235              :     void openStaffProperties();
     236              :     void openEditStringsDialog();
     237              :     void openBreaksDialog();
     238              :     void openTransposeDialog();
     239              :     void openPartsDialog();
     240              :     void openStaffTextPropertiesDialog();
     241              :     void openMeasurePropertiesDialog();
     242              :     void openEditGridSizeDialog();
     243              :     void openRealizeChordSymbolsDialog();
     244              :     muse::io::path_t selectStyleFile(bool forLoad);
     245              :     void loadStyle();
     246              :     void saveStyle();
     247              : 
     248              :     void toggleScoreConfig(ScoreConfigType configType);
     249              :     void toggleConcertPitch();
     250              : 
     251              :     void seekAndPlaySelectedElement(bool playChord = true);
     252              :     void seekSelectedElement();
     253              :     void playSelectedElement(bool playChord = true);
     254              : 
     255              :     bool isEditingText() const;
     256              :     bool isEditingElement() const;
     257              :     bool isNotEditingElement() const;
     258              : 
     259              :     muse::Ret pasteSelection(const PasteCommand& command);
     260              :     Fraction resolvePastingScale(const INotationInteractionPtr& interaction, PastingType type) const;
     261              : 
     262              :     enum class TextNavigationType {
     263              :         NearNoteOrRest,
     264              :         NearBeat,
     265              :         Fraction
     266              :     };
     267              : 
     268              :     bool textNavigationAvailable() const;
     269              :     bool textNavigationByBeatsAvailable() const;
     270              :     bool textNavigationByFractionAvailable() const;
     271              :     bool resolveTextNavigationAvailable(TextNavigationType type = TextNavigationType::NearNoteOrRest) const;
     272              : 
     273              :     muse::Ret nextTextElement();
     274              :     muse::Ret prevTextElement();
     275              :     muse::Ret nextWord();
     276              :     void nextBeatTextElement();
     277              :     void prevBeatTextElement();
     278              :     void navigateToTextElement(MoveDirection direction, bool nearNoteOrRest = false, bool moveOnly = true);
     279              :     muse::Ret editTextAdvance(const EditTextAdvanceCommand& command);
     280              :     void navigateToTextItemByFraction(const Fraction& fraction);
     281              :     void navigateToTextElementInNearMeasure(MoveDirection direction);
     282              : 
     283              :     bool toggleNoteInputAllowed() const;
     284              :     void startNoteInput();
     285              : 
     286              :     mu::engraving::EngravingItem* selectedElement() const;
     287              : 
     288              :     const mu::engraving::Harmony* editedChordSymbol() const;
     289              : 
     290              :     bool elementHasPopup(const EngravingItem* e) const;
     291              : 
     292              :     void checkForScoreCorruptions();
     293              : 
     294              :     void toggleAutomation();
     295              :     muse::Ret selectAutomationType(const muse::rcommand::Params& params);
     296              : 
     297              :     // commands
     298              :     template<muse::rcommand::TypedCommand C>
     299              :     void registerCommand(std::function<muse::Ret()>);
     300              :     template<muse::rcommand::TypedCommand C>
     301              :     void registerCommand(muse::Ret (NotationActionController::*)());
     302              :     template<muse::rcommand::TypedCommand C>
     303              :     void registerCommand(muse::Ret (NotationActionController::*)(const C&));
     304              :     template<muse::rcommand::HasOutput C>
     305              :     void registerRequestCommand(muse::RetVal<typename C::Output>(NotationActionController::*)() const);
     306              :     template<muse::rcommand::HasOutput C>
     307              :     void registerRequestCommand(muse::RetVal<typename C::Output>(NotationActionController::*)(const C&) const);
     308              : 
     309              :     void registerCommand(const muse::rcommand::Command&, std::function<void()>);
     310              :     void registerCommand(const muse::rcommand::Command&, std::function<void()>, bool (NotationActionController::*)() const);
     311              :     void registerCommandWithParams(const muse::rcommand::Command&, std::function<muse::Ret(const muse::rcommand::Params&)>);
     312              :     void registerCommand(const muse::rcommand::Command&, void (NotationActionController::*)());
     313              :     void registerCommand(const muse::rcommand::Command&, void (NotationActionController::*)(), bool (NotationActionController::*)() const);
     314              :     void registerCommandWithParams(const muse::rcommand::Command&, muse::Ret (NotationActionController::*)(const muse::rcommand::Params&));
     315              : 
     316              :     void registerCommand(const muse::rcommand::Command&, void (INotationInteraction::*)(), PlayMode = PlayMode::NoPlay,
     317              :                          bool (NotationActionController::*)() const = nullptr);
     318              :     template<typename P1>
     319              :     void registerCommand(const muse::rcommand::Command&, void (INotationInteraction::*)(P1), P1, PlayMode = PlayMode::NoPlay,
     320              :                          bool (NotationActionController::*)() const = nullptr);
     321              : 
     322              :     void registerGetCommand(const muse::rcommand::Command&, std::function<muse::RetVal<muse::rcommand::Params>()>);
     323              :     void registerGetCommand(const muse::rcommand::Command&, muse::RetVal<muse::rcommand::Params>(NotationActionController::*)() const);
     324              : 
     325              :     void registerViewCommand(const muse::rcommand::Command&, void (INotationViewController::*)());
     326              :     template<typename P1>
     327              :     void registerViewCommand(const muse::rcommand::Command&, void (INotationViewController::*)(P1), P1);
     328              : 
     329              :     muse::Ret zoomToPercent(const muse::rcommand::Params& params);
     330              : 
     331              :     muse::Ret setPianoKeyboardNumberOfKeys(const muse::rcommand::Params& params);
     332              : 
     333              :     INotationViewController* m_viewController = nullptr;
     334              : 
     335              :     muse::async::Channel<bool> m_hasSelectionChanged;
     336              :     muse::async::Channel<bool> m_textEditingChanged;
     337              :     muse::async::Notification m_stackChanged;
     338              :     muse::async::Notification m_selectionChanged;
     339              : 
     340              :     muse::async::Channel<bool> m_isNoteInputAllowedChanged;
     341              :     muse::async::Notification m_noteInputStateChanged;
     342              : 
     343              :     muse::async::Channel<ScoreConfigType> m_scoreConfigChanged;
     344              :     muse::async::Notification m_currentNotationStyleChanged;
     345              :     muse::async::Notification m_automationModeEnabledChanged;
     346              : };
     347              : }
        

Generated by: LCOV version 2.0-1