guitarpro 0.3.0

Rust library and command line interface (CLI) for guitar tab files.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
use crate::error::{GpError, GpResult};

/// An enumeration of different triplet feels.
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TripletFeel {
    None,
    Eighth,
    Sixteenth,
}
pub(crate) fn get_triplet_feel(value: i8) -> GpResult<TripletFeel> {
    match value {
        0 => Ok(TripletFeel::None),
        1 => Ok(TripletFeel::Eighth),
        2 => Ok(TripletFeel::Sixteenth),
        _ => Err(GpError::InvalidValue {
            context: "triplet feel",
            value: value as i64,
        }),
    }
}
pub(crate) fn from_triplet_feel(value: &TripletFeel) -> u8 {
    match value {
        TripletFeel::None => 0,
        TripletFeel::Eighth => 1,
        TripletFeel::Sixteenth => 2,
    }
}

/// An enumeration of available clefs
#[allow(dead_code)]
#[repr(u8)]
#[derive(Debug, Clone)]
pub enum MeasureClef {
    Treble,
    Bass,
    Tenor,
    Alto,
}
/// A line break directive: `NONE: no line break`, `BREAK: break line`, `Protect the line from breaking`.
#[repr(u8)]
#[derive(Debug, Clone)]
pub enum LineBreak {
    None,
    Break,
    Protect,
}
pub(crate) fn get_line_break(value: u8) -> LineBreak {
    match value {
        1 => LineBreak::Break,
        2 => LineBreak::Protect,
        _ => LineBreak::None,
    }
}
pub(crate) fn from_line_break(value: &LineBreak) -> u8 {
    match value {
        LineBreak::None => 0,
        LineBreak::Break => 1,
        LineBreak::Protect => 2,
    }
}

/// An enumeration of all supported slide types.
#[repr(i8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SlideType {
    IntoFromAbove = -2, //-2
    IntoFromBelow = -1, //-1
    None = 0,           //0
    ShiftSlideTo,
    LegatoSlideTo,
    OutDownwards,
    OutUpWards,
}
pub(crate) fn get_slide_type(value: i8) -> GpResult<SlideType> {
    match value {
        -2 => Ok(SlideType::IntoFromAbove),
        -1 => Ok(SlideType::IntoFromBelow),
        0 => Ok(SlideType::None),
        1 => Ok(SlideType::ShiftSlideTo),
        2 => Ok(SlideType::LegatoSlideTo),
        3 => Ok(SlideType::OutDownwards),
        4 => Ok(SlideType::OutUpWards),
        _ => Err(GpError::InvalidValue {
            context: "slide type",
            value: value as i64,
        }),
    }
}
pub(crate) fn from_slide_type(value: &SlideType) -> i8 {
    match value {
        SlideType::IntoFromAbove => -2,
        SlideType::IntoFromBelow => -1,
        SlideType::None => 0,
        SlideType::ShiftSlideTo => 1,
        SlideType::LegatoSlideTo => 2,
        SlideType::OutDownwards => 3,
        SlideType::OutUpWards => 4,
    }
}

/// An enumeration of all supported slide types.
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NoteType {
    Rest, //0
    Normal,
    Tie,
    Dead,
    Unknown(u8),
}
pub(crate) fn get_note_type(value: u8) -> NoteType {
    match value {
        0 => NoteType::Rest,
        1 => NoteType::Normal,
        2 => NoteType::Tie,
        3 => NoteType::Dead,
        _ => NoteType::Unknown(value), //panic!("Cannot read note type"),
    }
}
pub(crate) fn from_note_type(value: &NoteType) -> u8 {
    match value {
        NoteType::Rest => 0,
        NoteType::Normal => 1,
        NoteType::Tie => 2,
        NoteType::Dead => 3,
        NoteType::Unknown(value) => *value, //panic!("Cannot read note type"),
    }
}

#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BeatStatus {
    Empty,
    Normal,
    Rest,
}
pub(crate) fn get_beat_status(value: u8) -> BeatStatus {
    match value {
        0 => BeatStatus::Empty,
        1 => BeatStatus::Normal,
        2 => BeatStatus::Rest,
        _ => BeatStatus::Normal, //panic!("Cannot get beat status"),
    }
}
pub(crate) fn from_beat_status(value: &BeatStatus) -> u8 {
    match value {
        BeatStatus::Empty => 0,
        BeatStatus::Normal => 1,
        BeatStatus::Rest => 2,
    }
}

