Line data Source code
1 : #ifndef MU_IMPORTEXPORT_GPBEAT_H
2 : #define MU_IMPORTEXPORT_GPBEAT_H
3 :
4 : #include <map>
5 : #include <memory>
6 : #include <string>
7 :
8 : #include "gpnote.h"
9 : #include "gprhythm.h"
10 :
11 : namespace mu::iex::guitarpro {
12 : class GPBeat
13 : {
14 : public:
15 : enum class DynamicType {
16 : FFF, FF, F, MF, MP, P, PP, PPP
17 : };
18 : enum class LegatoType {
19 : None, Start, Mediate, End
20 : };
21 : enum class Arpeggio {
22 : None, Up, Down
23 : };
24 : enum class Brush {
25 : None, Up, Down
26 : };
27 : enum class GraceNotes {
28 : None, OnBeat, BeforeBeat
29 : };
30 : enum class VibratoWTremBar {
31 : None, Slight, Wide
32 : };
33 : enum class VibratoLeftHand {
34 : None, Slight, Wide
35 : };
36 : enum class Fadding {
37 : None, FadeIn, FadeOut, VolumeSwell
38 : };
39 : enum class Hairpin {
40 : None, Crescendo, Decrescendo
41 : };
42 : enum class PickStroke {
43 : None, Up, Down
44 : };
45 : enum class Wah {
46 : None, Open, Closed
47 : };
48 : enum class Golpe {
49 : None, Finger, Thumb
50 : };
51 : enum class TappingHand {
52 : None, Right, Left
53 : };
54 : enum class Rasgueado {
55 : None, II_1, MII_1, MII_2, PMP_1, PMP_2, PEI_1, PEI_2, PAI_1, PAI_2, AMI_1,
56 : AMI_2, PPP_1, AMII_1, AMIP_1, EAMI_1, EAMII_1, PEAMI_1
57 : };
58 :
59 : enum class OttavaType {
60 : None, ma15, va8, vb8, mb15
61 : };
62 :
63 : enum class HarmonicMarkType {
64 : None, Artificial, Pinch, Tap, Semi, FeedBack
65 : };
66 :
67 : struct HarmonicMarkInfo {
68 : bool artificial = false;
69 : bool pinch = false;
70 : bool tap = false;
71 : bool semi = false;
72 : bool feedback = false;
73 : };
74 :
75 : struct Tremolo {
76 : int numerator{ -1 };
77 : int denominator{ -1 };
78 : };
79 :
80 : struct Barre {
81 : int fret{ -1 };
82 : int string{ -1 };
83 : };
84 :
85 : struct StemOrientation {
86 : bool up = false; /// taken in consideration only if userDefined == true
87 : bool userDefined = false;
88 : };
89 :
90 : enum class BeamMode {
91 : AUTO,
92 : JOINED,
93 : BROKEN,
94 : BROKEN2,
95 : BROKEN2_JOINED
96 : };
97 :
98 : struct {
99 612 : bool operator()(const std::shared_ptr<GPNote>& a, const std::shared_ptr<GPNote>& b) const
100 : {
101 612 : auto aPitch = a->midiPitch().octave * 12 + a->midiPitch().tone;
102 612 : auto bPitch = b->midiPitch().octave * 12 + b->midiPitch().tone;
103 612 : return aPitch > bPitch;
104 : }
105 : } comparePitch;
106 :
107 : using Whammy = GPNote::Bend;
108 :
109 1530 : void addGPNote(const std::shared_ptr<GPNote>& n) { _notes.push_back(n); }
110 : void sortGPNotes();
111 1497 : void addGPRhythm(const std::shared_ptr<GPRhythm>& n) { _rhythm = n; }
112 1497 : void setDynamic(GPBeat::DynamicType t) { _dynamic = t; }
113 59 : void setLegatoType(GPBeat::LegatoType t) { _legato = t; }
114 51 : void setOttavaType(GPBeat::OttavaType ottavaType) { _ottavaType = ottavaType; }
115 2131 : GPBeat::OttavaType ottavaType() const { return _ottavaType; }
116 :
117 2131 : bool isRest() const { return _notes.empty(); }
118 :
119 1923 : DynamicType dynamic() const { return _dynamic; }
120 2261 : LegatoType legatoType() const { return _legato; }
121 :
122 : std::pair<int, GPRhythm::RhytmType> lenth() const;
123 : GPRhythm::Tuplet tuplet() const;
124 :
125 11 : void setLetRing(bool letRing) { _letRing = letRing; }
126 2095 : bool letRing() const { return _letRing; }
127 :
128 4 : void setPalmMute(bool palmMute) { _palmMute = palmMute; }
129 2095 : bool palmMute() const { return _palmMute; }
130 :
131 2 : void setTrill(bool trill) { _trill = trill; }
132 2095 : bool trill() const { return _trill; }
133 :
134 : void addHarmonicMarkType(GPBeat::HarmonicMarkType type);
135 2095 : bool harmonicMarkArtificial() const { return _harmonicMarkInfo.artificial; }
136 2095 : bool harmonicMarkPinch() const { return _harmonicMarkInfo.pinch; }
137 2095 : bool harmonicMarkTap() const { return _harmonicMarkInfo.tap; }
138 2095 : bool harmonicMarkSemi() const { return _harmonicMarkInfo.semi; }
139 2095 : bool harmonicMarkFeedback() const { return _harmonicMarkInfo.feedback; }
140 :
141 2 : void setTappingHand(TappingHand hand) { _tappingHand = hand; }
142 2097 : TappingHand tappingHand() const { return _tappingHand; }
143 :
144 7 : void setSlapped(bool s) { _slapped = s; }
145 2095 : bool slapped() const { return _slapped; }
146 :
147 6 : void setPopped(bool s) { _popped = s; }
148 2095 : bool popped() const { return _popped; }
149 :
150 4 : void setArpeggio(Arpeggio ar) { _arpeggio = ar; }
151 2099 : Arpeggio arpeggio() const { return _arpeggio; }
152 :
153 8 : void setArpeggioStretch(double arpeggioStretch) { _arpeggioStretch = arpeggioStretch; }
154 8 : double arpeggioStretch() const { return _arpeggioStretch; }
155 :
156 4 : void setBrush(Brush br) { _brush = br; }
157 2099 : Brush brush() const { return _brush; }
158 :
159 24 : void setGraceNotes(GraceNotes gn) { _graceNotes = gn; }
160 2167 : GraceNotes graceNotes() const { return _graceNotes; }
161 :
162 7 : void setFreeText(const muse::String& s) { _freeText = s; }
163 2102 : const muse::String& freeText() const { return _freeText; }
164 :
165 6 : void setTime(int t) { _time = t; }
166 2101 : int time() const { return _time; }
167 :
168 8 : void setVibratoWTremBar(VibratoWTremBar v) { _vibratoWTremBar = v; }
169 4190 : VibratoWTremBar vibratoWTremBar() const { return _vibratoWTremBar; }
170 :
171 9 : void setVibratoLeftHand(VibratoLeftHand v) { _vibratoLeftHand = v; }
172 4190 : VibratoLeftHand vibratoLeftHand() const { return _vibratoLeftHand; }
173 :
174 7 : void setFadding(Fadding f) { _fadding = f; }
175 2099 : Fadding fadding() const { return _fadding; }
176 :
177 14 : void setHairpin(Hairpin h) { _hairpin = h; }
178 4190 : Hairpin hairpin() const { return _hairpin; }
179 :
180 5 : void setRasgueado(Rasgueado r) { _rasgueado = r; }
181 2095 : Rasgueado rasgueado() const { return _rasgueado; }
182 :
183 4 : void setPickStroke(PickStroke p) { _pickStroke = p; }
184 2099 : PickStroke pickStroke() const { return _pickStroke; }
185 :
186 6 : void setTremolo(Tremolo tr) { _tremolo = tr; }
187 1601 : Tremolo tremolo() const { return _tremolo; }
188 :
189 4 : void setWah(Wah w) { _wah = w; }
190 2099 : Wah wah() const { return _wah; }
191 :
192 0 : void setGolpe(Golpe g) { m_golpe = g; }
193 2095 : Golpe golpe() const { return m_golpe; }
194 :
195 4 : void setBarreFret(int v) { _barre.fret = v; }
196 3 : void setBarreString(int v) { _barre.string = v; }
197 2103 : Barre barre() const { return _barre; }
198 :
199 1497 : void setId(int id) { _id = id; }
200 : int id() const { return _id; }
201 :
202 80 : void setWhammy(const Whammy& whammy) { m_whammy = whammy; }
203 86 : const Whammy& whammy() const { return m_whammy; }
204 2101 : bool hasWhammy() const { return !m_whammy.isEmpty(); }
205 :
206 3 : void setPickScrape(bool pickScrape) { m_pickScrape = pickScrape; }
207 2095 : bool pickScrape() const { return m_pickScrape; }
208 :
209 0 : void setDeadSlapped(bool deadSlapped) { m_deadSlapped = deadSlapped; }
210 0 : bool deadSlapped() const { return m_deadSlapped; }
211 :
212 1041 : void setStemOrientationUp(bool up) { m_stemOrientation.up = up; }
213 0 : void setStemOrientationUserDefined(bool userDefined) { m_stemOrientation.userDefined = userDefined; }
214 0 : bool stemOrientationUp() const { return m_stemOrientation.up; }
215 1595 : bool stemOrientationUserDefined() const { return m_stemOrientation.userDefined; }
216 :
217 29 : void setBeamMode(BeamMode mode) { m_beamMode = mode; }
218 6319 : BeamMode beamMode() const { return m_beamMode; }
219 :
220 2131 : const std::vector<std::shared_ptr<GPNote> >& notes() const { return _notes; }
221 :
222 : //! NOTE In GP version 6.2.0+ already arranged lyrics are written into bits, so the lyrics field of the beat is enough.
223 : //! In earlier versions of GP, there was no arrangement of lyrics by bits,
224 : //! i.e. it was necessary to parse the general lyrics each time a tab was opened and arrange them by bits.
225 : //! At the same time, the same beat can be used in different bars, even if it has different lyrics
226 : //! (i.e. the lyrics did not participate in determining the uniqueness of the beat).
227 : //! Therefore, in order to write lyrics into such bits, a key was added - the bar number (master bar)
228 :
229 : struct Key {
230 : int32_t trackId{ -1 };
231 : int32_t mbarId{ -1 };
232 : Key() {}
233 8400 : Key(int32_t ti, int32_t mi)
234 8400 : : trackId(ti), mbarId(mi) {}
235 100 : bool operator <(const Key& other) const
236 : {
237 100 : if (trackId != other.trackId) {
238 20 : return trackId < other.trackId;
239 : }
240 80 : return mbarId < other.mbarId;
241 : }
242 : };
243 :
244 0 : void setLyrics(const std::string& ly) { setLyrics(-1, -1, ly); }
245 0 : void setLyrics(int32_t ti, int32_t mi, const std::string& ly) { _lyrics[Key(ti, mi)] = ly; }
246 4190 : const std::string& lyrics(int32_t ti = -1, int32_t mi = -1) const
247 : {
248 4190 : Key key(ti, mi);
249 4190 : if (_lyrics.find(key) == _lyrics.end()) {
250 4190 : if (ti != -1 && mi != -1) {
251 2095 : return lyrics(-1, -1);
252 : }
253 :
254 2104 : static std::string dummy;
255 2095 : return dummy;
256 : }
257 0 : return _lyrics.at(key);
258 : }
259 :
260 : //! NOTE Same problem as with lyrics
261 20 : void setDiagramIdx(int idx) { setDiagramIdx(-1, -1, idx); }
262 20 : void setDiagramIdx(int32_t ti, int32_t mi, int idx) { _diagramIdx[Key(ti, mi)] = idx; }
263 4190 : int diagramIdx(int32_t ti = -1, int32_t mi = -1) const
264 : {
265 4190 : Key key(ti, mi);
266 4190 : if (_diagramIdx.find(key) == _diagramIdx.end()) {
267 4170 : if (ti != -1 && mi != -1) {
268 2095 : return diagramIdx(-1, -1);
269 : }
270 :
271 2075 : return -1;
272 : }
273 20 : return _diagramIdx.at(key);
274 : }
275 :
276 : private:
277 : int _id = -1;
278 : std::vector<std::shared_ptr<GPNote> > _notes;
279 : std::map<Key, std::string> _lyrics;
280 : std::map<Key, int> _diagramIdx;
281 : std::shared_ptr<GPRhythm> _rhythm;
282 : DynamicType _dynamic = DynamicType::MF;
283 : LegatoType _legato = LegatoType::None;
284 : OttavaType _ottavaType = OttavaType::None;
285 : bool _letRing = false;
286 : bool _palmMute = false;
287 : bool _trill = false;
288 : TappingHand _tappingHand = TappingHand::None;
289 : bool _slapped = false;
290 : bool _popped = false;
291 : HarmonicMarkInfo _harmonicMarkInfo;
292 : Arpeggio _arpeggio = Arpeggio::None;
293 : Brush _brush = Brush::None;
294 : GraceNotes _graceNotes = GraceNotes::None;
295 : int _time = -1;
296 : muse::String _freeText;
297 : VibratoWTremBar _vibratoWTremBar = VibratoWTremBar::None;
298 : VibratoLeftHand _vibratoLeftHand = VibratoLeftHand::None;
299 : Fadding _fadding = Fadding::None;
300 : Hairpin _hairpin = Hairpin::None;
301 : Rasgueado _rasgueado = Rasgueado::None;
302 : PickStroke _pickStroke = PickStroke::None;
303 : Tremolo _tremolo;
304 : Wah _wah = Wah::None;
305 : Golpe m_golpe = Golpe::None;
306 : Barre _barre;
307 : double _arpeggioStretch = 0.0;
308 : Whammy m_whammy;
309 : bool m_pickScrape = false;
310 : bool m_deadSlapped = false;
311 : StemOrientation m_stemOrientation;
312 : BeamMode m_beamMode = BeamMode::AUTO;
313 : };
314 : } // namespace mu::iex::guitarpro
315 :
316 : #endif // MU_IMPORTEXPORT_GPBEAT_H
|