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
use fraction::ToPrimitive;

use crate::{
    error::{GpError, GpResult, ToPrimitiveGp},
    io::primitive::*,
    model::{chord::*, enums::*, key_signature::*, song::*},
};

/// A single point within the BendEffect
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct BendPoint {
    pub position: u8,
    pub value: i8,
    pub vibrato: bool,
}
//impl Default for BendPoint { fn default() -> Self { BendPoint { position: 0, value: 0, vibrato: false }}}
impl BendPoint {
    /// Gets the exact time when the point need to be played (MIDI)
    /// * `duration`: the full duration of the effect
    fn _get_time(&self, duration: u8) -> GpResult<u16> {
        let time =
            f32::from(duration) * f32::from(self.position) / f32::from(BEND_EFFECT_MAX_POSITION);
        Ok(time.to_i16_gp("bend point time")? as u16)
    }
}

pub const BEND_EFFECT_MAX_POSITION: u8 = 12;

pub const GP_BEND_SEMITONE: f32 = 25.0;
pub const GP_BEND_POSITION: f32 = 60.0;
pub const GP_BEND_SEMITONE_LENGTH: f32 = 1.0;
/// This effect is used to describe string bends and tremolo bars
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BendEffect {
    pub kind: BendType,
    pub value: i16,
    pub points: Vec<BendPoint>,
    /// The note offset per bend point offset
    pub semitone_length: u8,
    /// The max position of the bend points (x axis)
    pub max_position: u8,
    /// The max value of the bend points (y axis)
    pub max_value: u8,
}
impl Default for BendEffect {
    fn default() -> Self {
        BendEffect {
            kind: BendType::None,
            value: 0,
            points: Vec::with_capacity(12),
            semitone_length: 1,
            max_position: BEND_EFFECT_MAX_POSITION,
            max_value: 12, /* semi_tone_length * 12 */
        }
    }
}

//A collection of velocities / dynamics
pub const MIN_VELOCITY: i16 = 15;
pub const VELOCITY_INCREMENT: i16 = 16;
//pub const PIANO_PIANISSIMO: i16 = MIN_VELOCITY * VELOCITY_INCREMENT;
//pub const PIANO: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 2;
//pub const MEZZO_PIANO: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 3;
//pub const MEZZO_FORTE: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 4;
pub const FORTE: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 5;
//pub const FORTISSIMO: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 6;
//pub const FORTE_FORTISSIMO: i16 = MIN_VELOCITY + VELOCITY_INCREMENT * 7;
pub const DEFAULT_VELOCITY: i16 = FORTE;
/// Convert Guitar Pro dynamic value to raw MIDI velocity
pub(crate) fn unpack_velocity(v: i16) -> i16 {
    //println!("unpack_velocity({})", v);
    MIN_VELOCITY + VELOCITY_INCREMENT * v - VELOCITY_INCREMENT
}

pub(crate) fn pack_velocity(velocity: i16) -> GpResult<i8> {
    ((velocity + VELOCITY_INCREMENT - MIN_VELOCITY) as f32 / VELOCITY_INCREMENT as f32)
        .ceil()
        .to_i8_gp("pack_velocity")
}

/// A grace note effect
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraceEffect {
    pub duration: u8,
    pub fret: i8,
    pub is_dead: bool,
    pub is_on_beat: bool,
    pub transition: GraceEffectTransition,
    pub velocity: i16,
}
impl Default for GraceEffect {
    fn default() -> Self {
        GraceEffect {
            duration: 1,
            fret: 0,
            is_dead: false,
            is_on_beat: false,
            transition: GraceEffectTransition::None,
            velocity: DEFAULT_VELOCITY,
        }
    }
}
impl GraceEffect {
    pub(crate) fn _duration_time(self) -> GpResult<i16> {
        let quarter_time =
            crate::model::key_signature::DURATION_QUARTER_TIME.to_i16_gp("quarter time")?;
        let time = f32::from(quarter_time) / 16f32 * f32::from(self.duration);
        time.to_i16_gp("grace duration time")
    }
}