#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TupletBracket {
    None,
    Start,
    End,
}

/// Octave signs
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Octave {
    None,
    Ottava,
    Quindicesima,
    OttavaBassa,
    QuindicesimaBassa,
}
pub(crate) fn get_octave(value: u8) -> GpResult<Octave> {
    match value {
        0 => Ok(Octave::None),
        1 => Ok(Octave::Ottava),
        2 => Ok(Octave::Quindicesima),
        3 => Ok(Octave::OttavaBassa),
        4 => Ok(Octave::QuindicesimaBassa),
        _ => Err(GpError::InvalidValue {
            context: "octave",
            value: value as i64,
        }),
    }
}
pub(crate) fn from_octave(value: &Octave) -> u8 {
    match value {
        Octave::None => 0,
        Octave::Ottava => 1,
        Octave::Quindicesima => 2,
        Octave::OttavaBassa => 3,
        Octave::QuindicesimaBassa => 4,
    }
}

/// All beat stroke directions
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BeatStrokeDirection {
    None,
    Up,
    Down,
}
pub(crate) fn get_beat_stroke_direction(value: i8) -> GpResult<BeatStrokeDirection> {
    match value {
        0 => Ok(BeatStrokeDirection::None),
        1 => Ok(BeatStrokeDirection::Up),
        2 => Ok(BeatStrokeDirection::Down),
        _ => Ok(BeatStrokeDirection::None),
    }
}
pub(crate) fn from_beat_stroke_direction(value: &BeatStrokeDirection) -> i8 {
    match value {
        BeatStrokeDirection::None => 0,
        BeatStrokeDirection::Up => 1,
        BeatStrokeDirection::Down => 2,
    }
}
/// Characteristic of articulation
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SlapEffect {
    None,
    Tapping,
    Slapping,
    Popping,
}
pub(crate) fn get_slap_effect(value: u8) -> GpResult<SlapEffect> {
    match value {
        0 => Ok(SlapEffect::None),
        1 => Ok(SlapEffect::Tapping),
        2 => Ok(SlapEffect::Slapping),
        3 => Ok(SlapEffect::Popping),
        _ => Ok(SlapEffect::None),
    }
}
pub(crate) fn from_slap_effect(value: &SlapEffect) -> u8 {
    match value {
        SlapEffect::None => 0,
        SlapEffect::Tapping => 1,
        SlapEffect::Slapping => 2,
        SlapEffect::Popping => 3,
    }
}

/// Voice directions indicating the direction of beams
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VoiceDirection {
    None,
    Up,
    Down,
}

/// Type of the chord.
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChordType {
    /// Major chord.
    Major,
    /// Dominant seventh chord.
    Seventh,
    /// Major seventh chord.
    MajorSeventh,
    /// Add sixth chord.
    Sixth,
    /// Minor chord.
    Minor,
    /// Minor seventh chord.
    MinorSeventh,
    /// Minor major seventh chord.
    MinorMajor,
    /// Minor add sixth chord.
    MinorSixth,
    /// Suspended second chord.
    SuspendedSecond,
    /// Suspended fourth chord.
    SuspendedFourth,
    /// Seventh suspended second chord.
    SeventhSuspendedSecond,
    /// Seventh suspended fourth chord.
    SeventhSuspendedFourth,
    /// Diminished chord.
    Diminished,
    /// Augmented chord.
    Augmented,
    /// Power chord.
    Power,

    Unknown(u8),
}
pub(crate) fn get_chord_type(value: u8) -> ChordType {
    match value {
        0 => ChordType::Major,
        1 => ChordType::Seventh,
        2 => ChordType::MajorSeventh,
        3 => ChordType::Sixth,
        4 => ChordType::Minor,
        5 => ChordType::MinorSeventh,
        6 => ChordType::MinorMajor,
        7 => ChordType::MinorSixth,
        8 => ChordType::SuspendedSecond,
        9 => ChordType::SuspendedFourth,
        10 => ChordType::SeventhSuspendedSecond,
        11 => ChordType::SeventhSuspendedFourth,
        12 => ChordType::Diminished,
        13 => ChordType::Augmented,
        14 => ChordType::Power,
        _ => ChordType::Unknown(value), //panic!("Cannot read chord type (new format)"),
    }
}
pub(crate) fn from_chord_type(value: &ChordType) -> u8 {
    match value {
        ChordType::Major => 0,
        ChordType::Seventh => 1,
        ChordType::MajorSeventh => 2,
        ChordType::Sixth => 3,
        ChordType::Minor => 4,
        ChordType::MinorSeventh => 5,
        ChordType::MinorMajor => 6,
        ChordType::MinorSixth => 7,
        ChordType::SuspendedSecond => 8,
        ChordType::SuspendedFourth => 9,
        ChordType::SeventhSuspendedSecond => 10,
        ChordType::SeventhSuspendedFourth => 11,
        ChordType::Diminished => 12,
        ChordType::Augmented => 13,
        ChordType::Power => 14,
        ChordType::Unknown(value) => *value,
    }
}

