LCOV - code coverage report
Current view: top level - src/engraving/dom - keylist.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 69.0 % 42 29
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "keylist.h"
      24              : 
      25              : using namespace mu;
      26              : 
      27              : namespace mu::engraving {
      28              : //---------------------------------------------------------
      29              : //   key
      30              : //
      31              : //    locates the key sig currently in effect at tick
      32              : //---------------------------------------------------------
      33              : 
      34      1786815 : KeySigEvent KeyList::key(int tick) const
      35              : {
      36      1786815 :     KeySigEvent ke;
      37      1786815 :     ke.setConcertKey(Key::C);
      38              : 
      39      1786815 :     if (empty()) {
      40       984056 :         return ke;
      41              :     }
      42       802759 :     auto i = upper_bound(tick);
      43       802759 :     if (i == begin()) {
      44         5574 :         return ke;
      45              :     }
      46       797185 :     return (--i)->second;
      47      1786815 : }
      48              : 
      49              : //---------------------------------------------------------
      50              : //   setKey
      51              : //---------------------------------------------------------
      52              : 
      53         3257 : void KeyList::setKey(int tick, KeySigEvent k)
      54              : {
      55         3257 :     auto i = find(tick);
      56         3257 :     if (i == end()) {
      57         1998 :         insert(std::pair<int, KeySigEvent>(tick, k));
      58              :     } else {
      59         1259 :         i->second = k;
      60              :     }
      61         3257 : }
      62              : 
      63              : //---------------------------------------------------------
      64              : //   nextKeyTick
      65              : //
      66              : //    return the tick at which the key sig after tick is located
      67              : //    return -1, if no such a key sig
      68              : //---------------------------------------------------------
      69              : 
      70          407 : int KeyList::nextKeyTick(int tick) const
      71              : {
      72          407 :     if (empty()) {
      73           50 :         return -1;
      74              :     }
      75          357 :     auto i = upper_bound(tick + 1);
      76          357 :     return i == end() ? -1 : i->first;
      77              : }
      78              : 
      79              : //---------------------------------------------------------
      80              : //   prevKey
      81              : //
      82              : //    returns the key before the current key for tick
      83              : //---------------------------------------------------------
      84              : 
      85            0 : KeySigEvent KeyList::prevKey(int tick) const
      86              : {
      87            0 :     KeySigEvent kc;
      88            0 :     kc.setConcertKey(Key::C);
      89              : 
      90            0 :     if (empty()) {
      91            0 :         return kc;
      92              :     }
      93            0 :     auto i = upper_bound(tick);
      94            0 :     if (i == begin()) {
      95            0 :         return kc;
      96              :     }
      97            0 :     --i;
      98            0 :     if (i == begin()) {
      99            0 :         return kc;
     100              :     }
     101            0 :     return (--i)->second;
     102            0 : }
     103              : 
     104              : //---------------------------------------------------------
     105              : //   currentKeyTick
     106              : //
     107              : //    return the tick position of the key currently
     108              : //    in effect at tick
     109              : //---------------------------------------------------------
     110              : 
     111        57923 : int KeyList::currentKeyTick(int tick) const
     112              : {
     113        57923 :     if (empty()) {
     114        35837 :         return 0;
     115              :     }
     116        22086 :     auto i = upper_bound(tick);
     117        22086 :     if (i == begin()) {
     118          103 :         return 0;
     119              :     }
     120        21983 :     --i;
     121        21983 :     return i->first;
     122              : }
     123              : }
        

Generated by: LCOV version 2.0-1