/// A harmonic note effect
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HarmonicEffect {
    pub kind: HarmonicType,
    //artificial harmonic
    pub pitch: Option<PitchClass>,
    pub octave: Option<Octave>,
    //tapped harmonic
    pub fret: Option<i8>,
}
impl Default for HarmonicEffect {
    fn default() -> Self {
        HarmonicEffect {
            kind: HarmonicType::Natural,
            pitch: None,
            octave: None,
            fret: None,
        }
    }
}

/// A tremolo picking effect.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TremoloPickingEffect {
    pub duration: Duration,
}
//impl Default for TremoloPickingEffect { fn default() -> Self {TremoloPickingEffect { duration: Duration::default() }}}
/// Convert tremolo picking speed to actual duration. Values are:
/// - *1*: eighth
/// - *2*: sixteenth
/// - *3*: thirtySecond
fn from_tremolo_value(value: i8) -> GpResult<u8> {
    match value {
        1 => Ok(DURATION_EIGHTH),
        2 => Ok(DURATION_SIXTEENTH),
        3 => Ok(DURATION_THIRTY_SECOND),
        _ => Ok(DURATION_SIXTEENTH),
    }
}

/// A trill effect.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TrillEffect {
    pub fret: i8,
    pub duration: Duration,
}
//impl Default for TrillEffect { fn default() -> Self {TrillEffect { fret:0, duration: Duration::default() }}}

pub trait SongEffectOps {
    fn read_bend_effect(&self, data: &[u8], seek: &mut usize) -> GpResult<Option<BendEffect>>;
    fn read_grace_effect(&self, data: &[u8], seek: &mut usize) -> GpResult<GraceEffect>;
    fn read_grace_effect_v5(&self, data: &[u8], seek: &mut usize) -> GpResult<GraceEffect>;
    fn read_tremolo_picking(&self, data: &[u8], seek: &mut usize)
    -> GpResult<TremoloPickingEffect>;
    fn read_slides_v5(&self, data: &[u8], seek: &mut usize) -> GpResult<Vec<SlideType>>;
    fn read_harmonic(
        &self,
        data: &[u8],
        seek: &mut usize,
        note: &crate::model::note::Note,
    ) -> GpResult<HarmonicEffect>;
    fn read_harmonic_v5(&mut self, data: &[u8], seek: &mut usize) -> GpResult<HarmonicEffect>;
    fn read_trill(&self, data: &[u8], seek: &mut usize) -> GpResult<TrillEffect>;
    // write methods
    fn write_bend(&self, data: &mut Vec<u8>, bend: &Option<BendEffect>) -> GpResult<()>;
    fn write_grace(&self, data: &mut Vec<u8>, grace: &Option<GraceEffect>) -> GpResult<()>;
    fn write_grace_v5(&self, data: &mut Vec<u8>, grace: &Option<GraceEffect>) -> GpResult<()>;
    fn write_harmonic(
        &self,
        data: &mut Vec<u8>,
        note: &crate::model::note::Note,
        strings: &[(i8, i8)],
    ) -> GpResult<()>;
    fn write_harmonic_v5(
        &self,
        data: &mut Vec<u8>,
        note: &crate::model::note::Note,
        strings: &[(i8, i8)],
    ) -> GpResult<()>;
    fn write_slides_v5(&self, data: &mut Vec<u8>, slides: &[SlideType]);
}

fn from_trill_period(period: i8) -> GpResult<u16> {
    match period {
        1 => Ok(u16::from(DURATION_SIXTEENTH)),
        2 => Ok(u16::from(DURATION_THIRTY_SECOND)),
        3 => Ok(u16::from(DURATION_SIXTY_FOURTH)),
        _ => Ok(u16::from(DURATION_SIXTEENTH)),
    }
}

