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

Generated by: LCOV version 2.0-1