LCOV - code coverage report
Current view: top level - src/engraving/dom - stringdata.h Coverage Total Hit
Test: filtered_coverage.info Lines: 90.0 % 10 9
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              : #pragma once
      24              : 
      25              : #include <cstddef>
      26              : #include <vector>
      27              : #include <map>
      28              : 
      29              : #include "../types/fraction.h"
      30              : #include "../types/types.h"
      31              : 
      32              : namespace mu::engraving {
      33              : class Chord;
      34              : class Note;
      35              : 
      36              : class Staff;
      37              : 
      38              : //---------------------------------------------------------
      39              : //   StringData
      40              : //---------------------------------------------------------
      41              : 
      42              : // defines the string of an instrument
      43              : struct instrString {
      44         8581 :     instrString(int p = 0, bool o = false, int s = 0)
      45         8581 :         : pitch(p), open(o), startFret(s) {}
      46              : 
      47              :     int pitch = 0;          // the pitch of the string
      48              :     bool open = false;          // true: string is open | false: string is fretted
      49              :     int startFret = 0;      // banjo 5th string starts on 5th fret
      50              :     bool useFlat = false;
      51              : 
      52            0 :     bool operator==(const instrString& d) const { return d.pitch == pitch && d.open == open; }
      53              : };
      54              : 
      55              : class StringData
      56              : {
      57              : public:
      58        19253 :     StringData() {}
      59              :     StringData(int numFrets, int numStrings, int strings[], bool useFlats = false);
      60              :     StringData(int numFrets, std::vector<instrString>& strings);
      61              : 
      62              :     bool isNull() const;
      63              : 
      64              :     void        set(const StringData& src);
      65              :     bool        convertPitch(int pitch, int pitchOffset, int* string, int* fret, const CapoParams& capo = {}) const;
      66              :     bool        convertPitch(int pitch, const Staff* staff, int* string, int* fret) const;
      67              :     bool        convertPitch(int pitch, const Staff* staff, const Fraction& tick, int* string, int* fret) const;
      68              :     int         fret(int pitch, int string, const Staff* staff) const;
      69              :     int         fret(int pitch, int string, const Staff* staff, const Fraction& tick) const;
      70              :     void        fretChords(Chord* chord) const;
      71              :     int         getPitch(int string, int fret, int pitchOffset) const;
      72              :     int         getPitch(int string, int fret, const Staff* staff) const;
      73              :     int         getPitch(int string, int fret, const Staff* staff, const Fraction& tick) const;
      74              :     static int  pitchOffsetAt(const Staff* staff);
      75              :     static int  pitchOffsetAt(const Staff* staff, const Fraction& tick);
      76              :     static int  pitchOffsetAt(const Staff* staff, const Fraction& tick, int string);
      77       126324 :     size_t      strings() const { return m_stringTable.size(); }
      78              :     int         frettedStrings() const;
      79         2120 :     const std::vector<instrString>& stringList() const { return m_stringTable; }
      80         9704 :     std::vector<instrString>& stringList() { return m_stringTable; }
      81          473 :     int         frets() const { return m_frets; }
      82         1452 :     void        setFrets(int val) { m_frets = val; }
      83         1800 :     bool operator==(const StringData& d) const { return d.m_frets == m_frets && d.m_stringTable == m_stringTable; }
      84              :     void        configBanjo5thString();
      85              :     int         adjustBanjo5thFret(int fret) const;
      86              :     bool        isFiveStringBanjo() const;
      87              :     bool        useFlats() const { return m_useFlats; }
      88              : 
      89              : private:
      90              : 
      91              :     int         fret(int pitch, int string, int pitchOffset) const;
      92              :     void        sortChordNotes(std::map<int, Note*>& sortedNotes, const Chord* chord, int* count) const;
      93              :     void        sortChordNotesUseSameString(const Chord* chord) const;
      94              :     bool        hasPendingPitchChange(const Chord* chord) const;
      95              :     void        updateFretsOnSameStrings(const Chord* chord) const;
      96              :     void        preferBassStringForNegativeFret(const Chord* chord) const;
      97              :     void        reassignNegativeFretNotes(const Chord* chord) const;
      98              :     bool        tryResolveStringConflictWithOutOfRangeFret(const Note* note, int numStrings, std::vector<int>& bUsed, int& nNewString,
      99              :                                                            int& nNewFret) const;
     100              : 
     101              :     //      std::vector<int>  stringTable { 40, 45, 50, 55, 59, 64 };   // guitar is default
     102              :     //      int         _frets = 19;
     103              :     std::vector<instrString> m_stringTable;                      // no strings by default
     104              :     int m_frets = 0;
     105              : 
     106              :     static bool bFretting;
     107              :     bool m_useFlats = false;
     108              : };
     109              : }
        

Generated by: LCOV version 2.0-1