impl SongEffectOps for Song {
    /// Read a bend. It is encoded as:
    /// - Bend type: `signed-byte`. See BendType.
    /// - Bend value: `int`.
    /// - Number of bend points: `int`.
    /// - List of points. Each point consists of:
    ///   * Position: `int`. Shows where point is set along *x*-axis.
    ///   * Value: `int`. Shows where point is set along *y*-axis.
    ///   * Vibrato: `bool`.
    fn read_bend_effect(&self, data: &[u8], seek: &mut usize) -> GpResult<Option<BendEffect>> {
        let mut be = BendEffect {
            kind: get_bend_type(read_signed_byte(data, seek)?)?,
            ..Default::default()
        };
        be.value = read_int(data, seek)?.to_i16().unwrap_or(0);
        let count: u8 = read_int(data, seek)?.to_u8().unwrap_or(0);
        for _ in 0..count {
            let mut bp = BendPoint {
                position: (f32::from(read_int(data, seek)?.to_i16().unwrap_or(0))
                    * f32::from(BEND_EFFECT_MAX_POSITION)
                    / GP_BEND_POSITION)
                    .round()
                    .to_u8()
                    .unwrap_or(0),
                ..Default::default()
            };
            bp.value = (f32::from(read_int(data, seek)?.to_i16().unwrap_or(0))
                * f32::from(be.semitone_length)
                / GP_BEND_SEMITONE)
                .round()
                .to_i8()
                .unwrap_or(0);
            bp.vibrato = read_bool(data, seek)?;
            be.points.push(bp);
        }
        //println!("read_bend_effect(): {:?}", be);
        if count > 0 { Ok(Some(be)) } else { Ok(None) }
    }
    /// Read grace note effect.
    ///
    /// - Fret: `signed-byte`. The fret number the grace note is made from.
    /// - Dynamic: `byte`. The grace note dynamic is coded like this (default value is 6):
    ///   * 1: ppp
    ///   * 2: pp
    ///   * 3: p
    ///   * 4: mp
    ///   * 5: mf
    ///   * 6: f
    ///   * 7: ff
    ///   * 8: fff
    /// - Transition: `byte`. This variable determines the transition type used to make the grace note: `0: None`, `1: Slide`, `2: Bend`, `3: Hammer` (defined in `GraceEffectTransition`).
    /// - Duration: `byte`. Determines the grace note duration, coded this way: `3: Sixteenth note`, `2: Twenty-fourth note`, `1: Thirty-second note`.
    fn read_grace_effect(&self, data: &[u8], seek: &mut usize) -> GpResult<GraceEffect> {
        //println!("read_grace_effect()");
        let mut g = GraceEffect {
            fret: read_signed_byte(data, seek)?,
            ..Default::default()
        };
        g.velocity = unpack_velocity(read_byte(data, seek)? as i16);
        g.duration = 1 << (7 - read_byte(data, seek)?);
        //g.duration = 1 << (7 - read_byte(data, seek));
        g.is_dead = g.fret == -1;
        g.transition = get_grace_effect_transition(read_signed_byte(data, seek)?)?;
        Ok(g)
    }

    /// Read grace note effect.
    /// - Fret: `signed-byte`. Number of fret.
    /// - Dynamic: `byte`. Dynamic of a grace note, as in `Note.velocity`.
    /// - Transition: `byte`. See `GraceEffectTransition`.
    /// - Duration: `byte`. Values are:
    ///   - *1*: Thirty-second note.
    ///   - *2*: Twenty-fourth note.
    ///   - *3*: Sixteenth note.
    /// - Flags: `byte`.
    ///   - *0x01*: grace note is muted (dead)
    ///   - *0x02*: grace note is on beat
    fn read_grace_effect_v5(&self, data: &[u8], seek: &mut usize) -> GpResult<GraceEffect> {
        let mut g = GraceEffect {
            fret: read_byte(data, seek)? as i8,
            ..Default::default()
        };
        g.velocity = unpack_velocity(read_byte(data, seek)? as i16);
        g.transition = get_grace_effect_transition(read_byte(data, seek)? as i8)?;
        let dur_byte = read_byte(data, seek)?;
        g.duration = if dur_byte <= 7 {
            1 << (7 - dur_byte)
        } else {
            1
        };
        let flags = read_byte(data, seek)?;
        g.is_dead = (flags & 0x01) == 0x01;
        g.is_on_beat = (flags & 0x02) == 0x02;
        Ok(g)
    }

