Beispiel #1
0
    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);
    }
Beispiel #2
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();
    }