LCOV - code coverage report
Current view: top level - src/engraving/dom - staff.h Coverage Total Hit
Test: filtered_coverage.info Lines: 97.0 % 33 32
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              : #pragma once
      24              : 
      25              : #include <map>
      26              : #include <vector>
      27              : 
      28              : #include "engravingitem.h"
      29              : 
      30              : #include "draw/types/color.h"
      31              : 
      32              : #include "cleflist.h"
      33              : #include "groups.h"
      34              : #include "keylist.h"
      35              : #include "mscore.h"
      36              : #include "stafftypelist.h"
      37              : 
      38              : #include "../types/types.h"
      39              : 
      40              : namespace mu::engraving {
      41              : class BracketItem;
      42              : class Clef;
      43              : class Factory;
      44              : class InstrumentTemplate;
      45              : class KeyList;
      46              : class Note;
      47              : class Part;
      48              : class Score;
      49              : class StaffType;
      50              : class TimeSig;
      51              : 
      52              : enum class Key : signed char;
      53              : 
      54              : //---------------------------------------------------------
      55              : //    Staff
      56              : ///    Global staff data not directly related to drawing.
      57              : //---------------------------------------------------------
      58              : 
      59              : class Staff final : public EngravingItem
      60              : {
      61         8183 :     OBJECT_ALLOCATOR(engraving, Staff)
      62              : 
      63              : public:
      64              :     Staff* clone() const override;
      65              : 
      66              :     void init(const InstrumentTemplate*, const StaffType* staffType, staff_idx_t templateStaffIdx);
      67              :     void initFromStaffType(const StaffType* staffType);
      68              :     void init(const Staff*);
      69              : 
      70              :     const ID& id() const;
      71              :     void setId(const ID& id);
      72              : 
      73              :     bool isTop() const;
      74              :     String partName() const;
      75              :     staff_idx_t rstaff() const;
      76              :     staff_idx_t idx() const;
      77              : 
      78      1133321 :     Part* part() const { return m_part; }
      79         4820 :     void setPart(Part* p) { m_part = p; }
      80              : 
      81              :     Part* originPart(const Fraction& tick) const;
      82              : 
      83          155 :     ClefList& clefList() { return m_clefs; }
      84              :     const ClefList& clefList() const { return m_clefs; }
      85              :     ClefTypeList clefType(const Fraction&) const;
      86        61137 :     ClefTypeList defaultClefType() const { return m_defaultClefType; }
      87         1422 :     void setDefaultClefType(const ClefTypeList& l) { m_defaultClefType = l; }
      88              :     ClefType clef(const Fraction&) const;
      89              :     Fraction nextClefTick(const Fraction&) const;
      90              :     Fraction currentClefTick(const Fraction&) const;
      91              : 
      92              :     String staffName() const;
      93              : 
      94              :     void setClef(Clef*);
      95              :     void removeClef(const Clef*);
      96              : 
      97              :     void addTimeSig(TimeSig*);
      98              :     void removeTimeSig(TimeSig*);
      99              :     void clearTimeSig();
     100              :     Fraction timeStretch(const Fraction&) const;
     101              :     TimeSig* timeSig(const Fraction&) const;
     102              :     TimeSig* nextTimeSig(const Fraction&) const;
     103              :     Fraction currentTimeSigTick(const Fraction&) const;
     104              : 
     105              :     const Groups& group(const Fraction&) const;
     106              : 
     107              :     Interval transpose(const Fraction& tick) const;
     108              : 
     109         2086 :     KeyList& keyList() { return m_keys; }
     110              :     const KeyList& keyList() const { return m_keys; }
     111      1609088 :     Key key(const Fraction& tick) const { return keySigEvent(tick).key(); }
     112        11267 :     Key concertKey(const Fraction& tick) const { return keySigEvent(tick).concertKey(); }
     113              :     KeySigEvent keySigEvent(const Fraction&) const;
     114              :     Fraction nextKeyTick(const Fraction&) const;
     115              :     Fraction currentKeyTick(const Fraction&) const;
     116              :     KeySigEvent prevKey(const Fraction&) const;
     117              :     void setKey(const Fraction&, KeySigEvent);
     118              :     void removeKey(const Fraction&);
     119              : 
     120              :     bool show() const;
     121              :     bool stemless(const Fraction&) const;
     122       156355 :     bool cutaway() const { return m_cutaway; }
     123           10 :     void setCutaway(bool val) { m_cutaway = val; }
     124         1984 :     bool showIfEntireSystemEmpty() const { return m_showIfEntireSystemEmpty; }
     125            0 :     void setShowIfEntireSystemEmpty(bool val) { m_showIfEntireSystemEmpty = val; }
     126              : 
     127       131217 :     bool hideSystemBarLine() const { return m_hideSystemBarLine; }
     128           10 :     void setHideSystemBarLine(bool val) { m_hideSystemBarLine = val; }
     129         8454 :     AutoOnOff hideWhenEmpty() const { return m_hideWhenEmpty; }
     130            9 :     void setHideWhenEmpty(AutoOnOff v) { m_hideWhenEmpty = v; }
     131         6444 :     AutoOnOff mergeMatchingRests() const { return m_mergeMatchingRests; }
     132           16 :     void setMergeMatchingRests(AutoOnOff val) { m_mergeMatchingRests = val; }
     133              :     bool shouldMergeMatchingRests() const;
     134              : 
     135       102016 :     bool barLineSpan() const { return m_barLineSpan; }
     136       100184 :     int barLineFrom() const { return m_barLineFrom; }
     137       100184 :     int barLineTo() const { return m_barLineTo; }
     138         1032 :     void setBarLineSpan(const bool val) { m_barLineSpan = val; }
     139           77 :     void setBarLineFrom(int val) { m_barLineFrom = val; }
     140          637 :     void setBarLineTo(int val) { m_barLineTo = val; }
     141              :     double staffHeight() const;
     142              :     double staffHeight(const Fraction& tick) const;
     143              : 
     144              :     int channel(const Fraction&, voice_idx_t voice) const;
     145              : 
     146        10520 :     void clearChannelList(voice_idx_t voice) { m_channelList[voice].clear(); }
     147          736 :     void insertIntoChannelList(voice_idx_t voice, const Fraction& tick, int channelId)
     148              :     {
     149          736 :         m_channelList[voice].insert({ tick.ticks(), channelId });
     150          736 :     }
     151              : 
     152              :     SwingParameters swing(const Fraction&)  const;
     153          269 :     void clearSwingMap() { m_swingMap.clear(); }
     154           10 :     void insertIntoSwingMap(const Fraction& tick, SwingParameters sp) { m_swingMap.insert({ tick.ticks(), sp }); }
     155              : 
     156              :     const CapoParams& capo(const Fraction&) const;
     157              :     void insertCapoParams(const Fraction& tick, const CapoParams& params, bool ignoreNotationUpdate);
     158              :     void removeCapoParams(const Fraction& tick);
     159              : 
     160              :     //==== staff type helper function
     161              :     const StaffType* staffType(const Fraction& = Fraction(0, 1)) const;
     162              :     const StaffType* constStaffType(const Fraction&) const;
     163              :     const StaffType* staffTypeForElement(const EngravingItem*) const;
     164              :     bool isStaffTypeStartFrom(const Fraction& = Fraction(0, 1)) const;
     165              :     void moveStaffType(const Fraction& from, const Fraction& to);
     166              :     StaffType* staffType(const Fraction&);
     167              :     StaffType* setStaffType(const Fraction&, const StaffType&);
     168              :     void removeStaffType(const Fraction&);
     169              :     void staffTypeListChanged(const Fraction&);
     170              : 
     171              :     std::pair<int, int> staffTypeRange(const Fraction&) const;
     172              : 
     173              :     bool isPitchedStaff(const Fraction&) const;
     174              :     bool isTabStaff(const Fraction&) const;
     175              :     bool isDrumStaff(const Fraction&) const;
     176              :     bool isJianpuStaff(const Fraction&) const;
     177              : 
     178              :     int lines(const Fraction&) const;
     179              :     void setLines(const Fraction&, int lines);
     180              :     double lineDistance(const Fraction&) const;
     181              : 
     182              :     bool isLinesInvisible(const Fraction&) const;
     183              :     void setIsLinesInvisible(const Fraction&, bool val);
     184              : 
     185              :     void setSlashStyle(const Fraction&, bool val);
     186              :     int middleLine(const Fraction&) const;
     187              :     int bottomLine(const Fraction&) const;
     188              : 
     189              :     double staffMag(const Fraction&) const;
     190              :     double staffMag(const EngravingItem* element) const;
     191              :     double spatium(const Fraction&) const;
     192              :     double spatium(const EngravingItem*) const;
     193              :     //===========
     194              : 
     195              :     int pitchOffset(const Fraction& tick) const;
     196              :     void updateOttava();
     197              : 
     198              :     std::vector<Staff*> staffList() const;
     199              :     Staff* primaryStaff() const;
     200              :     bool isPrimaryStaff() const;
     201              : 
     202        14577 :     Spatium userDist() const { return m_userDist; }
     203            7 :     void setUserDist(Spatium val) { m_userDist = val; }
     204              : 
     205              :     void setLocalSpatium(double oldVal, double newVal, Fraction tick);
     206              :     bool genKeySig();
     207              :     bool showLedgerLines(const Fraction&) const;
     208              : 
     209              :     using EngravingItem::color;
     210              :     using EngravingItem::setColor;
     211              :     Color color(const Fraction&) const;
     212              :     void setColor(const Fraction&, const Color& val);
     213              :     void insertTime(const Fraction&, const Fraction& len);
     214              : 
     215              :     PropertyValue getProperty(Pid) const override;
     216              :     bool setProperty(Pid, const PropertyValue&) override;
     217              :     PropertyValue propertyDefault(Pid) const override;
     218              : 
     219              :     bool playbackVoice(int voice) const;
     220              :     void setPlaybackVoice(int voice, bool val);
     221              : 
     222              :     const std::array<bool, MAX_VOICES>& visibilityVoices() const;
     223              :     bool isVoiceVisible(voice_idx_t voice) const;
     224              :     bool canDisableVoice() const;
     225              : 
     226              :     bool reflectTranspositionInLinkedTab() const;
     227              :     void setReflectTranspositionInLinkedTab(bool reflect);
     228              : 
     229              : #ifndef NDEBUG
     230              :     void dumpClefs(const char* title) const;
     231              :     void dumpKeys(const char* title) const;
     232              :     void dumpTimeSigs(const char*) const;
     233              : #else
     234              :     void dumpClefs(const char*) const {}
     235              :     void dumpKeys(const char*) const {}
     236              :     void dumpTimeSigs(const char*) const {}
     237              : #endif
     238              : 
     239              :     void triggerLayout() const override;
     240              :     void triggerLayout(const Fraction& tick);
     241              : 
     242              :     Staff* findLinkedInScore(const Score* score) const override;
     243              : 
     244              :     track_idx_t getLinkedTrackInStaff(const Staff* linkedStaff, const track_idx_t strack) const;
     245              :     bool trackHasLinksInVoiceZero(track_idx_t track);
     246              : 
     247              :     void undoSetShowMeasureNumbers(bool show);
     248              :     bool shouldShowMeasureNumbers() const;
     249              : 
     250              :     bool isLastOfScore() const;
     251              :     bool isSystemObjectStaff() const;
     252              :     bool hasSystemObjectsBelowBottomStaff() const;
     253              : 
     254              :     String individualStaffNameLong(const Fraction& tick) const;
     255              :     String individualStaffNameShort(const Fraction& tick) const;
     256              : 
     257              : private:
     258              : 
     259              :     friend class Factory;
     260              :     Staff(Part* parent);
     261              :     Staff(const Staff& staff);
     262              : 
     263              :     double staffMag(const StaffType*) const;
     264              : 
     265              :     friend class Excerpt;
     266              :     void setVoiceVisible(voice_idx_t voice, bool visible);
     267              :     void updateVisibilityVoices(const Staff* masterStaff, const TracksMap& tracks);
     268              : 
     269              :     ID m_id = INVALID_ID;
     270              :     Part* m_part = nullptr;
     271              : 
     272              :     ClefList m_clefs;
     273              :     ClefTypeList m_defaultClefType;
     274              : 
     275              :     KeyList m_keys;
     276              :     std::map<int, TimeSig*> m_timesigs;
     277              : 
     278              :     bool m_barLineSpan = false;          // true - span barline to next staff
     279              :     int m_barLineFrom = 0;              // line of start staff to draw the barline from (0 = staff top line, ...)
     280              :     int m_barLineTo = 0;                // line of end staff to draw the bar line to (0= staff bottom line, ...)
     281              : 
     282              :     bool m_cutaway = false;
     283              :     bool m_showIfEntireSystemEmpty = false;             // show this staff if system is empty and hideEmptyStaves is true
     284              :     bool m_hideSystemBarLine = false;       // no system barline if not preceded by staff with barline
     285              :     AutoOnOff m_mergeMatchingRests = AutoOnOff::AUTO;      // merge matching rests in multiple voices
     286              :     AutoOnOff m_hideWhenEmpty = AutoOnOff::AUTO;      // hide empty staves
     287              : 
     288              :     Color m_color;
     289              :     Spatium m_userDist { 0.0_sp };           ///< user edited extra distance
     290              : 
     291              :     StaffTypeList m_staffTypeList;
     292              : 
     293              :     std::map<int, int> m_channelList[MAX_VOICES];
     294              :     std::map<int, SwingParameters> m_swingMap;
     295              :     std::map<int, CapoParams> m_capoMap;
     296              :     std::map<int, int> m_pitchOffsetMap;
     297              :     bool m_playbackVoice[MAX_VOICES] { true, true, true, true };
     298              :     std::array<bool, MAX_VOICES> m_visibilityVoices { true, true, true, true };
     299              : 
     300              :     bool m_reflectTranspositionInLinkedTab = true;
     301              : 
     302              :     AutoOnOff m_showMeasureNumbers = AutoOnOff::AUTO;
     303              : };
     304              : }
        

Generated by: LCOV version 2.0-1