Пример #1
0
        private void ReadNotes(Track track, Beat.Beat beat, Duration duration, NoteEffect effect)
        {
            /* First byte lists played strings:
             *
             * - *0x01*: 7th string
             * - *0x02*: 6th string
             * - *0x04*: 5th string
             * - *0x08*: 4th string
             * - *0x10*: 3th string
             * - *0x20*: 2th string
             * - *0x40*: 1th string
             * - *0x80*: *blank**/

            var stringFlags = GpBase.ReadByte()[0];

            foreach (var str in track.Strings)
            {
                if ((stringFlags & 1 << (7 - str.Number)) != 0)
                {
                    var note = new Note(beat);
                    beat.Notes.Add(note);
                    ReadNote(note, str, track);
                }
                beat.Duration = duration;
            }
        }
Пример #2
0
 public Note()
 {
     Value      = 0;
     Velocity   = Velocities.Default;
     Str        = 1;
     IsTiedNote = false;
     Effect     = new NoteEffect();
 }
Пример #3
0
        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);
        }
Пример #4
0
        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 = (SlapEffects)flags2;
                if (beatEffects.SlapEffect == SlapEffects.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);
        }
Пример #5
0
    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);
    }
Пример #6
0
        private NoteEffect ParseEffect(JObject jNote)
        {
            var flag = jNote["effect"].SafeValue <int>();

            NoteEffect effect = new NoteEffect();

            if (flag == 4)
            {
                effect.Bend = new EffectBend();
                foreach (var jBendPoint in jNote["bend"].Value <JArray>())
                {
                    var x = jBendPoint["X"].SafeValue <int>();
                    var y = jBendPoint["Y"].SafeValue <int>();
                    effect.Bend.AddPoint(x, y);
                }
            }

            if (flag == 8)
            {
                effect.IsHammer = true;
            }

            if (flag == 512)
            {
            }

            if (flag == 2048)
            {
                effect.IsVibrato = true;
            }

            if (flag == 16)
            {
                effect.IsSlide = true;
            }


            if (jNote["harmonic"] != null)
            {
                effect.Harmonic      = new EffectHarmonic();
                effect.Harmonic.Type = jNote["harmonic"]["type"].SafeValue <int>();
                effect.Harmonic.Data = jNote["harmonic"]["data"].SafeValue <int>();
            }

            if (flag == 32768)
            {
                effect.TremoloPicking = new EffectTremoloPicking(); // TODO duration
            }
            return(effect);
        }
Пример #7
0
        private void WriteBeatEffects(Beat beat, NoteEffect effect)
        {
            int flags1 = 0;
            int flags2 = 0;

            if (effect.IsFadeIn)
            {
                flags1 |= 0x10;
            }
            if (effect.IsTapping || effect.IsSlapping || effect.IsPopping)
            {
                flags1 |= 0x20;
            }
            if (effect.TremoloBar != null)
            {
                flags2 |= 0x04;
            }
            if (beat.Stroke.Direction != Stroke.StrokeNone)
            {
                flags1 |= 0x40;
            }
            WriteUnsignedByte(flags1);
            WriteUnsignedByte(flags2);

            if ((flags1 & 0x20) != 0)
            {
                if (effect.IsTapping)
                {
                    WriteUnsignedByte(1);
                }
                else if (effect.IsSlapping)
                {
                    WriteUnsignedByte(2);
                }
                else if (effect.IsPopping)
                {
                    WriteUnsignedByte(3);
                }
            }
            if ((flags2 & 0x04) != 0)
            {
                WriteTremoloBar(effect.TremoloBar);
            }
            if ((flags1 & 0x40) != 0)
            {
                WriteUnsignedByte((beat.Stroke.Direction == Stroke.StrokeUp ? ToStrokeValue(beat.Stroke) : 0));
                WriteUnsignedByte((beat.Stroke.Direction == Stroke.StrokeDown ? ToStrokeValue(beat.Stroke) : 0));
            }
        }
