private BendEffect readBend() { /*Encoded as: * * -Bend type: :ref:`signed - byte`. See * :class:`guitarpro.models.BendType`. * * - Bend value: :ref:`int`. * * - Number of bend points: :ref:`int`. * * - List of points.Each point consists of: * * Position: :ref:`int`. Shows where point is set along * x*-axis. * * Value: :ref:`int`. Shows where point is set along *y*-axis. * * Vibrato: :ref:`bool`. */ var bendEffect = new BendEffect(); bendEffect.type = (BendType)GPBase.readSignedByte()[0]; bendEffect.value = GPBase.readInt()[0]; var pointCount = GPBase.readInt()[0]; for (int x = 0; x < pointCount; x++) { var position = (int)Math.Round(GPBase.readInt()[0] * BendEffect.maxPosition / (float)GPBase.bendPosition); var value = (int)Math.Round(GPBase.readInt()[0] * BendEffect.semitoneLength / (float)GPBase.bendSemitone); var vibrato = GPBase.readBool()[0]; bendEffect.points.Add(new BendPoint(position, value, vibrato)); } return(bendEffect); }
private void readMixTableChangeDurations(MixTableChange tableChange) { if (tableChange.volume != null) { tableChange.volume.duration = GPBase.readSignedByte()[0]; } if (tableChange.balance != null) { tableChange.balance.duration = GPBase.readSignedByte()[0]; } if (tableChange.chorus != null) { tableChange.chorus.duration = GPBase.readSignedByte()[0]; } if (tableChange.reverb != null) { tableChange.reverb.duration = GPBase.readSignedByte()[0]; } if (tableChange.phaser != null) { tableChange.phaser.duration = GPBase.readSignedByte()[0]; } if (tableChange.tremolo != null) { tableChange.tremolo.duration = GPBase.readSignedByte()[0]; } if (tableChange.tempo != null) { tableChange.tempo.duration = GPBase.readSignedByte()[0]; tableChange.hideTempo = false; } }
private List <SlideType> readSlides() { var ret_val = new List <SlideType>(); ret_val.Add((SlideType)GPBase.readSignedByte()[0]); return(ret_val); }
private GraceEffect readGrace() { /*- Fret: :ref:`signed-byte`. Number of fret. * * - Dynamic: :ref:`byte`. Dynamic of a grace note, as in * :attr:`guitarpro.models.Note.velocity`. * * - Transition: :ref:`byte`. See * :class:`guitarpro.models.GraceEffectTransition`. * * - Duration: :ref:`byte`. Values are: * * - *1*: Thirty-second note. * - *2*: Twenty-fourth note. * - *3*: Sixteenth note.*/ var grace = new GraceEffect(); grace.fret = GPBase.readSignedByte()[0]; grace.velocity = unpackVelocity(GPBase.readByte()[0]); grace.duration = 1 << (7 - GPBase.readByte()[0]); grace.isDead = (grace.fret == -1); grace.isOnBeat = false; grace.transition = (GraceEffectTransition)GPBase.readSignedByte()[0]; return(grace); }
private TrillEffect readTrill() { var trill = new TrillEffect(); trill.fret = GPBase.readSignedByte()[0]; trill.duration.value = fromTrillPeriod(GPBase.readSignedByte()[0]); return(trill); }
private TremoloPickingEffect readTremoloPicking() { var value = GPBase.readSignedByte()[0]; var tp = new TremoloPickingEffect(); tp.duration.value = fromTremoloValue(value); return(tp); }
private NoteEffect readNoteEffects(Note note) { /*First byte is note effects flags: * * - *0x01*: bend presence * - *0x02*: hammer-on/pull-off * - *0x04*: slide * - *0x08*: let-ring * - *0x10*: grace note presence * * Flags are followed by: * * - Bend. See :meth:`readBend`. * * - Grace note. See :meth:`readGrace`.*/ var noteEffect = note.effect; if (noteEffect == null) { noteEffect = new NoteEffect(); } var flags1 = GPBase.readSignedByte()[0]; var flags2 = GPBase.readSignedByte()[0]; noteEffect.hammer = ((flags1 & 0x02) != 0); noteEffect.letRing = ((flags1 & 0x08) != 0); noteEffect.staccato = ((flags2 & 0x01) != 0); noteEffect.palmMute = ((flags2 & 0x02) != 0); noteEffect.vibrato = ((flags2 & 0x40) != 0) || noteEffect.vibrato; if ((flags1 & 0x01) != 0) { noteEffect.bend = readBend(); } if ((flags1 & 0x10) != 0) { noteEffect.grace = readGrace(); } if ((flags2 & 0x04) != 0) { noteEffect.tremoloPicking = readTremoloPicking(); } if ((flags2 & 0x08) != 0) { noteEffect.slides = readSlides(); } if ((flags2 & 0x10) != 0) { noteEffect.harmonic = readHarmonic(note); } if ((flags2 & 0x20) != 0) { noteEffect.trill = readTrill(); } return(noteEffect); }
private BeatEffect readBeatEffects(NoteEffect effect) { /* * The first byte is effects flags: * * - *0x01*: vibrato * - *0x02*: wide vibrato * - *0x04*: natural harmonic * - *0x08*: artificial harmonic * - *0x10*: fade in * - *0x20*: tremolo bar or slap effect * - *0x40*: beat stroke direction * - *0x80*: *blank* * * - Tremolo bar or slap effect: :ref:`byte`. If it's 0 then * tremolo bar should be read (see :meth:`readTremoloBar`). Else * it's tapping and values of the byte map to: * * - *1*: tap * - *2*: slap * - *3*: pop * * - Beat stroke direction. See :meth:`readBeatStroke`.*/ var beatEffect = new BeatEffect(); var flags1 = GPBase.readSignedByte()[0]; var flags2 = GPBase.readSignedByte()[0]; //effect.vibrato = ((flags1 & 0x01) != 0) || effect.vibrato; beatEffect.vibrato = ((flags1 & 0x02) != 0) || beatEffect.vibrato; beatEffect.fadeIn = ((flags1 & 0x10) != 0); if ((flags1 & 0x20) != 0) { var value = GPBase.readSignedByte()[0]; beatEffect.slapEffect = (SlapEffect)value; } if ((flags2 & 0x04) != 0) { beatEffect.tremoloBar = readTremoloBar(); } if ((flags1 & 0x40) != 0) { beatEffect.stroke = readBeatStroke(); } if ((flags2 & 0x02) != 0) { var direction = GPBase.readSignedByte()[0]; beatEffect.pickStroke = (BeatStrokeDirection)direction; } return(beatEffect); }
private BeatStroke readBeatStroke() { var strokeDown = GPBase.readSignedByte()[0]; var strokeUp = GPBase.readSignedByte()[0]; if (strokeUp > 0) { return(new BeatStroke(BeatStrokeDirection.up, toStrokeValue(strokeUp), 0.0f)); } else { return(new BeatStroke(BeatStrokeDirection.down, toStrokeValue(strokeDown), 0.0f)); } }
private HarmonicEffect readHarmonic(Note note) { /*Harmonic is encoded in :ref:`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 */ var harmonicType = GPBase.readSignedByte()[0]; HarmonicEffect harmonic = null; switch (harmonicType) { case 1: harmonic = new NaturalHarmonic(); break; case 3: harmonic = new TappedHarmonic(); break; case 4: harmonic = new PinchHarmonic(); break; case 5: harmonic = new SemiHarmonic(); break; case 15: var pitch = new PitchClass((note.realValue() + 7) % 12, -1, "", "", 7.0f); var octave = Octave.ottava; harmonic = new ArtificialHarmonic(pitch, octave); break; case 17: pitch = new PitchClass(note.realValue(), -1, "", "", 12.0f); octave = Octave.quindicesima; harmonic = new ArtificialHarmonic(pitch, octave); break; case 22: pitch = new PitchClass(note.realValue(), -1, "", "", 5.0f); octave = Octave.ottava; harmonic = new ArtificialHarmonic(pitch, octave); break; } return(harmonic); }
private void readMixTableChangeValues(MixTableChange tableChange, Measure measure) { var instrument = GPBase.readSignedByte()[0]; var volume = GPBase.readSignedByte()[0]; var balance = GPBase.readSignedByte()[0]; var chorus = GPBase.readSignedByte()[0]; var reverb = GPBase.readSignedByte()[0]; var phaser = GPBase.readSignedByte()[0]; var tremolo = GPBase.readSignedByte()[0]; var tempo = GPBase.readInt()[0]; if (instrument >= 0) { tableChange.instrument = new MixTableItem(instrument); } if (volume >= 0) { tableChange.volume = new MixTableItem(volume); } if (balance >= 0) { tableChange.balance = new MixTableItem(balance); } if (chorus >= 0) { tableChange.chorus = new MixTableItem(chorus); } if (reverb >= 0) { tableChange.reverb = new MixTableItem(reverb); } if (phaser >= 0) { tableChange.phaser = new MixTableItem(phaser); } if (tremolo >= 0) { tableChange.tremolo = new MixTableItem(tremolo); } if (tempo >= 0) { tableChange.tempo = new MixTableItem(tempo); measure.tempo().value = tempo; } }
private Duration readDuration(byte flags) { /*Duration is composed of byte signifying duration and an integer * that maps to :class:`guitarpro.models.Tuplet`. * * The byte maps to following values: * * - *-2*: whole note * - *-1*: half note * - *0*: quarter note * - *1*: eighth note * - *2*: sixteenth note * - *3*: thirty-second note * * If flag at *0x20* is true, the tuplet is read.*/ var duration = new Duration(); duration.value = 1 << (GPBase.readSignedByte()[0] + 2); duration.isDotted = ((flags & 0x01) != 0); if ((flags & 0x20) != 0) { var iTuplet = GPBase.readInt()[0]; switch (iTuplet) { case 3: duration.tuplet.enters = 3; duration.tuplet.times = 2; break; case 5: duration.tuplet.enters = 5; duration.tuplet.times = 4; break; case 6: duration.tuplet.enters = 6; duration.tuplet.times = 4; break; case 7: duration.tuplet.enters = 7; duration.tuplet.times = 4; break; case 9: duration.tuplet.enters = 9; duration.tuplet.times = 8; break; case 10: duration.tuplet.enters = 10; duration.tuplet.times = 8; break; case 11: duration.tuplet.enters = 11; duration.tuplet.times = 8; break; case 12: duration.tuplet.enters = 12; duration.tuplet.times = 8; break; } } return(duration); }
private void readMixTableChangeFlags(MixTableChange tableChange) { /* The meaning of flags: * * - *0x01*: change volume for all tracks * - *0x02*: change balance for all tracks * - *0x04*: change chorus for all tracks * - *0x08*: change reverb for all tracks * - *0x10*: change phaser for all tracks * - *0x20*: change tremolo for all tracks*/ var flags = GPBase.readSignedByte()[0]; if (tableChange.volume != null) { tableChange.volume.allTracks = ((flags & 0x01) != 0); } if (tableChange.balance != null) { tableChange.balance.allTracks = ((flags & 0x02) != 0); } if (tableChange.chorus != null) { tableChange.chorus.allTracks = ((flags & 0x04) != 0); } if (tableChange.reverb != null) { tableChange.reverb.allTracks = ((flags & 0x08) != 0); } if (tableChange.phaser != null) { tableChange.phaser.allTracks = ((flags & 0x10) != 0); } if (tableChange.tremolo != null) { tableChange.tremolo.allTracks = ((flags & 0x20) != 0); } }
public override void readSong() { //HEADERS //VERSION version = readVersion(); versionTuple = readVersionTuple(); clipboard = readClipboard(); //INFORMATION ABOUT THE PIECE readInfo(); _tripletFeel = GPBase.readBool()[0] ? TripletFeel.eigth : TripletFeel.none; readLyrics(); tempo = GPBase.readInt()[0]; key = (KeySignature)(GPBase.readInt()[0] * 10); //key + 0 GPBase.readSignedByte(); //octave readMidiChannels(); measureCount = GPBase.readInt()[0]; trackCount = GPBase.readInt()[0]; readMeasureHeaders(measureCount); readTracks(trackCount, channels); readMeasures(); }
private void readNewChord(Chord chord) { /*Read new-style (GP4) chord diagram. * * New-style chord diagram is read as follows: * * - Sharp: :ref:`bool`. If true, display all semitones as sharps, * otherwise display as flats. * * - Blank space, 3 :ref:`Bytes <byte>`. * * - Root: :ref:`int`. Values are: * * -1 for customized chords * 0: C * 1: C# * ... * * - Type: :ref:`int`. Determines the chord type as followed. See * :class:`guitarpro.models.ChordType` for mapping. * * - Chord extension: :ref:`int`. See * :class:`guitarpro.models.ChordExtension` for mapping. * * - Bass note: :ref:`int`. Lowest note of chord as in *C/Am*. * * - Tonality: :ref:`int`. See * :class:`guitarpro.models.ChordAlteration` for mapping. * * - Add: :ref:`bool`. Determines if an "add" (added note) is * present in the chord. * * - Name: :ref:`byte-size-string`. Max length is 22. * * - Fifth alteration: :ref:`int`. Maps to * :class:`guitarpro.models.ChordAlteration`. * * - Ninth alteration: :ref:`int`. Maps to * :class:`guitarpro.models.ChordAlteration`. * * - Eleventh alteration: :ref:`int`. Maps to * :class:`guitarpro.models.ChordAlteration`. * * - List of frets: 6 :ref:`Ints <int>`. Fret values are saved as * in default format. * * - Count of barres: :ref:`int`. Maximum count is 2. * * - Barre frets: 2 :ref:`Ints <int>`. * * - Barre start strings: 2 :ref:`Ints <int>`. * * - Barre end string: 2 :ref:`Ints <int>`. * * - Omissions: 7 :ref:`Bools <bool>`. If the value is true then * note is played in chord. * * - Blank space, 1 :ref:`byte`.*/ chord.sharp = GPBase.readBool()[0]; var intonation = chord.sharp ? "sharp" : "flat"; GPBase.skip(3); chord.root = new PitchClass(GPBase.readByte()[0], -1, "", intonation); chord.type = (ChordType)GPBase.readByte()[0]; chord.extension = (ChordExtension)GPBase.readByte()[0]; chord.bass = new PitchClass(GPBase.readInt()[0], -1, "", intonation); chord.tonality = (ChordAlteration)GPBase.readInt()[0]; chord.add = GPBase.readBool()[0]; chord.name = GPBase.readByteSizeString(22); chord.fifth = (ChordAlteration)GPBase.readByte()[0]; chord.ninth = (ChordAlteration)GPBase.readByte()[0]; chord.eleventh = (ChordAlteration)GPBase.readByte()[0]; chord.firstFret = GPBase.readInt()[0]; for (int i = 0; i < 7; i++) { var fret = GPBase.readInt()[0]; if (i < chord.strings.Length) { chord.strings[i] = fret; } } chord.barres.Clear(); var barresCount = GPBase.readByte()[0]; var barreFrets = GPBase.readByte(5); var barreStarts = GPBase.readByte(5); var barreEnds = GPBase.readByte(5); for (int x = 0; x < Math.Min(5, (int)barresCount); x++) { var barre = new Barre(barreFrets[x], barreStarts[x], barreEnds[x]); chord.barres.Add(barre); } chord.omissions = GPBase.readBool(7); GPBase.skip(1); List <Fingering> f = new List <Fingering>(); for (int x = 0; x < 7; x++) { f.Add((Fingering)GPBase.readSignedByte()[0]); } chord.fingerings = f; chord.show = GPBase.readBool()[0]; }
private void readNote(Note note, GuitarString guitarString, Track track) { /*The first byte is note flags: * * - *0x01*: time-independent duration * - *0x02*: heavy accentuated note * - *0x04*: ghost note * - *0x08*: presence of note effects * - *0x10*: dynamics * - *0x20*: fret * - *0x40*: accentuated note * - *0x80*: right hand or left hand fingering * * Flags are followed by: * * - Note type: :ref:`byte`. Note is normal if values is 1, tied if * value is 2, dead if value is 3. * * - Time-independent duration: 2 :ref:`SignedBytes <signed-byte>`. * Correspond to duration and tuplet. See :meth:`readDuration` * for reference. * * - Note dynamics: :ref:`signed-byte`. See :meth:`unpackVelocity`. * * - Fret number: :ref:`signed-byte`. If flag at *0x20* is set then * read fret number. * * - Fingering: 2 :ref:`SignedBytes <signed-byte>`. See * :class:`guitarpro.models.Fingering`. * * - Note effects. See :meth:`readNoteEffects`.*/ var flags = GPBase.readByte()[0]; note.str = guitarString.number; note.effect.ghostNote = ((flags & 0x04) != 0); if ((flags & 0x20) != 0) { note.type = (NoteType)(GPBase.readByte()[0]); } if ((flags & 0x01) != 0) { note.duration = GPBase.readSignedByte()[0]; note.tuplet = GPBase.readSignedByte()[0]; } if ((flags & 0x10) != 0) { var dyn = GPBase.readSignedByte()[0]; note.velocity = unpackVelocity(dyn); } if ((flags & 0x20) != 0) { int value; var fret = GPBase.readSignedByte()[0]; if (note.type == NoteType.tie) { value = getTiedNoteValue(guitarString.number, track); } else { value = fret; } note.value = Math.Max(0, Math.Min(99, value)); } if ((flags & 0x80) != 0) { note.effect.leftHandFinger = (Fingering)GPBase.readSignedByte()[0]; note.effect.rightHandFinger = (Fingering)GPBase.readSignedByte()[0]; } if ((flags & 0x08) != 0) { note.effect = readNoteEffects(note); if (note.effect.isHarmonic() && note.effect.harmonic is TappedHarmonic) { note.effect.harmonic.fret = note.value + 12; } } }
private MeasureHeader readMeasureHeader(int number, MeasureHeader previous = null) { /*Read measure header. * * The first byte is the measure's flags. It lists the data given in the * current measure. * * - *0x01*: numerator of the key signature * - *0x02*: denominator of the key signature * - *0x04*: beginning of repeat * - *0x08*: end of repeat * - *0x10*: number of alternate ending * - *0x20*: presence of a marker * - *0x40*: tonality of the measure * - *0x80*: presence of a double bar * * Each of these elements is present only if the corresponding bit * is a 1. * * The different elements are written (if they are present) from * lowest to highest bit. * * Exceptions are made for the double bar and the beginning of * repeat whose sole presence is enough, complementary data is not * necessary. * * - Numerator of the key signature: :ref:`byte`. * * - Denominator of the key signature: :ref:`byte`. * * - End of repeat: :ref:`byte`. * Number of repeats until the previous beginning of repeat. * * - Number of alternate ending: :ref:`byte`. * * - Marker: see :meth:`GP3File.readMarker`. * * - Tonality of the measure: 2 :ref:`Bytes <byte>`. These values * encode a key signature change on the current piece. First byte * is key signature root, second is key signature type. */ byte flags = GPBase.readByte()[0]; MeasureHeader header = new MeasureHeader(); header.number = number; header.start = 0; header.tempo.value = tempo; header.tripletFeel = _tripletFeel; if ((flags & 0x01) != 0) { header.timeSignature.numerator = GPBase.readSignedByte()[0]; } else { header.timeSignature.numerator = previous.timeSignature.numerator; } if ((flags & 0x02) != 0) { header.timeSignature.denominator.value = GPBase.readSignedByte()[0]; } else { header.timeSignature.denominator.value = previous.timeSignature.denominator.value; } header.isRepeatOpen = (bool)((flags & 0x04) != 0); if ((flags & 0x08) != 0) { header.repeatClose = GPBase.readSignedByte()[0]; } if ((flags & 0x10) != 0) { header.repeatAlternatives.Add(readRepeatAlternative(measureHeaders)); } if ((flags & 0x20) != 0) { header.marker = readMarker(header); } if ((flags & 0x40) != 0) { sbyte root = GPBase.readSignedByte()[0]; sbyte type_ = GPBase.readSignedByte()[0]; int dir = (root < 0) ? -1 : 1; header.keySignature = (KeySignature)((int)root * 10 + dir * type_); } else if (header.number > 1) { header.keySignature = previous.keySignature; } header.hasDoubleBar = ((flags & 0x80) != 0); return(header); }