/// Tonality of the chord
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChordAlteration {
    /// Perfect.
    Perfect,
    /// Diminished.
    Diminished,
    /// Augmented.
    Augmented,
}
pub(crate) fn get_chord_alteration(value: u8) -> GpResult<ChordAlteration> {
    match value {
        0 => Ok(ChordAlteration::Perfect),
        1 => Ok(ChordAlteration::Diminished),
        2 => Ok(ChordAlteration::Augmented),
        _ => Ok(ChordAlteration::Perfect),
    }
}
pub(crate) fn from_chord_alteration(value: &ChordAlteration) -> u8 {
    match value {
        ChordAlteration::Perfect => 0,
        ChordAlteration::Diminished => 1,
        ChordAlteration::Augmented => 2,
    }
}

/// Extension type of the chord
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChordExtension {
    None,
    /// Ninth chord.
    Ninth,
    /// Eleventh chord.
    Eleventh,
    /// Thirteenth chord.
    Thirteenth,
    Unknown(u8),
}
pub(crate) fn get_chord_extension(value: u8) -> ChordExtension {
    match value {
        0 => ChordExtension::None,
        1 => ChordExtension::Ninth,
        2 => ChordExtension::Eleventh,
        3 => ChordExtension::Thirteenth,
        _ => ChordExtension::Unknown(value), //panic!("Cannot read chord type (new format)"),
    }
}
pub(crate) fn from_chord_extension(value: &ChordExtension) -> u8 {
    match value {
        ChordExtension::None => 0,
        ChordExtension::Ninth => 1,
        ChordExtension::Eleventh => 2,
        ChordExtension::Thirteenth => 3,
        ChordExtension::Unknown(value) => *value, //panic!("Cannot read chord type (new format)"),
    }
}

/// Left and right hand fingering used in tabs and chord diagram editor.
#[repr(i8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Fingering {
    /// Open or muted.
    Open = -1, //-1?
    /// Thumb.
    Thumb = 0,
    /// Index finger.
    Index,
    /// Middle finger.
    Middle,
    /// Annular finger.
    Annular,
    /// Little finger.
    Little,

    Unknown(i8),
}

pub(crate) fn get_fingering(value: i8) -> Fingering {
    match value {
        -1 => Fingering::Open,
        0 => Fingering::Thumb,
        1 => Fingering::Index,
        2 => Fingering::Middle,
        3 => Fingering::Annular,
        4 => Fingering::Little,
        _ => Fingering::Unknown(value), //panic!("Cannot get fingering! How can you have more than 5 fingers per hand?!?"),
    }
}
pub(crate) fn from_fingering(value: &Fingering) -> i8 {
    match value {
        Fingering::Open => -1,
        Fingering::Thumb => 0,
        Fingering::Index => 1,
        Fingering::Middle => 2,
        Fingering::Annular => 3,
        Fingering::Little => 4,
        Fingering::Unknown(value) => *value, //panic!("Cannot get fingering! How can you have more than 5 fingers per hand?!?"),
    }
}

