private void readOldChord(Chord chord) { /*Read chord diagram encoded in GP3 format. * * Chord diagram is read as follows: * * - Name: :ref:`int-byte-size-string`. Name of the chord, e.g. * Em*. * * - First fret: :ref:`int`. The fret from which the chord is * displayed in chord editor. * * - List of frets: 6 :ref:`Ints <int>`. Frets are listed in order: * fret on the string 1, fret on the string 2, ..., fret on the * string 6. If string is untouched then the values of fret is *-1*.*/ chord.name = GPBase.readIntByteSizeString(); chord.firstFret = GPBase.readInt()[0]; if (chord.firstFret > 0) { for (int i = 0; i < 6; i++) { var fret = GPBase.readInt()[0]; if (i < chord.strings.Length) { chord.strings[i] = fret; } } } }
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 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 beatEffects = new BeatEffect(); var flags1 = GPBase.readByte()[0]; effect.vibrato = ((flags1 & 0x01) != 0) || effect.vibrato; beatEffects.vibrato = ((flags1 & 0x02) != 0) || beatEffects.vibrato; beatEffects.fadeIn = ((flags1 & 0x10) != 0); if ((flags1 & 0x20) != 0) { var flags2 = GPBase.readByte()[0]; beatEffects.slapEffect = (SlapEffect)flags2; if (beatEffects.slapEffect == SlapEffect.none) { beatEffects.tremoloBar = readTremoloBar(); } else { GPBase.readInt(); } } if ((flags1 & 0x40) != 0) { beatEffects.stroke = readBeatStroke(); } if ((flags1 & 0x04) != 0) { effect.harmonic = new NaturalHarmonic(); } if ((flags1 & 0x08) != 0) { effect.harmonic = new ArtificialHarmonic(); } return(beatEffects); }
private void readVoice(int start, Voice voice) { //TODO: The pointer is 13 bytes too early here (when reading for measure 0xa of track 0x2, beats should return 1, not 898989) var beats = GPBase.readInt()[0]; for (int beat = 0; beat < beats; beat++) { start += readBeat(start, voice); } }
private BendEffect readTremoloBar() { var barEffect = new BendEffect(); barEffect.type = BendType.dip; barEffect.value = GPBase.readInt()[0]; barEffect.points = new List <BendPoint>(); barEffect.points.Add(new BendPoint(0, 0)); barEffect.points.Add(new BendPoint((int)Math.Round(BendEffect.maxPosition / 2.0f), (int)Math.Round(-barEffect.value / (double)GPBase.bendSemitone))); barEffect.points.Add(new BendPoint(BendEffect.maxPosition, 0)); return(barEffect); }
public Clipboard readClipboard() { if (!isClipboard()) { return(null); } var clipboard = new Clipboard(); clipboard.startMeasure = GPBase.readInt()[0]; clipboard.stopMeasure = GPBase.readInt()[0]; clipboard.startTrack = GPBase.readInt()[0]; clipboard.stopTrack = GPBase.readInt()[0]; return(clipboard); }
private void readMidiChannels() { /*Read MIDI channels. * * Guitar Pro format provides 64 channels(4 MIDI ports by 16 * channels), the channels are stored in this order: * * -port1 / channel1 * - port1 / channel2 * - ... * - port1 / channel16 * - port2 / channel1 * - ... * - port4 / channel16 * * Each channel has the following form: * -Instrument: :ref:`int`. * -Volume: :ref:`byte`. * -Balance: :ref:`byte`. * -Chorus: :ref:`byte`. * -Reverb: :ref:`byte`. * -Phaser: :ref:`byte`. * -Tremolo: :ref:`byte`. * -blank1: :ref:`byte`. * -blank2: :ref:`byte`.*/ MidiChannel[] _channels = new MidiChannel[64]; for (int i = 0; i < 64; i++) { var newChannel = new MidiChannel(); newChannel.channel = i; newChannel.effectChannel = i; var instrument = GPBase.readInt()[0]; if (newChannel.isPercussionChannel() && instrument == -1) { instrument = 0; } newChannel.instrument = instrument; newChannel.volume = toChannelShort(GPBase.readByte()[0]); newChannel.balance = toChannelShort(GPBase.readByte()[0]); newChannel.chorus = toChannelShort(GPBase.readByte()[0]); newChannel.reverb = toChannelShort(GPBase.readByte()[0]); newChannel.phaser = toChannelShort(GPBase.readByte()[0]); newChannel.tremolo = toChannelShort(GPBase.readByte()[0]); _channels[i] = newChannel; GPBase.skip(2); } channels = _channels; }
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 readLyrics() { /*Read lyrics. * First, read an :ref:`int` that points to the track lyrics are * bound to. Then it is followed by 5 lyric lines. Each one * consists of number of starting measure encoded in :ref:`int` * and :ref:`int-size-string` holding text of the lyric line.*/ lyrics = new List <Lyrics>(); var _lyrics = new Lyrics(); _lyrics.trackChoice = GPBase.readInt()[0]; for (int x = 0; x < _lyrics.lines.Length; x++) { _lyrics.lines[x].startingMeasure = GPBase.readInt()[0]; _lyrics.lines[x].lyrics = GPBase.readIntSizeString(); } lyrics.Add(_lyrics); }
public override void readSong() { //HEADERS //VERSION version = readVersion(); versionTuple = readVersionTuple(); //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 readInfo() { /*Read score information. * * Score information consists of sequence of * :ref:`IntByteSizeStrings <int-byte-size-string>`: * * - title * - subtitle * - artist * - album * - words * - copyright * - tabbed by * - instructions * * The sequence if followed by notice. Notice starts with the * number of notice lines stored in :ref:`int`. Each line is * encoded in :ref:`int-byte-size-string`.*/ title = GPBase.readIntByteSizeString(); subtitle = GPBase.readIntByteSizeString(); interpret = GPBase.readIntByteSizeString(); album = GPBase.readIntByteSizeString(); author = GPBase.readIntByteSizeString(); copyright = GPBase.readIntByteSizeString(); tab_author = GPBase.readIntByteSizeString(); instructional = GPBase.readIntByteSizeString(); int notesCount = GPBase.readInt()[0]; notice = new string[notesCount]; for (int x = 0; x < notesCount; x++) { notice[x] = GPBase.readIntByteSizeString(); } }
private MidiChannel readChannel(MidiChannel[] channels) { /*Read MIDI channel. * * MIDI channel in Guitar Pro is represented by two integers. First * is zero-based number of channel, second is zero-based number of * channel used for effects.*/ var index = GPBase.readInt()[0] - 1; MidiChannel trackChannel = new MidiChannel(); var effectChannel = GPBase.readInt()[0] - 1; if (0 <= index && index < channels.Length) { trackChannel = channels[index]; if (trackChannel.instrument < 0) { trackChannel.instrument = 0; } if (!trackChannel.isPercussionChannel()) { trackChannel.effectChannel = effectChannel; } } return(trackChannel); }
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 readTrack(Track track, MidiChannel[] channels) { /* * Read track. * * The first byte is the track's flags. It presides the track's * attributes: * * - *0x01*: drums track * - *0x02*: 12 stringed guitar track * - *0x04*: banjo track * - *0x08*: *blank* * - *0x10*: *blank* * - *0x20*: *blank* * - *0x40*: *blank* * - *0x80*: *blank* * * Flags are followed by: * * - Name: :ref:`byte-size-string`. A 40 characters long string * containing the track's name. * * - Number of strings: :ref:`int`. An integer equal to the number * of strings of the track. * * - Tuning of the strings: List of 7 :ref:`Ints <int>`. The tuning * of the strings is stored as a 7-integers table, the "Number of * strings" first integers being really used. The strings are * stored from the highest to the lowest. * * - Port: :ref:`int`. The number of the MIDI port used. * * - Channel. See :meth:`GP3File.readChannel`. * * - Number of frets: :ref:`int`. The number of frets of the * instrument. * * - Height of the capo: :ref:`int`. The number of the fret on * which a capo is set. If no capo is used, the value is 0. * * - Track's color. The track's displayed color in Guitar Pro.*/ byte flags = GPBase.readByte()[0]; track.isPercussionTrack = ((flags & 0x01) != 0); track.is12StringedGuitarTrack = ((flags & 0x02) != 0); track.isBanjoTrack = ((flags & 0x04) != 0); track.name = GPBase.readByteSizeString(40); var stringCount = GPBase.readInt()[0]; for (int i = 0; i < 7; i++) { int iTuning = GPBase.readInt()[0]; if (stringCount > i) { var oString = new GuitarString(i + 1, iTuning); track.strings.Add(oString); } } track.port = GPBase.readInt()[0]; track.channel = readChannel(channels); if (track.channel.channel == 9) { track.isPercussionTrack = true; } track.fretCount = GPBase.readInt()[0]; track.offset = GPBase.readInt()[0]; track.color = readColor(); }