Пример #8
0
        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 flags = GpBase.ReadByte()[0];

            noteEffect.Hammer  = ((flags & 0x02) != 0);
            noteEffect.LetRing = ((flags & 0x08) != 0);
            if ((flags & 0x01) != 0)
            {
                noteEffect.Bend = ReadBend();
            }
            if ((flags & 0x10) != 0)
            {
                noteEffect.Grace = ReadGrace();
            }
            if ((flags & 0x04) != 0)
            {
                noteEffect.Slides = ReadSlides();
            }
            return(noteEffect);
        }
Пример #9
0
        private int ReadBeat(int start, Voice voice)
        {
            /* The first byte is the beat flags. It lists the data present in
             * the current beat:
             *
             * - *0x01*: dotted notes
             * - *0x02*: presence of a chord diagram
             * - *0x04*: presence of a text
             * - *0x08*: presence of effects
             * - *0x10*: presence of a mix table change event
             * - *0x20*: the beat is a n-tuplet
             * - *0x40*: status: True if the beat is empty of if it is a rest
             * - *0x80*: *blank*
             *
             * Flags are followed by:
             *
             * - Status: :ref:`byte`. If flag at *0x40* is true, read one byte.
             * If value of the byte is *0x00* then beat is empty, if value is
             * 0x02* then the beat is rest.
             *
             * - Beat duration: :ref:`byte`. See :meth:`readDuration`.
             *
             * - Chord diagram. See :meth:`readChord`.
             *
             * - Text. See :meth:`readText`.
             *
             * - Beat effects. See :meth:`readBeatEffects`.
             *
             * - Mix table change effect. See :meth:`readMixTableChange`.*/

            var flags = GpBase.ReadByte()[0];
            var beat  = GetBeat(voice, start);

            if ((flags & 0x40) != 0)
            {
                beat.Status = (BeatStatuses)((int)GpBase.ReadByte()[0]);
            }
            else
            {
                beat.Status = BeatStatuses.Normal;
            }
            var duration = ReadDuration(flags);
            var effect   = new NoteEffect();

            if ((flags & 0x02) != 0)
            {
                beat.Effect.Chord = ReadChord(voice.Measure.Track.Strings.Count);
            }
            if ((flags & 0x04) != 0)
            {
                beat.Text = ReadText();
            }
            if ((flags & 0x08) != 0)
            {
                beat.Effect = ReadBeatEffects(effect);
            }
            if ((flags & 0x10) != 0)
            {
                var mixTableChange = ReadMixTableChange(voice.Measure);
                beat.Effect.MixTableChange = mixTableChange;
            }
            ReadNotes(voice.Measure.Track, beat, duration, effect);
            return((beat.Status != BeatStatuses.Empty) ? duration.Time() : 0);
        }
Пример #10
0
        private void WriteNoteEffects(NoteEffect effect)
        {
            int flags1 = 0;
            int flags2 = 0;

            if (effect.Bend != null)
            {
                flags1 |= 0x01;
            }
            if (effect.IsHammer)
            {
                flags1 |= 0x02;
            }
            if (effect.Grace != null)
            {
                flags1 |= 0x10;
            }
            if (effect.IsStaccato)
            {
                flags2 |= 0x01;
            }
            if (effect.IsPalmMute)
            {
                flags2 |= 0x02;
            }
            if (effect.TremoloPicking != null)
            {
                flags2 |= 0x04;
            }
            if (effect.IsSlide)
            {
                flags2 |= 0x08;
            }
            if (effect.Harmonic != null)
            {
                flags2 |= 0x10;
            }
            if (effect.Trill != null)
            {
                flags2 |= 0x20;
            }
            if (effect.IsVibrato)
            {
                flags2 |= 0x40;
            }
            WriteUnsignedByte(flags1);
            WriteUnsignedByte(flags2);
            if ((flags1 & 0x01) != 0)
            {
                WriteBend(effect.Bend);
            }

            if ((flags1 & 0x10) != 0)
            {
                WriteGrace(effect.Grace);
            }

            if ((flags2 & 0x04) != 0)
            {
                WriteTremoloPicking(effect.TremoloPicking);
            }

            if ((flags2 & 0x08) != 0)
            {
                WriteByte((byte)1);
            }

            if ((flags2 & 0x10) != 0)
            {
                WriteByte((byte)1);
            }

            if ((flags2 & 0x20) != 0)
            {
                WriteTrill(effect.Trill);
            }
        }
