LCOV - code coverage report
Current view: top level - src/engraving/dom - note.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 55.8 % 2208 1231
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              : /**
      24              :  \file
      25              :  Implementation of classes Note and ShadowNote.
      26              : */
      27              : 
      28              : #include "note.h"
      29              : 
      30              : #include <cassert>
      31              : 
      32              : #include "translation.h"
      33              : 
      34              : #include "iengravingconfiguration.h" // IWYU pragma: keep
      35              : #include "iengravingfont.h"
      36              : 
      37              : #include "../editing/addremoveelement.h"
      38              : #include "../editing/editchord.h"
      39              : #include "../editing/editnote.h"
      40              : #include "../editing/editparentheses.h"
      41              : #include "../editing/editstavesharing.h"
      42              : #include "../editing/noteinput.h"
      43              : #include "../editing/transaction/transaction.h"
      44              : #include "../editing/transpose.h"
      45              : #include "types/typesconv.h"
      46              : 
      47              : #include "rendering/score/horizontalspacing.h"
      48              : 
      49              : #include "accidental.h"
      50              : #include "actionicon.h"
      51              : #include "articulation.h"
      52              : #include "bagpembell.h"
      53              : #include "barline.h"
      54              : #include "beam.h"
      55              : #include "chord.h"
      56              : #include "chordline.h"
      57              : #include "drumset.h"
      58              : #include "factory.h"
      59              : #include "fingering.h"
      60              : #include "glissando.h"
      61              : #include "guitarbend.h"
      62              : #include "jianpuoctavedot.h"
      63              : #include "laissezvib.h"
      64              : #include "linkedobjects.h"
      65              : #include "measure.h"
      66              : #include "notedot.h"
      67              : #include "noteline.h"
      68              : #include "parenthesis.h"
      69              : #include "part.h"
      70              : #include "partialtie.h"
      71              : #include "pitchspelling.h"
      72              : #include "score.h"
      73              : #include "segment.h"
      74              : #include "spanner.h"
      75              : #include "staff.h"
      76              : #include "stafftype.h"
      77              : #include "stringdata.h"
      78              : #include "tie.h"
      79              : #include "utils.h"
      80              : #include "volta.h"
      81              : 
      82              : #include "log.h"
      83              : 
      84              : using namespace mu;
      85              : using namespace muse::draw;
      86              : using namespace mu::engraving;
      87              : using namespace mu::engraving::rendering::score;
      88              : 
      89              : namespace mu::engraving {
      90              : //---------------------------------------------------------
      91              : //   noteHeads
      92              : //    notehead groups
      93              : //---------------------------------------------------------
      94              : 
      95              : //int(NoteHeadGroup::HEAD_GROUPS) - 1: "-1" is needed to prevent building CUSTOM_GROUP noteheads set, since it is built by users and keep a specific set of existing noteheads
      96              : static const SymId noteHeads[2][int(NoteHeadGroup::HEAD_GROUPS) - 1][int(NoteHeadType::HEAD_TYPES)] = {
      97              :     {    // down stem
      98              :         { SymId::noteheadWhole,               SymId::noteheadHalf,                SymId::noteheadBlack,
      99              :           SymId::noteheadDoubleWhole },
     100              :         { SymId::noteheadXWhole,              SymId::noteheadXHalf,               SymId::noteheadXBlack,
     101              :           SymId::noteheadXDoubleWhole },
     102              :         { SymId::noteheadPlusWhole,           SymId::noteheadPlusHalf,            SymId::noteheadPlusBlack,
     103              :           SymId::noteheadPlusDoubleWhole },
     104              :         { SymId::noteheadCircleXWhole,        SymId::noteheadCircleXHalf,         SymId::noteheadCircleX,
     105              :           SymId::noteheadCircleXDoubleWhole },
     106              :         { SymId::noteheadWholeWithX,          SymId::noteheadHalfWithX,           SymId::noteheadVoidWithX,
     107              :           SymId::noteheadDoubleWholeWithX },
     108              :         { SymId::noteheadTriangleUpWhole,     SymId::noteheadTriangleUpHalf,      SymId::noteheadTriangleUpBlack,
     109              :           SymId::noteheadTriangleUpDoubleWhole },
     110              :         { SymId::noteheadTriangleDownWhole,   SymId::noteheadTriangleDownHalf,    SymId::noteheadTriangleDownBlack,
     111              :           SymId::noteheadTriangleDownDoubleWhole },
     112              :         { SymId::noteheadSlashedWhole1,       SymId::noteheadSlashedHalf1,        SymId::noteheadSlashedBlack1,
     113              :           SymId::noteheadSlashedDoubleWhole1 },
     114              :         { SymId::noteheadSlashedWhole2,       SymId::noteheadSlashedHalf2,        SymId::noteheadSlashedBlack2,
     115              :           SymId::noteheadSlashedDoubleWhole2 },
     116              :         { SymId::noteheadDiamondWhole,        SymId::noteheadDiamondHalf,         SymId::noteheadDiamondBlack,
     117              :           SymId::noteheadDiamondDoubleWhole },
     118              :         { SymId::noteheadDiamondWholeOld,     SymId::noteheadDiamondHalfOld,      SymId::noteheadDiamondBlackOld,
     119              :           SymId::noteheadDiamondDoubleWholeOld },
     120              :         { SymId::noteheadCircledWhole,        SymId::noteheadCircledHalf,         SymId::noteheadCircledBlack,
     121              :           SymId::noteheadCircledDoubleWhole },
     122              :         { SymId::noteheadCircledWholeLarge,   SymId::noteheadCircledHalfLarge,    SymId::noteheadCircledBlackLarge,
     123              :           SymId::noteheadCircledDoubleWholeLarge },
     124              :         { SymId::noteheadLargeArrowUpWhole,   SymId::noteheadLargeArrowUpHalf,    SymId::noteheadLargeArrowUpBlack,
     125              :           SymId::noteheadLargeArrowUpDoubleWhole },
     126              :         { SymId::noteheadWhole,               SymId::noteheadHalf,                SymId::noteheadBlack,
     127              :           SymId::noteheadDoubleWholeSquare },
     128              : 
     129              :         { SymId::noteheadSlashWhiteWhole,     SymId::noteheadSlashWhiteHalf,      SymId::noteheadSlashHorizontalEnds,
     130              :           SymId::noteheadSlashWhiteWhole },
     131              :         { SymId::noteheadSlashDiamondWhite,   SymId::noteheadSlashDiamondWhite,   SymId::noteheadSlashHorizontalEnds,
     132              :           SymId::noteheadSlashWhiteWhole },
     133              : 
     134              :         { SymId::noteShapeRoundWhite,         SymId::noteShapeRoundWhite,         SymId::noteShapeRoundBlack,
     135              :           SymId::noteShapeRoundDoubleWhole },
     136              :         { SymId::noteShapeSquareWhite,        SymId::noteShapeSquareWhite,        SymId::noteShapeSquareBlack,
     137              :           SymId::noteShapeSquareDoubleWhole },
     138              :         { SymId::noteShapeTriangleRightWhite, SymId::noteShapeTriangleRightWhite, SymId::noteShapeTriangleRightBlack,
     139              :           SymId::noteShapeTriangleRightDoubleWhole },
     140              :         { SymId::noteShapeDiamondWhite,       SymId::noteShapeDiamondWhite,       SymId::noteShapeDiamondBlack,
     141              :           SymId::noteShapeDiamondDoubleWhole },
     142              :         { SymId::noteShapeTriangleUpWhite,    SymId::noteShapeTriangleUpWhite,    SymId::noteShapeTriangleUpBlack,
     143              :           SymId::noteShapeTriangleUpDoubleWhole },
     144              :         { SymId::noteShapeMoonWhite,          SymId::noteShapeMoonWhite,          SymId::noteShapeMoonBlack,
     145              :           SymId::noteShapeMoonDoubleWhole },
     146              :         { SymId::noteShapeTriangleRoundWhite, SymId::noteShapeTriangleRoundWhite, SymId::noteShapeTriangleRoundBlack,
     147              :           SymId::noteShapeTriangleRoundDoubleWhole },
     148              : 
     149              :         { SymId::noteheadHeavyX,              SymId::noteheadHeavyX,              SymId::noteheadHeavyX,
     150              :           SymId::noteheadHeavyX },
     151              :         { SymId::noteheadHeavyXHat,           SymId::noteheadHeavyXHat,           SymId::noteheadHeavyXHat,
     152              :           SymId::noteheadHeavyXHat },
     153              : 
     154              :         { SymId::noteShapeKeystoneWhite,          SymId::noteShapeKeystoneWhite,          SymId::noteShapeKeystoneBlack,
     155              :           SymId::noteShapeKeystoneDoubleWhole },
     156              :         { SymId::noteShapeQuarterMoonWhite,       SymId::noteShapeQuarterMoonWhite,       SymId::noteShapeQuarterMoonBlack,
     157              :           SymId::noteShapeQuarterMoonDoubleWhole },
     158              :         { SymId::noteShapeIsoscelesTriangleWhite, SymId::noteShapeIsoscelesTriangleWhite, SymId::noteShapeIsoscelesTriangleBlack,
     159              :           SymId::noteShapeIsoscelesTriangleDoubleWhole },
     160              :         { SymId::noteShapeMoonLeftWhite,          SymId::noteShapeMoonLeftWhite,          SymId::noteShapeMoonLeftBlack,
     161              :           SymId::noteShapeMoonLeftDoubleWhole },
     162              :         { SymId::noteShapeArrowheadLeftWhite,     SymId::noteShapeArrowheadLeftWhite,     SymId::noteShapeArrowheadLeftBlack,
     163              :           SymId::noteShapeArrowheadLeftDoubleWhole },
     164              :         { SymId::noteShapeTriangleRoundLeftWhite, SymId::noteShapeTriangleRoundLeftWhite, SymId::noteShapeTriangleRoundLeftBlack,
     165              :           SymId::noteShapeTriangleRoundLeftDoubleWhole },
     166              : 
     167              :         { SymId::noteDoWhole,  SymId::noteDoHalf,  SymId::noteDoBlack,  SymId::noSym },
     168              :         { SymId::noteDiWhole,  SymId::noteDiHalf,  SymId::noteDiBlack,  SymId::noSym },
     169              :         { SymId::noteRaWhole,  SymId::noteRaHalf,  SymId::noteRaBlack,  SymId::noSym },
     170              :         { SymId::noteReWhole,  SymId::noteReHalf,  SymId::noteReBlack,  SymId::noSym },
     171              :         { SymId::noteRiWhole,  SymId::noteRiHalf,  SymId::noteRiBlack,  SymId::noSym },
     172              :         { SymId::noteMeWhole,  SymId::noteMeHalf,  SymId::noteMeBlack,  SymId::noSym },
     173              :         { SymId::noteMiWhole,  SymId::noteMiHalf,  SymId::noteMiBlack,  SymId::noSym },
     174              :         { SymId::noteFaWhole,  SymId::noteFaHalf,  SymId::noteFaBlack,  SymId::noSym },
     175              :         { SymId::noteFiWhole,  SymId::noteFiHalf,  SymId::noteFiBlack,  SymId::noSym },
     176              :         { SymId::noteSeWhole,  SymId::noteSeHalf,  SymId::noteSeBlack,  SymId::noSym },
     177              :         { SymId::noteSoWhole,  SymId::noteSoHalf,  SymId::noteSoBlack,  SymId::noSym },
     178              :         { SymId::noteLeWhole,  SymId::noteLeHalf,  SymId::noteLeBlack,  SymId::noSym },
     179              :         { SymId::noteLaWhole,  SymId::noteLaHalf,  SymId::noteLaBlack,  SymId::noSym },
     180              :         { SymId::noteLiWhole,  SymId::noteLiHalf,  SymId::noteLiBlack,  SymId::noSym },
     181              :         { SymId::noteTeWhole,  SymId::noteTeHalf,  SymId::noteTeBlack,  SymId::noSym },
     182              :         { SymId::noteTiWhole,  SymId::noteTiHalf,  SymId::noteTiBlack,  SymId::noSym },
     183              :         { SymId::noteSiWhole,  SymId::noteSiHalf,  SymId::noteSiBlack,  SymId::noSym },
     184              : 
     185              :         { SymId::noteASharpWhole,  SymId::noteASharpHalf,  SymId::noteASharpBlack,  SymId::noSym },
     186              :         { SymId::noteAWhole,       SymId::noteAHalf,       SymId::noteABlack,       SymId::noSym },
     187              :         { SymId::noteAFlatWhole,   SymId::noteAFlatHalf,   SymId::noteAFlatBlack,   SymId::noSym },
     188              :         { SymId::noteBSharpWhole,  SymId::noteBSharpHalf,  SymId::noteBSharpBlack,  SymId::noSym },
     189              :         { SymId::noteBWhole,       SymId::noteBHalf,       SymId::noteBBlack,       SymId::noSym },
     190              :         { SymId::noteBFlatWhole,   SymId::noteBFlatHalf,   SymId::noteBFlatBlack,   SymId::noSym },
     191              :         { SymId::noteCSharpWhole,  SymId::noteCSharpHalf,  SymId::noteCSharpBlack,  SymId::noSym },
     192              :         { SymId::noteCWhole,       SymId::noteCHalf,       SymId::noteCBlack,       SymId::noSym },
     193              :         { SymId::noteCFlatWhole,   SymId::noteCFlatHalf,   SymId::noteCFlatBlack,   SymId::noSym },
     194              :         { SymId::noteDSharpWhole,  SymId::noteDSharpHalf,  SymId::noteDSharpBlack,  SymId::noSym },
     195              :         { SymId::noteDWhole,       SymId::noteDHalf,       SymId::noteDBlack,       SymId::noSym },
     196              :         { SymId::noteDFlatWhole,   SymId::noteDFlatHalf,   SymId::noteDFlatBlack,   SymId::noSym },
     197              :         { SymId::noteESharpWhole,  SymId::noteESharpHalf,  SymId::noteESharpBlack,  SymId::noSym },
     198              :         { SymId::noteEWhole,       SymId::noteEHalf,       SymId::noteEBlack,       SymId::noSym },
     199              :         { SymId::noteEFlatWhole,   SymId::noteEFlatHalf,   SymId::noteEFlatBlack,   SymId::noSym },
     200              :         { SymId::noteFSharpWhole,  SymId::noteFSharpHalf,  SymId::noteFSharpBlack,  SymId::noSym },
     201              :         { SymId::noteFWhole,       SymId::noteFHalf,       SymId::noteFBlack,       SymId::noSym },
     202              :         { SymId::noteFFlatWhole,   SymId::noteFFlatHalf,   SymId::noteFFlatBlack,   SymId::noSym },
     203              :         { SymId::noteGSharpWhole,  SymId::noteGSharpHalf,  SymId::noteGSharpBlack,  SymId::noSym },
     204              :         { SymId::noteGWhole,       SymId::noteGHalf,       SymId::noteGBlack,       SymId::noSym },
     205              :         { SymId::noteGFlatWhole,   SymId::noteGFlatHalf,   SymId::noteGFlatBlack,   SymId::noSym },
     206              :         { SymId::noteHWhole,       SymId::noteHHalf,       SymId::noteHBlack,       SymId::noSym },
     207              :         { SymId::noteHSharpWhole,  SymId::noteHSharpHalf,  SymId::noteHSharpBlack,  SymId::noSym },
     208              : 
     209              :         { SymId::noSym, SymId::swissRudimentsNoteheadHalfFlam,   SymId::swissRudimentsNoteheadBlackFlam,   SymId::noSym },
     210              :         { SymId::noSym, SymId::swissRudimentsNoteheadHalfDouble, SymId::swissRudimentsNoteheadBlackDouble, SymId::noSym }
     211              :     },
     212              :     {    // up stem
     213              :         { SymId::noteheadWhole,               SymId::noteheadHalf,                SymId::noteheadBlack,
     214              :           SymId::noteheadDoubleWhole },
     215              :         { SymId::noteheadXWhole,              SymId::noteheadXHalf,               SymId::noteheadXBlack,
     216              :           SymId::noteheadXDoubleWhole },
     217              :         { SymId::noteheadPlusWhole,           SymId::noteheadPlusHalf,            SymId::noteheadPlusBlack,
     218              :           SymId::noteheadPlusDoubleWhole },
     219              :         { SymId::noteheadCircleXWhole,        SymId::noteheadCircleXHalf,         SymId::noteheadCircleX,
     220              :           SymId::noteheadCircleXDoubleWhole },
     221              :         { SymId::noteheadWholeWithX,          SymId::noteheadHalfWithX,           SymId::noteheadVoidWithX,
     222              :           SymId::noteheadDoubleWholeWithX },
     223              :         { SymId::noteheadTriangleUpWhole,     SymId::noteheadTriangleUpHalf,      SymId::noteheadTriangleUpBlack,
     224              :           SymId::noteheadTriangleUpDoubleWhole },
     225              :         { SymId::noteheadTriangleDownWhole,   SymId::noteheadTriangleDownHalf,    SymId::noteheadTriangleDownBlack,
     226              :           SymId::noteheadTriangleDownDoubleWhole },
     227              :         { SymId::noteheadSlashedWhole1,       SymId::noteheadSlashedHalf1,        SymId::noteheadSlashedBlack1,
     228              :           SymId::noteheadSlashedDoubleWhole1 },
     229              :         { SymId::noteheadSlashedWhole2,       SymId::noteheadSlashedHalf2,        SymId::noteheadSlashedBlack2,
     230              :           SymId::noteheadSlashedDoubleWhole2 },
     231              :         { SymId::noteheadDiamondWhole,        SymId::noteheadDiamondHalf,         SymId::noteheadDiamondBlack,
     232              :           SymId::noteheadDiamondDoubleWhole },
     233              :         { SymId::noteheadDiamondWholeOld,     SymId::noteheadDiamondHalfOld,      SymId::noteheadDiamondBlackOld,
     234              :           SymId::noteheadDiamondDoubleWholeOld },
     235              :         { SymId::noteheadCircledWhole,        SymId::noteheadCircledHalf,         SymId::noteheadCircledBlack,
     236              :           SymId::noteheadCircledDoubleWhole },
     237              :         { SymId::noteheadCircledWholeLarge,   SymId::noteheadCircledHalfLarge,    SymId::noteheadCircledBlackLarge,
     238              :           SymId::noteheadCircledDoubleWholeLarge },
     239              :         // different from down, find source?
     240              :         { SymId::noteheadLargeArrowDownWhole, SymId::noteheadLargeArrowDownHalf,  SymId::noteheadLargeArrowDownBlack,
     241              :           SymId::noteheadLargeArrowDownDoubleWhole },
     242              :         { SymId::noteheadWhole,               SymId::noteheadHalf,                SymId::noteheadBlack,
     243              :           SymId::noteheadDoubleWholeSquare },
     244              : 
     245              :         { SymId::noteheadSlashWhiteWhole,     SymId::noteheadSlashWhiteHalf,      SymId::noteheadSlashHorizontalEnds,
     246              :           SymId::noteheadSlashWhiteDoubleWhole },
     247              :         { SymId::noteheadSlashDiamondWhite,   SymId::noteheadSlashDiamondWhite,   SymId::noteheadSlashHorizontalEnds,
     248              :           SymId::noteheadSlashWhiteDoubleWhole },
     249              : 
     250              :         { SymId::noteShapeRoundWhite,         SymId::noteShapeRoundWhite,         SymId::noteShapeRoundBlack,
     251              :           SymId::noteShapeRoundDoubleWhole },
     252              :         { SymId::noteShapeSquareWhite,        SymId::noteShapeSquareWhite,        SymId::noteShapeSquareBlack,
     253              :           SymId::noteShapeSquareDoubleWhole },
     254              :         // different from down
     255              :         { SymId::noteShapeTriangleLeftWhite,  SymId::noteShapeTriangleLeftWhite,  SymId::noteShapeTriangleLeftBlack,
     256              :           SymId::noteShapeTriangleLeftDoubleWhole },
     257              :         { SymId::noteShapeDiamondWhite,       SymId::noteShapeDiamondWhite,       SymId::noteShapeDiamondBlack,
     258              :           SymId::noteShapeDiamondDoubleWhole },
     259              :         { SymId::noteShapeTriangleUpWhite,    SymId::noteShapeTriangleUpWhite,    SymId::noteShapeTriangleUpBlack,
     260              :           SymId::noteShapeTriangleUpDoubleWhole },
     261              :         { SymId::noteShapeMoonWhite,          SymId::noteShapeMoonWhite,          SymId::noteShapeMoonBlack,
     262              :           SymId::noteShapeMoonDoubleWhole },
     263              :         { SymId::noteShapeTriangleRoundWhite, SymId::noteShapeTriangleRoundWhite, SymId::noteShapeTriangleRoundBlack,
     264              :           SymId::noteShapeTriangleRoundDoubleWhole },
     265              : 
     266              :         { SymId::noteheadHeavyX,              SymId::noteheadHeavyX,              SymId::noteheadHeavyX,
     267              :           SymId::noteheadHeavyX },
     268              :         { SymId::noteheadHeavyXHat,           SymId::noteheadHeavyXHat,           SymId::noteheadHeavyXHat,
     269              :           SymId::noteheadHeavyXHat },
     270              : 
     271              :         { SymId::noteShapeKeystoneWhite,          SymId::noteShapeKeystoneWhite,          SymId::noteShapeKeystoneBlack,
     272              :           SymId::noteShapeKeystoneDoubleWhole },
     273              :         { SymId::noteShapeQuarterMoonWhite,       SymId::noteShapeQuarterMoonWhite,       SymId::noteShapeQuarterMoonBlack,
     274              :           SymId::noteShapeQuarterMoonDoubleWhole },
     275              :         { SymId::noteShapeIsoscelesTriangleWhite, SymId::noteShapeIsoscelesTriangleWhite, SymId::noteShapeIsoscelesTriangleBlack,
     276              :           SymId::noteShapeIsoscelesTriangleDoubleWhole },
     277              :         { SymId::noteShapeMoonLeftWhite,          SymId::noteShapeMoonLeftWhite,          SymId::noteShapeMoonLeftBlack,
     278              :           SymId::noteShapeMoonLeftDoubleWhole },
     279              :         { SymId::noteShapeArrowheadLeftWhite,     SymId::noteShapeArrowheadLeftWhite,     SymId::noteShapeArrowheadLeftBlack,
     280              :           SymId::noteShapeArrowheadLeftDoubleWhole },
     281              :         { SymId::noteShapeTriangleRoundLeftWhite, SymId::noteShapeTriangleRoundLeftWhite, SymId::noteShapeTriangleRoundLeftBlack,
     282              :           SymId::noteShapeTriangleRoundLeftDoubleWhole },
     283              : 
     284              :         { SymId::noteDoWhole,  SymId::noteDoHalf,  SymId::noteDoBlack,  SymId::noSym },
     285              :         { SymId::noteDiWhole,  SymId::noteDiHalf,  SymId::noteDiBlack,  SymId::noSym },
     286              :         { SymId::noteRaWhole,  SymId::noteRaHalf,  SymId::noteRaBlack,  SymId::noSym },
     287              :         { SymId::noteReWhole,  SymId::noteReHalf,  SymId::noteReBlack,  SymId::noSym },
     288              :         { SymId::noteRiWhole,  SymId::noteRiHalf,  SymId::noteRiBlack,  SymId::noSym },
     289              :         { SymId::noteMeWhole,  SymId::noteMeHalf,  SymId::noteMeBlack,  SymId::noSym },
     290              :         { SymId::noteMiWhole,  SymId::noteMiHalf,  SymId::noteMiBlack,  SymId::noSym },
     291              :         { SymId::noteFaWhole,  SymId::noteFaHalf,  SymId::noteFaBlack,  SymId::noSym },
     292              :         { SymId::noteFiWhole,  SymId::noteFiHalf,  SymId::noteFiBlack,  SymId::noSym },
     293              :         { SymId::noteSeWhole,  SymId::noteSeHalf,  SymId::noteSeBlack,  SymId::noSym },
     294              :         { SymId::noteSoWhole,  SymId::noteSoHalf,  SymId::noteSoBlack,  SymId::noSym },
     295              :         { SymId::noteLeWhole,  SymId::noteLeHalf,  SymId::noteLeBlack,  SymId::noSym },
     296              :         { SymId::noteLaWhole,  SymId::noteLaHalf,  SymId::noteLaBlack,  SymId::noSym },
     297              :         { SymId::noteLiWhole,  SymId::noteLiHalf,  SymId::noteLiBlack,  SymId::noSym },
     298              :         { SymId::noteTeWhole,  SymId::noteTeHalf,  SymId::noteTeBlack,  SymId::noSym },
     299              :         { SymId::noteTiWhole,  SymId::noteTiHalf,  SymId::noteTiBlack,  SymId::noSym },
     300              :         { SymId::noteSiWhole,  SymId::noteSiHalf,  SymId::noteSiBlack,  SymId::noSym },
     301              : 
     302              :         { SymId::noteASharpWhole,  SymId::noteASharpHalf,  SymId::noteASharpBlack,  SymId::noSym },
     303              :         { SymId::noteAWhole,       SymId::noteAHalf,       SymId::noteABlack,       SymId::noSym },
     304              :         { SymId::noteAFlatWhole,   SymId::noteAFlatHalf,   SymId::noteAFlatBlack,   SymId::noSym },
     305              :         { SymId::noteBSharpWhole,  SymId::noteBSharpHalf,  SymId::noteBSharpBlack,  SymId::noSym },
     306              :         { SymId::noteBWhole,       SymId::noteBHalf,       SymId::noteBBlack,       SymId::noSym },
     307              :         { SymId::noteBFlatWhole,   SymId::noteBFlatHalf,   SymId::noteBFlatBlack,   SymId::noSym },
     308              :         { SymId::noteCSharpWhole,  SymId::noteCSharpHalf,  SymId::noteCSharpBlack,  SymId::noSym },
     309              :         { SymId::noteCWhole,       SymId::noteCHalf,       SymId::noteCBlack,       SymId::noSym },
     310              :         { SymId::noteCFlatWhole,   SymId::noteCFlatHalf,   SymId::noteCFlatBlack,   SymId::noSym },
     311              :         { SymId::noteDSharpWhole,  SymId::noteDSharpHalf,  SymId::noteDSharpBlack,  SymId::noSym },
     312              :         { SymId::noteDWhole,       SymId::noteDHalf,       SymId::noteDBlack,       SymId::noSym },
     313              :         { SymId::noteDFlatWhole,   SymId::noteDFlatHalf,   SymId::noteDFlatBlack,   SymId::noSym },
     314              :         { SymId::noteESharpWhole,  SymId::noteESharpHalf,  SymId::noteESharpBlack,  SymId::noSym },
     315              :         { SymId::noteEWhole,       SymId::noteEHalf,       SymId::noteEBlack,       SymId::noSym },
     316              :         { SymId::noteEFlatWhole,   SymId::noteEFlatHalf,   SymId::noteEFlatBlack,   SymId::noSym },
     317              :         { SymId::noteFSharpWhole,  SymId::noteFSharpHalf,  SymId::noteFSharpBlack,  SymId::noSym },
     318              :         { SymId::noteFWhole,       SymId::noteFHalf,       SymId::noteFBlack,       SymId::noSym },
     319              :         { SymId::noteFFlatWhole,   SymId::noteFFlatHalf,   SymId::noteFFlatBlack,   SymId::noSym },
     320              :         { SymId::noteGSharpWhole,  SymId::noteGSharpHalf,  SymId::noteGSharpBlack,  SymId::noSym },
     321              :         { SymId::noteGWhole,       SymId::noteGHalf,       SymId::noteGBlack,       SymId::noSym },
     322              :         { SymId::noteGFlatWhole,   SymId::noteGFlatHalf,   SymId::noteGFlatBlack,   SymId::noSym },
     323              :         { SymId::noteHWhole,       SymId::noteHHalf,       SymId::noteHBlack,       SymId::noSym },
     324              :         { SymId::noteHSharpWhole,  SymId::noteHSharpHalf,  SymId::noteHSharpBlack,  SymId::noSym },
     325              : 
     326              :         { SymId::noSym, SymId::swissRudimentsNoteheadHalfFlam,   SymId::swissRudimentsNoteheadBlackFlam,   SymId::noSym },
     327              :         { SymId::noSym, SymId::swissRudimentsNoteheadHalfDouble, SymId::swissRudimentsNoteheadBlackDouble, SymId::noSym }
     328              :     }
     329              : };
     330              : 
     331              : //---------------------------------------------------------
     332              : //   noteHead
     333              : //---------------------------------------------------------
     334              : 
     335            2 : SymId Note::noteHead(int direction, NoteHeadGroup group, NoteHeadType t)
     336              : {
     337            2 :     return noteHeads[direction][int(group)][int(t)];
     338              : }
     339              : 
     340      1545990 : SymId Note::noteHead(int direction, NoteHeadGroup group, NoteHeadType t, int tpc, Key key, NoteHeadScheme scheme)
     341              : {
     342              :     // shortcut
     343      1545990 :     if (scheme == NoteHeadScheme::HEAD_NORMAL) {
     344      1543549 :         return noteHeads[direction][int(group)][int(t)];
     345              :     }
     346              :     // other schemes
     347         2441 :     if (scheme == NoteHeadScheme::HEAD_PITCHNAME || scheme == NoteHeadScheme::HEAD_PITCHNAME_GERMAN
     348          656 :         || scheme == NoteHeadScheme::HEAD_PITCHNAME_NO_ACCIDENTALS
     349          656 :         || scheme == NoteHeadScheme::HEAD_PITCHNAME_GERMAN_NO_ACCIDENTALS) {
     350         1785 :         const bool no_accidentals = scheme == NoteHeadScheme::HEAD_PITCHNAME_NO_ACCIDENTALS
     351         1785 :                                     || scheme == NoteHeadScheme::HEAD_PITCHNAME_GERMAN_NO_ACCIDENTALS;
     352         1785 :         const bool german = scheme == NoteHeadScheme::HEAD_PITCHNAME_GERMAN
     353         1785 :                             || scheme == NoteHeadScheme::HEAD_PITCHNAME_GERMAN_NO_ACCIDENTALS;
     354              : 
     355         1785 :         if (tpc == Tpc::TPC_A) {
     356          201 :             group = NoteHeadGroup::HEAD_A;
     357         1584 :         } else if (tpc == Tpc::TPC_B) {
     358          137 :             if (german) {
     359           27 :                 group = NoteHeadGroup::HEAD_H;
     360              :             } else {
     361          110 :                 group = NoteHeadGroup::HEAD_B;
     362              :             }
     363         1447 :         } else if (tpc == Tpc::TPC_C) {
     364          175 :             group = NoteHeadGroup::HEAD_C;
     365         1272 :         } else if (tpc == Tpc::TPC_D) {
     366          280 :             group = NoteHeadGroup::HEAD_D;
     367          992 :         } else if (tpc == Tpc::TPC_E) {
     368          254 :             group = NoteHeadGroup::HEAD_E;
     369          738 :         } else if (tpc == Tpc::TPC_F) {
     370          129 :             group = NoteHeadGroup::HEAD_F;
     371          609 :         } else if (tpc == Tpc::TPC_G) {
     372          197 :             group = NoteHeadGroup::HEAD_G;
     373          412 :         } else if (tpc == Tpc::TPC_A_S) {
     374            0 :             if (no_accidentals) {
     375            0 :                 group = NoteHeadGroup::HEAD_A;
     376              :             } else {
     377            0 :                 group = NoteHeadGroup::HEAD_A_SHARP;
     378              :             }
     379          412 :         } else if (tpc == Tpc::TPC_B_S) {
     380            0 :             if (no_accidentals) {
     381            0 :                 if (german) {
     382            0 :                     group = NoteHeadGroup::HEAD_H;
     383              :                 } else {
     384            0 :                     group = NoteHeadGroup::HEAD_B;
     385              :                 }
     386              :             } else {
     387            0 :                 if (german) {
     388            0 :                     group = NoteHeadGroup::HEAD_H_SHARP;
     389              :                 } else {
     390            0 :                     group = NoteHeadGroup::HEAD_B_SHARP;
     391              :                 }
     392              :             }
     393          412 :         } else if (tpc == Tpc::TPC_C_S) {
     394           84 :             if (no_accidentals) {
     395            0 :                 group = NoteHeadGroup::HEAD_C;
     396              :             } else {
     397           84 :                 group = NoteHeadGroup::HEAD_C_SHARP;
     398              :             }
     399          328 :         } else if (tpc == Tpc::TPC_D_S) {
     400           28 :             if (no_accidentals) {
     401            0 :                 group = NoteHeadGroup::HEAD_D;
     402              :             } else {
     403           28 :                 group = NoteHeadGroup::HEAD_D_SHARP;
     404              :             }
     405          300 :         } else if (tpc == Tpc::TPC_E_S) {
     406            0 :             if (no_accidentals) {
     407            0 :                 group = NoteHeadGroup::HEAD_E;
     408              :             } else {
     409            0 :                 group = NoteHeadGroup::HEAD_E_SHARP;
     410              :             }
     411          300 :         } else if (tpc == Tpc::TPC_F_S) {
     412          112 :             if (no_accidentals) {
     413            0 :                 group = NoteHeadGroup::HEAD_F;
     414              :             } else {
     415          112 :                 group = NoteHeadGroup::HEAD_F_SHARP;
     416              :             }
     417          188 :         } else if (tpc == Tpc::TPC_G_S) {
     418           44 :             if (no_accidentals) {
     419            0 :                 group = NoteHeadGroup::HEAD_G;
     420              :             } else {
     421           44 :                 group = NoteHeadGroup::HEAD_G_SHARP;
     422              :             }
     423          144 :         } else if (tpc == Tpc::TPC_A_B) {
     424           44 :             if (no_accidentals) {
     425            0 :                 group = NoteHeadGroup::HEAD_A;
     426              :             } else {
     427           44 :                 group = NoteHeadGroup::HEAD_A_FLAT;
     428              :             }
     429          100 :         } else if (tpc == Tpc::TPC_B_B) {
     430           28 :             if (no_accidentals) {
     431            0 :                 group = NoteHeadGroup::HEAD_B;
     432              :             } else {
     433           28 :                 if (german) {
     434           28 :                     group = NoteHeadGroup::HEAD_B;
     435              :                 } else {
     436            0 :                     group = NoteHeadGroup::HEAD_B_FLAT;
     437              :                 }
     438              :             }
     439           72 :         } else if (tpc == Tpc::TPC_C_B) {
     440            0 :             if (no_accidentals) {
     441            0 :                 group = NoteHeadGroup::HEAD_C;
     442              :             } else {
     443            0 :                 group = NoteHeadGroup::HEAD_C_FLAT;
     444              :             }
     445           72 :         } else if (tpc == Tpc::TPC_D_B) {
     446            0 :             if (no_accidentals) {
     447            0 :                 group = NoteHeadGroup::HEAD_D;
     448              :             } else {
     449            0 :                 group = NoteHeadGroup::HEAD_D_FLAT;
     450              :             }
     451           72 :         } else if (tpc == Tpc::TPC_E_B) {
     452           72 :             if (no_accidentals) {
     453            0 :                 group = NoteHeadGroup::HEAD_E;
     454              :             } else {
     455           72 :                 group = NoteHeadGroup::HEAD_E_FLAT;
     456              :             }
     457            0 :         } else if (tpc == Tpc::TPC_F_B) {
     458            0 :             if (no_accidentals) {
     459            0 :                 group = NoteHeadGroup::HEAD_F;
     460              :             } else {
     461            0 :                 group = NoteHeadGroup::HEAD_F_FLAT;
     462              :             }
     463            0 :         } else if (tpc == Tpc::TPC_G_B) {
     464            0 :             if (no_accidentals) {
     465            0 :                 group = NoteHeadGroup::HEAD_G;
     466              :             } else {
     467            0 :                 group = NoteHeadGroup::HEAD_G_FLAT;
     468              :             }
     469            0 :         } else if (no_accidentals) {
     470              :             // for TPCs that don't have their own heads (i.e. with 2 or 3 accidentals),
     471              :             // fall back to using the corresponding ones without accidentals
     472              :             // rather than using the (smaller!) normal noteheads
     473            0 :             if (tpc == Tpc::TPC_A_SS || tpc == Tpc::TPC_A_SSS) {
     474            0 :                 group = NoteHeadGroup::HEAD_A;
     475            0 :             } else if (tpc == Tpc::TPC_B_SS || tpc == Tpc::TPC_B_SSS) {
     476            0 :                 if (german) {
     477            0 :                     group = NoteHeadGroup::HEAD_H;
     478              :                 } else {
     479            0 :                     group = NoteHeadGroup::HEAD_B;
     480              :                 }
     481            0 :             } else if (tpc == Tpc::TPC_C_SS || tpc == Tpc::TPC_C_SSS) {
     482            0 :                 group = NoteHeadGroup::HEAD_C;
     483            0 :             } else if (tpc == Tpc::TPC_D_SS || tpc == Tpc::TPC_D_SSS) {
     484            0 :                 group = NoteHeadGroup::HEAD_D;
     485            0 :             } else if (tpc == Tpc::TPC_E_SS || tpc == Tpc::TPC_E_SSS) {
     486            0 :                 group = NoteHeadGroup::HEAD_E;
     487            0 :             } else if (tpc == Tpc::TPC_F_SS || tpc == Tpc::TPC_F_SSS) {
     488            0 :                 group = NoteHeadGroup::HEAD_F;
     489            0 :             } else if (tpc == Tpc::TPC_G_SS || tpc == Tpc::TPC_G_SSS) {
     490            0 :                 group = NoteHeadGroup::HEAD_G;
     491            0 :             } else if (tpc == Tpc::TPC_A_BB || tpc == Tpc::TPC_A_BBB) {
     492            0 :                 group = NoteHeadGroup::HEAD_A;
     493            0 :             } else if (tpc == Tpc::TPC_B_BB || tpc == Tpc::TPC_B_BBB) {
     494            0 :                 if (german) {
     495            0 :                     group = NoteHeadGroup::HEAD_H;
     496              :                 } else {
     497            0 :                     group = NoteHeadGroup::HEAD_B;
     498              :                 }
     499            0 :             } else if (tpc == Tpc::TPC_C_BB || tpc == Tpc::TPC_C_BBB) {
     500            0 :                 group = NoteHeadGroup::HEAD_C;
     501            0 :             } else if (tpc == Tpc::TPC_D_BB || tpc == Tpc::TPC_D_BBB) {
     502            0 :                 group = NoteHeadGroup::HEAD_D;
     503            0 :             } else if (tpc == Tpc::TPC_E_BB || tpc == Tpc::TPC_E_BBB) {
     504            0 :                 group = NoteHeadGroup::HEAD_E;
     505            0 :             } else if (tpc == Tpc::TPC_F_BB || tpc == Tpc::TPC_F_BBB) {
     506            0 :                 group = NoteHeadGroup::HEAD_F;
     507            0 :             } else if (tpc == Tpc::TPC_G_BB || tpc == Tpc::TPC_G_BBB) {
     508            0 :                 group = NoteHeadGroup::HEAD_G;
     509              :             }
     510              :         }
     511         2441 :     } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_4) {
     512            0 :         int degree = tpc2degree(tpc, key);
     513            0 :         switch (degree) {
     514            0 :         case 0:
     515              :         case 3:
     516            0 :             group = NoteHeadGroup::HEAD_FA;
     517            0 :             break;
     518            0 :         case 1:
     519              :         case 4:
     520            0 :             group = NoteHeadGroup::HEAD_SOL;
     521            0 :             break;
     522            0 :         case 2:
     523              :         case 5:
     524            0 :             group = NoteHeadGroup::HEAD_LA;
     525            0 :             break;
     526            0 :         case 6:
     527            0 :             group = NoteHeadGroup::HEAD_MI;
     528            0 :             break;
     529              :         }
     530          656 :     } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_AIKIN
     531          656 :                || scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_FUNK
     532          656 :                || scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_WALKER) {
     533            0 :         int degree = tpc2degree(tpc, key);
     534            0 :         switch (degree) {
     535            0 :         case 0:
     536            0 :             if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_AIKIN) {
     537            0 :                 group = NoteHeadGroup::HEAD_DO;
     538            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_FUNK) {
     539            0 :                 group = NoteHeadGroup::HEAD_DO_FUNK;
     540            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_WALKER) {
     541            0 :                 group = NoteHeadGroup::HEAD_DO_WALKER;
     542              :             }
     543            0 :             break;
     544            0 :         case 1:
     545            0 :             if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_AIKIN) {
     546            0 :                 group = NoteHeadGroup::HEAD_RE;
     547            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_FUNK) {
     548            0 :                 group = NoteHeadGroup::HEAD_RE_FUNK;
     549            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_WALKER) {
     550            0 :                 group = NoteHeadGroup::HEAD_RE_WALKER;
     551              :             }
     552            0 :             break;
     553            0 :         case 2:
     554            0 :             group = NoteHeadGroup::HEAD_MI;
     555            0 :             break;
     556            0 :         case 3:
     557            0 :             group = NoteHeadGroup::HEAD_FA;
     558            0 :             break;
     559            0 :         case 4:
     560            0 :             group = NoteHeadGroup::HEAD_SOL;
     561            0 :             break;
     562            0 :         case 5:
     563            0 :             group = NoteHeadGroup::HEAD_LA;
     564            0 :             break;
     565            0 :         case 6:
     566            0 :             if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_AIKIN) {
     567            0 :                 group = NoteHeadGroup::HEAD_TI;
     568            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_FUNK) {
     569            0 :                 group = NoteHeadGroup::HEAD_TI_FUNK;
     570            0 :             } else if (scheme == NoteHeadScheme::HEAD_SHAPE_NOTE_7_WALKER) {
     571            0 :                 group = NoteHeadGroup::HEAD_TI_WALKER;
     572              :             }
     573            0 :             break;
     574              :         }
     575          656 :     } else if (scheme == NoteHeadScheme::HEAD_SOLFEGE) {
     576          383 :         int degree = tpc2degree(tpc, key);
     577          383 :         int alteration = tpc2alterByKey(tpc, key);
     578          383 :         if (degree == 0 && alteration == 0) {
     579            0 :             group = NoteHeadGroup::HEAD_DO_NAME;
     580          383 :         } else if (degree == 0 && alteration == 1) {
     581           48 :             group = NoteHeadGroup::HEAD_DI_NAME;
     582          335 :         } else if (degree == 1 && alteration == -1) {
     583           44 :             group = NoteHeadGroup::HEAD_RA_NAME;
     584          291 :         } else if (degree == 1 && alteration == 0) {
     585            0 :             group = NoteHeadGroup::HEAD_RE_NAME;
     586          291 :         } else if (degree == 1 && alteration == 1) {
     587           44 :             group = NoteHeadGroup::HEAD_RI_NAME;
     588          247 :         } else if (degree == 2 && alteration == -1) {
     589           44 :             group = NoteHeadGroup::HEAD_ME_NAME;
     590          203 :         } else if (degree == 2 && alteration == 0) {
     591            0 :             group = NoteHeadGroup::HEAD_MI_NAME;
     592          203 :         } else if (degree == 3 && alteration == 0) {
     593            0 :             group = NoteHeadGroup::HEAD_FA_NAME;
     594          203 :         } else if (degree == 3 && alteration == 1) {
     595           44 :             group = NoteHeadGroup::HEAD_FI_NAME;
     596          159 :         } else if (degree == 4 && alteration == -1) {
     597           44 :             group = NoteHeadGroup::HEAD_SE_NAME;
     598          115 :         } else if (degree == 4 && alteration == 0) {
     599           43 :             group = NoteHeadGroup::HEAD_SOL_NAME;
     600           72 :         } else if (degree == 4 && alteration == 1) {
     601            0 :             group = NoteHeadGroup::HEAD_SI_NAME;
     602           72 :         } else if (degree == 5 && alteration == -1) {
     603            0 :             group = NoteHeadGroup::HEAD_LE_NAME;
     604           72 :         } else if (degree == 5 && alteration == 0) {
     605            0 :             group = NoteHeadGroup::HEAD_LA_NAME;
     606           72 :         } else if (degree == 5 && alteration == 1) {
     607           44 :             group = NoteHeadGroup::HEAD_LI_NAME;
     608           28 :         } else if (degree == 6 && alteration == -1) {
     609           28 :             group = NoteHeadGroup::HEAD_TE_NAME;
     610            0 :         } else if (degree == 6 && alteration == 0) {
     611            0 :             group = NoteHeadGroup::HEAD_TI_NAME;
     612              :         }
     613          273 :     } else if (scheme == NoteHeadScheme::HEAD_SOLFEGE_FIXED) {
     614          273 :         Char stepName = tpc2stepName(tpc);
     615          273 :         if (stepName == u'C') {
     616           74 :             group = NoteHeadGroup::HEAD_DO_NAME;
     617          199 :         } else if (stepName == u'D') {
     618           43 :             group = NoteHeadGroup::HEAD_RE_NAME;
     619          156 :         } else if (stepName == u'E') {
     620           43 :             group = NoteHeadGroup::HEAD_MI_NAME;
     621          113 :         } else if (stepName == u'F') {
     622           43 :             group = NoteHeadGroup::HEAD_FA_NAME;
     623           70 :         } else if (stepName == u'G') {
     624            0 :             group = NoteHeadGroup::HEAD_SOL_NAME;
     625           70 :         } else if (stepName == u'A') {
     626           43 :             group = NoteHeadGroup::HEAD_LA_NAME;
     627           27 :         } else if (stepName == u'B') {
     628           27 :             group = NoteHeadGroup::HEAD_SI_NAME;
     629              :         }
     630              :     }
     631         2441 :     return noteHeads[direction][int(group)][int(t)];
     632              : }
     633              : 
     634            0 : NoteHead::NoteHead(DummyParentOr<Note> parent)
     635            0 :     : Symbol(ElementType::NOTEHEAD, parent) {}
     636              : 
     637              : //---------------------------------------------------------
     638              : //   headGroup
     639              : //   used only when dropping a notehead from the palette
     640              : //   they are either half note, either double whole
     641              : //---------------------------------------------------------
     642              : 
     643            0 : NoteHeadGroup NoteHead::headGroup() const
     644              : {
     645            0 :     NoteHeadGroup group = NoteHeadGroup::HEAD_INVALID;
     646            0 :     for (int i = 0; i < int(NoteHeadGroup::HEAD_DO_WALKER); ++i) {
     647            0 :         if (noteHeads[0][i][1] == m_sym || noteHeads[0][i][3] == m_sym) {
     648            0 :             group = (NoteHeadGroup)i;
     649            0 :             break;
     650              :         }
     651              :     }
     652            0 :     return group;
     653              : }
     654              : 
     655              : //---------------------------------------------------------
     656              : //   Note
     657              : //---------------------------------------------------------
     658              : 
     659        38135 : Note::Note(DummyParentOr<Chord> ch)
     660        38135 :     : EngravingItem(ElementType::NOTE, ch, ElementFlag::MOVABLE)
     661              : {
     662        38135 :     m_playEvents.push_back(NoteEvent());      // add default play event
     663        38135 : }
     664              : 
     665        79020 : Note::~Note()
     666              : {
     667        39510 :     delete m_accidental;
     668        39510 :     muse::DeleteAll(m_el);
     669              : 
     670        39510 :     if (m_tieFor && m_tieFor->parent() == this) {
     671          793 :         delete m_tieFor;
     672              :     }
     673              : 
     674        39510 :     muse::DeleteAll(m_dots);
     675        39510 :     muse::DeleteAll(m_jianpuOctaveDots);
     676        79020 : }
     677              : 
     678         7867 : std::vector<Note*> Note::compoundNotes() const
     679              : {
     680         7867 :     std::vector<Note*> elements;
     681         7867 :     if (Note* note = firstTiedNote()) {
     682         7867 :         elements.push_back(note);
     683              :     }
     684              : 
     685         7867 :     if (Note* note = lastTiedNote()) {
     686         7867 :         elements.push_back(note);
     687              :     }
     688              : 
     689         7868 :     for (Spanner* e : m_spannerFor) {
     690            1 :         elements.push_back(toNote(e->endElement()));
     691              :     }
     692         7868 :     for (Spanner* e : m_spannerBack) {
     693            1 :         elements.push_back(toNote(e->startElement()));
     694              :     }
     695              : 
     696         7867 :     Beam* beam = chord()->beam();
     697         7867 :     if (beam) {
     698         3176 :         for (EngravingItem* e : beam->elements()) {
     699         2480 :             if (e && e->isNote() && e != this) {
     700            0 :                 elements.push_back(toNote(e));
     701              :             }
     702              :         }
     703              :     }
     704              : 
     705         7867 :     return elements;
     706            0 : }
     707              : 
     708         6289 : Note::Note(const Note& n, bool link)
     709         6289 :     : EngravingItem(n, link)
     710              : {
     711         6289 :     if (link) {
     712         1080 :         score()->undo(new Link(this, const_cast<Note*>(&n)));
     713              :     }
     714         6289 :     m_subchannel        = n.m_subchannel;
     715         6289 :     m_line              = n.m_line;
     716         6289 :     m_fret              = n.m_fret;
     717         6289 :     m_harmonicFret     = n.m_harmonicFret;
     718         6289 :     m_displayFret      = n.m_displayFret;
     719         6289 :     m_string            = n.m_string;
     720         6289 :     m_fretConflict      = n.m_fretConflict;
     721         6289 :     m_ghost             = n.m_ghost;
     722         6289 :     m_deadNote          = n.m_deadNote;
     723         6289 :     m_pitch             = n.m_pitch;
     724         6289 :     m_centOffset        = n.m_centOffset;
     725         6289 :     m_tpc[0]            = n.m_tpc[0];
     726         6289 :     m_tpc[1]            = n.m_tpc[1];
     727         6289 :     m_dotsHidden        = n.m_dotsHidden;
     728         6289 :     m_hidden            = n.m_hidden;
     729         6289 :     m_play              = n.m_play;
     730         6289 :     m_tuning            = n.m_tuning;
     731         6289 :     m_veloType          = n.m_veloType;
     732         6289 :     m_userVelocity      = n.m_userVelocity;
     733         6289 :     m_headScheme        = n.m_headScheme;
     734         6289 :     m_headGroup         = n.m_headGroup;
     735         6289 :     m_headType          = n.m_headType;
     736         6289 :     m_userMirror        = n.m_userMirror;
     737         6289 :     m_isSmall          = n.m_isSmall;
     738         6289 :     m_userDotPosition   = n.m_userDotPosition;
     739         6289 :     m_fixed             = n.m_fixed;
     740         6289 :     m_fixedLine         = n.m_fixedLine;
     741         6289 :     m_harmonic          = n.m_harmonic;
     742         6289 :     m_hasParens         = n.m_hasParens;
     743         6289 :     m_hideGeneratedParens = n.m_hideGeneratedParens;
     744              : 
     745         6289 :     if (n.m_accidental) {
     746           30 :         add(new Accidental(*(n.m_accidental)));
     747              :     }
     748              : 
     749              :     // types in _el: SYMBOL, IMAGE, FINGERING, TEXT, BEND
     750         6289 :     const Staff* stf = staff();
     751         6289 :     bool tabFingering = stf ? stf->staffTypeForElement(this)->showTabFingering() : false;
     752         6314 :     for (EngravingItem* e : n.m_el) {
     753           25 :         if (e->isFingering() && staff()->isTabStaff(tick()) && !tabFingering) {      // tablature has no fingering
     754            0 :             continue;
     755              :         }
     756           25 :         EngravingItem* ce = e->clone();
     757           25 :         add(ce);
     758           25 :         if (link) {
     759           25 :             score()->undo(new Link(ce, const_cast<EngravingItem*>(e)));
     760              :         }
     761              :     }
     762              : 
     763         6289 :     m_playEvents = n.m_playEvents;
     764              : 
     765         6289 :     if (n.laissezVib()) {
     766            0 :         m_tieFor = Factory::copyLaissezVib(*toLaissezVib(n.m_tieFor));
     767            0 :         m_tieFor->setOwnershipParent(this);
     768            0 :         m_tieFor->setStartNote(this);
     769            0 :         m_tieFor->setTick(tick());
     770            0 :         if (link) {
     771            0 :             score()->undo(new Link(m_tieFor, n.m_tieFor));
     772              :         }
     773         6289 :     } else if (n.outgoingPartialTie()) {
     774            0 :         setTieFor(Factory::copyPartialTie(*toPartialTie(n.m_tieFor)));
     775            0 :         m_tieFor->setOwnershipParent(this);
     776            0 :         m_tieFor->setStartNote(this);
     777            0 :         m_tieFor->setTick(tick());
     778            0 :         if (link) {
     779            0 :             score()->undo(new Link(m_tieFor, n.m_tieFor));
     780              :         }
     781         6289 :     } else if (n.m_tieFor) {
     782          425 :         m_tieFor = Factory::copyTie(*n.m_tieFor);
     783          425 :         m_tieFor->setStartNote(this);
     784          425 :         m_tieFor->setTick(tick());
     785          425 :         m_tieFor->setEndNote(0);
     786              :     }
     787              : 
     788         6289 :     if (n.incomingPartialTie()) {
     789            0 :         setTieBack(Factory::copyPartialTie(*toPartialTie(n.m_tieBack)));
     790            0 :         m_tieBack->setOwnershipParent(this);
     791            0 :         m_tieBack->setEndNote(this);
     792            0 :         m_tieBack->setTick(tick());
     793            0 :         if (link) {
     794            0 :             score()->undo(new Link(m_tieBack, n.m_tieBack));
     795              :         }
     796              :     }
     797              : 
     798         6323 :     for (NoteDot* dot : n.m_dots) {
     799           34 :         add(Factory::copyNoteDot(*dot));
     800              :     }
     801         6289 :     m_mark = n.m_mark;
     802         6289 :     m_jianpuDigit = n.m_jianpuDigit;
     803         6289 :     m_jianpuAccidental = n.m_jianpuAccidental;
     804              : 
     805         6289 :     setDropTarget(false);
     806         6289 : }
     807              : 
     808          354 : void Note::setOwnershipParent(DummyParentOr<Chord> ch)
     809              : {
     810          354 :     EngravingItem::setOwnershipParent(ch);
     811          354 : }
     812              : 
     813              : //---------------------------------------------------------
     814              : //   concertPitchIdx
     815              : //---------------------------------------------------------
     816              : 
     817      1901196 : inline int Note::concertPitchIdx() const
     818              : {
     819      1901196 :     return concertPitch() ? 0 : 1;
     820              : }
     821              : 
     822              : //---------------------------------------------------------
     823              : //   setPitch
     824              : //---------------------------------------------------------
     825              : 
     826        41683 : void Note::setPitch(int val, bool notifyAboutChanged)
     827              : {
     828        41683 :     assert(pitchIsValid(val));
     829        41683 :     if (m_pitch != val) {
     830        39623 :         m_pitch = val;
     831              : 
     832        39623 :         if (notifyAboutChanged) {
     833              : #ifndef ENGRAVING_NO_ACCESSIBILITY
     834        19922 :             notifyAboutNameChanged();
     835              : #endif
     836              :         }
     837              :     }
     838        41683 : }
     839              : 
     840         7831 : void Note::setPitch(int pitch, int tpc1, int tpc2)
     841              : {
     842         7831 :     assert(tpcIsValid(tpc1));
     843         7831 :     assert(tpcIsValid(tpc2));
     844         7831 :     m_tpc[0] = tpc1;
     845         7831 :     m_tpc[1] = tpc2;
     846         7831 :     setPitch(pitch);
     847         7831 : }
     848              : 
     849              : //---------------------------------------------------------
     850              : //   tpc1default
     851              : //---------------------------------------------------------
     852              : 
     853            0 : int Note::tpc1default(int p) const
     854              : {
     855            0 :     Key key = Key::C;
     856            0 :     if (staff() && chord()) {
     857            0 :         Fraction tick = chord()->tick();
     858            0 :         key = staff()->concertKey(tick);
     859              :     }
     860            0 :     return pitch2tpc(p, key, Prefer::NEAREST);
     861              : }
     862              : 
     863              : //---------------------------------------------------------
     864              : //   tpc2default
     865              : //---------------------------------------------------------
     866              : 
     867            0 : int Note::tpc2default(int p) const
     868              : {
     869            0 :     Key key = Key::C;
     870            0 :     if (staff() && chord()) {
     871            0 :         Fraction tick = chord()->tick();
     872            0 :         key = staff()->key(tick);
     873            0 :         if (concertPitch()) {
     874            0 :             Interval interval = originPart()->instrument(tick)->transpose();
     875            0 :             if (!interval.isZero()) {
     876            0 :                 interval.flip();
     877            0 :                 key = Transpose::transposeKey(key, interval);
     878              :             }
     879              :         }
     880              :     }
     881            0 :     return pitch2tpc(p - transposition(), key, Prefer::NEAREST);
     882              : }
     883              : 
     884              : //---------------------------------------------------------
     885              : //   setTpcFromPitch
     886              : //---------------------------------------------------------
     887              : 
     888         5232 : void Note::setTpcFromPitch(Prefer prefer /* = Prefer::NEAREST */)
     889              : {
     890              :     // works best if note is already added to score, otherwise we can't determine transposition or key
     891         5232 :     Fraction tick = chord() ? chord()->tick() : Fraction(-1, 1);
     892         5232 :     Interval v = staff() ? staff()->transpose(tick) : Interval();
     893         5232 :     Key cKey = (staff() && chord()) ? staff()->concertKey(chord()->tick()) : Key::C;
     894              :     // set concert pitch tpc
     895         5232 :     m_tpc[0] = pitch2tpc(m_pitch, cKey, prefer);
     896              :     // set transposed tpc
     897         5232 :     if (v.isZero()) {
     898         3088 :         m_tpc[1] = m_tpc[0];
     899              :     } else {
     900         2144 :         v.flip();
     901         2144 :         m_tpc[1] = Transpose::transposeTpc(m_tpc[0], v, true);
     902              :     }
     903         5232 :     assert(tpcIsValid(m_tpc[0]));
     904         5232 :     assert(tpcIsValid(m_tpc[1]));
     905         5232 : }
     906              : 
     907              : //---------------------------------------------------------
     908              : //   setTpc
     909              : //---------------------------------------------------------
     910              : 
     911           13 : void Note::setTpc(int v)
     912              : {
     913           13 :     IF_ASSERT_FAILED(tpcIsValid(v)) {
     914            0 :         return;
     915              :     }
     916           13 :     m_tpc[concertPitchIdx()] = v;
     917              : }
     918              : 
     919              : //---------------------------------------------------------
     920              : //   undoSetTpc
     921              : //    change the current tpc
     922              : //---------------------------------------------------------
     923              : 
     924          130 : void Note::undoSetTpc(int v)
     925              : {
     926          130 :     if (concertPitch()) {
     927            0 :         if (v != tpc1()) {
     928            0 :             undoChangeProperty(Pid::TPC1, v);
     929              :         }
     930              :     } else {
     931          130 :         if (v != tpc2()) {
     932          130 :             undoChangeProperty(Pid::TPC2, v);
     933              :         }
     934              :     }
     935          130 : }
     936              : 
     937              : //---------------------------------------------------------
     938              : //   tpc
     939              : //---------------------------------------------------------
     940              : 
     941      1901183 : int Note::tpc() const
     942              : {
     943      1901183 :     return m_tpc[concertPitchIdx()];
     944              : }
     945              : 
     946              : //---------------------------------------------------------
     947              : //   tpcUserName
     948              : //---------------------------------------------------------
     949              : 
     950            0 : String Note::tpcUserName(const bool explicitAccidental, bool full) const
     951              : {
     952            0 :     String pitchName = engraving::tpcUserName(tpc(), epitch() + ottaveCapoFret(), explicitAccidental, full);
     953              : 
     954            0 :     pitchName = muse::mtrc("global/pitchName", pitchName);
     955              : 
     956            0 :     if (fixed() && headGroup() == NoteHeadGroup::HEAD_SLASH) {
     957              :         // see Note::accessibleInfo(), but we return what we have
     958            0 :         return pitchName;
     959              :     }
     960            0 :     if (staff()->isDrumStaff(tick()) && originPart()->instrument(tick())->drumset()) {
     961              :         // see Note::accessibleInfo(), but we return what we have
     962            0 :         return pitchName;
     963              :     }
     964            0 :     if (staff()->isTabStaff(tick())) {
     965              :         // no further translation
     966            0 :         return pitchName;
     967              :     }
     968              : 
     969            0 :     String pitchOffset;
     970            0 :     if (tuning() != 0) {
     971              :         static constexpr size_t bufferSize = 50;
     972              :         char buffer[bufferSize];
     973            0 :         snprintf(buffer, bufferSize, "%+.3f", tuning());
     974            0 :         pitchOffset = String::fromAscii(buffer);
     975              :     }
     976              : 
     977            0 :     if (!concertPitch() && transposition()) {
     978            0 :         String soundingPitch = engraving::tpcUserName(tpc1(), ppitch(), explicitAccidental);
     979            0 :         soundingPitch = muse::mtrc("global/pitchName", soundingPitch);
     980            0 :         return muse::mtrc("engraving", "%1 (sounding as %2%3)").arg(pitchName, soundingPitch, pitchOffset);
     981            0 :     }
     982            0 :     return pitchName + pitchOffset;
     983            0 : }
     984              : 
     985              : //---------------------------------------------------------
     986              : //   transposeTpc
     987              : //    return transposed tpc
     988              : //    If in concertPitch mode return tpc for transposed view
     989              : //    else return tpc for concert pitch view.
     990              : //---------------------------------------------------------
     991              : 
     992          308 : int Note::transposeTpc(int tpc) const
     993              : {
     994          308 :     Fraction tick = chord() ? chord()->tick() : Fraction(-1, 1);
     995          308 :     Interval v = staff()->transpose(tick);
     996          308 :     if (v.isZero()) {
     997           35 :         return tpc;
     998              :     }
     999          273 :     if (concertPitch()) {
    1000            0 :         v.flip();
    1001            0 :         return Transpose::transposeTpc(tpc, v, true);
    1002              :     } else {
    1003          273 :         return Transpose::transposeTpc(tpc, v, true);
    1004              :     }
    1005              : }
    1006              : 
    1007         1574 : int Note::playingTpc() const
    1008              : {
    1009         1574 :     int result = tpc();
    1010              : 
    1011         1574 :     if (!concertPitch() && transposition()) {
    1012           88 :         int tpc1 = this->tpc1();
    1013           88 :         if (tpc1 == Tpc::TPC_INVALID) {
    1014            0 :             result = transposeTpc(result);
    1015              :         } else {
    1016           88 :             result = tpc1;
    1017              :         }
    1018              :     }
    1019              : 
    1020         1574 :     int steps = ottaveCapoFret();
    1021         1574 :     if (steps != 0) {
    1022            0 :         result = Transpose::transposeTpc(result, Interval(steps), true);
    1023              :     }
    1024              : 
    1025         1574 :     return result;
    1026              : }
    1027              : 
    1028              : //---------------------------------------------------------
    1029              : //   noteHead
    1030              : //---------------------------------------------------------
    1031              : 
    1032      1545990 : SymId Note::noteHead() const
    1033              : {
    1034              :     int up;
    1035              :     NoteHeadType ht;
    1036      1545990 :     if (chord()) {
    1037      1545990 :         up = chord()->up();
    1038      1545990 :         ht = chord()->durationType().headType();
    1039              :     } else {
    1040            0 :         up = 1;
    1041            0 :         ht = NoteHeadType::HEAD_QUARTER;
    1042              :     }
    1043      1545990 :     if (m_headType != NoteHeadType::HEAD_AUTO) {
    1044         1500 :         ht = m_headType;
    1045              :     }
    1046              : 
    1047      1545990 :     const Staff* st = chord() ? chord()->staff() : nullptr;
    1048              : 
    1049      1545990 :     NoteHeadGroup headGroup = m_headGroup;
    1050      1545990 :     if (m_headGroup == NoteHeadGroup::HEAD_CUSTOM) {
    1051            0 :         if (st) {
    1052            0 :             if (st->staffTypeForElement(chord())->isDrumStaff()) {
    1053            0 :                 Fraction t = chord()->tick();
    1054            0 :                 Instrument* inst = originPart()->instrument(t);
    1055            0 :                 Drumset* d = inst->drumset();
    1056            0 :                 if (d) {
    1057            0 :                     return d->noteHeads(m_pitch, ht);
    1058              :                 } else {
    1059            0 :                     LOGD("no drumset");
    1060            0 :                     return noteHead(up, NoteHeadGroup::HEAD_NORMAL, ht);
    1061              :                 }
    1062              :             } else {
    1063            0 :                 headGroup = NoteHeadGroup::HEAD_NORMAL;
    1064              :             }
    1065              :         } else {
    1066            0 :             return ldata()->cachedNoteheadSym.value();
    1067              :         }
    1068              :     }
    1069              : 
    1070      1545990 :     Key key = Key::C;
    1071      1545990 :     NoteHeadScheme scheme = m_headScheme;
    1072      1545990 :     if (st) {
    1073      1545990 :         Fraction tick = chord()->tick();
    1074      1545990 :         if (tick >= Fraction(0, 1)) {
    1075      1545990 :             key    = st->key(tick);
    1076      1545990 :             if (scheme == NoteHeadScheme::HEAD_AUTO) {
    1077      1543549 :                 scheme = st->staffTypeForElement(chord())->noteHeadScheme();
    1078              :             }
    1079              :         }
    1080              :     }
    1081      1545990 :     if (scheme == NoteHeadScheme::HEAD_AUTO) {
    1082            0 :         scheme = NoteHeadScheme::HEAD_NORMAL;
    1083              :     }
    1084      1545990 :     SymId t = noteHead(up, headGroup, ht, tpc(), key, scheme);
    1085      1545990 :     if (t == SymId::noSym) {
    1086            0 :         LOGD("invalid notehead %d/%d", int(headGroup), int(ht));
    1087            0 :         t = noteHead(up, NoteHeadGroup::HEAD_NORMAL, ht);
    1088              :     }
    1089      1545990 :     return t;
    1090              : }
    1091              : 
    1092              : //---------------------------------------------------------
    1093              : //   headWidth
    1094              : //
    1095              : //    returns the x of the symbol bbox. It is different from headWidth() because zero point could be different from leftmost bbox position.
    1096              : //---------------------------------------------------------
    1097        63424 : double Note::bboxRightPos() const
    1098              : {
    1099        63424 :     const auto& bbox = score()->engravingFont()->bbox(noteHead(), magS());
    1100       126848 :     return bbox.right();
    1101              : }
    1102              : 
    1103              : //---------------------------------------------------------
    1104              : //   headBodyWidth
    1105              : //
    1106              : //    returns the width of the notehead "body". It is actual for slashed noteheads like -O-, where O is body.
    1107              : //---------------------------------------------------------
    1108       276579 : double Note::headBodyWidth() const
    1109              : {
    1110       276579 :     const StaffType* st = staffType();
    1111       276579 :     if (st && st->isTabStaff()) {
    1112          335 :         return tabHeadWidth(st);
    1113              :     }
    1114       276244 :     return headWidth() + 2 * bboxXShift();
    1115              : }
    1116              : 
    1117              : //---------------------------------------------------------
    1118              : //   outsideTieAttachX
    1119              : //
    1120              : //    returns the X-position for tie attachment for this particular notehead
    1121              : //---------------------------------------------------------
    1122            0 : double Note::outsideTieAttachX(bool up) const
    1123              : {
    1124            0 :     double xo = 0;
    1125              : 
    1126              :     // tab staff notes just use center of bounding box
    1127            0 :     if (staffType()->isTabStaff()) {
    1128            0 :         return x() + ((width() / 2) * mag());
    1129              :     }
    1130              :     // special cases:
    1131            0 :     if (m_headGroup == NoteHeadGroup::HEAD_SLASH) {
    1132            0 :         xo = (up ? headWidth() * 0.75 : headWidth() * 0.25);
    1133            0 :         if (chord()->durationType().hasStem()) {
    1134              :             // for quarters and halves, we can safely move a little bit outwards
    1135            0 :             xo += spatium() * 0.13 * (chord()->up() ? -mag() : mag());
    1136              :         }
    1137            0 :         return x() + xo;
    1138              :     }
    1139            0 :     if (m_headGroup == NoteHeadGroup::HEAD_SLASHED1 || m_headGroup == NoteHeadGroup::HEAD_SLASHED2) {
    1140              :         // just use the very center of the notehead
    1141            0 :         return x() + ((headBodyWidth() / 2) * mag());
    1142              :     }
    1143              :     /* Noteheads do not have optical centers at this time, but here's the code
    1144              :        to future-proof
    1145              :     xo = symSmuflAnchor(noteHead(), SmuflAnchorId::opticalCenter).x() * mag();
    1146              :     if (xo > 0) {
    1147              :         return x() + xo;
    1148              :     }
    1149              :     */
    1150              :     // try for average of cutouts
    1151            0 :     if (up) {
    1152            0 :         double xNE = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutNE).x();
    1153            0 :         double xNW = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutNW).x();
    1154            0 :         xo = ((xNE + xNW) / 2);
    1155            0 :         if (xNE < xNW) {
    1156              :             // musejazz is busted
    1157            0 :             xo = 0;
    1158              :         }
    1159              :     } else {
    1160            0 :         double xSE = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutSE).x();
    1161            0 :         double xSW = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutSW).x();
    1162            0 :         xo = ((xSE + xSW) / 2);
    1163            0 :         if (xSE < xSW) {
    1164            0 :             xo = 0;
    1165              :         }
    1166              :     }
    1167            0 :     if (xo > 0) {
    1168            0 :         return x() + xo;
    1169              :     }
    1170              :     // no cutout, not a slash head, default to middle of notehead
    1171            0 :     return x() + (headWidth() / 2);
    1172              : }
    1173              : 
    1174            0 : void Note::updateHeadGroup(const NoteHeadGroup headGroup)
    1175              : {
    1176            0 :     NoteHeadGroup group = headGroup;
    1177              : 
    1178            0 :     if (group == NoteHeadGroup::HEAD_INVALID) {
    1179            0 :         LOGD("unknown notehead");
    1180            0 :         group = NoteHeadGroup::HEAD_NORMAL;
    1181              :     }
    1182              : 
    1183            0 :     if (group == m_headGroup) {
    1184            0 :         return;
    1185              :     }
    1186              : 
    1187            0 :     if (links()) {
    1188            0 :         for (EngravingObject* scoreElement : *links()) {
    1189            0 :             scoreElement->undoChangeProperty(Pid::HEAD_GROUP, group);
    1190            0 :             Note* note = toNote(scoreElement);
    1191              : 
    1192            0 :             if (note->staff() && !note->staff()->isDrumStaff(chord()->tick()) && group == NoteHeadGroup::HEAD_CROSS) {
    1193            0 :                 scoreElement->undoChangeProperty(Pid::DEAD, true);
    1194              :             }
    1195              :         }
    1196              :     } else {
    1197            0 :         undoChangeProperty(Pid::HEAD_GROUP, group);
    1198              :     }
    1199              : }
    1200              : 
    1201              : //---------------------------------------------------------
    1202              : //   headWidth
    1203              : //
    1204              : //    returns the width of the symbol bbox
    1205              : //    or the width of the string representation of the fret mark
    1206              : //---------------------------------------------------------
    1207              : 
    1208       355681 : double Note::headWidth() const
    1209              : {
    1210       355681 :     return symWidth(noteHead());
    1211              : }
    1212              : 
    1213              : //---------------------------------------------------------
    1214              : //   bboxXShift
    1215              : //
    1216              : //    returns the x shift of the notehead bounding box
    1217              : //---------------------------------------------------------
    1218       298039 : double Note::bboxXShift() const
    1219              : {
    1220       298039 :     const auto& bbox = score()->engravingFont()->bbox(noteHead(), magS());
    1221       298039 :     return bbox.bottomLeft().x();
    1222              : }
    1223              : 
    1224              : //---------------------------------------------------------
    1225              : //   noteheadCenterX
    1226              : //
    1227              : //    returns the x coordinate of the notehead center related to the basepoint of the notehead bbox
    1228              : //---------------------------------------------------------
    1229         9099 : double Note::noteheadCenterX() const
    1230              : {
    1231         9099 :     return score()->engravingFont()->width(noteHead(), magS()) / 2 + bboxXShift();
    1232              : }
    1233              : 
    1234              : //---------------------------------------------------------
    1235              : //   tabHeadWidth
    1236              : //---------------------------------------------------------
    1237              : 
    1238         3899 : double Note::tabHeadWidth(const StaffType* tab) const
    1239              : {
    1240              :     double val;
    1241         3899 :     if (tab && tab->isTabStaff() && m_fret != INVALID_FRET_INDEX && m_string != INVALID_STRING_INDEX) {
    1242         2044 :         Font f = tab->fretFont();
    1243         2044 :         f.setPointSizeF(tab->fretFontSize());
    1244         2044 :         val = FontMetrics::width(f, m_fretString) * magS();
    1245         2044 :     } else {
    1246         1855 :         val = headWidth();
    1247              :     }
    1248         3899 :     return val;
    1249              : }
    1250              : 
    1251              : //---------------------------------------------------------
    1252              : //   headHeight
    1253              : //
    1254              : //    returns the height of the notehead symbol
    1255              : //    or the height of the string representation of the fret mark
    1256              : //---------------------------------------------------------
    1257              : 
    1258         8170 : double Note::headHeight() const
    1259              : {
    1260         8170 :     return symHeight(noteHead());
    1261              : }
    1262              : 
    1263              : //---------------------------------------------------------
    1264              : //   tabHeadHeight
    1265              : //---------------------------------------------------------
    1266              : 
    1267            0 : double Note::tabHeadHeight(const StaffType* tab) const
    1268              : {
    1269            0 :     if (tab && m_fret != INVALID_FRET_INDEX && m_string != INVALID_STRING_INDEX) {
    1270            0 :         return tab->fretBoxH() * magS();
    1271              :     }
    1272            0 :     return headHeight();
    1273              : }
    1274              : 
    1275              : //---------------------------------------------------------
    1276              : //   stemDownNW
    1277              : //---------------------------------------------------------
    1278              : 
    1279       336341 : PointF Note::stemDownNW() const
    1280              : {
    1281       336341 :     return symSmuflAnchor(noteHead(), SmuflAnchorId::stemDownNW);
    1282              : }
    1283              : 
    1284              : //---------------------------------------------------------
    1285              : //   stemUpSE
    1286              : //---------------------------------------------------------
    1287              : 
    1288       410144 : PointF Note::stemUpSE() const
    1289              : {
    1290       410144 :     return symSmuflAnchor(noteHead(), SmuflAnchorId::stemUpSE);
    1291              : }
    1292              : 
    1293              : //---------------------------------------------------------
    1294              : //   playTicks
    1295              : ///   Return total tick len of tied notes
    1296              : //---------------------------------------------------------
    1297              : 
    1298          722 : int Note::playTicks() const
    1299              : {
    1300          722 :     return playTicksFraction().ticks();
    1301              : }
    1302              : 
    1303              : //---------------------------------------------------------
    1304              : //   playTicksFraction
    1305              : ///   Return total tick len of tied notes
    1306              : //---------------------------------------------------------
    1307              : 
    1308          722 : Fraction Note::playTicksFraction() const
    1309              : {
    1310          722 :     if (!m_tieBack && !m_tieFor && chord()) {
    1311          670 :         return chord()->actualTicks();
    1312              :     }
    1313           52 :     return lastTiedNote()->chord()->endTick() - firstTiedNote()->chord()->tick();
    1314              : }
    1315              : 
    1316              : //---------------------------------------------------------
    1317              : //   addSpanner
    1318              : //---------------------------------------------------------
    1319              : 
    1320          394 : void Note::addSpanner(Spanner* l)
    1321              : {
    1322          394 :     EngravingItem* e = l->endElement();
    1323          394 :     if (e && e->isNote()) {
    1324          375 :         Note* note = toNote(e);
    1325          375 :         note->addSpannerBack(l);
    1326              :     }
    1327          394 :     addSpannerFor(l);
    1328          394 : }
    1329              : 
    1330              : //---------------------------------------------------------
    1331              : //   removeSpanner
    1332              : //---------------------------------------------------------
    1333              : 
    1334            0 : void Note::removeSpanner(Spanner* l)
    1335              : {
    1336            0 :     Note* e = toNote(l->endElement());
    1337            0 :     if (e && e->isNote()) {
    1338            0 :         if (!e->removeSpannerBack(l)) {
    1339            0 :             LOGD("Note::removeSpanner(%p): cannot remove spannerBack %s %p", this, l->typeName(), l);
    1340              :             // abort();
    1341              :         }
    1342              :     }
    1343            0 :     if (!removeSpannerFor(l)) {
    1344            0 :         LOGD("Note(%p): cannot remove spannerFor %s %p", this, l->typeName(), l);
    1345              :         // abort();
    1346              :     }
    1347            0 : }
    1348              : 
    1349              : //---------------------------------------------------------
    1350              : //   add
    1351              : //---------------------------------------------------------
    1352              : 
    1353         7185 : void Note::add(EngravingItem* e)
    1354              : {
    1355         7185 :     if (e->ownershipParent() != this) {
    1356          349 :         e->setOwnershipParent(this);
    1357              :     }
    1358         7185 :     e->setTrack(track());
    1359              : 
    1360         7185 :     switch (e->type()) {
    1361          724 :     case ElementType::NOTEDOT:
    1362          724 :         m_dots.push_back(toNoteDot(e));
    1363          724 :         break;
    1364          338 :     case ElementType::BEND:
    1365              :     case ElementType::FINGERING:
    1366              :     case ElementType::IMAGE:
    1367              :     case ElementType::TEXT:
    1368          338 :         m_el.push_back(e);
    1369          338 :         break;
    1370           32 :     case ElementType::SYMBOL: {
    1371           32 :         m_el.push_back(e);
    1372           32 :     } break;
    1373           19 :     case ElementType::LAISSEZ_VIB: {
    1374           19 :         LaissezVib* lv = toLaissezVib(e);
    1375           19 :         lv->setStartNote(this);
    1376           19 :         lv->setTick(lv->startNote()->tick());
    1377           19 :         setTieFor(lv);
    1378           19 :         break;
    1379              :     }
    1380           75 :     case ElementType::PARTIAL_TIE: {
    1381           75 :         PartialTie* pt = toPartialTie(e);
    1382           75 :         pt->setTick(tick());
    1383           75 :         if (pt->isOutgoing()) {
    1384           24 :             pt->setStartNote(this);
    1385           24 :             setTieFor(pt);
    1386              :         } else {
    1387           51 :             pt->setEndNote(this);
    1388           51 :             setTieBack(pt);
    1389              :         }
    1390           75 :         break;
    1391              :     }
    1392          499 :     case ElementType::TIE: {
    1393          499 :         Tie* tie = toTie(e);
    1394          499 :         tie->setStartNote(this);
    1395          499 :         tie->setTick(tie->startNote()->tick());
    1396          499 :         setTieFor(tie);
    1397          499 :         if (tie->endNote()) {
    1398          382 :             tie->endNote()->setTieBack(tie);
    1399              :         }
    1400              :     }
    1401          499 :     break;
    1402         5104 :     case ElementType::ACCIDENTAL:
    1403         5104 :         m_accidental = toAccidental(e);
    1404         5104 :         m_centOffset = Accidental::subtype2centOffset(toAccidental(e)->accidentalType());
    1405         5104 :         break;
    1406          394 :     case ElementType::TEXTLINE:
    1407              :     case ElementType::NOTELINE:
    1408              :     case ElementType::GLISSANDO:
    1409              :     case ElementType::GUITAR_BEND:
    1410          394 :         addSpanner(toSpanner(e));
    1411          394 :         break;
    1412            0 :     default:
    1413            0 :         EngravingItem::add(e);
    1414            0 :         break;
    1415              :     }
    1416         7185 :     triggerLayout();
    1417              : 
    1418         7185 :     e->added();
    1419         7185 : }
    1420              : 
    1421              : //---------------------------------------------------------
    1422              : //   remove
    1423              : //---------------------------------------------------------
    1424              : 
    1425         2877 : void Note::remove(EngravingItem* e)
    1426              : {
    1427         2877 :     switch (e->type()) {
    1428           13 :     case ElementType::NOTEDOT:
    1429           13 :         m_dots.pop_back();
    1430           13 :         break;
    1431              : 
    1432           24 :     case ElementType::BEND:
    1433              :     case ElementType::TEXT:
    1434              :     case ElementType::IMAGE:
    1435              :     case ElementType::FINGERING:
    1436           24 :         if (!m_el.remove(e)) {
    1437            0 :             LOGD("Note::remove(): cannot find %s", e->typeName());
    1438              :         }
    1439           24 :         break;
    1440           12 :     case ElementType::SYMBOL:
    1441           12 :         if (!m_el.remove(e)) {
    1442            0 :             LOGD("Note::remove(): cannot find %s", e->typeName());
    1443              :         }
    1444           12 :         break;
    1445           39 :     case ElementType::PARTIAL_TIE: {
    1446           39 :         PartialTie* pt = toPartialTie(e);
    1447           39 :         assert((pt->isOutgoing() ? pt->startNote() : pt->endNote()) == this);
    1448           39 :         if (pt->isOutgoing()) {
    1449           10 :             setTieFor(nullptr);
    1450              :         } else {
    1451           29 :             setTieBack(nullptr);
    1452           29 :             pt->setJumpPoint(nullptr);
    1453              :         }
    1454           39 :         break;
    1455              :     }
    1456         1008 :     case ElementType::LAISSEZ_VIB:
    1457              :     case ElementType::TIE: {
    1458         1008 :         Tie* tie = toTie(e);
    1459         1008 :         assert(tie->startNote() == this);
    1460         1008 :         setTieFor(nullptr);
    1461         1008 :         tie->setJumpPoint(nullptr);
    1462         1008 :         if (tie->endNote()) {
    1463          992 :             tie->endNote()->setTieBack(0);
    1464              :         }
    1465              :     }
    1466         1008 :     break;
    1467              : 
    1468         1781 :     case ElementType::ACCIDENTAL:
    1469         1781 :         m_accidental = 0;
    1470         1781 :         m_centOffset = 0;
    1471         1781 :         break;
    1472              : 
    1473            0 :     case ElementType::TEXTLINE:
    1474              :     case ElementType::NOTELINE:
    1475              :     case ElementType::GLISSANDO:
    1476              :     case ElementType::GUITAR_BEND:
    1477            0 :         removeSpanner(toSpanner(e));
    1478            0 :         break;
    1479              : 
    1480            0 :     default:
    1481            0 :         EngravingItem::remove(e);
    1482            0 :         break;
    1483              :     }
    1484         2877 :     triggerLayout();
    1485         2877 :     e->removed();
    1486         2877 : }
    1487              : 
    1488              : //---------------------------------------------------------
    1489              : //   isNoteName
    1490              : //---------------------------------------------------------
    1491              : 
    1492        60502 : bool Note::isNoteName() const
    1493              : {
    1494        60502 :     if (chord() && chord()->staff()) {
    1495        60502 :         const Staff* st = staff();
    1496        60502 :         NoteHeadScheme s = m_headScheme;
    1497        60502 :         if (s == NoteHeadScheme::HEAD_AUTO) {
    1498        60365 :             s = st->staffTypeForElement(this)->noteHeadScheme();
    1499              :         }
    1500        60410 :         return s == NoteHeadScheme::HEAD_PITCHNAME || s == NoteHeadScheme::HEAD_PITCHNAME_GERMAN
    1501        60397 :                || s == NoteHeadScheme::HEAD_PITCHNAME_NO_ACCIDENTALS || s == NoteHeadScheme::HEAD_PITCHNAME_GERMAN_NO_ACCIDENTALS
    1502       120912 :                || s == NoteHeadScheme::HEAD_SOLFEGE || s == NoteHeadScheme::HEAD_SOLFEGE_FIXED;
    1503              :     }
    1504            0 :     return false;
    1505              : }
    1506              : 
    1507         1030 : void Note::updateFrettingForTiesAndBends()
    1508              : {
    1509         1030 :     Note* prevNote = nullptr;
    1510         1030 :     if (m_tieBack) {
    1511           37 :         prevNote = m_tieBack->startNote();
    1512              :     } else {
    1513          993 :         GuitarBend* bend = bendBack();
    1514          993 :         if (bend) {
    1515           25 :             prevNote = bend->startNote();
    1516              :         }
    1517              :     }
    1518              : 
    1519         1030 :     if (!prevNote) {
    1520          968 :         return;
    1521              :     }
    1522              : 
    1523           62 :     setString(prevNote->string());
    1524           62 :     setFret(prevNote->fret());
    1525              : }
    1526              : 
    1527        26840 : bool Note::shouldHideFret() const
    1528              : {
    1529        26840 :     if (!tieBack() || shouldForceShowFret() || !staffType()->isTabStaff()) {
    1530        26521 :         return false;
    1531              :     }
    1532              : 
    1533          319 :     if (isContinuationOfBend() && !rtick().isZero()) {
    1534           10 :         return true;
    1535              :     }
    1536              : 
    1537          309 :     ShowTiedFret showTiedFret = style().value(Sid::tabShowTiedFret).value<ShowTiedFret>();
    1538          309 :     if (showTiedFret == ShowTiedFret::TIE_AND_FRET) {
    1539          309 :         return false;
    1540              :     }
    1541              : 
    1542            0 :     ParenthesizeTiedFret parenthTiedFret = style().value(Sid::tabParenthesizeTiedFret).value<ParenthesizeTiedFret>();
    1543            0 :     if (parenthTiedFret == ParenthesizeTiedFret::NEVER || !rtick().isZero()) {
    1544            0 :         return true;
    1545              :     }
    1546              : 
    1547            0 :     if (parenthTiedFret == ParenthesizeTiedFret::START_OF_MEASURE) {
    1548            0 :         return false;
    1549              :     }
    1550              : 
    1551            0 :     const Measure* measure = findMeasure();
    1552            0 :     bool isStartOfSystem = measure && measure->system() && measure->isFirstInSystem();
    1553              : 
    1554            0 :     return !isStartOfSystem;
    1555              : }
    1556              : 
    1557        13163 : bool Note::shouldForceShowFret() const
    1558              : {
    1559        13163 :     if (!style().styleB(Sid::parenthesizeTiedFretIfArticulation)) {
    1560            0 :         return false;
    1561              :     }
    1562              : 
    1563        13163 :     Chord* ch = chord();
    1564        13163 :     if (!ch) {
    1565            0 :         return false;
    1566              :     }
    1567              : 
    1568        13091 :     auto hasTremoloBar = [&] () {
    1569        13491 :         for (EngravingItem* item : ch->segment()->annotations()) {
    1570          400 :             if (item && item->isTremoloBar() && item->track() == track()) {
    1571            0 :                 return true;
    1572              :             }
    1573              :         }
    1574        13091 :         return false;
    1575        13163 :     };
    1576              : 
    1577        13091 :     auto hasVibratoLine = [&] () {
    1578        13091 :         auto spanners = score()->spannerMap().findOverlapping(tick().ticks(), ch->endTick().ticks());
    1579        15760 :         for (auto interval : spanners) {
    1580         2677 :             Spanner* sp = interval.value;
    1581         2677 :             if (sp->isVibrato() && sp->startElement() == ch) {
    1582            8 :                 return true;
    1583              :             }
    1584              :         }
    1585        13083 :         return false;
    1586        13091 :     };
    1587              : 
    1588        13163 :     const GuitarBend* bendF = bendFor();
    1589        13163 :     bool startUnconnectedBend = bendF && !bendF->findPrecedingBend();
    1590        13163 :     bool startsNonBendSpanner = !spannerFor().empty() && !bendF;
    1591              : 
    1592        13163 :     bool chordHasDip = false;
    1593        32242 :     for (Note* note : chord()->notes()) {
    1594        19197 :         for (Spanner* sp : note->spannerFor()) {
    1595          118 :             if (sp->isGuitarBend() && toGuitarBend(sp)->bendType() == GuitarBendType::DIP) {
    1596            8 :                 chordHasDip = true;
    1597            8 :                 break;
    1598              :             }
    1599              :         }
    1600        19087 :         if (chordHasDip) {
    1601            8 :             break;
    1602              :         }
    1603              :     }
    1604              : 
    1605        26314 :     return !ch->articulations().empty() || ch->chordLine() || startsNonBendSpanner || startUnconnectedBend || hasTremoloBar()
    1606        26314 :            || hasVibratoLine() || chordHasDip;
    1607              : }
    1608              : 
    1609         5294 : void Note::setVisible(bool v)
    1610              : {
    1611         5294 :     EngravingItem::setVisible(v);
    1612         5294 :     if (!chord() || chord()->noteParentheses().empty()) {
    1613         5282 :         return;
    1614              :     }
    1615              : 
    1616           12 :     const NoteParenthesisInfo* noteParenInfo = chord()->findNoteParenthesisInfo(this);
    1617              : 
    1618           12 :     if (!noteParenInfo) {
    1619            0 :         return;
    1620              :     }
    1621              : 
    1622           12 :     const std::vector<Note*>& notes = noteParenInfo->notes();
    1623           12 :     bool visible = false;
    1624           22 :     for (const Note* note : notes) {
    1625           12 :         if (note->visible()) {
    1626            2 :             visible = true;
    1627            2 :             break;
    1628              :         }
    1629              :     }
    1630              : 
    1631           12 :     if (noteParenInfo->leftParen()) {
    1632           12 :         noteParenInfo->leftParen()->setVisible(visible);
    1633              :     }
    1634           12 :     if (noteParenInfo->rightParen()) {
    1635           12 :         noteParenInfo->rightParen()->setVisible(visible);
    1636              :     }
    1637              : }
    1638              : 
    1639         4346 : bool Note::isExactUnison(Note* other)
    1640              : {
    1641         4346 :     return other->pitch() == m_pitch && other->tpc() == tpc();
    1642              : }
    1643              : 
    1644        19701 : void Note::setupAfterRead(const Fraction& ctxTick, bool pasteMode)
    1645              : {
    1646              :     // ensure sane values:
    1647        19701 :     m_pitch = std::clamp(m_pitch, 0, 127);
    1648              : 
    1649        19701 :     if (!tpcIsValid(m_tpc[0]) && !tpcIsValid(m_tpc[1])) {
    1650            0 :         Key key = (staff() && chord()) ? staff()->key(chord()->tick()) : Key::C;
    1651            0 :         int tpc = pitch2tpc(m_pitch, key, Prefer::NEAREST);
    1652            0 :         if (concertPitch()) {
    1653            0 :             m_tpc[0] = tpc;
    1654              :         } else {
    1655            0 :             m_tpc[1] = tpc;
    1656              :         }
    1657              :     }
    1658        19701 :     if (!(tpcIsValid(m_tpc[0]) && tpcIsValid(m_tpc[1]))) {
    1659            0 :         Fraction tick = chord() ? chord()->tick() : Fraction(-1, 1);
    1660            0 :         Interval v = staff() ? staff()->transpose(tick) : Interval();
    1661            0 :         if (tpcIsValid(m_tpc[0])) {
    1662            0 :             v.flip();
    1663            0 :             if (v.isZero()) {
    1664            0 :                 m_tpc[1] = m_tpc[0];
    1665              :             } else {
    1666            0 :                 m_tpc[1] = Transpose::transposeTpc(m_tpc[0], v, true);
    1667              :             }
    1668              :         } else {
    1669            0 :             if (v.isZero()) {
    1670            0 :                 m_tpc[0] = m_tpc[1];
    1671              :             } else {
    1672            0 :                 m_tpc[0] = Transpose::transposeTpc(m_tpc[1], v, true);
    1673              :             }
    1674              :         }
    1675              :     }
    1676              : 
    1677              :     // check consistency of pitch, tpc1, tpc2, and transposition
    1678              :     // see note in InstrumentChange::read() about a known case of tpc corruption produced in 2.0.x
    1679              :     // but since there are other causes of tpc corruption (eg, https://musescore.org/en/node/74746)
    1680              :     // including perhaps some we don't know about yet,
    1681              :     // we will attempt to fix some problems here regardless of version
    1682              : 
    1683        19701 :     if (staff() && !staff()->isDrumStaff(ctxTick) && !pasteMode && !MScore::testMode) {
    1684            0 :         int tpc1Pitch = (tpc2pitch(m_tpc[0]) + 12) % 12;
    1685            0 :         int tpc2Pitch = (tpc2pitch(m_tpc[1]) + 12) % 12;
    1686            0 :         int soundingPitch = m_pitch % 12;
    1687            0 :         if (tpc1Pitch != soundingPitch) {
    1688            0 :             LOGD("bad tpc1 - soundingPitch = %d, tpc1 = %d", soundingPitch, tpc1Pitch);
    1689            0 :             m_pitch += tpc1Pitch - soundingPitch;
    1690              :         }
    1691            0 :         if (staff()) {
    1692            0 :             Interval v = staff()->transpose(ctxTick);
    1693            0 :             int writtenPitch = (m_pitch - v.chromatic) % 12;
    1694            0 :             if (tpc2Pitch != writtenPitch) {
    1695            0 :                 LOGD("bad tpc2 - writtenPitch = %d, tpc2 = %d", writtenPitch, tpc2Pitch);
    1696            0 :                 if (concertPitch()) {
    1697              :                     // assume we want to keep sounding pitch
    1698              :                     // so fix written pitch (tpc only)
    1699            0 :                     v.flip();
    1700            0 :                     m_tpc[1] = Transpose::transposeTpc(m_tpc[0], v, true);
    1701              :                 } else {
    1702              :                     // assume we want to keep written pitch
    1703              :                     // so fix sounding pitch (both tpc and pitch)
    1704            0 :                     m_tpc[0] = Transpose::transposeTpc(m_tpc[1], v, true);
    1705            0 :                     m_pitch += tpc2Pitch - writtenPitch;
    1706              :                 }
    1707              :             }
    1708              :         }
    1709              :     }
    1710              : 
    1711        19701 :     const StaffType* st = staffType();
    1712        19701 :     if (st && st->isTabStaff() && st->fretUseTextStyle() && color() == configuration()->defaultColor()) {
    1713           49 :         setColor(propertyDefault(Pid::COLOR).value<Color>());
    1714              :     }
    1715        19701 : }
    1716              : 
    1717              : //---------------------------------------------------------
    1718              : //   transposition
    1719              : //---------------------------------------------------------
    1720              : 
    1721       213699 : int Note::transposition() const
    1722              : {
    1723       213699 :     Fraction tick = chord() ? chord()->tick() : Fraction(-1, 1);
    1724       213699 :     Part* origin = originPart();
    1725       427398 :     return origin ? origin->instrument(tick)->transpose().chromatic : 0;
    1726              : }
    1727              : 
    1728              : //---------------------------------------------------------
    1729              : //   NoteEditData
    1730              : //---------------------------------------------------------
    1731              : 
    1732              : class NoteEditData : public ElementEditData
    1733              : {
    1734            0 :     OBJECT_ALLOCATOR(engraving, NoteEditData)
    1735              : public:
    1736              :     enum EditMode : unsigned char {
    1737              :         EditMode_ChangePitch = 0,
    1738              :         EditMode_AddSpacing,
    1739              :         EditMode_Undefined,
    1740              :     };
    1741              : 
    1742              :     int line = 0;
    1743              :     int string = 0;
    1744              :     EditMode mode = EditMode_Undefined;
    1745              :     PointF delta;
    1746              : 
    1747            0 :     virtual EditDataType type() override { return EditDataType::NoteEditData; }
    1748              : 
    1749              :     static constexpr double MODE_TRANSITION_LIMIT_DEGREES = 15.0;
    1750              : 
    1751            0 :     static inline EditMode editModeByDragDirection(const double& deltaX, const double& deltaY)
    1752              :     {
    1753            0 :         double x = std::abs(deltaX);
    1754            0 :         double y = std::abs(deltaY);
    1755              : 
    1756            0 :         PointF normalizedVector(x, y);
    1757              : 
    1758            0 :         normalizedVector.normalize();
    1759              : 
    1760            0 :         float radians = PointF::dotProduct(normalizedVector, PointF(1, 0));
    1761              : 
    1762            0 :         double degrees = (std::acos(radians) * 180.0) / M_PI;
    1763              : 
    1764            0 :         LOGD() << "NOTE DRAG DEGREES " << degrees;
    1765              : 
    1766            0 :         if (degrees >= MODE_TRANSITION_LIMIT_DEGREES) {
    1767            0 :             return NoteEditData::EditMode_ChangePitch;
    1768              :         } else {
    1769            0 :             return NoteEditData::EditMode_AddSpacing;
    1770              :         }
    1771              :     }
    1772              : };
    1773              : 
    1774              : //---------------------------------------------------------
    1775              : //   acceptDrop
    1776              : //---------------------------------------------------------
    1777              : 
    1778           18 : bool Note::acceptDrop(EditData& data) const
    1779              : {
    1780           18 :     EngravingItem* e = data.dropElement;
    1781           18 :     switch (e->type()) {
    1782            0 :     case ElementType::GLISSANDO:
    1783              :     case ElementType::GUITAR_BEND:
    1784            0 :         for (auto ee : m_spannerFor) {
    1785            0 :             if (ee->isGlissando() || ee->isGuitarBend()) {
    1786            0 :                 return false;
    1787              :             }
    1788              :         }
    1789            0 :         return true;
    1790            0 :     case ElementType::FINGERING:
    1791            0 :         return staff()->isTabStaff(tick()) ? staffType()->showTabFingering() : true;
    1792           10 :     case ElementType::ARTICULATION:
    1793              :     case ElementType::ORNAMENT:
    1794              :     case ElementType::TAPPING:
    1795              :     case ElementType::CHORDLINE:
    1796              :     case ElementType::TEXT:
    1797              :     case ElementType::ACCIDENTAL:
    1798              :     case ElementType::ARPEGGIO:
    1799              :     case ElementType::CHORD_BRACKET:
    1800              :     case ElementType::NOTEHEAD:
    1801              :     case ElementType::NOTE:
    1802              :     case ElementType::TREMOLO_SINGLECHORD:
    1803              :     case ElementType::TREMOLO_TWOCHORD:
    1804              :     case ElementType::IMAGE:
    1805              :     case ElementType::CHORD:
    1806              :     case ElementType::SYMBOL:
    1807              :     case ElementType::BAR_LINE:
    1808              :     case ElementType::STICKING:
    1809              :     case ElementType::BEND:
    1810              :     case ElementType::FIGURED_BASS:
    1811              :     case ElementType::LYRICS:
    1812           10 :         return true;
    1813            0 :     case ElementType::BAGPIPE_EMBELLISHMENT:
    1814            0 :         return noteType() == NoteType::NORMAL;
    1815            0 :     case ElementType::ACTION_ICON: {
    1816            0 :         switch (toActionIcon(e)->actionType()) {
    1817            0 :         case ActionIconType::ACCIACCATURA:
    1818              :         case ActionIconType::APPOGGIATURA:
    1819              :         case ActionIconType::GRACE4:
    1820              :         case ActionIconType::GRACE16:
    1821              :         case ActionIconType::GRACE32:
    1822              :         case ActionIconType::GRACE8_AFTER:
    1823              :         case ActionIconType::GRACE16_AFTER:
    1824              :         case ActionIconType::GRACE32_AFTER:
    1825              :         case ActionIconType::PARENTHESES:
    1826              :         case ActionIconType::STANDARD_BEND:
    1827              :         case ActionIconType::PRE_BEND:
    1828              :         case ActionIconType::GRACE_NOTE_BEND:
    1829              :         case ActionIconType::SLIGHT_BEND:
    1830              :         case ActionIconType::DIVE:
    1831              :         case ActionIconType::PRE_DIVE:
    1832              :         case ActionIconType::DIP:
    1833              :         case ActionIconType::SCOOP:
    1834              :         case ActionIconType::NOTE_ANCHORED_LINE:
    1835            0 :             return true;
    1836            0 :         case ActionIconType::STAVE_SHARING_CHANGE:
    1837              :         case ActionIconType::RESET_STAVE_SHARING_CHANGE:
    1838            0 :             return part() && part()->isSharedPart();
    1839            0 :         default: break;
    1840              :         }
    1841            0 :         break;
    1842              :     }
    1843            8 :     default:
    1844            8 :         if (e->isSpanner()) {
    1845            0 :             return e->type() != ElementType::TIE && e->type() != ElementType::PARTIAL_TIE;
    1846              :         }
    1847            8 :         break;
    1848              :     }
    1849            8 :     return toChordRest(chord())->acceptDrop(data);
    1850              : }
    1851              : 
    1852              : //---------------------------------------------------------
    1853              : //   drop
    1854              : //---------------------------------------------------------
    1855              : 
    1856           48 : EngravingItem* Note::drop(Transaction& tx, EditData& data)
    1857              : {
    1858           48 :     EngravingItem* e = data.dropElement;
    1859              : 
    1860           48 :     const Staff* st = staff();
    1861           48 :     bool isTablature = st->isTabStaff(tick());
    1862           48 :     bool tabFingering = st->staffTypeForElement(this)->showTabFingering();
    1863           48 :     Chord* ch = chord();
    1864              : 
    1865           48 :     switch (e->type()) {
    1866            6 :     case ElementType::SYMBOL:
    1867              :     case ElementType::IMAGE:
    1868            6 :         e->setOwnershipParent(this);
    1869            6 :         score()->undoAddElement(e);
    1870            6 :         return e;
    1871              : 
    1872            3 :     case ElementType::FINGERING:
    1873            3 :         if (!isTablature || tabFingering) {
    1874            3 :             e->setOwnershipParent(this);
    1875            3 :             score()->undoAddElement(e);
    1876            3 :             return e;
    1877              :         } else {
    1878            0 :             delete e;
    1879              :         }
    1880            0 :         return 0;
    1881              : 
    1882            0 :     case ElementType::LYRICS:
    1883            0 :         e->setOwnershipParent(ch);
    1884            0 :         e->setTrack(track());
    1885            0 :         score()->undoAddElement(e);
    1886            0 :         return e;
    1887              : 
    1888            0 :     case ElementType::ACCIDENTAL:
    1889            0 :         EditNote::changeAccidental(score(), this, toAccidental(e)->accidentalType());
    1890            0 :         break;
    1891              : 
    1892            0 :     case ElementType::BEND:
    1893            0 :         e->setOwnershipParent(this);
    1894            0 :         e->setTrack(track());
    1895            0 :         score()->undoAddElement(e);
    1896            0 :         return e;
    1897              : 
    1898            0 :     case ElementType::NOTEHEAD:
    1899              :     {
    1900            0 :         NoteHead* s = toNoteHead(e);
    1901            0 :         NoteHeadGroup group = s->headGroup();
    1902            0 :         if (group == NoteHeadGroup::HEAD_INVALID) {
    1903            0 :             LOGD("unknown notehead");
    1904            0 :             group = NoteHeadGroup::HEAD_NORMAL;
    1905              :         }
    1906            0 :         delete s;
    1907              : 
    1908            0 :         if (group != m_headGroup) {
    1909            0 :             if (links()) {
    1910            0 :                 for (EngravingObject* se : *links()) {
    1911            0 :                     se->undoChangeProperty(Pid::HEAD_GROUP, group);
    1912            0 :                     Note* note = toNote(se);
    1913            0 :                     if (note->staff() && !note->staff()->isDrumStaff(ch->tick())) {
    1914            0 :                         se->undoChangeProperty(Pid::DEAD, group == NoteHeadGroup::HEAD_CROSS);
    1915              :                     }
    1916              :                 }
    1917              :             } else {
    1918            0 :                 undoChangeProperty(Pid::HEAD_GROUP, group);
    1919            0 :                 if (!staff()->isDrumStaff(ch->tick())) {
    1920            0 :                     undoChangeProperty(Pid::DEAD, group == NoteHeadGroup::HEAD_CROSS);
    1921              :                 }
    1922              :             }
    1923              :         }
    1924              :     }
    1925            0 :     break;
    1926              : 
    1927            0 :     case ElementType::ACTION_ICON:
    1928              :     {
    1929            0 :         switch (toActionIcon(e)->actionType()) {
    1930            0 :         case ActionIconType::ACCIACCATURA:
    1931              :         {
    1932            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::ACCIACCATURA, Constants::DIVISION / 2);
    1933            0 :             score()->select(note, SelectType::SINGLE, 0);
    1934            0 :             break;
    1935              :         }
    1936            0 :         case ActionIconType::APPOGGIATURA:
    1937              :         {
    1938            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::APPOGGIATURA, Constants::DIVISION / 2);
    1939            0 :             score()->select(note, SelectType::SINGLE, 0);
    1940            0 :             break;
    1941              :         }
    1942            0 :         case ActionIconType::GRACE4:
    1943              :         {
    1944            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE4, Constants::DIVISION);
    1945            0 :             score()->select(note, SelectType::SINGLE, 0);
    1946            0 :             break;
    1947              :         }
    1948            0 :         case ActionIconType::GRACE16:
    1949              :         {
    1950            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE16,  Constants::DIVISION / 4);
    1951            0 :             score()->select(note, SelectType::SINGLE, 0);
    1952            0 :             break;
    1953              :         }
    1954            0 :         case ActionIconType::GRACE32:
    1955              :         {
    1956            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE32, Constants::DIVISION / 8);
    1957            0 :             score()->select(note, SelectType::SINGLE, 0);
    1958            0 :             break;
    1959              :         }
    1960            0 :         case ActionIconType::GRACE8_AFTER:
    1961              :         {
    1962            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE8_AFTER, Constants::DIVISION / 2);
    1963            0 :             score()->select(note, SelectType::SINGLE, 0);
    1964            0 :             break;
    1965              :         }
    1966            0 :         case ActionIconType::GRACE16_AFTER:
    1967              :         {
    1968            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE16_AFTER, Constants::DIVISION / 4);
    1969            0 :             score()->select(note, SelectType::SINGLE, 0);
    1970            0 :             break;
    1971              :         }
    1972            0 :         case ActionIconType::GRACE32_AFTER:
    1973              :         {
    1974            0 :             Note* note = score()->setGraceNote(ch, pitch(), NoteType::GRACE32_AFTER, Constants::DIVISION / 8);
    1975            0 :             score()->select(note, SelectType::SINGLE, 0);
    1976            0 :             break;
    1977              :         }
    1978              : 
    1979            0 :         case ActionIconType::PARENTHESES: {
    1980            0 :             EditParentheses::addParenthesesToNotes(tx, { this });
    1981            0 :             break;
    1982              :         }
    1983            0 :         case ActionIconType::STANDARD_BEND:
    1984              :         case ActionIconType::SLIGHT_BEND:
    1985              :         case ActionIconType::DIVE:
    1986              :         case ActionIconType::DIP:
    1987              :         case ActionIconType::SCOOP:
    1988            0 :             score()->addGuitarBend(GuitarBend::bendTypeFromActionIcon(toActionIcon(e)->actionType()), this);
    1989            0 :             break;
    1990            0 :         case ActionIconType::PRE_BEND:
    1991              :         case ActionIconType::GRACE_NOTE_BEND:
    1992              :         case ActionIconType::PRE_DIVE:
    1993              :         {
    1994            0 :             GuitarBendType type = GuitarBend::bendTypeFromActionIcon(toActionIcon(e)->actionType());
    1995            0 :             GuitarBend* guitarBend = score()->addGuitarBend(type, this);
    1996            0 :             if (!guitarBend) {
    1997            0 :                 break;
    1998              :             }
    1999            0 :             Note* note = guitarBend->startNote();
    2000            0 :             IF_ASSERT_FAILED(note) {
    2001            0 :                 LOGE() << "not valid start note of the bend";
    2002            0 :                 break;
    2003              :             }
    2004              : 
    2005            0 :             score()->select(note, SelectType::SINGLE, 0);
    2006            0 :             break;
    2007              :         }
    2008            0 :         case ActionIconType::NOTE_ANCHORED_LINE:
    2009            0 :             score()->addNoteLine();
    2010            0 :             break;
    2011            0 :         default:
    2012            0 :             break;
    2013              :         }
    2014            0 :         return ch->drop(tx, data);
    2015              :     }
    2016              : 
    2017            0 :     case ElementType::GUITAR_BEND:
    2018              :     {
    2019            0 :         GuitarBend* newGuitarBend = score()->addGuitarBend(toGuitarBend(e)->bendType(), this);
    2020            0 :         delete e;
    2021            0 :         return newGuitarBend;
    2022              :     }
    2023              : 
    2024            0 :     case ElementType::BAGPIPE_EMBELLISHMENT:
    2025              :     {
    2026            0 :         BagpipeEmbellishment* b = toBagpipeEmbellishment(e);
    2027            0 :         BagpipeNoteList nl = b->resolveNoteList();
    2028              :         // add grace notes in reverse order, as setGraceNote adds a grace note
    2029              :         // before the current note
    2030            0 :         for (int i = static_cast<int>(nl.size()) - 1; i >= 0; --i) {
    2031            0 :             int p = BagpipeEmbellishment::BAGPIPE_NOTEINFO_LIST[nl.at(i)].pitch;
    2032            0 :             score()->setGraceNote(ch, p, NoteType::GRACE32, Constants::DIVISION / 8);
    2033              :         }
    2034            0 :     }
    2035            0 :         delete e;
    2036            0 :         break;
    2037              : 
    2038           14 :     case ElementType::NOTE:
    2039              :     {
    2040              :         // calculate correct transposed tpc
    2041           14 :         Note* n = toNote(e);
    2042           14 :         const Segment* segment = ch->segment();
    2043           14 :         Interval v = staff()->transpose(ch->tick());
    2044           14 :         v.flip();
    2045           14 :         n->setTpc2(Transpose::transposeTpc(n->tpc1(), v, true));
    2046              :         // replace this note with new note
    2047           14 :         n->setOwnershipParent(ch);
    2048           14 :         if (this->tieBack()) {
    2049            4 :             n->setTieBack(this->tieBack());
    2050            4 :             n->tieBack()->setEndNote(n);
    2051            4 :             this->setTieBack(nullptr);
    2052              :         }
    2053              :         // Set correct stem direction for drum staves
    2054           14 :         const StaffGroup staffGroup = st->staffType(segment->tick())->group();
    2055           14 :         DirectionV stemDirection = DirectionV::AUTO;
    2056           14 :         if (staffGroup == StaffGroup::PERCUSSION) {
    2057            2 :             const Drumset* ds = originPart()->instrument(segment->tick())->drumset();
    2058            2 :             DO_ASSERT(ds);
    2059              : 
    2060            2 :             if (ds) {
    2061            2 :                 stemDirection = ds->stemDirection(n->noteVal().pitch);
    2062              :             }
    2063              :         }
    2064           14 :         ch->setStemDirection(stemDirection);
    2065              : 
    2066           14 :         score()->undoRemoveElement(this);
    2067           14 :         score()->undoAddElement(n);
    2068           14 :         return n;
    2069              :     }
    2070              :     break;
    2071              : 
    2072           11 :     case ElementType::GLISSANDO:
    2073              :     {
    2074           11 :         for (auto ee : m_spannerFor) {
    2075            0 :             if (ee->isGlissando()) {
    2076            0 :                 LOGD("there is already a glissando");
    2077            0 :                 delete e;
    2078            0 :                 return 0;
    2079              :             }
    2080              :         }
    2081              : 
    2082           11 :         Glissando* gliss = toGlissando(e);
    2083           11 :         EngravingItem* endEl = gliss->endElement();
    2084           11 :         Note* finalNote = endEl && endEl->isNote() ? toNote(endEl) : SLine::guessFinalNote(this);
    2085           11 :         if (finalNote) {
    2086              :             // init glissando data
    2087           11 :             gliss->setStartElement(this);
    2088           11 :             gliss->setEndElement(finalNote);
    2089           11 :             gliss->setTick(ch->tick());
    2090           11 :             gliss->setTick2(finalNote->chord()->tick());
    2091           11 :             gliss->setTrack(track());
    2092           11 :             gliss->setTrack2(finalNote->track());
    2093              :             // in TAB, use straight line with no text
    2094           11 :             if (staff()->isTabStaff(finalNote->chord()->tick())) {
    2095            0 :                 gliss->setGlissandoType(GlissandoType::STRAIGHT);
    2096            0 :                 gliss->setShowText(false);
    2097              :             }
    2098           11 :             gliss->setOwnershipParent(this);
    2099              : 
    2100           11 :             const Sid styleId = gliss->getPropertyStyle(Pid::GLISS_STYLE);
    2101           11 :             if (gliss->isStyled(Pid::GLISS_STYLE) && score()->style().isDefault(styleId)) {
    2102           11 :                 const GlissandoStyle instrumentStyle = originPart()->instrument(gliss->tick())->glissandoStyle();
    2103           11 :                 if (instrumentStyle != gliss->glissandoStyle()) {
    2104            0 :                     gliss->setGlissandoStyle(instrumentStyle);
    2105            0 :                     gliss->setPropertyFlags(Pid::GLISS_STYLE, PropertyFlags::UNSTYLED);
    2106              :                 }
    2107              :             }
    2108              : 
    2109           11 :             score()->undoAddElement(e);
    2110              :         } else {
    2111            0 :             LOGD("no segment for second note of glissando found");
    2112            0 :             delete e;
    2113            0 :             return 0;
    2114              :         }
    2115              :     }
    2116           11 :     break;
    2117              : 
    2118            0 :     case ElementType::CHORD:
    2119              :     {
    2120            0 :         Chord* c      = toChord(e);
    2121            0 :         Note* n       = c->upNote();
    2122            0 :         DirectionV dir = c->stemDirection();
    2123            0 :         track_idx_t t = track(); // (staff2track(staffIdx()) + n->voice());
    2124            0 :         score()->select(0, SelectType::SINGLE, 0);
    2125            0 :         NoteVal nval;
    2126            0 :         nval.pitch = n->pitch();
    2127            0 :         nval.headGroup = n->headGroup();
    2128            0 :         const ChordRest* cr = nullptr;
    2129            0 :         if (data.modifiers & ShiftModifier) {
    2130              :             // add note to chord
    2131            0 :             NoteInput::addNote(tx, score(), ch, nval);
    2132              :         } else {
    2133              :             // replace current chord
    2134            0 :             Segment* seg = score()->setNoteRest(ch->segment(), t, nval,
    2135            0 :                                                 score()->inputState().duration().fraction(), dir);
    2136            0 :             cr = seg ? toChordRest(seg->element(t)) : nullptr;
    2137              :         }
    2138            0 :         if (cr) {
    2139            0 :             NoteInput::nextInputPos(tx, score(), cr, false);
    2140              :         }
    2141            0 :         delete e;
    2142              :     }
    2143            0 :     break;
    2144              : 
    2145            3 :     case ElementType::CHORDLINE:
    2146            3 :         toChordLine(e)->setNote(this);
    2147            3 :         return ch->drop(tx, data);
    2148              : 
    2149           11 :     default:
    2150              :         Spanner* spanner;
    2151           11 :         if (e->isSpanner() && (spanner = toSpanner(e))->anchor() == Spanner::Anchor::NOTE) {
    2152            0 :             spanner->setOwnershipParent(this);
    2153            0 :             spanner->setStartElement(this);
    2154            0 :             spanner->setTick(tick());
    2155            0 :             spanner->setTrack(track());
    2156            0 :             spanner->setTrack2(track());
    2157            0 :             spanner->computeEndElement();
    2158            0 :             score()->undoAddElement(spanner);
    2159            0 :             return e;
    2160              :         }
    2161           11 :         return ch->drop(tx, data);
    2162              :     }
    2163           11 :     return 0;
    2164              : }
    2165              : 
    2166              : //---------------------------------------------------------
    2167              : //   dotIsUp
    2168              : //---------------------------------------------------------
    2169              : 
    2170            0 : bool Note::dotIsUp() const
    2171              : {
    2172            0 :     if (m_dots.empty()) {
    2173            0 :         return true;
    2174              :     }
    2175            0 :     if (m_userDotPosition == DirectionV::AUTO) {
    2176            0 :         return m_dots[0]->y() < spatium() * .1;
    2177              :     } else {
    2178            0 :         return m_userDotPosition == DirectionV::UP;
    2179              :     }
    2180              : }
    2181              : 
    2182        55847 : static bool hasAlteredUnison(Note* note)
    2183              : {
    2184        55847 :     const auto& chordNotes = note->chord()->notes();
    2185        55847 :     AccidentalVal accVal = tpc2alter(note->tpc());
    2186        55847 :     int absLine = absStep(note->tpc(), note->epitch());
    2187        55847 :     return std::find_if(chordNotes.begin(), chordNotes.end(), [note, accVal, absLine](Note* n) {
    2188        82282 :         return n != note && !n->hidden() && absStep(n->tpc(), n->epitch()) == absLine && tpc2alter(n->tpc()) != accVal;
    2189       111694 :     }) != chordNotes.end();
    2190              : }
    2191              : 
    2192              : //---------------------------------------------------------
    2193              : //   updateAccidental
    2194              : //    set _accidental and _line depending on tpc
    2195              : //---------------------------------------------------------
    2196              : 
    2197        59704 : void Note::updateAccidental(AccidentalState* as)
    2198              : {
    2199        59704 :     if (deadNote() && configuration()->keepDeadNotesUnchangedOnTranspose()) {
    2200            0 :         if (m_accidental) {
    2201            0 :             score()->undoRemoveElement(m_accidental);
    2202              :         }
    2203            0 :         int eAbsLine = absStep(tpc(), epitch());
    2204            0 :         as->setAccidentalVal(eAbsLine, tpc2alter(tpc()), false);
    2205            0 :         updateRelLine(eAbsLine, true);
    2206            0 :         return;
    2207              :     }
    2208              : 
    2209        59704 :     int absLine = absStep(tpc(), epitch());
    2210              : 
    2211              :     // Ensure m_centOffset and microtonal accidental match (they can mismatch when switching from TAB)
    2212        59704 :     if (muse::RealIsNull(m_centOffset)) {
    2213        59621 :         if (m_accidental && !muse::RealIsNull(Accidental::subtype2centOffset(m_accidental->accidentalType()))) {
    2214            0 :             score()->undoRemoveElement(m_accidental);
    2215              :         }
    2216              :     } else {
    2217           83 :         if (m_accidental) {
    2218           83 :             bool correct = muse::RealIsEqual(Accidental::subtype2centOffset(m_accidental->accidentalType()), m_centOffset);
    2219           83 :             if (!correct) {
    2220            0 :                 m_accidental->undoChangeProperty(Pid::ACCIDENTAL_TYPE, static_cast<int>(Accidental::centOffset2Subtype(m_centOffset)));
    2221              :             }
    2222              :         } else {
    2223            0 :             AccidentalType accType = Accidental::value2MicrotonalSubtype(tpc2alter(tpc()), quarterToneOffset());
    2224            0 :             updateLine();
    2225            0 :             EditNote::changeAccidental(score(), this, accType);
    2226              :         }
    2227              :     }
    2228              : 
    2229              :     // don't touch accidentals that don't concern tpc such as
    2230              :     // quarter tones
    2231        59704 :     if (!(m_accidental && Accidental::isMicrotonal(m_accidental->accidentalType()))) {
    2232              :         // calculate accidental
    2233        59618 :         AccidentalType acci = AccidentalType::NONE;
    2234              : 
    2235        59618 :         AccidentalVal accVal = tpc2alter(tpc());
    2236        59618 :         bool error = false;
    2237        59618 :         int eAbsLine = absStep(tpc(), epitch());
    2238        59618 :         AccidentalVal absLineAccVal = as->accidentalVal(eAbsLine, error);
    2239        59618 :         if (error) {
    2240            0 :             LOGD("error accidentalVal()");
    2241            0 :             return;
    2242              :         }
    2243        59618 :         if ((accVal != absLineAccVal) || hidden() || as->tieContext(eAbsLine) || as->forceRestateAccidental(eAbsLine)) {
    2244         3771 :             as->setAccidentalVal(eAbsLine, accVal, m_tieBack != 0 && m_accidental == 0);
    2245         3771 :             acci = Accidental::value2subtype(accVal);
    2246              :             // if previous tied note has same tpc, don't show accidental
    2247         3771 :             if (tieBackNonPartial() && m_tieBack->startNote()->tpc1() == tpc1()) {
    2248           45 :                 acci = AccidentalType::NONE;
    2249         3726 :             } else if (acci == AccidentalType::NONE) {
    2250          588 :                 acci = AccidentalType::NATURAL;
    2251              :             }
    2252        55847 :         } else if (hasAlteredUnison(this)) {
    2253            3 :             if ((acci = Accidental::value2subtype(accVal)) == AccidentalType::NONE) {
    2254            3 :                 acci = AccidentalType::NATURAL;
    2255              :             }
    2256              :         }
    2257        59618 :         if (acci != AccidentalType::NONE && !m_hidden) {
    2258         3729 :             if (m_accidental == 0) {
    2259         1914 :                 Accidental* a = Factory::createAccidental(this);
    2260         1914 :                 a->setAccidentalType(acci);
    2261         1914 :                 a->setVisible(visible());
    2262         1914 :                 score()->undoAddElement(a);
    2263         1815 :             } else if (m_accidental->accidentalType() != acci) {
    2264          100 :                 Accidental* a = m_accidental->clone();
    2265          100 :                 a->setOwnershipParent(this);
    2266          100 :                 a->setAccidentalType(acci);
    2267          100 :                 score()->undoChangeElement(m_accidental, a);
    2268              :             }
    2269         3729 :         } else {
    2270        55889 :             if (m_accidental) {
    2271              :                 // remove this if it was AUTO:
    2272         1804 :                 if (m_accidental->role() == AccidentalRole::AUTO) {
    2273         1621 :                     score()->undoRemoveElement(m_accidental);
    2274              :                 } else {
    2275              :                     // keep it, but update type if needed
    2276          183 :                     acci = Accidental::value2subtype(accVal);
    2277          183 :                     if (acci == AccidentalType::NONE) {
    2278          142 :                         acci = AccidentalType::NATURAL;
    2279              :                     }
    2280          183 :                     if (m_accidental->accidentalType() != acci) {
    2281           15 :                         Accidental* a = m_accidental->clone();
    2282           15 :                         a->setOwnershipParent(this);
    2283           15 :                         a->setAccidentalType(acci);
    2284           15 :                         score()->undoChangeElement(m_accidental, a);
    2285              :                     }
    2286              :                 }
    2287              :             }
    2288              :         }
    2289              :     } else {
    2290              :         // microtonal accidentals playback as naturals
    2291              :         // in 1.X, they had no effect on accidental state of measure
    2292              :         // ultimately, they should probably get their own state
    2293              :         // for now, at least change state to natural, so subsequent notes playback as might be expected
    2294              :         // this is an incompatible change, but better to break it for 2.0 than wait until later
    2295           86 :         AccidentalVal accVal = Accidental::subtype2value(m_accidental->accidentalType());
    2296           86 :         as->setAccidentalVal(absLine, accVal, m_tieBack != 0 && m_accidental == 0);
    2297              :     }
    2298              : 
    2299        59704 :     as->setForceRestateAccidental(absLine, false);
    2300        59704 :     updateRelLine(absLine, true);
    2301              : }
    2302              : 
    2303              : //---------------------------------------------------------
    2304              : //   noteType
    2305              : //---------------------------------------------------------
    2306              : 
    2307      1443062 : NoteType Note::noteType() const
    2308              : {
    2309      1443062 :     return chord()->noteType();
    2310              : }
    2311              : 
    2312              : //---------------------------------------------------------
    2313              : //   noteTypeUserName
    2314              : //---------------------------------------------------------
    2315              : 
    2316            0 : String Note::noteTypeUserName() const
    2317              : {
    2318            0 :     switch (noteType()) {
    2319            0 :     case NoteType::ACCIACCATURA:
    2320            0 :         return muse::mtrc("engraving", "Acciaccatura");
    2321            0 :     case NoteType::APPOGGIATURA:
    2322            0 :         return muse::mtrc("engraving", "Appoggiatura");
    2323            0 :     case NoteType::GRACE8_AFTER:
    2324              :     case NoteType::GRACE16_AFTER:
    2325              :     case NoteType::GRACE32_AFTER:
    2326            0 :         return muse::mtrc("engraving", "Grace note after");
    2327            0 :     case NoteType::GRACE4:
    2328              :     case NoteType::GRACE16:
    2329              :     case NoteType::GRACE32:
    2330            0 :         return muse::mtrc("engraving", "Grace note before");
    2331            0 :     default:
    2332            0 :         return muse::mtrc("engraving", "Note");
    2333              :     }
    2334              : }
    2335              : 
    2336              : //---------------------------------------------------------
    2337              : //   scanElements
    2338              : //---------------------------------------------------------
    2339              : 
    2340        16907 : void Note::scanElements(std::function<void(EngravingItem*)> func)
    2341              : {
    2342        16907 :     func(this);
    2343              : 
    2344        17017 :     for (EngravingItem* e : m_el) {
    2345          110 :         e->scanElements(func);
    2346              :     }
    2347        16984 :     for (Spanner* sp : m_spannerFor) {
    2348           77 :         sp->scanElements(func);
    2349              :     }
    2350              : 
    2351        16907 :     if (m_accidental) {
    2352          801 :         func(m_accidental);
    2353              :     }
    2354        17218 :     for (NoteDot* dot : m_dots) {
    2355          311 :         func(dot);
    2356              :     }
    2357        16909 :     for (JianpuOctaveDot* od : m_jianpuOctaveDots) {
    2358            2 :         func(od);
    2359              :     }
    2360        16907 : }
    2361              : 
    2362              : //---------------------------------------------------------
    2363              : //   setTrack
    2364              : //---------------------------------------------------------
    2365              : 
    2366        86071 : void Note::setTrack(track_idx_t val)
    2367              : {
    2368        86071 :     EngravingItem::setTrack(val);
    2369        86071 :     if (tieForNonPartial()) {
    2370          526 :         m_tieFor->setTrack(val);
    2371         1020 :         for (SpannerSegment* seg : m_tieFor->spannerSegments()) {
    2372          494 :             seg->setTrack(val);
    2373              :         }
    2374              :     }
    2375        86071 :     if (tieBackNonPartial()) {
    2376          220 :         m_tieBack->setTrack2(val);
    2377              :     }
    2378        86071 :     if (laissezVib() || outgoingPartialTie()) {
    2379           27 :         m_tieFor->setTrack(val);
    2380           27 :         m_tieFor->setTrack2(val);
    2381           31 :         for (SpannerSegment* seg : m_tieFor->spannerSegments()) {
    2382            4 :             seg->setTrack(val);
    2383              :         }
    2384              :     }
    2385        86071 :     if (incomingPartialTie()) {
    2386           31 :         m_tieBack->setTrack(val);
    2387           31 :         m_tieBack->setTrack2(val);
    2388           33 :         for (SpannerSegment* seg : m_tieBack->spannerSegments()) {
    2389            2 :             seg->setTrack(val);
    2390              :         }
    2391              :     }
    2392        86223 :     for (Spanner* s : m_spannerFor) {
    2393          152 :         s->setTrack(val);
    2394              :     }
    2395        86262 :     for (Spanner* s : m_spannerBack) {
    2396          191 :         s->setTrack2(val);
    2397              :     }
    2398        86301 :     for (EngravingItem* e : m_el) {
    2399          230 :         e->setTrack(val);
    2400              :     }
    2401        86071 :     if (m_accidental) {
    2402         4942 :         m_accidental->setTrack(val);
    2403              :     }
    2404        86071 :     if (!chord()) {     // if note is dragged with shift+ctrl
    2405           30 :         return;
    2406              :     }
    2407        86124 :     for (NoteDot* dot : m_dots) {
    2408           83 :         dot->setTrack(val);
    2409              :     }
    2410        86045 :     for (JianpuOctaveDot* dot : m_jianpuOctaveDots) {
    2411            4 :         dot->setTrack(val);
    2412              :     }
    2413              : }
    2414              : 
    2415              : //---------------------------------------------------------
    2416              : //    reset
    2417              : //---------------------------------------------------------
    2418              : 
    2419            0 : void Note::reset()
    2420              : {
    2421            0 :     undoChangeProperty(Pid::OFFSET, PointF());
    2422            0 :     undoResetProperty(Pid::LEADING_SPACE);
    2423            0 :     chord()->undoChangeProperty(Pid::OFFSET, PropertyValue::fromValue(PointF()));
    2424            0 :     chord()->undoChangeProperty(Pid::STEM_DIRECTION, PropertyValue::fromValue<DirectionV>(DirectionV::AUTO));
    2425            0 :     setOverrideBendVisibilityRules(false);
    2426            0 :     setHideGeneratedParens(false);
    2427            0 : }
    2428              : 
    2429         1558 : float Note::userVelocityFraction() const
    2430              : {
    2431         1558 :     return m_userVelocity / 127.f;
    2432              : }
    2433              : 
    2434              : //---------------------------------------------------------
    2435              : //   mag
    2436              : //---------------------------------------------------------
    2437              : 
    2438      3749431 : double Note::mag() const
    2439              : {
    2440      3749431 :     double m = chord() ? chord()->mag() : 1.0;
    2441      3749431 :     if (m_isSmall) {
    2442         2861 :         m *= style().styleD(Sid::smallNoteMag);
    2443              :     }
    2444      3749431 :     return m;
    2445              : }
    2446              : 
    2447              : //---------------------------------------------------------
    2448              : //   elementBase
    2449              : //---------------------------------------------------------
    2450            0 : EngravingItem* Note::elementBase() const
    2451              : {
    2452            0 :     return chord();
    2453              : }
    2454              : 
    2455              : //---------------------------------------------------------
    2456              : //   setSmall
    2457              : //---------------------------------------------------------
    2458              : 
    2459         5329 : void Note::setSmall(bool val)
    2460              : {
    2461         5329 :     m_isSmall = val;
    2462         5329 : }
    2463              : 
    2464        36753 : GuitarBend* Note::bendFor() const
    2465              : {
    2466              :     /// Returns bend or dive going forward from this note. In the edge case of having both, returns the bend.
    2467        36753 :     GuitarBend* diveFor = nullptr;
    2468              : 
    2469        39872 :     for (Spanner* sp : m_spannerFor) {
    2470         5325 :         if (!sp->isGuitarBend()) {
    2471          189 :             continue;
    2472              :         }
    2473              : 
    2474         5136 :         GuitarBend* bend = toGuitarBend(sp);
    2475         5136 :         if (bend->bendType() == GuitarBendType::SCOOP) {
    2476            6 :             continue;
    2477              :         }
    2478              : 
    2479         5130 :         if (!bend->isDive()) {
    2480         2206 :             return bend;
    2481              :         } else {
    2482         2924 :             diveFor = bend;
    2483              :         }
    2484              :     }
    2485              : 
    2486        34547 :     return diveFor;
    2487              : }
    2488              : 
    2489        28073 : GuitarBend* Note::bendBack() const
    2490              : {
    2491              :     /// Returns bend or dive going back from this note. In the edge case of having both, returns the bend.
    2492        28073 :     GuitarBend* diveBack = nullptr;
    2493              : 
    2494        30280 :     for (Spanner* sp : m_spannerBack) {
    2495         4875 :         if (!sp->isGuitarBend()) {
    2496          181 :             continue;
    2497              :         }
    2498              : 
    2499         4694 :         GuitarBend* bend = toGuitarBend(sp);
    2500         4694 :         if (bend->bendType() == GuitarBendType::SLIGHT_BEND || bend->bendType() == GuitarBendType::DIP) {
    2501          223 :             continue;
    2502              :         }
    2503              : 
    2504         4471 :         if (!bend->isDive()) {
    2505         2668 :             return bend;
    2506              :         } else {
    2507         1803 :             diveBack = bend;
    2508              :         }
    2509              :     }
    2510              : 
    2511        25405 :     return diveBack;
    2512              : }
    2513              : 
    2514         1176 : GuitarBend* Note::diveFor() const
    2515              : {
    2516         2306 :     for (Spanner* sp : m_spannerFor) {
    2517         1130 :         if (sp->isGuitarBend() && toGuitarBend(sp)->isDive() && toGuitarBend(sp)->bendType() != GuitarBendType::SCOOP) {
    2518            0 :             return toGuitarBend(sp);
    2519              :         }
    2520              :     }
    2521              : 
    2522         1176 :     return nullptr;
    2523              : }
    2524              : 
    2525         6167 : GuitarBend* Note::diveBack() const
    2526              : {
    2527         7890 :     for (Spanner* sp : m_spannerBack) {
    2528         2844 :         if (sp->isGuitarBend() && toGuitarBend(sp)->isDive() && toGuitarBend(sp)->bendType() != GuitarBendType::DIP) {
    2529         1121 :             return toGuitarBend(sp);
    2530              :         }
    2531              :     }
    2532              : 
    2533         5046 :     return nullptr;
    2534              : }
    2535              : 
    2536        92817 : Tie* Note::tieForNonPartial() const
    2537              : {
    2538        92817 :     if (!m_tieFor || m_tieFor->type() != ElementType::TIE) {
    2539        92103 :         return nullptr;
    2540              :     }
    2541              : 
    2542          714 :     return m_tieFor;
    2543              : }
    2544              : 
    2545       178383 : Tie* Note::tieBackNonPartial() const
    2546              : {
    2547       178383 :     if (!m_tieBack || m_tieBack->type() != ElementType::TIE) {
    2548       175259 :         return nullptr;
    2549              :     }
    2550              : 
    2551         3124 :     return m_tieBack;
    2552              : }
    2553              : 
    2554       593922 : LaissezVib* Note::laissezVib() const
    2555              : {
    2556       593922 :     if (!m_tieFor || !m_tieFor->isLaissezVib()) {
    2557       593597 :         return nullptr;
    2558              :     }
    2559              : 
    2560          325 :     return toLaissezVib(m_tieFor);
    2561              : }
    2562              : 
    2563       153742 : PartialTie* Note::incomingPartialTie() const
    2564              : {
    2565       153742 :     if (!m_tieBack || !m_tieBack->isPartialTie()) {
    2566       153326 :         return nullptr;
    2567              :     }
    2568              : 
    2569          416 :     return toPartialTie(m_tieBack);
    2570              : }
    2571              : 
    2572       127214 : PartialTie* Note::outgoingPartialTie() const
    2573              : {
    2574       127214 :     if (!m_tieFor || !m_tieFor->isPartialTie()) {
    2575       127143 :         return nullptr;
    2576              :     }
    2577              : 
    2578           71 :     return toPartialTie(m_tieFor);
    2579              : }
    2580              : 
    2581         3532 : void Note::setTieFor(Tie* t)
    2582              : {
    2583         3532 :     if (!t) {
    2584         1367 :         m_jumpPoints.clear();
    2585              :     }
    2586         3532 :     m_tieFor = t;
    2587         3532 :     if (m_tieFor && !m_tieFor->isLaissezVib()) {
    2588         2144 :         m_tieFor->updatePossibleJumpPoints();
    2589              :     }
    2590         3532 : }
    2591              : 
    2592         3212 : void Note::setTieBack(Tie* t)
    2593              : {
    2594         3212 :     if (m_tieBack && t && m_tieBack->jumpPoint()) {
    2595            0 :         t->setJumpPoint(m_tieBack->jumpPoint());
    2596            0 :         m_tieBack->setJumpPoint(nullptr);
    2597              :     }
    2598         3212 :     m_tieBack = t;
    2599         3212 : }
    2600              : 
    2601              : //---------------------------------------------------------
    2602              : //   line
    2603              : //---------------------------------------------------------
    2604              : 
    2605      1330306 : int Note::line() const
    2606              : {
    2607      1330306 :     return fixed() ? m_fixedLine : m_line;
    2608              : }
    2609              : 
    2610              : //---------------------------------------------------------
    2611              : //   setHeadScheme
    2612              : //---------------------------------------------------------
    2613              : 
    2614           70 : void Note::setHeadScheme(NoteHeadScheme val)
    2615              : {
    2616           70 :     IF_ASSERT_FAILED(int(val) >= -1 && int(val) < int(NoteHeadScheme::HEAD_SCHEMES)) {
    2617            0 :         val = NoteHeadScheme::HEAD_AUTO;
    2618              :     }
    2619           70 :     m_headScheme = val;
    2620           70 : }
    2621              : 
    2622              : //---------------------------------------------------------
    2623              : //   setHeadGroup
    2624              : //---------------------------------------------------------
    2625              : 
    2626         8117 : void Note::setHeadGroup(NoteHeadGroup val)
    2627              : {
    2628         8117 :     assert(int(val) >= 0 && int(val) < int(NoteHeadGroup::HEAD_GROUPS));
    2629         8117 :     m_headGroup = val;
    2630         8117 : }
    2631              : 
    2632              : //---------------------------------------------------------
    2633              : //   ottaveCapoFret
    2634              : //    offset added by Ottava's and Capo Fret.
    2635              : //---------------------------------------------------------
    2636              : 
    2637        13130 : int Note::ottaveCapoFret() const
    2638              : {
    2639        13130 :     const Chord* ch = chord();
    2640        13130 :     Fraction segmentTick = ch->segment()->tick();
    2641        13130 :     const Staff* staff = this->staff();
    2642              : 
    2643        13130 :     const CapoParams& capo = staff->capo(segmentTick);
    2644        13130 :     int capoFret = 0;
    2645              : 
    2646              :     using MODE = CapoParams::TransposeMode;
    2647        13130 :     if (capo.active && MODE::PLAYBACK_ONLY == capo.transposeMode) {
    2648            0 :         if (capo.ignoredStrings.empty() || !muse::contains(capo.ignoredStrings, static_cast<string_idx_t>(m_string))) {
    2649            0 :             capoFret = capo.fretPosition;
    2650              :         }
    2651              :     }
    2652              : 
    2653        26260 :     return staff->pitchOffset(segmentTick) + capoFret;
    2654              : }
    2655              : 
    2656              : //---------------------------------------------------------
    2657              : //   ppitch
    2658              : //    playback pitch
    2659              : //---------------------------------------------------------
    2660              : 
    2661        10314 : int Note::ppitch() const
    2662              : {
    2663        10314 :     const Chord* ch = chord();
    2664              : 
    2665              :     // if staff is drum
    2666              :     // match tremolo and articulation between variants and chord
    2667        10314 :     if (m_play && ch) {
    2668        10255 :         const Staff* staff = ch->staff();
    2669        10255 :         Fraction tick = ch->tick();
    2670              : 
    2671        10255 :         if (staff && staff->isDrumStaff(tick)) {
    2672          105 :             const Drumset* ds = originPart()->instrument(tick)->drumset();
    2673          105 :             if (ds) {
    2674          105 :                 DrumInstrumentVariant div = ds->findVariant(m_pitch, ch->articulations(), ch->tremoloType());
    2675          105 :                 if (div.pitch != INVALID_PITCH) {
    2676            0 :                     return div.pitch;
    2677              :                 }
    2678          105 :             }
    2679              :         }
    2680              :     }
    2681              : 
    2682        10314 :     return m_pitch + ottaveCapoFret() + linkedOttavaPitchOffset();
    2683              : }
    2684              : 
    2685              : //---------------------------------------------------------
    2686              : //   epitch
    2687              : //    effective pitch, i.e. a pitch which is visible in the
    2688              : //    currently used written notation.
    2689              : //    honours transposing instruments
    2690              : //---------------------------------------------------------
    2691              : 
    2692       213016 : int Note::epitch() const
    2693              : {
    2694       213016 :     return m_pitch - (concertPitch() ? 0 : transposition()) + linkedOttavaPitchOffset();
    2695              : }
    2696              : 
    2697              : //---------------------------------------------------------
    2698              : //   linkedOttavaPitchOffset
    2699              : //    if an ottava exists in another part but has been excluded
    2700              : //    from this one, this returns the corresponding pitch offset
    2701              : //---------------------------------------------------------
    2702              : 
    2703       223330 : int Note::linkedOttavaPitchOffset() const
    2704              : {
    2705       223330 :     int linkedOttavaPitchOffset = 0;
    2706       223330 :     if (links() && staff()->pitchOffset(tick()) == 0) {
    2707        38732 :         for (EngravingObject* link : *links()) {
    2708        25946 :             int offset = toNote(link)->staff()->pitchOffset(tick());
    2709        25946 :             if (offset != 0) {
    2710            0 :                 linkedOttavaPitchOffset = offset;
    2711            0 :                 break;
    2712              :             }
    2713              :         }
    2714              :     }
    2715       223330 :     return linkedOttavaPitchOffset;
    2716              : }
    2717              : 
    2718              : //---------------------------------------------------------
    2719              : //   octave
    2720              : //    compute octave number from note information
    2721              : //---------------------------------------------------------
    2722              : 
    2723         1242 : int Note::octave() const
    2724              : {
    2725         1242 :     return ((epitch() + ottaveCapoFret() - static_cast<int>(tpc2alter(tpc()))) / 12) - 1;
    2726              : }
    2727              : 
    2728         1574 : int Note::playingOctave() const
    2729              : {
    2730         1574 :     return mu::engraving::playingOctave(ppitch(), tpc1());
    2731              : }
    2732              : 
    2733         1558 : double Note::playingTuning() const
    2734              : {
    2735         1558 :     return m_tuning + m_centOffset;
    2736              : }
    2737              : 
    2738              : //---------------------------------------------------------
    2739              : //   customizeVelocity
    2740              : //    Input is the global velocity determined by dynamic
    2741              : //    signs and crescendo/diminuendo etc.
    2742              : //    Returns the actual play velocity for this note
    2743              : //    modified by veloOffset
    2744              : //---------------------------------------------------------
    2745              : 
    2746            0 : int Note::customizeVelocity(int velo) const
    2747              : {
    2748            0 :     if (m_veloType == VeloType::OFFSET_VAL) {
    2749            0 :         velo = velo + (velo * userVelocity()) / 100;
    2750            0 :     } else if (m_veloType == VeloType::USER_VAL) {
    2751            0 :         velo = userVelocity();
    2752              :     }
    2753            0 :     return std::clamp(velo, 1, 127);
    2754              : }
    2755              : 
    2756              : //---------------------------------------------------------
    2757              : //   startDrag
    2758              : //---------------------------------------------------------
    2759              : 
    2760            0 : void Note::startDrag(EditData& ed)
    2761              : {
    2762            0 :     std::shared_ptr<NoteEditData> ned = std::make_shared<NoteEditData>();
    2763            0 :     ned->e      = this;
    2764            0 :     ned->line   = m_line;
    2765            0 :     ned->string = m_string;
    2766            0 :     ned->pushProperty(Pid::PITCH);
    2767            0 :     ned->pushProperty(Pid::TPC1);
    2768            0 :     ned->pushProperty(Pid::TPC2);
    2769            0 :     ned->pushProperty(Pid::FRET);
    2770            0 :     ned->pushProperty(Pid::STRING);
    2771              : 
    2772            0 :     ed.addData(ned);
    2773            0 : }
    2774              : 
    2775              : //---------------------------------------------------------
    2776              : //   drag
    2777              : //---------------------------------------------------------
    2778              : 
    2779            0 : RectF Note::drag(EditData& ed)
    2780              : {
    2781            0 :     NoteEditData* noteEditData = static_cast<NoteEditData*>(ed.getData(this).get());
    2782            0 :     IF_ASSERT_FAILED(noteEditData) {
    2783            0 :         return RectF();
    2784              :     }
    2785              : 
    2786            0 :     if (ed.isEditMode) {
    2787            0 :         dragInEditMode(ed);
    2788            0 :         return RectF();
    2789              :     }
    2790              : 
    2791            0 :     PointF delta = ed.evtDelta;
    2792            0 :     noteEditData->delta = delta;
    2793              : 
    2794            0 :     if (noteEditData->mode == NoteEditData::EditMode_Undefined) {
    2795            0 :         noteEditData->mode = NoteEditData::editModeByDragDirection(delta.x(), delta.y());
    2796              :     }
    2797              : 
    2798            0 :     bool isSingleNoteSelection = score()->getSelectedElement() == this;
    2799            0 :     if (noteEditData->mode == NoteEditData::EditMode_AddSpacing && isSingleNoteSelection && !(ed.modifiers & ControlModifier)) {
    2800            0 :         horizontalDrag(ed);
    2801            0 :     } else if (noteEditData->mode == NoteEditData::EditMode_ChangePitch) {
    2802            0 :         verticalDrag(ed);
    2803              :     }
    2804              : 
    2805            0 :     return RectF();
    2806              : }
    2807              : 
    2808              : //---------------------------------------------------------
    2809              : //   endDrag
    2810              : //---------------------------------------------------------
    2811              : 
    2812            0 : void Note::endDrag(EditData& ed)
    2813              : {
    2814            0 :     NoteEditData* ned = static_cast<NoteEditData*>(ed.getData(this).get());
    2815            0 :     IF_ASSERT_FAILED(ned) {
    2816            0 :         return;
    2817              :     }
    2818            0 :     for (Note* nn : tiedNotes()) {
    2819            0 :         for (const auto& [id, data, flags] : ned->propertyData) {
    2820            0 :             setPropertyFlags(id, flags); // reset initial property flags state
    2821            0 :             score()->undoPropertyChanged(nn, id, data);
    2822              :         }
    2823            0 :     }
    2824              : }
    2825              : 
    2826              : //---------------------------------------------------------
    2827              : //   dragInEditMode
    2828              : //---------------------------------------------------------
    2829              : 
    2830            0 : void Note::dragInEditMode(EditData& editData)
    2831              : {
    2832            0 :     Chord* ch = chord();
    2833            0 :     Segment* seg = ch->segment();
    2834              : 
    2835            0 :     if (editData.modifiers & ShiftModifier) {
    2836            0 :         const Spatium deltaSp = Spatium(editData.delta.x() / spatium());
    2837            0 :         seg->undoChangeProperty(Pid::LEADING_SPACE, seg->extraLeadingSpace() + deltaSp);
    2838            0 :     } else if (ch->notes().size() == 1) {
    2839              :         // if the chord contains only this note, then move the whole chord
    2840              :         // including stem, flag etc.
    2841            0 :         ch->undoChangeProperty(Pid::OFFSET, PropertyValue::fromValue(ch->offset() + offset() + editData.evtDelta));
    2842            0 :         setOffset(PointF());
    2843              :     } else {
    2844            0 :         setOffset(offset() + editData.evtDelta);
    2845              :     }
    2846              : 
    2847            0 :     triggerLayout();
    2848            0 : }
    2849              : 
    2850              : //---------------------------------------------------------
    2851              : //   verticalDrag
    2852              : //---------------------------------------------------------
    2853              : 
    2854            0 : void Note::verticalDrag(EditData& ed)
    2855              : {
    2856            0 :     Fraction _tick = chord()->tick();
    2857            0 :     if (originPart()->instrument(_tick)->useDrumset()) {
    2858            0 :         return;
    2859              :     }
    2860              : 
    2861            0 :     NoteEditData* ned   = static_cast<NoteEditData*>(ed.getData(this).get());
    2862              : 
    2863            0 :     const bool tab = staffType()->isTabStaff();
    2864            0 :     double step    = spatium() * staffType()->lineDistance().val() * (tab ? 1.0 : 0.5);
    2865            0 :     int lineOffset = lrint(ed.moveDelta.y() / step);
    2866              : 
    2867            0 :     if (tab) {
    2868            0 :         const StringData* strData = originPart()->stringData(_tick, staffIdx());
    2869            0 :         const int pitchOffset = staff()->pitchOffset(_tick);
    2870            0 :         int nString = ned->string + (staffType()->upsideDown() ? -lineOffset : lineOffset);
    2871            0 :         int nFret   = strData->fret(m_pitch + pitchOffset, nString, staff(), tick());
    2872              : 
    2873            0 :         if (nFret >= 0) {                        // no fret?
    2874            0 :             if (fret() != nFret || string() != nString) {
    2875            0 :                 for (Note* nn : tiedNotes()) {
    2876            0 :                     nn->setFret(nFret);
    2877            0 :                     nn->setString(nString);
    2878            0 :                     strData->fretChords(nn->chord());
    2879            0 :                     nn->triggerLayout();
    2880            0 :                 }
    2881              :             }
    2882              :         }
    2883              :     } else {
    2884            0 :         staff_idx_t idx = chord()->vStaffIdx();
    2885            0 :         bool error = false;
    2886            0 :         AccidentalVal accOffs = firstTiedNote()->chord()->measure()->findAccidental(
    2887            0 :             firstTiedNote()->chord()->segment(), idx, ned->line + lineOffset, error);
    2888            0 :         if (error) {
    2889            0 :             accOffs = Accidental::subtype2value(AccidentalType::NONE);
    2890              :         }
    2891            0 :         int nStep = absStep(ned->line + lineOffset, score()->staff(idx)->clef(_tick));
    2892            0 :         nStep = std::max(0, nStep);
    2893            0 :         int octave = nStep / STEP_DELTA_OCTAVE;
    2894            0 :         int newPitch = step2pitch(nStep) + octave * PITCH_DELTA_OCTAVE + int(accOffs);
    2895              : 
    2896            0 :         int newTpc1 = step2tpc(nStep % STEP_DELTA_OCTAVE, accOffs);
    2897            0 :         int newTpc2 = newTpc1;
    2898            0 :         if (concertPitch()) {
    2899            0 :             newTpc2 = transposeTpc(newTpc1);
    2900              :         } else {
    2901            0 :             newPitch += staff()->transpose(_tick).chromatic;
    2902            0 :             newTpc1 = transposeTpc(newTpc2);
    2903              :         }
    2904              : 
    2905            0 :         int clampedPitch = clampPitch(newPitch);
    2906            0 :         if (clampedPitch != newPitch) {
    2907              :             // newTpc1/newTpc2 were derived from a step/accidental that no longer
    2908              :             // matches the clamped pitch; respell them so tpc and pitch stay in sync
    2909            0 :             Key key = score()->staff(idx)->key(_tick);
    2910            0 :             if (concertPitch()) {
    2911            0 :                 newTpc1 = pitch2tpc(clampedPitch, key, Prefer::NEAREST);
    2912            0 :                 newTpc2 = transposeTpc(newTpc1);
    2913              :             } else {
    2914            0 :                 newTpc2 = pitch2tpc(clampedPitch - staff()->transpose(_tick).chromatic, key, Prefer::NEAREST);
    2915            0 :                 newTpc1 = transposeTpc(newTpc2);
    2916              :             }
    2917            0 :             newPitch = clampedPitch;
    2918              :         }
    2919              : 
    2920            0 :         for (Note* nn : tiedNotes()) {
    2921            0 :             nn->setAccidentalType(AccidentalType::NONE);
    2922            0 :             nn->setPitch(newPitch, newTpc1, newTpc2);
    2923            0 :             nn->triggerLayout();
    2924            0 :         }
    2925              :     }
    2926            0 :     score()->inputState().setAccidentalType(AccidentalType::NONE);
    2927              : }
    2928              : 
    2929              : //---------------------------------------------------------
    2930              : //   normalizeLeftDragDelta
    2931              : //---------------------------------------------------------
    2932              : 
    2933            0 : void Note::normalizeLeftDragDelta(Segment* seg, EditData& ed, NoteEditData* ned)
    2934              : {
    2935            0 :     Segment* previous = seg->prev();
    2936              : 
    2937            0 :     if (previous) {
    2938            0 :         double minDist = HorizontalSpacing::minHorizontalDistance(previous, seg, 1.0);
    2939              : 
    2940            0 :         double diff = (ed.pos.x()) - (previous->pageX() + minDist);
    2941              : 
    2942            0 :         double distanceBetweenSegments = (previous->pageX() + minDist) - seg->pageX();
    2943              : 
    2944            0 :         if (diff < 0) {
    2945            0 :             ned->delta.setX(distanceBetweenSegments);
    2946              :         }
    2947              :     } else {
    2948            0 :         Measure* measure = seg->measure();
    2949              : 
    2950            0 :         double minDist = style().styleAbsolute(Sid::barNoteDistance);
    2951              : 
    2952            0 :         double diff = (ed.pos.x()) - (measure->pageX() + minDist);
    2953              : 
    2954            0 :         double distanceBetweenSegments = (measure->pageX() + minDist) - seg->pageX();
    2955              : 
    2956            0 :         if (diff < 0) {
    2957            0 :             ned->delta.setX(distanceBetweenSegments);
    2958              :         }
    2959              :     }
    2960            0 : }
    2961              : 
    2962              : //---------------------------------------------------------
    2963              : //   horizontalDrag
    2964              : //---------------------------------------------------------
    2965              : 
    2966            0 : void Note::horizontalDrag(EditData& ed)
    2967              : {
    2968            0 :     Chord* ch = chord();
    2969            0 :     Segment* seg = ch->segment();
    2970              : 
    2971            0 :     NoteEditData* ned = static_cast<NoteEditData*>(ed.getData(this).get());
    2972              : 
    2973            0 :     if (ed.moveDelta.x() < 0) {
    2974            0 :         normalizeLeftDragDelta(seg, ed, ned);
    2975              :     }
    2976              : 
    2977            0 :     const Spatium deltaSp = Spatium(ned->delta.x() / spatium());
    2978              : 
    2979            0 :     if (seg->extraLeadingSpace() + deltaSp < 0_sp) {
    2980            0 :         return;
    2981              :     }
    2982              : 
    2983            0 :     seg->undoChangeProperty(Pid::LEADING_SPACE, seg->extraLeadingSpace() + deltaSp);
    2984              : 
    2985            0 :     triggerLayout();
    2986              : }
    2987              : 
    2988              : //---------------------------------------------------------
    2989              : //   updateRelLine
    2990              : //    calculate the real note line depending on clef,
    2991              : //    absLine is the absolute line
    2992              : //---------------------------------------------------------
    2993              : 
    2994        60199 : void Note::updateRelLine(int absLine, bool undoable)
    2995              : {
    2996        60199 :     if (!staff()) {
    2997            0 :         return;
    2998              :     }
    2999              :     // int idx      = staffIdx() + chord()->staffMove();
    3000        60199 :     assert(staffIdx() == chord()->staffIdx());
    3001        60199 :     staff_idx_t idx      = chord()->vStaffIdx();
    3002              : 
    3003        60199 :     const Staff* staff  = score()->staff(idx);
    3004        60199 :     const StaffType* st = staff->staffTypeForElement(this);
    3005        60199 :     if (st->isTabStaff()) {
    3006              :         // tab staff is already correct, and the following relStep method doesn't apply whatsoever to tab staves
    3007            1 :         return;
    3008              :     }
    3009        60198 :     ClefType clef = staff->clef(chord()->tick());
    3010        60198 :     int line      = relStep(absLine, clef);
    3011              : 
    3012        60198 :     if (undoable && (m_line != INVALID_LINE) && (line != m_line)) {
    3013          732 :         undoChangeProperty(Pid::LINE, line);
    3014              :     } else {
    3015        59466 :         setLine(line);
    3016              :     }
    3017              : 
    3018        60198 :     int off  = st->stepOffset();
    3019        60198 :     double ld = st->lineDistance().val();
    3020        60198 :     mutldata()->setPosY((m_line + off * 2.0) * spatium() * .5 * ld);
    3021              : }
    3022              : 
    3023              : //---------------------------------------------------------
    3024              : //   updateLine
    3025              : //---------------------------------------------------------
    3026              : 
    3027          495 : void Note::updateLine()
    3028              : {
    3029          495 :     int absLine = absStep(tpc(), epitch());
    3030          495 :     updateRelLine(absLine, false);
    3031          495 : }
    3032              : 
    3033              : //---------------------------------------------------------
    3034              : //   setNval
    3035              : //    set note properties from NoteVal
    3036              : //---------------------------------------------------------
    3037              : 
    3038         5301 : void Note::setNval(const NoteVal& nval, Fraction tick)
    3039              : {
    3040         5301 :     setPitch(nval.pitch);
    3041         5301 :     m_userVelocity = nval.velocityOverride;
    3042         5301 :     m_fret   = nval.fret;
    3043         5301 :     m_string = nval.string;
    3044              : 
    3045         5301 :     m_tpc[0] = nval.tpc1;
    3046         5301 :     m_tpc[1] = nval.tpc2;
    3047              : 
    3048         5301 :     if (tick == Fraction(-1, 1) && chord()) {
    3049         1661 :         tick = chord()->tick();
    3050              :     }
    3051         5301 :     Interval v = staff()->transpose(tick);
    3052         5301 :     if (nval.tpc1 == Tpc::TPC_INVALID) {
    3053         3389 :         if (nval.tpc2 == Tpc::TPC_INVALID) {
    3054         1204 :             Key key = staff()->concertKey(tick);
    3055         1204 :             m_tpc[0] = pitch2tpc(nval.pitch, key, Prefer::NEAREST);
    3056              :         } else {
    3057         2185 :             if (v.isZero()) {
    3058         2060 :                 m_tpc[0] = m_tpc[1];
    3059              :             } else {
    3060          125 :                 m_tpc[0] = Transpose::transposeTpc(m_tpc[1], v, true);
    3061              :             }
    3062              :         }
    3063              :     }
    3064         5301 :     if (nval.tpc2 == Tpc::TPC_INVALID) {
    3065         1348 :         if (v.isZero()) {
    3066         1204 :             m_tpc[1] = m_tpc[0];
    3067              :         } else {
    3068          144 :             v.flip();
    3069          144 :             m_tpc[1] = Transpose::transposeTpc(m_tpc[0], v, true);
    3070              :         }
    3071              :     }
    3072              : 
    3073         5301 :     m_headGroup = NoteHeadGroup(nval.headGroup);
    3074         5301 : }
    3075              : 
    3076              : //---------------------------------------------------------
    3077              : //   localSpatiumChanged
    3078              : //---------------------------------------------------------
    3079              : 
    3080            0 : void Note::localSpatiumChanged(double oldValue, double newValue)
    3081              : {
    3082            0 :     EngravingItem::localSpatiumChanged(oldValue, newValue);
    3083            0 :     for (EngravingItem* e : dots()) {
    3084            0 :         e->localSpatiumChanged(oldValue, newValue);
    3085              :     }
    3086            0 :     for (EngravingItem* e : el()) {
    3087            0 :         e->localSpatiumChanged(oldValue, newValue);
    3088              :     }
    3089            0 :     for (Spanner* spanner : spannerBack()) {
    3090            0 :         for (auto k : spanner->spannerSegments()) {
    3091            0 :             k->localSpatiumChanged(oldValue, newValue);
    3092              :         }
    3093              :     }
    3094            0 : }
    3095              : 
    3096              : //---------------------------------------------------------
    3097              : //   getProperty
    3098              : //---------------------------------------------------------
    3099              : 
    3100       727161 : PropertyValue Note::getProperty(Pid propertyId) const
    3101              : {
    3102       727161 :     switch (propertyId) {
    3103        23753 :     case Pid::PITCH:
    3104        23753 :         return pitch();
    3105        23753 :     case Pid::CENT_OFFSET:
    3106        23753 :         return centOffset();
    3107        47701 :     case Pid::TPC1:
    3108        47701 :         return m_tpc[0];
    3109        24196 :     case Pid::TPC2:
    3110        24196 :         return m_tpc[1];
    3111        23753 :     case Pid::SMALL:
    3112        23753 :         return isSmall();
    3113        23753 :     case Pid::MIRROR_HEAD:
    3114        23753 :         return userMirror();
    3115        23753 :     case Pid::DOT_POSITION:
    3116        23753 :         return PropertyValue::fromValue<DirectionV>(userDotPosition());
    3117        23753 :     case Pid::HEAD_SCHEME:
    3118        23753 :         return headScheme();
    3119        26408 :     case Pid::HEAD_GROUP:
    3120        26408 :         return headGroup();
    3121        23753 :     case Pid::USER_VELOCITY:
    3122        23753 :         return userVelocity();
    3123        23753 :     case Pid::TUNING:
    3124        23753 :         return tuning();
    3125        24314 :     case Pid::FRET:
    3126        24314 :         return fret();
    3127        24307 :     case Pid::STRING:
    3128        24307 :         return string();
    3129        23753 :     case Pid::GHOST:
    3130        23753 :         return ghost();
    3131        23753 :     case Pid::DEAD:
    3132        23753 :         return deadNote();
    3133        23753 :     case Pid::HEAD_TYPE:
    3134        23753 :         return headType();
    3135            0 :     case Pid::VELO_TYPE:
    3136            0 :         return m_veloType;
    3137        24166 :     case Pid::PLAY:
    3138        24166 :         return play();
    3139         2348 :     case Pid::LINE:
    3140         2348 :         return m_line;
    3141        24097 :     case Pid::FIXED:
    3142        24097 :         return fixed();
    3143        24097 :     case Pid::FIXED_LINE:
    3144        24097 :         return fixedLine();
    3145        27796 :     case Pid::HAS_PARENTHESES:
    3146        27796 :         return m_hasParens ? ParenthesesMode::BOTH : ParenthesesMode::NONE;
    3147        23874 :     case Pid::HIDE_GENERATED_PARENTHESES:
    3148        23874 :         return m_hideGeneratedParens;
    3149        47538 :     case Pid::POSITION_LINKED_TO_MASTER:
    3150              :     case Pid::APPEARANCE_LINKED_TO_MASTER:
    3151        47538 :         if (chord()) {
    3152        47538 :             return EngravingItem::getProperty(propertyId).toBool() && chord()->getProperty(propertyId).toBool();
    3153              :         }
    3154              :     default:
    3155       145036 :         break;
    3156              :     }
    3157       145036 :     return EngravingItem::getProperty(propertyId);
    3158              : }
    3159              : 
    3160              : //---------------------------------------------------------
    3161              : //   setProperty
    3162              : //---------------------------------------------------------
    3163              : 
    3164         3186 : bool Note::setProperty(Pid propertyId, const PropertyValue& v)
    3165              : {
    3166         3186 :     Measure* m = chord() ? chord()->measure() : nullptr;
    3167         3186 :     switch (propertyId) {
    3168            1 :     case Pid::PITCH:
    3169            1 :         setPitch(v.toInt());
    3170            1 :         break;
    3171            0 :     case Pid::CENT_OFFSET:
    3172            0 :         setCentOffset(v.toDouble());
    3173            0 :         break;
    3174           67 :     case Pid::TPC1:
    3175           67 :         m_tpc[0] = v.toInt();
    3176           67 :         break;
    3177          144 :     case Pid::TPC2:
    3178          144 :         m_tpc[1] = v.toInt();
    3179          144 :         break;
    3180          884 :     case Pid::LINE:
    3181          884 :         setLine(v.toInt());
    3182          884 :         break;
    3183            2 :     case Pid::SMALL:
    3184            2 :         setSmall(v.toBool());
    3185            2 :         break;
    3186            7 :     case Pid::MIRROR_HEAD:
    3187            7 :         setUserMirror(v.value<DirectionH>());
    3188            7 :         break;
    3189            7 :     case Pid::DOT_POSITION:
    3190            7 :         setUserDotPosition(v.value<DirectionV>());
    3191            7 :         break;
    3192            6 :     case Pid::HEAD_SCHEME:
    3193            6 :         setHeadScheme(v.value<NoteHeadScheme>());
    3194            6 :         break;
    3195          753 :     case Pid::HEAD_GROUP:
    3196          753 :         setHeadGroup(v.value<NoteHeadGroup>());
    3197          753 :         if (links()) {
    3198            0 :             for (EngravingObject* scoreElement : *links()) {
    3199            0 :                 Note* note = toNote(scoreElement);
    3200            0 :                 note->setDeadNote(staff() && !staff()->isDrumStaff(tick()) && m_headGroup == NoteHeadGroup::HEAD_CROSS);
    3201            0 :                 note->setHeadGroup(m_headGroup);
    3202              :             }
    3203              :         } else {
    3204          753 :             setDeadNote(staff() && !staff()->isDrumStaff(tick()) && m_headGroup == NoteHeadGroup::HEAD_CROSS);
    3205          753 :             setHeadGroup(m_headGroup);
    3206              :         }
    3207          753 :         break;
    3208            1 :     case Pid::USER_VELOCITY:
    3209            1 :         setUserVelocity(v.toInt());
    3210            1 :         break;
    3211            1 :     case Pid::TUNING:
    3212            1 :         setTuning(v.toDouble());
    3213            1 :         break;
    3214          167 :     case Pid::FRET:
    3215          167 :         setFret(v.toInt());
    3216          167 :         break;
    3217          158 :     case Pid::STRING:
    3218          158 :         setString(v.toInt());
    3219          158 :         break;
    3220            2 :     case Pid::GHOST:
    3221            2 :         setGhost(v.toBool());
    3222            2 :         break;
    3223            0 :     case Pid::DEAD:
    3224            0 :         setDeadNote(v.toBool());
    3225            0 :         if (!staff()->isDrumStaff(tick())) {
    3226            0 :             NoteHeadGroup head
    3227            0 :                 = (m_deadNote && m_headGroup != NoteHeadGroup::HEAD_CROSS) ? NoteHeadGroup::HEAD_CROSS : NoteHeadGroup::HEAD_NORMAL;
    3228            0 :             setHeadGroup(head);
    3229              :         }
    3230            0 :         break;
    3231          118 :     case Pid::HEAD_TYPE:
    3232          118 :         setHeadType(v.value<NoteHeadType>());
    3233          118 :         break;
    3234            3 :     case Pid::VELO_TYPE:
    3235            3 :         m_veloType = v.value<VeloType>();
    3236            3 :         break;
    3237           79 :     case Pid::VISIBLE: {
    3238           79 :         setVisible(v.toBool());
    3239           79 :         if (m) {
    3240           79 :             m->checkMultiVoices(chord()->staffIdx());
    3241              :         }
    3242           79 :         break;
    3243              :     }
    3244          164 :     case Pid::PLAY:
    3245          164 :         setPlay(v.toBool());
    3246          164 :         break;
    3247          164 :     case Pid::FIXED:
    3248          164 :         setFixed(v.toBool());
    3249          164 :         break;
    3250          164 :     case Pid::FIXED_LINE:
    3251          164 :         setFixedLine(v.toInt());
    3252          164 :         break;
    3253          165 :     case Pid::HAS_PARENTHESES:
    3254          165 :         if (v.value<ParenthesesMode>() != ParenthesesMode::BOTH && v.value<ParenthesesMode>() != ParenthesesMode::NONE) {
    3255            0 :             ASSERT_X("Notes cannot set left & right parens individually");
    3256              :         }
    3257          165 :         m_hasParens = v.value<ParenthesesMode>() == ParenthesesMode::BOTH;
    3258          165 :         break;
    3259           53 :     case Pid::HIDE_GENERATED_PARENTHESES:
    3260           53 :         setHideGeneratedParens(v.toBool());
    3261           53 :         break;
    3262           32 :     case Pid::POSITION_LINKED_TO_MASTER:
    3263              :     case Pid::APPEARANCE_LINKED_TO_MASTER:
    3264           32 :         if (v.toBool() == true && chord()) {
    3265              :             // when re-linking, also re-link the parent chord
    3266            0 :             chord()->setProperty(propertyId, v);
    3267              :         }
    3268              :     // fall through
    3269              :     default:
    3270           76 :         if (!EngravingItem::setProperty(propertyId, v)) {
    3271            0 :             return false;
    3272              :         }
    3273           76 :         break;
    3274              :     }
    3275         3186 :     triggerLayout();
    3276         3186 :     return true;
    3277              : }
    3278              : 
    3279              : //---------------------------------------------------------
    3280              : //   propertyDefault
    3281              : //---------------------------------------------------------
    3282              : 
    3283       688957 : PropertyValue Note::propertyDefault(Pid propertyId) const
    3284              : {
    3285       688957 :     switch (propertyId) {
    3286        23753 :     case Pid::CENT_OFFSET:
    3287        23753 :         return 0.0;
    3288        71259 :     case Pid::GHOST:
    3289              :     case Pid::DEAD:
    3290              :     case Pid::SMALL:
    3291        71259 :         return false;
    3292        23753 :     case Pid::MIRROR_HEAD:
    3293        23753 :         return DirectionH::AUTO;
    3294        23753 :     case Pid::DOT_POSITION:
    3295        23753 :         return DirectionV::AUTO;
    3296        23753 :     case Pid::HEAD_SCHEME:
    3297        23753 :         return NoteHeadScheme::HEAD_AUTO;
    3298        23753 :     case Pid::HEAD_GROUP:
    3299        23753 :         return NoteHeadGroup::HEAD_NORMAL;
    3300        23753 :     case Pid::USER_VELOCITY:
    3301        23753 :         return 0;
    3302        23753 :     case Pid::TUNING:
    3303        23753 :         return 0.0;
    3304        47506 :     case Pid::FRET:
    3305              :     case Pid::STRING:
    3306        47506 :         return -1;
    3307        23753 :     case Pid::HEAD_TYPE:
    3308        23753 :         return NoteHeadType::HEAD_AUTO;
    3309            0 :     case Pid::VELO_TYPE:
    3310            0 :         return VeloType::USER_VAL;
    3311        23753 :     case Pid::PLAY:
    3312        23753 :         return true;
    3313        23753 :     case Pid::FIXED:
    3314        23753 :         return false;
    3315        23753 :     case Pid::FIXED_LINE:
    3316        23753 :         return 0;
    3317        23753 :     case Pid::TPC2:
    3318        23753 :         return getProperty(Pid::TPC1);
    3319        47506 :     case Pid::PITCH:
    3320              :     case Pid::TPC1:
    3321        47506 :         return PropertyValue();
    3322        23753 :     case Pid::VISIBLE:
    3323        23753 :         if (staffType() && staffType()->isTabStaff()) {
    3324          401 :             GuitarBend* bend = bendBack();
    3325          401 :             if (bend && !bend->isFullRelease()) {
    3326            0 :                 return false;
    3327              :             }
    3328              :         }
    3329        23753 :         return EngravingItem::propertyDefault(propertyId);
    3330        23802 :     case Pid::COLOR: {
    3331        23802 :         const StaffType* st = staffType();
    3332        23802 :         if (st && st->isTabStaff() && st->fretUseTextStyle()) {
    3333          448 :             return style().styleV(Sid::tabFretNumberColor);
    3334              :         }
    3335        23354 :         return EngravingItem::propertyDefault(propertyId);
    3336              :     }
    3337        23753 :     case Pid::HIDE_GENERATED_PARENTHESES:
    3338        23753 :         return false;
    3339       166342 :     default:
    3340       166342 :         break;
    3341              :     }
    3342       166342 :     return EngravingItem::propertyDefault(propertyId);
    3343              : }
    3344              : 
    3345          898 : void Note::styleChanged()
    3346              : {
    3347          898 :     const StaffType* st = staffType();
    3348          898 :     if (st && st->isTabStaff() && st->fretUseTextStyle()) {
    3349            0 :         setProperty(Pid::COLOR, style().styleV(Sid::tabFretNumberColor));
    3350              :     }
    3351          898 :     EngravingItem::styleChanged();
    3352          898 : }
    3353              : 
    3354              : //---------------------------------------------------------
    3355              : //   setHeadType
    3356              : //---------------------------------------------------------
    3357              : 
    3358          214 : void Note::setHeadType(NoteHeadType t)
    3359              : {
    3360          214 :     m_headType = t;
    3361          214 : }
    3362              : 
    3363              : //---------------------------------------------------------
    3364              : //   setOnTimeOffset
    3365              : //---------------------------------------------------------
    3366              : 
    3367            0 : void Note::setOnTimeOffset(int val)
    3368              : {
    3369            0 :     m_playEvents[0].setOntime(val);
    3370            0 :     chord()->setPlayEventType(PlayEventType::User);
    3371            0 : }
    3372              : 
    3373              : //---------------------------------------------------------
    3374              : //   setOffTimeOffset
    3375              : //---------------------------------------------------------
    3376              : 
    3377            0 : void Note::setOffTimeOffset(int val)
    3378              : {
    3379            0 :     m_playEvents[0].setLen(val - m_playEvents[0].ontime());
    3380            0 :     chord()->setPlayEventType(PlayEventType::User);
    3381            0 : }
    3382              : 
    3383              : //---------------------------------------------------------
    3384              : //   setScore
    3385              : //---------------------------------------------------------
    3386              : 
    3387         5720 : void Note::setScore(Score* s)
    3388              : {
    3389         5720 :     EngravingItem::setScore(s);
    3390         5720 :     if (m_tieFor) {
    3391           83 :         m_tieFor->setScore(s);
    3392              :     }
    3393         5720 :     if (m_accidental) {
    3394           32 :         m_accidental->setScore(s);
    3395              :     }
    3396         5749 :     for (NoteDot* dot : m_dots) {
    3397           29 :         dot->setScore(s);
    3398              :     }
    3399         5720 :     for (JianpuOctaveDot* dot : m_jianpuOctaveDots) {
    3400            0 :         dot->setScore(s);
    3401              :     }
    3402         5745 :     for (EngravingItem* el : m_el) {
    3403           25 :         el->setScore(s);
    3404              :     }
    3405         5720 : }
    3406              : 
    3407              : //---------------------------------------------------------
    3408              : //   accessibleInfo
    3409              : //---------------------------------------------------------
    3410              : 
    3411            0 : String Note::accessibleInfo() const
    3412              : {
    3413            0 :     if (!chord() || !staff()) {
    3414            0 :         return String();
    3415              :     }
    3416              : 
    3417            0 :     String duration = chord()->durationUserName();
    3418            0 :     String voice = muse::mtrc("engraving", "Voice: %1").arg(track() % VOICES + 1);
    3419            0 :     String pitchName;
    3420            0 :     String onofftime;
    3421            0 :     if (!m_playEvents.empty()) {
    3422            0 :         int on = m_playEvents[0].ontime();
    3423            0 :         int off = m_playEvents[0].offtime();
    3424            0 :         if (on != 0 || off != NoteEvent::NOTE_LENGTH) {
    3425              :             //: Note-on and note-off times relative to note duration, expressed in thousandths (per mille)
    3426            0 :             onofftime = u" " + muse::mtrc("engraving", "(on %1‰ off %2‰)").arg(on, off);
    3427              :         }
    3428              :     }
    3429              : 
    3430            0 :     const Drumset* drumset = originPart()->instrument(chord()->tick())->drumset();
    3431            0 :     if (fixed() && headGroup() == NoteHeadGroup::HEAD_SLASH) {
    3432            0 :         pitchName = chord()->noStem() ? muse::mtrc("engraving", "Beat slash") : muse::mtrc("engraving", "Rhythm slash");
    3433            0 :     } else if (staff()->isDrumStaff(tick()) && drumset) {
    3434            0 :         pitchName = drumset->translatedName(pitch());
    3435            0 :     } else if (staff()->isTabStaff(tick())) {
    3436            0 :         pitchName = muse::mtrc("engraving", "%1; String: %2; Fret: %3")
    3437            0 :                     .arg(tpcUserName(false), String::number(string() + 1), String::number(fret()));
    3438              :     } else {
    3439            0 :         pitchName = tpcUserName(false);
    3440              :     }
    3441              : 
    3442            0 :     return muse::mtrc("engraving", "%1; Pitch: %2; Duration: %3%4%5")
    3443            0 :            .arg(noteTypeUserName(), pitchName, duration, onofftime, (chord()->isGrace() ? u"" : String(u"; %1").arg(voice)));
    3444            0 : }
    3445              : 
    3446              : //---------------------------------------------------------
    3447              : //   screenReaderInfo
    3448              : //---------------------------------------------------------
    3449              : 
    3450            0 : String Note::screenReaderInfo() const
    3451              : {
    3452            0 :     const Part* part = originPart();
    3453            0 :     if (!part) {
    3454            0 :         return String(); // part is nullptr on Linux after an instrument is deleted.
    3455              :     }
    3456              : 
    3457            0 :     const Fraction tick = this->tick();
    3458            0 :     const Chord* chord = this->chord();
    3459            0 :     const Instrument* instrument = part->instrument(tick);
    3460              : 
    3461            0 :     IF_ASSERT_FAILED(chord && instrument) {
    3462            0 :         return String();
    3463              :     }
    3464              : 
    3465            0 :     String duration = chord->durationUserName();
    3466            0 :     Measure* m = chord->measure();
    3467            0 :     bool voices = m ? m->hasVoices(staffIdx()) : false;
    3468            0 :     String voice = voices ? muse::mtrc("engraving", "Voice: %1").arg(track() % VOICES + 1) : u"";
    3469            0 :     String pitchName;
    3470            0 :     String pitchOutOfRangeWarning;
    3471            0 :     if (fixed() && headGroup() == NoteHeadGroup::HEAD_SLASH) {
    3472            0 :         pitchName = chord->noStem() ? muse::mtrc("engraving", "Beat slash") : muse::mtrc("engraving", "Rhythm slash");
    3473            0 :     } else if (const Drumset* d = instrument->drumset(); d&& instrument->useDrumset()) {
    3474            0 :         pitchName = d->translatedName(m_pitch);
    3475            0 :     } else if (const Staff* staff = this->staff(); staff&& staff->isTabStaff(tick)) {
    3476            0 :         pitchName = muse::mtrc("engraving", "%1; String: %2; Fret: %3")
    3477            0 :                     .arg(tpcUserName(true, true), String::number(string() + 1), String::number(fret()));
    3478              :     } else {
    3479            0 :         pitchName = m_headGroup == NoteHeadGroup::HEAD_NORMAL
    3480            0 :                     ? tpcUserName(true, true)
    3481              :                     //: head as in note head. %1 is head type (circle, cross, etc.). %2 is pitch (e.g. Db4).
    3482            0 :                     : muse::mtrc("engraving", "%1 head %2").arg(translatedSubtypeUserName()).arg(tpcUserName(true));
    3483            0 :         if (chord->staffMove() < 0) {
    3484            0 :             duration += u"; " + muse::mtrc("engraving", "Cross-staff above");
    3485            0 :         } else if (chord->staffMove() > 0) {
    3486            0 :             duration += u"; " + muse::mtrc("engraving", "Cross-staff below");
    3487              :         }
    3488              : 
    3489            0 :         if (m_pitch < instrument->minPitchP()) {
    3490            0 :             pitchOutOfRangeWarning = u" " + muse::mtrc("engraving", "too low");
    3491            0 :         } else if (m_pitch > instrument->maxPitchP()) {
    3492            0 :             pitchOutOfRangeWarning = u" " + muse::mtrc("engraving", "too high");
    3493            0 :         } else if (m_pitch < instrument->minPitchA()) {
    3494            0 :             pitchOutOfRangeWarning = u" " + muse::mtrc("engraving", "too low for amateurs");
    3495            0 :         } else if (m_pitch > instrument->maxPitchA()) {
    3496            0 :             pitchOutOfRangeWarning = u" " + muse::mtrc("engraving", "too high for amateurs");
    3497              :         }
    3498              :     }
    3499            0 :     return String(u"%1 %2 %3%4%5").arg(noteTypeUserName(), pitchName, duration, pitchOutOfRangeWarning,
    3500            0 :                                        (chord->isGrace() ? u"" : String(u"; %1").arg(voice)));
    3501            0 : }
    3502              : 
    3503              : //---------------------------------------------------------
    3504              : //   accessibleExtraInfo
    3505              : //---------------------------------------------------------
    3506              : 
    3507            0 : String Note::accessibleExtraInfo() const
    3508              : {
    3509            0 :     String rez;
    3510            0 :     if (accidental()) {
    3511            0 :         rez = String(u"%1 %2").arg(rez, accidental()->screenReaderInfo());
    3512              :     }
    3513            0 :     if (!el().empty()) {
    3514            0 :         for (EngravingItem* e : el()) {
    3515            0 :             if (!score()->selectionFilter().canSelect(e)) {
    3516            0 :                 continue;
    3517              :             }
    3518            0 :             rez = String(u"%1 %2").arg(rez, e->screenReaderInfo());
    3519              :         }
    3520              :     }
    3521            0 :     if (tieFor()) {
    3522            0 :         rez += u" " + muse::mtrc("engraving", "Start of %1").arg(tieFor()->screenReaderInfo());
    3523              :     }
    3524              : 
    3525            0 :     if (tieBack()) {
    3526            0 :         rez += u" " + muse::mtrc("engraving", "End of %1").arg(tieBack()->screenReaderInfo());
    3527              :     }
    3528              : 
    3529            0 :     if (!spannerFor().empty()) {
    3530            0 :         for (Spanner* s : spannerFor()) {
    3531            0 :             if (!score()->selectionFilter().canSelect(s)) {
    3532            0 :                 continue;
    3533              :             }
    3534            0 :             rez += u" " + muse::mtrc("engraving", "Start of %1").arg(s->screenReaderInfo());
    3535              :         }
    3536              :     }
    3537            0 :     if (!spannerBack().empty()) {
    3538            0 :         for (Spanner* s : spannerBack()) {
    3539            0 :             if (!score()->selectionFilter().canSelect(s)) {
    3540            0 :                 continue;
    3541              :             }
    3542            0 :             rez += u" " + muse::mtrc("engraving", "End of %1").arg(s->screenReaderInfo());
    3543              :         }
    3544              :     }
    3545              : 
    3546              :     // only read extra information for top note of chord
    3547              :     // (it is reached directly on next/previous element)
    3548            0 :     if (this == chord()->upNote()) {
    3549            0 :         rez = String(u"%1 %2").arg(rez, chord()->accessibleExtraInfo());
    3550              :     }
    3551              : 
    3552            0 :     return rez;
    3553            0 : }
    3554              : 
    3555          110 : NoteVal Note::noteVal() const
    3556              : {
    3557          110 :     NoteVal nval;
    3558          110 :     nval.pitch = pitch();
    3559          110 :     nval.velocityOverride = userVelocity();
    3560          110 :     nval.tpc1 = tpc1();
    3561          110 :     nval.tpc2 = tpc2();
    3562          110 :     nval.fret = fret();
    3563          110 :     nval.string = string();
    3564          110 :     nval.headGroup = headGroup();
    3565              : 
    3566          110 :     return nval;
    3567              : }
    3568              : 
    3569              : //---------------------------------------------------------
    3570              : //   subtypeUserName
    3571              : //---------------------------------------------------------
    3572              : 
    3573            0 : TranslatableString Note::subtypeUserName() const
    3574              : {
    3575            0 :     return TConv::userName(m_headGroup);
    3576              : }
    3577              : 
    3578              : //---------------------------------------------------------
    3579              : //   nextInEl
    3580              : //   returns next element in _el
    3581              : //---------------------------------------------------------
    3582              : 
    3583            0 : EngravingItem* Note::nextInEl(EngravingItem* e)
    3584              : {
    3585            0 :     if (e == m_el.back()) {
    3586            0 :         return nullptr;
    3587              :     }
    3588            0 :     auto i = std::find(m_el.begin(), m_el.end(), e);
    3589            0 :     if (i == m_el.end()) {
    3590            0 :         return nullptr;
    3591              :     }
    3592            0 :     return *(i + 1);
    3593              : }
    3594              : 
    3595              : //---------------------------------------------------------
    3596              : //   prevInEl
    3597              : //   returns prev element in _el
    3598              : //---------------------------------------------------------
    3599              : 
    3600            0 : EngravingItem* Note::prevInEl(EngravingItem* e)
    3601              : {
    3602            0 :     if (e == m_el.front()) {
    3603            0 :         return nullptr;
    3604              :     }
    3605            0 :     auto i = std::find(m_el.begin(), m_el.end(), e);
    3606            0 :     if (i == m_el.end()) {
    3607            0 :         return nullptr;
    3608              :     }
    3609            0 :     return *(i - 1);
    3610              : }
    3611              : 
    3612            0 : static bool tieValid(Tie* tie)
    3613              : {
    3614            0 :     return tie && !tie->segmentsEmpty();
    3615              : }
    3616              : 
    3617              : //---------------------------------------------------------
    3618              : //   nextElement
    3619              : //---------------------------------------------------------
    3620              : 
    3621            0 : EngravingItem* Note::nextElement()
    3622              : {
    3623            0 :     EngravingItem* e = score()->selection().element();
    3624            0 :     if (!e && !score()->selection().elements().empty()) {
    3625            0 :         e = score()->selection().elements().front();
    3626              :     }
    3627            0 :     if (!e) {
    3628            0 :         return nullptr;
    3629              :     }
    3630            0 :     switch (e->type()) {
    3631            0 :     case ElementType::SYMBOL:
    3632              :     case ElementType::IMAGE:
    3633              :     case ElementType::FINGERING:
    3634              :     case ElementType::TEXT:
    3635              :     case ElementType::BEND: {
    3636            0 :         EngravingItem* next = nextInEl(e);           // return next element in _el
    3637            0 :         if (next) {
    3638            0 :             return next;
    3639            0 :         } else if (tieValid(m_tieFor)) {
    3640            0 :             return m_tieFor->frontSegment();
    3641            0 :         } else if (!m_spannerFor.empty()) {
    3642            0 :             for (auto i : m_spannerFor) {
    3643            0 :                 if (i->isGlissando()) {
    3644            0 :                     return i->spannerSegments().front();
    3645              :                 }
    3646              :             }
    3647              :         }
    3648            0 :         return nullptr;
    3649              :     }
    3650              : 
    3651            0 :     case ElementType::TIE_SEGMENT:
    3652              :     case ElementType::LAISSEZ_VIB_SEGMENT:
    3653              :     case ElementType::PARTIAL_TIE_SEGMENT:
    3654            0 :         if (!m_spannerFor.empty()) {
    3655            0 :             for (auto i : m_spannerFor) {
    3656            0 :                 if (i->isGlissando()) {
    3657            0 :                     return i->spannerSegments().front();
    3658              :                 }
    3659              :             }
    3660              :         }
    3661            0 :         return chord()->nextElement();
    3662              : 
    3663            0 :     case ElementType::NOTELINE_SEGMENT:
    3664              :     case ElementType::GLISSANDO_SEGMENT:
    3665              :     case ElementType::GUITAR_BEND_SEGMENT:
    3666            0 :         return chord()->nextElement();
    3667              : 
    3668            0 :     case ElementType::ACCIDENTAL:
    3669            0 :         if (!m_el.empty()) {
    3670            0 :             return m_el[0];
    3671              :         }
    3672            0 :         if (tieValid(m_tieFor)) {
    3673            0 :             return m_tieFor->frontSegment();
    3674              :         }
    3675            0 :         if (!m_spannerFor.empty()) {
    3676            0 :             for (auto i : m_spannerFor) {
    3677            0 :                 if (i->isGlissando()) {
    3678            0 :                     return i->spannerSegments().front();
    3679              :                 }
    3680              :             }
    3681              :         }
    3682            0 :         return nullptr;
    3683              : 
    3684            0 :     case ElementType::NOTE: {
    3685            0 :         if (isPreBendOrDiveStart() || isGraceBendStart()) {
    3686            0 :             return bendFor()->frontSegment();
    3687              :         }
    3688              : 
    3689            0 :         GraceNotesGroup& graceNotesAfter = chord()->graceNotesAfter();
    3690            0 :         if (!graceNotesAfter.empty()) {
    3691            0 :             Chord* graceNotesAfterFirstChord = graceNotesAfter.front();
    3692            0 :             if (graceNotesAfterFirstChord) {
    3693            0 :                 return graceNotesAfterFirstChord->notes().front();
    3694              :             }
    3695              :         }
    3696              : 
    3697            0 :         if (!m_el.empty()) {
    3698            0 :             return m_el[0];
    3699              :         }
    3700            0 :         if (tieValid(m_tieFor)) {
    3701            0 :             return m_tieFor->frontSegment();
    3702              :         }
    3703            0 :         if (!m_spannerFor.empty()) {
    3704            0 :             for (auto i : m_spannerFor) {
    3705            0 :                 if (i->isGlissando() || i->isGuitarBend()) {
    3706            0 :                     return i->spannerSegments().front();
    3707              :                 }
    3708              :             }
    3709              :         }
    3710            0 :         return nullptr;
    3711              :     }
    3712            0 :     default:
    3713            0 :         return nullptr;
    3714              :     }
    3715              : }
    3716              : 
    3717              : //---------------------------------------------------------
    3718              : //   prevElement
    3719              : //---------------------------------------------------------
    3720              : 
    3721            0 : EngravingItem* Note::prevElement()
    3722              : {
    3723            0 :     EngravingItem* e = score()->selection().element();
    3724            0 :     if (!e && !score()->selection().elements().empty()) {
    3725            0 :         e = score()->selection().elements().back();
    3726              :     }
    3727            0 :     if (!e) {
    3728            0 :         return nullptr;
    3729              :     }
    3730            0 :     switch (e->type()) {
    3731            0 :     case ElementType::SYMBOL:
    3732              :     case ElementType::IMAGE:
    3733              :     case ElementType::FINGERING:
    3734              :     case ElementType::TEXT:
    3735              :     case ElementType::BEND: {
    3736            0 :         EngravingItem* prev = prevInEl(e);           // return prev element in _el
    3737            0 :         if (prev) {
    3738            0 :             return prev;
    3739              :         }
    3740              :     }
    3741            0 :         return this;
    3742            0 :     case ElementType::TIE_SEGMENT:
    3743              :     case ElementType::PARTIAL_TIE_SEGMENT:
    3744              :     case ElementType::LAISSEZ_VIB_SEGMENT:
    3745            0 :         if (!m_el.empty()) {
    3746            0 :             return m_el.back();
    3747              :         }
    3748            0 :         return this;
    3749            0 :     case ElementType::NOTELINE_SEGMENT:
    3750              :     case ElementType::GLISSANDO_SEGMENT:
    3751              :     case ElementType::GUITAR_BEND_SEGMENT:
    3752            0 :         if (tieValid(m_tieFor)) {
    3753            0 :             return m_tieFor->frontSegment();
    3754            0 :         } else if (!m_el.empty()) {
    3755            0 :             return m_el.back();
    3756              :         }
    3757            0 :         return this;
    3758            0 :     case ElementType::ACCIDENTAL:
    3759            0 :         return this;
    3760            0 :     default:
    3761            0 :         return nullptr;
    3762              :     }
    3763              : }
    3764              : 
    3765              : //---------------------------------------------------------
    3766              : //   lastElementBeforeSegment
    3767              : //---------------------------------------------------------
    3768              : 
    3769            0 : EngravingItem* Note::lastElementBeforeSegment()
    3770              : {
    3771            0 :     if (!m_spannerFor.empty()) {
    3772            0 :         for (auto i : m_spannerFor) {
    3773            0 :             if (i->isGlissando() || i->isGuitarBend() || i->isNoteLine()) {
    3774            0 :                 return i->spannerSegments().front();
    3775              :             }
    3776              :         }
    3777              :     }
    3778            0 :     if (tieValid(m_tieFor)) {
    3779            0 :         return m_tieFor->frontSegment();
    3780              :     }
    3781            0 :     if (!m_el.empty()) {
    3782            0 :         return m_el.back();
    3783              :     }
    3784            0 :     return this;
    3785              : }
    3786              : 
    3787              : //---------------------------------------------------------
    3788              : //   nextSegmentElement
    3789              : //---------------------------------------------------------
    3790              : 
    3791            0 : EngravingItem* Note::nextSegmentElement()
    3792              : {
    3793            0 :     if (chord()->isGrace()) {
    3794            0 :         return EngravingItem::nextSegmentElement();
    3795              :     }
    3796              : 
    3797            0 :     const std::vector<Note*>& notes = chord()->notes();
    3798            0 :     if (this == notes.front()) {
    3799            0 :         return chord()->nextSegmentElement();
    3800              :     }
    3801            0 :     auto i = std::find(notes.begin(), notes.end(), this);
    3802            0 :     return *(i - 1);
    3803              : }
    3804              : 
    3805              : //---------------------------------------------------------
    3806              : //   prevSegmentElement
    3807              : //---------------------------------------------------------
    3808              : 
    3809            0 : EngravingItem* Note::prevSegmentElement()
    3810              : {
    3811            0 :     if (chord()->isGrace()) {
    3812            0 :         return EngravingItem::prevSegmentElement();
    3813              :     }
    3814              : 
    3815            0 :     const std::vector<Note*>& notes = chord()->notes();
    3816            0 :     if (this == notes.back()) {
    3817            0 :         return chord()->prevSegmentElement();
    3818              :     }
    3819            0 :     auto i = std::find(notes.begin(), notes.end(), this);
    3820            0 :     return *++i;
    3821              : }
    3822              : 
    3823              : //---------------------------------------------------------
    3824              : //   lastTiedNote
    3825              : //---------------------------------------------------------
    3826              : 
    3827         7970 : Note* Note::lastTiedNote(bool ignorePlayback) const
    3828              : {
    3829         7970 :     std::vector<const Note*> notes;
    3830         7970 :     const Note* note = this;
    3831         7970 :     notes.push_back(note);
    3832         8430 :     while (note->tieFor() && (ignorePlayback || note->tieFor()->playSpanner())) {
    3833          468 :         if (std::find(notes.begin(), notes.end(), note->tieFor()->endNote()) != notes.end()) {
    3834            0 :             break;
    3835              :         }
    3836          468 :         if (!note->tieFor()->endNote()) {
    3837            8 :             break;
    3838              :         }
    3839          460 :         note = note->tieFor()->endNote();
    3840          460 :         notes.push_back(note);
    3841              :     }
    3842         7970 :     return const_cast<Note*>(note);
    3843         7970 : }
    3844              : 
    3845              : //---------------------------------------------------------
    3846              : //   firstTiedNote
    3847              : //    if note has ties, return last note in chain
    3848              : //    - handle recursion in connected notes
    3849              : //---------------------------------------------------------
    3850              : 
    3851         8055 : Note* Note::firstTiedNote(bool ignorePlayback) const
    3852              : {
    3853         8055 :     std::vector<const Note*> notes;
    3854         8055 :     const Note* note = this;
    3855         8055 :     notes.push_back(note);
    3856         8532 :     while (note->tieBack() && (ignorePlayback || note->tieBack()->playSpanner())) {
    3857          480 :         if (std::find(notes.begin(), notes.end(), note->tieBack()->startNote()) != notes.end()) {
    3858            0 :             break;
    3859              :         }
    3860          480 :         if (!note->tieBack()->startNote()) {
    3861            3 :             break;
    3862              :         }
    3863          477 :         note = note->tieBack()->startNote();
    3864          477 :         notes.push_back(note);
    3865              :     }
    3866         8055 :     return const_cast<Note*>(note);
    3867         8055 : }
    3868              : 
    3869              : //---------------------------------------------------------
    3870              : //   tiedNotes
    3871              : //---------------------------------------------------------
    3872              : 
    3873          134 : std::vector<Note*> Note::findTiedNotes(Note* startNote, bool followPartialTies)
    3874              : {
    3875              :     // Returns all notes ahead of startNote in a chain of ties
    3876              :     // Follows partial tie paths recursively
    3877          134 :     Note* note = startNote;
    3878          134 :     std::vector<Note*> notes;
    3879          134 :     notes.push_back(note);
    3880              : 
    3881          137 :     while (note->tieFor()) {
    3882            3 :         if (followPartialTies) {
    3883            3 :             for (TieJumpPoint* jumpPoint : *note->tieJumpPoints()) {
    3884            0 :                 if (!jumpPoint->active() || jumpPoint->followingNote()) {
    3885            0 :                     continue;
    3886              :                 }
    3887            0 :                 if (!jumpPoint->note() || std::find(notes.begin(), notes.end(), jumpPoint->note()) != notes.end()) {
    3888            0 :                     continue;
    3889              :                 }
    3890              :                 // ONLY backtrack when end point is a full tie eg. around a segno
    3891            0 :                 const bool endTieIsFullTie = jumpPoint->endTie() && !jumpPoint->endTie()->isPartialTie();
    3892            0 :                 Note* jumpPointNote = endTieIsFullTie ? jumpPoint->endTie()->startNote()->firstTiedNote() : jumpPoint->note();
    3893            0 :                 std::vector<Note*> partialTieNotes = findTiedNotes(jumpPointNote, !endTieIsFullTie);
    3894            0 :                 notes.insert(notes.end(), partialTieNotes.begin(), partialTieNotes.end());
    3895            0 :             }
    3896              :         }
    3897              : 
    3898            3 :         Note* endNote = note->tieFor()->endNote();
    3899            3 :         if (!endNote || std::find(notes.begin(), notes.end(), endNote) != notes.end()) {
    3900            0 :             break;
    3901              :         }
    3902            3 :         note = endNote;
    3903            3 :         notes.push_back(note);
    3904              :     }
    3905              : 
    3906          134 :     return notes;
    3907            0 : }
    3908              : 
    3909          134 : std::vector<Note*> Note::tiedNotes() const
    3910              : {
    3911              :     // Backtrack to the first tied note in a chain, then return all notes in the chain ahead of it
    3912          134 :     Note* note = firstTiedNote();
    3913              : 
    3914          134 :     std::vector<Note*> notes = findTiedNotes(note);
    3915              : 
    3916          134 :     return notes;
    3917              : }
    3918              : 
    3919              : //---------------------------------------------------------
    3920              : //   unisonIndex
    3921              : //---------------------------------------------------------
    3922              : 
    3923          889 : int Note::unisonIndex() const
    3924              : {
    3925          889 :     int index = 0;
    3926         1095 :     for (Note* n : chord()->notes()) {
    3927         1095 :         if (n->pitch() == pitch()) {
    3928          889 :             if (n == this) {
    3929          889 :                 return index;
    3930              :             } else {
    3931            0 :                 ++index;
    3932              :             }
    3933              :         }
    3934              :     }
    3935            0 :     return 0;
    3936              : }
    3937              : 
    3938              : //---------------------------------------------------------
    3939              : //   disconnectTiedNotes
    3940              : //---------------------------------------------------------
    3941              : 
    3942         2791 : void Note::disconnectTiedNotes()
    3943              : {
    3944         2791 :     if (tieBack() && tieBack()->startNote()) {
    3945            0 :         tieBack()->startNote()->remove(tieBack());
    3946              :     }
    3947         2791 :     if (tieFor() && tieFor()->endNote()) {
    3948            0 :         tieFor()->endNote()->setTieBack(0);
    3949              :     }
    3950         2791 : }
    3951              : 
    3952              : //---------------------------------------------------------
    3953              : //   connectTiedNotes
    3954              : //---------------------------------------------------------
    3955              : 
    3956        44184 : void Note::connectTiedNotes()
    3957              : {
    3958        44184 :     if (tieBack() && !tieBack()->isPartialTie()) {
    3959           43 :         tieBack()->setEndNote(this);
    3960           43 :         if (tieBack()->startNote()) {
    3961           43 :             tieBack()->startNote()->add(tieBack());
    3962              :         }
    3963              :     }
    3964        44184 :     if (tieFor() && tieFor()->endNote() && !tieFor()->isPartialTie()) {
    3965            0 :         tieFor()->endNote()->setTieBack(tieFor());
    3966              :     }
    3967        44184 : }
    3968              : 
    3969              : //---------------------------------------------------------
    3970              : //   accidentalType
    3971              : //---------------------------------------------------------
    3972              : 
    3973         1504 : AccidentalType Note::accidentalType() const
    3974              : {
    3975         1504 :     return m_accidental ? m_accidental->accidentalType() : AccidentalType::NONE;
    3976              : }
    3977              : 
    3978              : //---------------------------------------------------------
    3979              : //   setAccidentalType
    3980              : //---------------------------------------------------------
    3981              : 
    3982            0 : void Note::setAccidentalType(AccidentalType type)
    3983              : {
    3984            0 :     if (score()) {
    3985            0 :         EditNote::changeAccidental(score(), this, type);
    3986              :     }
    3987            0 : }
    3988              : 
    3989              : //---------------------------------------------------------
    3990              : //   undoUnlink
    3991              : //---------------------------------------------------------
    3992              : 
    3993          181 : void Note::undoUnlink()
    3994              : {
    3995          181 :     EngravingItem::undoUnlink();
    3996          190 :     for (EngravingItem* e : m_el) {
    3997            9 :         e->undoUnlink();
    3998              :     }
    3999          181 :     for (Spanner* s : m_spannerFor) {
    4000            0 :         s->undoUnlink();
    4001              :     }
    4002          181 :     if (m_tieFor) {
    4003            8 :         m_tieFor->undoUnlink();
    4004              :     }
    4005          181 : }
    4006              : 
    4007              : //---------------------------------------------------------
    4008              : //   slides
    4009              : //---------------------------------------------------------
    4010              : 
    4011          119 : static bool isSlideTo(Note::SlideType slideType)
    4012              : {
    4013          119 :     return slideType == Note::SlideType::UpToNote || slideType == Note::SlideType::DownToNote;
    4014              : }
    4015              : 
    4016           58 : static bool isSlideFrom(Note::SlideType slideType)
    4017              : {
    4018           58 :     return slideType == Note::SlideType::UpFromNote || slideType == Note::SlideType::DownFromNote;
    4019              : }
    4020              : 
    4021          119 : void Note::attachSlide(SlideType slideType)
    4022              : {
    4023          119 :     if (isSlideTo(slideType)) {
    4024           61 :         m_slideToType = slideType;
    4025           58 :     } else if (isSlideFrom(slideType)) {
    4026           58 :         m_slideFromType = slideType;
    4027              :     }
    4028          119 : }
    4029              : 
    4030          336 : bool Note::hasSlideToNote() const
    4031              : {
    4032          336 :     return m_slideToType != SlideType::Undefined;
    4033              : }
    4034              : 
    4035          719 : bool Note::hasSlideFromNote() const
    4036              : {
    4037          719 :     return m_slideFromType != SlideType::Undefined;
    4038              : }
    4039              : 
    4040          148 : void Note::setParenthesesMode(const ParenthesesMode& v, bool addToLinked, bool generated)
    4041              : {
    4042          148 :     IF_ASSERT_FAILED(v == ParenthesesMode::BOTH || v == ParenthesesMode::NONE) {
    4043            0 :         LOGE() << "Notes cannot set left & right parens individually";
    4044            0 :         return;
    4045              :     }
    4046              : 
    4047          148 :     if ((m_hasParens && v == ParenthesesMode::BOTH) || (!m_hasParens && v == ParenthesesMode::NONE)) {
    4048           50 :         return;
    4049              :     }
    4050              : 
    4051           98 :     const NoteParenthesisInfo* noteParenInfo = parenthesisInfo();
    4052              : 
    4053           98 :     Parenthesis* leftParen = noteParenInfo ? noteParenInfo->leftParen() : nullptr;
    4054              : 
    4055           98 :     const bool hasGeneratedParen = leftParen && leftParen->generated();
    4056           98 :     const bool hasUserParen = leftParen && !leftParen->generated();
    4057              : 
    4058           98 :     bool hasParen = v == ParenthesesMode::BOTH;
    4059              : 
    4060           98 :     if (generated && hasParen == hasGeneratedParen) {
    4061            0 :         return;
    4062              :     }
    4063              : 
    4064           98 :     if (!generated && hasParen == hasUserParen) {
    4065            0 :         return;
    4066              :     }
    4067              : 
    4068           98 :     m_hasParens = hasParen;
    4069              : 
    4070           98 :     if (hasParen) {
    4071          294 :         EditChord::addChordParentheses(chord(), { this }, addToLinked, generated);
    4072              :     } else {
    4073            0 :         EditChord::removeChordParentheses(chord(), { this }, addToLinked, generated);
    4074              :     }
    4075              : }
    4076              : 
    4077        75388 : const NoteParenthesisInfo* Note::parenthesisInfo() const
    4078              : {
    4079        75388 :     return chord() ? chord()->findNoteParenthesisInfo(this) : nullptr;
    4080              : }
    4081              : 
    4082      1442990 : bool Note::isGrace() const
    4083              : {
    4084      1442990 :     return noteType() != NoteType::NORMAL;
    4085              : }
    4086              : 
    4087          392 : bool Note::isPreBendOrDiveStart() const
    4088              : {
    4089          392 :     if (!isGrace()) {
    4090          269 :         return false;
    4091              :     }
    4092              : 
    4093          123 :     const GuitarBend* bend = bendFor();
    4094          123 :     if (!bend) {
    4095           84 :         return false;
    4096              :     }
    4097              : 
    4098           39 :     const GuitarBendType bendType = bend->bendType();
    4099           39 :     return bendType == GuitarBendType::PRE_BEND || bendType == GuitarBendType::PRE_DIVE;
    4100              : }
    4101              : 
    4102          328 : bool Note::isGraceBendStart() const
    4103              : {
    4104          328 :     if (!isGrace()) {
    4105          257 :         return false;
    4106              :     }
    4107              : 
    4108           71 :     const GuitarBend* bend = bendFor();
    4109              : 
    4110           71 :     return bend && bend->bendType() == GuitarBendType::GRACE_NOTE_BEND;
    4111              : }
    4112              : 
    4113          409 : bool Note::isContinuationOfBend() const
    4114              : {
    4115          409 :     if (bendBack()) {
    4116            4 :         return true;
    4117              :     }
    4118              : 
    4119          405 :     Tie* tie = tieBack();
    4120          405 :     Note* note = nullptr;
    4121          976 :     while (tie && tie->startNote()) {
    4122          583 :         note = tie->startNote();
    4123          583 :         if (note->bendBack()) {
    4124           12 :             return true;
    4125              :         }
    4126              : 
    4127          571 :         if (tie == note->tieBack()) {
    4128            0 :             return false;
    4129              :         }
    4130              : 
    4131          571 :         tie = note->tieBack();
    4132              :     }
    4133              : 
    4134          393 :     return false;
    4135              : }
    4136              : 
    4137         9223 : bool Note::hasAnotherStraightAboveOrBelow(bool above) const
    4138              : {
    4139         9223 :     if (!chord()) {
    4140            0 :         return false;
    4141              :     }
    4142              : 
    4143         9223 :     const std::vector<Note*>& notes = chord()->notes();
    4144              : 
    4145         9223 :     if ((above && this == notes.back()) || (!above && this == notes.front())) {
    4146         8684 :         return false;
    4147              :     }
    4148              : 
    4149          539 :     const double limitDiff = 0.5 * spatium();
    4150         1119 :     for (Note* note : notes) {
    4151         1111 :         if (note == this) {
    4152          154 :             continue;
    4153              :         }
    4154          957 :         if (std::fabs(note->pos().x() - pos().x()) > limitDiff) {
    4155          531 :             return false;
    4156              :         }
    4157          812 :         if ((above && note->line() < m_line) || (!above && note->line() > m_line)) {
    4158          386 :             return true;
    4159              :         }
    4160              :     }
    4161              : 
    4162            8 :     return false;
    4163              : }
    4164              : 
    4165        12347 : PointF Note::posInStaffCoordinates()
    4166              : {
    4167        12347 :     double X = x() + chord()->x() + chord()->segment()->x() + chord()->measure()->x();
    4168        12347 :     return PointF(X, y());
    4169              : }
    4170              : 
    4171           16 : void Note::setIsTrillCueNote(bool v)
    4172              : {
    4173           16 :     m_isTrillCueNote = v;
    4174           16 :     if (chord()) {
    4175           16 :         chord()->setIsTrillCueNote(v);
    4176              :     }
    4177           16 : }
    4178              : 
    4179        12347 : void Note::addLineAttachPoint(PointF point, EngravingItem* line, bool start)
    4180              : {
    4181              :     // IMPORTANT: the point is expected in *staff* coordinates
    4182              :     // We transform into note coordinates by subtracting the note position in staff coordinates
    4183        12347 :     point -= posInStaffCoordinates();
    4184        12347 :     m_lineAttachPoints.push_back(LineAttachPoint(line, point.x(), point.y(), start));
    4185        12347 : }
    4186              : 
    4187         5481 : bool Note::negativeFretUsed() const
    4188              : {
    4189         5481 :     return configuration()->negativeFretsAllowed() && m_fret < 0 && m_string != INVALID_STRING_INDEX;
    4190              : }
    4191              : 
    4192        94542 : int Note::stringOrLine() const
    4193              : {
    4194              :     // The number string() returns doesn't count spaces.  This should be used where it is expected even numbers are spaces and odd are lines
    4195        94542 :     return staff()->staffType(tick())->isTabStaff() ? string() * 2 : line();
    4196              : }
    4197              : 
    4198              : //---------------------------------------------------------
    4199              : //   Note::transposeDiatonic
    4200              : //---------------------------------------------------------
    4201              : 
    4202          662 : bool Note::transposeDiatonic(int interval, bool keepAlterations, bool useDoubleAccidentals)
    4203              : {
    4204              :     // compute note current absolute step
    4205              :     int alter;
    4206          662 :     Fraction tick = chord()->segment()->tick();
    4207          662 :     Key key       = staff() ? staff()->key(tick) : Key::C;
    4208          662 :     int absStep   = pitch2absStepByKey(epitch(), tpc(), key, alter);
    4209              : 
    4210              :     // get pitch and tcp corresponding to unaltered degree for this key
    4211          662 :     int newPitch = absStep2pitchByKey(absStep + interval, key);
    4212          662 :     int newTpc   = step2tpcByKey((absStep + interval) % STEP_DELTA_OCTAVE, key);
    4213              : 
    4214          662 :     if (!pitchIsValid(newPitch)) {
    4215            0 :         return false;
    4216              :     }
    4217              : 
    4218              :     // if required, transfer original degree alteration to new pitch and tpc
    4219          662 :     if (keepAlterations) {
    4220          232 :         newPitch += alter;
    4221          232 :         newTpc  += alter * TPC_DELTA_SEMITONE;
    4222              :     }
    4223              : 
    4224              :     // transpose appropriately
    4225          662 :     int newTpc1 = TPC_INVALID;
    4226          662 :     int newTpc2 = TPC_INVALID;
    4227          662 :     Interval v  = staff() ? staff()->transpose(tick) : Interval(0);
    4228          662 :     if (concertPitch()) {
    4229            0 :         v.flip();
    4230            0 :         newTpc1 = clampEnharmonic(newTpc, useDoubleAccidentals);
    4231            0 :         newTpc2 = Transpose::transposeTpc(newTpc, v, useDoubleAccidentals);
    4232              :     } else {
    4233          662 :         newPitch += v.chromatic;
    4234          662 :         newTpc1 = Transpose::transposeTpc(newTpc, v, useDoubleAccidentals);
    4235          662 :         newTpc2 = clampEnharmonic(newTpc, useDoubleAccidentals);
    4236              :     }
    4237              : 
    4238              :     // check pitch is in range
    4239          662 :     newPitch = clampPitchOctaved(newPitch);
    4240              : 
    4241              :     // store new data
    4242          662 :     EditNote::undoChangePitch(score(), this, newPitch, newTpc1, newTpc2);
    4243          662 :     return true;
    4244              : }
    4245              : 
    4246          635 : bool Note::transpose(Interval interval, bool useDoubleSharpsFlats)
    4247              : {
    4248          635 :     int npitch = pitch() + interval.chromatic;
    4249          635 :     if (!pitchIsValid(npitch)) {
    4250            0 :         return false;
    4251              :     }
    4252          635 :     int ntpc1 = Transpose::transposeTpc(tpc1(), interval, useDoubleSharpsFlats);
    4253          635 :     int ntpc2 = ntpc1;
    4254          635 :     if (transposition()) {
    4255            6 :         if (staff()) {
    4256            6 :             Interval v = staff()->transpose(tick());
    4257            6 :             v.flip();
    4258            6 :             ntpc2 = Transpose::transposeTpc(ntpc1, v, useDoubleSharpsFlats);
    4259              :         } else {
    4260            0 :             ntpc2 = Transpose::transposeTpc(tpc2(), interval, useDoubleSharpsFlats);
    4261              :         }
    4262              :     }
    4263          635 :     EditNote::undoChangePitch(score(), this, npitch, ntpc1, ntpc2);
    4264          635 :     return true;
    4265              : }
    4266              : 
    4267       146422 : staff_idx_t Note::vStaffIdx() const
    4268              : {
    4269       146422 :     const Chord* c = chord();
    4270       146422 :     return c ? c->vStaffIdx() : EngravingItem::vStaffIdx();
    4271              : }
    4272              : 
    4273        62176 : void Note::setJianpuOctaveDotCount(size_t count)
    4274              : {
    4275        63151 :     while (m_jianpuOctaveDots.size() < count) {
    4276          975 :         JianpuOctaveDot* dot = new JianpuOctaveDot(this);
    4277          975 :         dot->setOwnershipParent(this);
    4278          975 :         dot->setTrack(track());
    4279          975 :         m_jianpuOctaveDots.push_back(dot);
    4280              :     }
    4281        62295 :     while (m_jianpuOctaveDots.size() > count) {
    4282          119 :         delete m_jianpuOctaveDots.back();
    4283          119 :         m_jianpuOctaveDots.pop_back();
    4284              :     }
    4285        62176 : }
    4286              : }
        

Generated by: LCOV version 2.0-1