/// All Bend presets
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BendType {
    /// No Preset.
    None,

    //Bends
    /// A simple bend.
    Bend,
    /// A bend and release afterwards.
    BendRelease,
    /// A bend, then release and rebend.
    BendReleaseBend,
    /// Prebend.
    Prebend,
    /// Prebend and then release.
    PrebendRelease,

    //Tremolo Bar
    /// Dip the bar down and then back up.
    Dip,
    /// Dive the bar.
    Dive,
    /// Release the bar up.
    ReleaseUp,
    /// Dip the bar up and then back down.
    InvertedDip,
    /// Return the bar.
    Return,
    /// Release the bar down.
    ReleaseDown,
}
pub(crate) fn get_bend_type(value: i8) -> GpResult<BendType> {
    match value {
        0 => Ok(BendType::None),
        1 => Ok(BendType::Bend),
        2 => Ok(BendType::BendRelease),
        3 => Ok(BendType::BendReleaseBend),
        4 => Ok(BendType::Prebend),
        5 => Ok(BendType::PrebendRelease),
        6 => Ok(BendType::Dip),
        7 => Ok(BendType::Dive),
        8 => Ok(BendType::ReleaseUp),
        9 => Ok(BendType::InvertedDip),
        10 => Ok(BendType::Return),
        11 => Ok(BendType::ReleaseDown),
        _ => Ok(BendType::None),
    }
}
pub(crate) fn from_bend_type(value: &BendType) -> i8 {
    match value {
        BendType::None => 0,
        BendType::Bend => 1,
        BendType::BendRelease => 2,
        BendType::BendReleaseBend => 3,
        BendType::Prebend => 4,
        BendType::PrebendRelease => 5,
        BendType::Dip => 6,
        BendType::Dive => 7,
        BendType::ReleaseUp => 8,
        BendType::InvertedDip => 9,
        BendType::Return => 10,
        BendType::ReleaseDown => 11,
    }
}

/// All transition types for grace notes.
#[repr(i8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraceEffectTransition {
    ///No transition
    None = 0,
    ///Slide from the grace note to the real one.
    Slide,
    ///Perform a bend from the grace note to the real one.
    Bend,
    ///Perform a hammer on.
    Hammer,
}
pub(crate) fn get_grace_effect_transition(value: i8) -> GpResult<GraceEffectTransition> {
    match value {
        0 => Ok(GraceEffectTransition::None),
        1 => Ok(GraceEffectTransition::Slide),
        2 => Ok(GraceEffectTransition::Bend),
        3 => Ok(GraceEffectTransition::Hammer),
        _ => Ok(GraceEffectTransition::None),
    }
}
pub(crate) fn from_grace_effect_transition(value: &GraceEffectTransition) -> i8 {
    match value {
        GraceEffectTransition::None => 0,
        GraceEffectTransition::Slide => 1,
        GraceEffectTransition::Bend => 2,
        GraceEffectTransition::Hammer => 3,
    }
}

#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HarmonicType {
    Natural = 1, //1
    Artificial,
    Tapped,
    Pinch,
    Semi, //5
}
pub(crate) fn from_harmonic_type(value: &HarmonicType) -> i8 {
    match value {
        HarmonicType::Natural => 1,
        HarmonicType::Artificial => 2,
        HarmonicType::Tapped => 3,
        HarmonicType::Pinch => 4,
        HarmonicType::Semi => 5,
    }
}

/// Values of auto-accentuation on the beat found in track RSE settings
#[repr(u8)]
#[derive(Debug, Clone)]
pub enum Accentuation {
    None,
    VerySoft,
    Soft,
    Medium,
    Strong,
    VeryStrong,
}
pub(crate) fn get_accentuation(value: u8) -> GpResult<Accentuation> {
    match value {
        0 => Ok(Accentuation::None),
        1 => Ok(Accentuation::VerySoft),
        2 => Ok(Accentuation::Soft),
        3 => Ok(Accentuation::Medium),
        4 => Ok(Accentuation::Strong),
        5 => Ok(Accentuation::VeryStrong),
        _ => Err(GpError::InvalidValue {
            context: "accentuation",
            value: value as i64,
        }),
    }
}
pub(crate) fn from_accentuation(value: &Accentuation) -> u8 {
    match value {
        Accentuation::None => 0,
        Accentuation::VerySoft => 1,
        Accentuation::Soft => 2,
        Accentuation::Medium => 3,
        Accentuation::Strong => 4,
        Accentuation::VeryStrong => 5,
    }
}

/// A navigation sign like *Coda* (𝄌: U+1D10C) or *Segno* (𝄋 or 𝄉: U+1D10B or U+1D109).
#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DirectionSign {
    Coda,
    DoubleCoda,
    Segno,
    SegnoSegno,
    Fine,
    DaCapo,
    DaCapoAlCoda,
    DaCapoAlDoubleCoda,
    DaCapoAlFine,
    DaSegno,
    DaSegnoAlCoda,
    DaSegnoAlDoubleCoda,
    DaSegnoAlFine,
    DaSegnoSegno,
    DaSegnoSegnoAlCoda,
    DaSegnoSegnoAlDoubleCoda,
    DaSegnoSegnoAlFine,
    DaCoda,
    DaDoubleCoda,
}