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 : #ifndef MU_IEX_BB_BB_H
24 : #define MU_IEX_BB_BB_H
25 :
26 : #include "engraving/compat/midi/event.h"
27 : #include "engraving/dom/score.h"
28 : #include "engraving/dom/sig.h"
29 :
30 : namespace mu::iex::bb {
31 : constexpr int MAX_BARS = 255;
32 :
33 : class BBFile;
34 : struct MNote;
35 :
36 : //---------------------------------------------------------
37 : // BBTrack
38 : //---------------------------------------------------------
39 :
40 : class BBTrack
41 : {
42 : BBFile* bb;
43 : engraving::EventList _events;
44 : int _outChannel;
45 : bool _drumTrack;
46 :
47 : void quantize(int startTick, int endTick, engraving::EventList* dst);
48 :
49 : public:
50 : BBTrack(BBFile*);
51 : ~BBTrack();
52 : bool empty() const;
53 2 : const engraving::EventList events() const { return _events; }
54 0 : engraving::EventList& events() { return _events; }
55 2 : int outChannel() const { return _outChannel; }
56 2 : void setOutChannel(int n) { _outChannel = n; }
57 : void insert(const engraving::Event& e) { _events.insert(e); }
58 2 : void append(const engraving::Event& e) { _events.push_back(e); }
59 :
60 : void findChords();
61 : int separateVoices(int);
62 : void cleanup();
63 :
64 : friend class BBFile;
65 : };
66 :
67 : //---------------------------------------------------------
68 : // BBChord
69 : //---------------------------------------------------------
70 :
71 : struct BBChord {
72 : int beat;
73 : unsigned char bass;
74 : unsigned char root;
75 : unsigned char extension;
76 90359 : BBChord()
77 90359 : {
78 90359 : beat = 0;
79 90359 : bass = 0;
80 90359 : root = 0;
81 90359 : extension = 0;
82 90359 : }
83 : };
84 :
85 : //---------------------------------------------------------
86 : // BBStyle
87 : //---------------------------------------------------------
88 :
89 : struct BBStyle {
90 : int timesigZ, timesigN;
91 : };
92 :
93 : //---------------------------------------------------------
94 : // BBStyle
95 : //---------------------------------------------------------
96 :
97 : static const BBStyle styles[] = {
98 : { 4, 4 }, // Jazz Swing
99 : { 12, 8 }, // Country 12/8
100 : { 4, 4 }, // Country 4/4
101 : { 4, 4 }, // Bossa Nova
102 : { 4, 4 }, // Ethnic
103 : { 4, 4 }, // Blues Shuffle
104 : { 4, 4 }, // Blues Straight
105 : { 3, 4 }, // Waltz
106 : { 4, 4 }, // Pop Ballad
107 : { 4, 4 }, // should be Rock Shuffle
108 : { 4, 4 }, // lite Rock
109 : { 4, 4 }, // medium Rock
110 : { 4, 4 }, // Heavy Rock
111 : { 4, 4 }, // Miami Rock
112 : { 4, 4 }, // Milly Pop
113 : { 4, 4 }, // Funk
114 : { 3, 4 }, // Jazz Waltz
115 : { 4, 4 }, // Rhumba
116 : { 4, 4 }, // Cha Cha
117 : { 4, 4 }, // Bouncy
118 : { 4, 4 }, // Irish
119 : { 12, 8 }, // Pop Ballad 12/8
120 : { 12, 8 }, // Country12/8 old
121 : { 4, 4 }, // Reggae
122 : };
123 :
124 : //---------------------------------------------------------
125 : // BBFile
126 : //---------------------------------------------------------
127 :
128 : class BBFile
129 : {
130 : QString _path;
131 : unsigned char _version;
132 : char* _title;
133 : int _style, _key, _bpm;
134 :
135 : unsigned char _barType[MAX_BARS];
136 : QList<BBChord> _chords;
137 :
138 : int _startChorus;
139 : int _endChorus;
140 : int _repeats;
141 : char* _styleName;
142 : QList<BBTrack*> _tracks;
143 : int _measures;
144 : engraving::TimeSigMap _siglist;
145 :
146 : QByteArray ba;
147 : const unsigned char* a;
148 : int size;
149 : int bbDivision;
150 :
151 180363 : int timesigZ() { return styles[_style].timesigZ; }
152 177057 : int timesigN() { return styles[_style].timesigN; }
153 593448 : bool checkRange(int idx, int n) const
154 : {
155 593448 : return idx >= 0 && n >= 0 && n <= size && idx <= size - n;
156 : }
157 :
158 : engraving::Fraction processPendingNotes(engraving::Score*, QList<MNote*>* notes, const engraving::Fraction&, int);
159 :
160 : public:
161 : BBFile();
162 : ~BBFile();
163 : bool read(const QString&);
164 6 : QList<BBTrack*>* tracks() { return &_tracks; }
165 196 : int measures() const { return _measures; }
166 4 : const char* title() const { return _title; }
167 4 : engraving::TimeSigMap siglist() const { return _siglist; }
168 4 : QList<BBChord> chords() { return _chords; }
169 4 : int startChorus() const { return _startChorus; }
170 4 : int endChorus() const { return _endChorus; }
171 0 : int repeats() const { return _repeats; }
172 4 : int key() const { return _key; }
173 : void convertTrack(engraving::Score* score, BBTrack* track, int staffIdx);
174 : };
175 : }
176 :
177 : #endif // MU_IEX_BB_BB_H
|