    /// Read tremolo picking. Tremolo constists of picking speed encoded in `signed-byte`. For value mapping refer to `from_tremolo_value()`.
    fn read_tremolo_picking(
        &self,
        data: &[u8],
        seek: &mut usize,
    ) -> GpResult<TremoloPickingEffect> {
        let mut tp = TremoloPickingEffect::default();
        tp.duration.value = u16::from(from_tremolo_value(read_signed_byte(data, seek)?)?);
        Ok(tp)
    }
    ///// Read slides. Slide is encoded in `signed-byte`. See `SlideType` for value mapping.
    //pub(crate) fn read_slides(&self, data: &[u8], seek: &mut usize) -> SlideType { get_slide_type(read_signed_byte(data, seek)) }

    /// Read slides. First `byte` stores slide types:
    /// - *0x01*: shift slide
    /// - *0x02*: legato slide
    /// - *0x04*: slide out downwards
    /// - *0x08*: slide out upwards
    /// - *0x10*: slide into from below
    /// - *0x20*: slide into from above
    fn read_slides_v5(&self, data: &[u8], seek: &mut usize) -> GpResult<Vec<SlideType>> {
        let t = read_byte(data, seek)?;
        let mut v: Vec<SlideType> = Vec::with_capacity(6);
        if (t & 0x01) == 0x01 {
            v.push(SlideType::ShiftSlideTo);
        }
        if (t & 0x02) == 0x02 {
            v.push(SlideType::LegatoSlideTo);
        }
        if (t & 0x04) == 0x04 {
            v.push(SlideType::OutDownwards);
        }
        if (t & 0x08) == 0x08 {
            v.push(SlideType::OutUpWards);
        }
        if (t & 0x10) == 0x10 {
            v.push(SlideType::IntoFromBelow);
        }
        if (t & 0x20) == 0x20 {
            v.push(SlideType::IntoFromAbove);
        }
        Ok(v)
    }
    /// Read harmonic. Harmonic is encoded in `signed-byte`. Values correspond to:
    /// - *1*: natural harmonic
    /// - *3*: tapped harmonic
    /// - *4*: pinch harmonic
    /// - *5*: semi-harmonic
    /// - *15*: artificial harmonic on (*n + 5*)th fret
    /// - *17*: artificial harmonic on (*n + 7*)th fret
    /// - *22*: artificial harmonic on (*n + 12*)th fret
    fn read_harmonic(
        &self,
        data: &[u8],
        seek: &mut usize,
        note: &crate::model::note::Note,
    ) -> GpResult<HarmonicEffect> {
        let mut he = HarmonicEffect::default();
        match read_signed_byte(data, seek)? {
            1 => he.kind = HarmonicType::Natural,
            3 => he.kind = HarmonicType::Tapped,
            4 => he.kind = HarmonicType::Pinch,
            5 => he.kind = HarmonicType::Semi,
            15 => {
                he.pitch = Some(PitchClass::from(((note.value + 7) % 12) as i8, None, None));
                he.octave = Some(Octave::Ottava);
                he.kind = HarmonicType::Artificial;
            }
            17 => {
                let track_idx = self.current_track.ok_or(GpError::MissingState {
                    field: "current_track",
                })?;
                he.pitch = Some(PitchClass::from(
                    note.real_value(&self.tracks[track_idx].strings)?,
                    None,
                    None,
                ));
                he.octave = Some(Octave::Quindicesima);
                he.kind = HarmonicType::Artificial;
            }
            22 => {
                let track_idx = self.current_track.ok_or(GpError::MissingState {
                    field: "current_track",
                })?;
                he.pitch = Some(PitchClass::from(
                    note.real_value(&self.tracks[track_idx].strings)?,
                    None,
                    None,
                ));
                he.octave = Some(Octave::Ottava);
                he.kind = HarmonicType::Artificial;
            }
            _ => he.kind = HarmonicType::Natural,
        };
        Ok(he)
    }

