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) 2024 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 "musicxmlvoicedesc.h"
24 :
25 : using namespace mu::engraving;
26 : using namespace mu::iex::musicxml;
27 : //---------------------------------------------------------
28 : // VoiceDesc
29 : //---------------------------------------------------------
30 :
31 587 : VoiceDesc::VoiceDesc()
32 587 : : m_staff(-1), m_voice(-1), m_overlaps(false)
33 : {
34 2935 : for (int i = 0; i < MAX_STAVES; ++i) {
35 2348 : m_chordRests[i] = 0;
36 2348 : m_staffAlloc[i] = -1;
37 2348 : m_voices[i] = -1;
38 : }
39 587 : }
40 :
41 6978 : void VoiceDesc::incrChordRests(int s)
42 : {
43 6978 : if (0 <= s && s < MAX_STAVES) {
44 6978 : m_chordRests[s]++;
45 : }
46 6978 : }
47 :
48 1485 : int VoiceDesc::numberChordRests() const
49 : {
50 1485 : int res = 0;
51 7425 : for (int i = 0; i < MAX_STAVES; ++i) {
52 5940 : res += m_chordRests[i];
53 : }
54 1485 : return res;
55 : }
56 :
57 579 : int VoiceDesc::preferredStaff() const
58 : {
59 579 : int max = 0;
60 579 : int res = 0;
61 2895 : for (int i = 0; i < MAX_STAVES; ++i) {
62 2316 : if (m_chordRests[i] > max) {
63 580 : max = m_chordRests[i];
64 580 : res = i;
65 : }
66 : }
67 579 : return res;
68 : }
69 :
70 0 : String VoiceDesc::toString() const
71 : {
72 0 : String res = u"[";
73 0 : for (int i = 0; i < MAX_STAVES; ++i) {
74 0 : res += String(u" %1").arg(m_chordRests[i]);
75 : }
76 0 : res += String(u" ] overlaps %1").arg(m_overlaps);
77 0 : if (m_overlaps) {
78 0 : res += u" staffAlloc [";
79 0 : for (int i = 0; i < MAX_STAVES; ++i) {
80 0 : res += String(u" %1").arg(m_staffAlloc[i]);
81 : }
82 0 : res += u" ] voices [";
83 0 : for (int i = 0; i < MAX_STAVES; ++i) {
84 0 : res += String(u" %1").arg(m_voices[i]);
85 : }
86 0 : res += u" ]";
87 : } else {
88 0 : res += String(u" staff %1 voice %2").arg(m_staff + 1).arg(m_voice + 1);
89 : }
90 0 : return res;
91 0 : }
|