Пример #11
0
        private void WriteBeat(Voice voice, Beat beat, Measure measure, bool changeTempo)
        {
            Duration   duration = voice.Duration;
            NoteEffect effect   = new NoteEffect();

            for (int i = 0; i < voice.Notes.Count; i++)
            {
                var playedNote = voice.Notes[i];

                if (playedNote.Effect.IsFadeIn)
                {
                    effect.IsFadeIn = true;
                }
                if (playedNote.Effect.TremoloBar != null)
                {
                    effect.TremoloBar = playedNote.Effect.TremoloBar;
                }
                if (playedNote.Effect.IsTapping)
                {
                    effect.IsTapping = true;
                }
                if (playedNote.Effect.IsSlapping)
                {
                    effect.IsSlapping = true;
                }
                if (playedNote.Effect.IsPopping)
                {
                    effect.IsPopping = true;
                }
            }

            int flags = 0;

            if (duration.IsDotted || duration.IsDoubleDotted)
            {
                flags |= 0x01;
            }
            if (voice.Index == 0 && beat.Chord != null)
            {
                flags |= 0x02;
            }
            if (voice.Index == 0 && beat.Text != null)
            {
                flags |= 0x04;
            }
            if (beat.Stroke.Direction != Stroke.StrokeNone)
            {
                flags |= 0x08;
            }
            else if (effect.TremoloBar != null || effect.IsTapping || effect.IsSlapping || effect.IsPopping ||
                     effect.IsFadeIn)
            {
                flags |= 0x08;
            }
            if (changeTempo)
            {
                flags |= 0x10;
            }
            if (!duration.Division.Equals(DivisionType.Normal))
            {
                flags |= 0x20;
            }
            if (voice.IsEmpty || voice.IsRestVoice)
            {
                flags |= 0x40;
            }
            WriteUnsignedByte(flags);

            if ((flags & 0x40) != 0)
            {
                WriteUnsignedByte((voice.IsEmpty ? 0x00 : 0x02));
            }
            WriteByte(ParseDuration(duration));
            if ((flags & 0x20) != 0)
            {
                WriteInt(duration.Division.Enters);
            }

            if ((flags & 0x02) != 0)
            {
                WriteChord(beat.Chord);
            }

            if ((flags & 0x04) != 0)
            {
                WriteText(beat.Text);
            }

            if ((flags & 0x08) != 0)
            {
                WriteBeatEffects(beat, effect);
            }

            if ((flags & 0x10) != 0)
            {
                WriteMixChange(measure.Header.Tempo);
            }
            int stringFlags = 0;

            if (!voice.IsRestVoice)
            {
                for (int i = 0; i < voice.Notes.Count; i++)
                {
                    Note playedNote = voice.Notes[i];
                    int  str        = (7 - playedNote.Str);
                    stringFlags |= (1 << str);
                }
            }
            WriteUnsignedByte(stringFlags);
            for (int i = 6; i >= 0; i--)
            {
                if ((stringFlags & (1 << i)) != 0)
                {
                    for (int n = 0; n < voice.Notes.Count; n++)
                    {
                        var playedNote = voice.Notes[n];
                        if (playedNote.Str == (6 - i + 1))
                        {
                            WriteNote(playedNote);
                            break;
                        }
                    }
                }
            }

            SkipBytes(2);
        }