    /// Read harmonic. First `byte` is harmonic type:
    /// - *1*: natural harmonic
    /// - *2*: artificial harmonic
    /// - *3*: tapped harmonic
    /// - *4*: pinch harmonic
    /// - *5*: semi-harmonic
    ///
    /// In case harmonic types is artificial, following data is read:
    /// - Note: `byte`.
    /// - Accidental: `signed-byte`.
    /// - Octave: `byte`.
    ///
    /// If harmonic type is tapped:
    /// - Fret: `byte`.
    fn read_harmonic_v5(&mut self, data: &[u8], seek: &mut usize) -> GpResult<HarmonicEffect> {
        let mut he = HarmonicEffect::default();
        match read_signed_byte(data, seek)? {
            1 => he.kind = HarmonicType::Natural,
            2 => {
                // C = 0, D = 2, E = 4, F = 5...
                // b = -1, # = 1
                // loco = 0, 8va = 1, 15ma = 2
                he.kind = HarmonicType::Artificial;
                let semitone = read_byte(data, seek)? as i8;
                let accidental = read_signed_byte(data, seek)?;
                he.pitch = Some(PitchClass::from(semitone, Some(accidental), None));
                he.octave = Some(get_octave(read_byte(data, seek)?)?);
            }
            3 => {
                he.kind = HarmonicType::Tapped;
                he.fret = Some(read_byte(data, seek)? as i8);
            }
            4 => he.kind = HarmonicType::Pinch,
            5 => he.kind = HarmonicType::Semi,
            _ => he.kind = HarmonicType::Natural,
        };
        Ok(he)
    }
    /// Read trill.
    /// - Fret: `signed-byte`.
    /// - Period: `signed-byte`. See `from_trill_period`.
    fn read_trill(&self, data: &[u8], seek: &mut usize) -> GpResult<TrillEffect> {
        let mut t = TrillEffect {
            fret: read_signed_byte(data, seek)?,
            ..Default::default()
        };
        t.duration.value = from_trill_period(read_signed_byte(data, seek)?)?;
        Ok(t)
    }

    fn write_bend(&self, data: &mut Vec<u8>, bend: &Option<BendEffect>) -> GpResult<()> {
        if let Some(b) = bend {
            write_signed_byte(data, from_bend_type(&b.kind));
            write_i32(data, i32::from(b.value));
            write_i32(data, b.points.len().to_i32_gp("bend points count")?);
            for i in 0..b.points.len() {
                write_i32(
                    data,
                    (f32::from(b.points[i].position) * GP_BEND_POSITION
                        / f32::from(BEND_EFFECT_MAX_POSITION))
                    .round()
                    .to_i32_gp("bend point position")?,
                );
                write_i32(
                    data,
                    (f32::from(b.points[i].value) * GP_BEND_SEMITONE / GP_BEND_SEMITONE_LENGTH)
                        .round()
                        .to_i32_gp("bend point value")?,
                );
                write_bool(data, b.points[i].vibrato);
            }
        }
        Ok(())
    }
    fn write_grace(&self, data: &mut Vec<u8>, grace: &Option<GraceEffect>) -> GpResult<()> {
        let g = grace.as_ref().ok_or(GpError::MissingState {
            field: "grace effect",
        })?;
        write_signed_byte(data, g.fret);
        write_byte(data, pack_velocity(g.velocity)?.to_u8_gp("grace velocity")?);
        write_byte(data, g.duration.leading_zeros() as u8); //8 - grace.duration.bit_length()
        write_signed_byte(data, from_grace_effect_transition(&g.transition));
        Ok(())
    }
    fn write_grace_v5(&self, data: &mut Vec<u8>, grace: &Option<GraceEffect>) -> GpResult<()> {
        let g = grace.as_ref().ok_or(GpError::MissingState {
            field: "grace effect",
        })?;
        write_byte(data, g.fret.to_u8_gp("grace fret")?);
        write_byte(data, pack_velocity(g.velocity)?.to_u8_gp("grace velocity")?);
        write_byte(
            data,
            from_grace_effect_transition(&g.transition).to_u8_gp("grace transition")?,
        );
        write_byte(data, g.duration.leading_zeros() as u8); //8 - grace.duration.bit_length()
        let mut flags = 0u8;
        if g.is_dead {
            flags |= 0x01;
        }
        if g.is_on_beat {
            flags |= 0x02;
        }
        write_byte(data, flags);
        Ok(())
    }
    fn write_harmonic(
        &self,
        data: &mut Vec<u8>,
        note: &crate::model::note::Note,
        strings: &[(i8, i8)],
    ) -> GpResult<()> {
        if let Some(h) = &note.effect.harmonic {
            let mut byte = from_harmonic_type(&h.kind);
            if h.kind == HarmonicType::Artificial {
                // Default to 22 for Artificial harmonics
                byte = 22;

                if let (Some(p), Some(o)) = (&h.pitch, &h.octave) {
                    let real_val = note.real_value(strings)?;
                    if p.value == ((real_val + 7) % 12) && *o == Octave::Ottava {
                        byte = 15;
                    } else if p.value == (real_val % 12) && *o == Octave::Quindicesima {
                        byte = 17;
                    }
                    /* else if p.value == (real_val % 12) && *o == Octave::Ottava {
                        byte = 22;
                    }*/
                } else {
                    byte = 22;
                }
            }
            write_signed_byte(data, byte);
        }
        Ok(())
    }
    fn write_harmonic_v5(
        &self,
        data: &mut Vec<u8>,
        note: &crate::model::note::Note,
        strings: &[(i8, i8)],
    ) -> GpResult<()> {
        if let Some(h) = &note.effect.harmonic {
            write_signed_byte(data, from_harmonic_type(&h.kind));
            if h.kind == HarmonicType::Artificial {
                if let (Some(p), Some(o)) = (&h.pitch, &h.octave) {
                    write_byte(data, p.just.to_u8_gp("pitch class just")?);
                    write_signed_byte(data, p.accidental);
                    write_byte(data, from_octave(o));
                } else {
                    let p = PitchClass::from(note.real_value(strings)? % 12, None, None);
                    let o = Octave::Ottava;
                    write_byte(data, p.just.to_u8_gp("pitch class just")?);
                    write_signed_byte(data, p.accidental);
                    write_byte(data, from_octave(&o));
                }
            } else if h.kind == HarmonicType::Tapped {
                let fret = h.fret.ok_or(GpError::MissingState {
                    field: "harmonic fret",
                })?;
                write_byte(data, fret.to_u8_gp("harmonic fret")?);
            }
        }
        Ok(())
    }
    fn write_slides_v5(&self, data: &mut Vec<u8>, slides: &[SlideType]) {
        let mut st = 0u8; //slide type
        for s in slides {
            if s == &SlideType::ShiftSlideTo {
                st |= 0x01;
            } else if s == &SlideType::LegatoSlideTo {
                st |= 0x02;
            } else if s == &SlideType::OutDownwards {
                st |= 0x04;
            } else if s == &SlideType::OutUpWards {
                st |= 0x08;
            } else if s == &SlideType::IntoFromBelow {
                st |= 0x10;
            } else if s == &SlideType::IntoFromAbove {
                st |= 0x20;
            }
        }
        write_byte(data, st);
    }
}