protected Track ReadTrack(int number)
        {
            Track track = new Track();

            track.Header = ReadByte();
            //TODO: move this code into header's setter
            track.IsDrumsTrack = ((track.Header & 0x01) != 0);
            track.Is12StringedGuitarTrack = ((track.Header & 0x02) != 0);
            track.IsBanjoTrack = ((track.Header & 0x04) != 0);

            stream.ReadByte();
            /*stream.ReadByte();
            stream.ReadByte();*/
            track.Name = ReadString(40).TrimEnd('\0');
            track.StringNumber = ReadInt();
            for (int i = 0; i < 7; i++)
                track.StringTuning[i] = ReadInt();

            track.Port = ReadInt();
            track.Channel = ReadInt();
            track.ChannelEffects = ReadInt();
            track.FretsNumber = ReadInt();
            track.CapoHeight = ReadInt();
            track.Color = ReadColor();
            return track;
        }
        public static TabFile CreateFromGp(Stream stream)
        {
            TabFile file = new TabFile();

            var gpFile = GpFactory.CreateFile(stream);
            int tracksCount = gpFile.Body.Tracks.Length;
            int measureTrackPairsCount = gpFile.Body.MeasureTrackPairs.Length;
            int measureCount = gpFile.Body.Measures.Length;
            //tracks init
            for (int i = 0; i < tracksCount; i++)
            {
                //TODO: init track header
                Track track = new Track
                {
                    Index = i,
                    Name = gpFile.Body.Tracks[i].Name,
                    IsDrum = gpFile.Body.Tracks[i].IsDrumsTrack,
                    StringNumber = gpFile.Body.Tracks[i].StringNumber
                };
                for (int j = 0; j < measureCount; j++)
                {
                    // if ((j + i) % tracksCount != 0)
                    //     continue;//other track measure
                    //TODO init measure
                    Measure measure = new Measure();
                    measure.NumeratorSignature = gpFile.Body.Measures[j].NumeratorSignature;
                    measure.DenominatorSignature = gpFile.Body.Measures[j].DenominatorSignature;
                    measure.StringsNumber = gpFile.Body.Tracks[i].StringNumber; //TODO: ambiguous usage
                    foreach (var gpBeat in gpFile.Body.MeasureTrackPairs[j * tracksCount + i].Beats)
                    {
                        //TODO init beat
                        Beat beat = new Beat();
                        beat.Duration = (Tablature.Duration)gpBeat.Duration;
                        beat.Tuplet = gpBeat.NTuplet;
                        beat.IsDotted = gpBeat.DottedNotes;
                        //TODO this is for 6-strings only
                        var stringCount = gpBeat.Strings.Length;
                        beat.Notes = new List<Note>();
                        for (int s = 0; s < stringCount; s++)
                            beat.Notes.Add(new Note() { Fret = "" });

                        int noteIndex = 0;
                        for (int stringIndex = 0; stringIndex < stringCount; stringIndex++)
                        {
                            var gpIdx = stringCount-1-stringIndex;
                            if (!gpBeat.Strings[gpIdx])
                                continue;

                            var effects = gpBeat.Notes[noteIndex].Effects ?? new EffectsOnNote();
                            beat.Notes[stringIndex] = new Note()
                            {
                                Fret = gpBeat.Notes[noteIndex].FretNumber.ToString(),
                                IsLegato = effects.HammerOnPullOff,
                                Bend = effects.Bend == null ? null : new Bend(),
                                Slide = effects.Slide ==
                                PhoneGuitarTab.Tablature.GuitarPro.Slide.NoSlide ? null : new Slide()
                            };
                            noteIndex++;
                        }

                        measure.Beats.Add(beat);
                    }
                    track.Measures.Add(measure);
                }
                file.Tracks.Add(track);
            }
            return file;
        }
        protected Track ReadTrack(int number)
        {
            Track track = new Track();

            track.Header = ReadByte();
            if (number == 1 || Version.Minor == "00")
                Skip(1);
            //TODO: move this code into header's setter
            track.IsDrumsTrack = ((track.Header & 0x01) != 0);
            track.Is12StringedGuitarTrack = ((track.Header & 0x02) != 0);
            track.IsBanjoTrack = ((track.Header & 0x04) != 0);

            //NOTE ???
            if (number != 1)
                stream.ReadByte();

            track.Name = ReadString(40).TrimEnd('\0');
            track.StringNumber = ReadInt();
            for (int i = 0; i < 7; i++)
                track.StringTuning[i] = ReadInt();

            track.Port = ReadInt();
            track.Channel = ReadChannel();
            ReadInt();
            ReadInt();
            track.Color = ReadColor();
            Skip((Version.Minor != "00") ? 49 : 44);
            if (Version.Minor != "00")
            {
                ReadHeaderEntry();
                ReadHeaderEntry();
            }

            return track;
        }
        protected Beat ReadBeat(int voiceIndex, Track track)
        {
            Beat beat = new Beat();
            //Voice voice = new Voice() { Index = voiceIndex };
            var header = ReadByte();
            beat.Header = header;

            // Beat status
            if ((header & 0x40) != 0)
            {
                int beatStatus = ReadByte();
                //beat.EmptyBit = beatStatus == 0x00;
                // voice.Empty = (beatStatus & 0x02) == 0;
                beat.EmptyBit = (beatStatus & 0x02) == 0;
                beat.RestBit = beatStatus == 0x02;
            }

            // Dotted notes
            beat.DottedNotes = ((header & 0x01) != 0);

            // Beat duration
            //TODO different!
            beat.Duration = ReadDuration();

            // N-Tuplet
            if ((header & 0x20) != 0)
                beat.NTuplet = ReadInt();

            // Chord diagram
            if ((header & 0x02) != 0)
                beat.ChordDiagram = ReadChordDiagram();

            // Text
            if ((header & 0x04) != 0)
                beat.Text = ReadHeaderEntry();

            // Effects on the beat
            if ((header & 0x08) != 0)
                beat.Effects = ReadEffectsOnBeat();

            // Mix table change
            if ((header & 0x10) != 0)
                beat.MixTableChange = ReadMixTableChange();

            /*byte stringFlags = ReadByte();
            beat.Notes = new Note[7];
            for (int i = 6; i >= 0; i--)
            {
                if ((stringFlags & (1 << i)) != 0 && (6 - i) < 6) //TODO strings count
                {
                    beat.Notes[0] = ReadNote();
                    //voice.Notes.Add(note);
                }
            }*/

            byte stringsPlayed = ReadByte();
            /* byte numberOfStrings = 0;
             byte stringCount = 6;
             for (int i = 0; i < 7; i++)
             {
                 if (((stringsPlayed & (1 << i)) != 0)&&( i < stringCount))
                 {
                     numberOfStrings++;
                     beat.Strings[i] = true;
                 }
             }

             // Gets the corresponding notes
             beat.Notes = new Note[numberOfStrings];
             for (int i = 0; i < numberOfStrings; i++)
                 beat.Notes[i] = ReadNote();*/

            int stringCount = track.StringNumber;
            List<Note> notes = new List<Note>();
            for (int i = 6; i >= 0; i--)
                if (((stringsPlayed & (1 << i)) != 0) && ((6 - i) < stringCount))
                {
                    beat.Strings[i] = true;
                    notes.Add(ReadNote());
                }

            beat.Notes = notes.ToArray();

            Skip(1);

            int read = ReadByte();
            //if (read == 8 || read == 10)
            if ((read & 0x08) != 0)
                Skip(1);

            return beat;
        }
        protected MeasureTrackPair ReadMeasureTrackPair(Track track)
        {
            MeasureTrackPair pair = new MeasureTrackPair();
            pair.Beats = new List<Beat>();
            for (int voice = 0; voice < 2; voice++)
            {
                var beatsNumber = ReadInt();

                for (int i = 0; i < beatsNumber; i++)
                {
                    var beat = ReadBeat(voice, track);
                    //if (beat.Notes.Count() > 0)
                    if (!beat.EmptyBit)
                        pair.Beats.Add(beat);
                }
            }
            //pair.Beats = pair.Beats.Where(b => !b.RestBit).ToList();
            //NOTE add code is here
            /* List emptyBeats = new List<Beat>();
             for (int i = 0; i < pair.Beats.Count(); i++)
             {
                 TGBeat beat = measure.getBeat(i);
                 boolean empty = true;
                 for (int v = 0; v < beat.countVoices(); v++)
                 {
                     if (!beat.getVoice(v).isEmpty())
                     {
                         empty = false;
                     }
                 }
                 if (empty)
                 {
                     emptyBeats.add(beat);
                 }
             }
             Iterator it = emptyBeats.iterator();
             while (it.hasNext())
             {
                 TGBeat beat = (TGBeat)it.next();
                 measure.removeBeat(beat);
             }
             )*/
            return pair;
        }
Esempio n. 6
0
        public static TabFile CreateFromGp(Stream stream)
        {
            TabFile file = new TabFile();

            var gpFile                 = GpFactory.CreateFile(stream);
            int tracksCount            = gpFile.Body.Tracks.Length;
            int measureTrackPairsCount = gpFile.Body.MeasureTrackPairs.Length;
            int measureCount           = gpFile.Body.Measures.Length;

            //tracks init
            for (int i = 0; i < tracksCount; i++)
            {
                //TODO: init track header
                Track track = new Track
                {
                    Index        = i,
                    Name         = gpFile.Body.Tracks[i].Name,
                    IsDrum       = gpFile.Body.Tracks[i].IsDrumsTrack,
                    StringNumber = gpFile.Body.Tracks[i].StringNumber
                };
                for (int j = 0; j < measureCount; j++)
                {
                    // if ((j + i) % tracksCount != 0)
                    //     continue;//other track measure
                    //TODO init measure
                    Measure measure = new Measure();
                    measure.NumeratorSignature   = gpFile.Body.Measures[j].NumeratorSignature;
                    measure.DenominatorSignature = gpFile.Body.Measures[j].DenominatorSignature;
                    measure.StringsNumber        = gpFile.Body.Tracks[i].StringNumber; //TODO: ambiguous usage
                    foreach (var gpBeat in gpFile.Body.MeasureTrackPairs[j * tracksCount + i].Beats)
                    {
                        //TODO init beat
                        Beat beat = new Beat();
                        beat.Duration = (Tablature.Duration)gpBeat.Duration;
                        beat.Tuplet   = gpBeat.NTuplet;
                        beat.IsDotted = gpBeat.DottedNotes;
                        //TODO this is for 6-strings only
                        var stringCount = gpBeat.Strings.Length;
                        beat.Notes = new List <Note>();
                        for (int s = 0; s < stringCount; s++)
                        {
                            beat.Notes.Add(new Note()
                            {
                                Fret = ""
                            });
                        }

                        int noteIndex = 0;
                        for (int stringIndex = 0; stringIndex < stringCount; stringIndex++)
                        {
                            var gpIdx = stringCount - 1 - stringIndex;
                            if (!gpBeat.Strings[gpIdx])
                            {
                                continue;
                            }

                            var effects = gpBeat.Notes[noteIndex].Effects ?? new EffectsOnNote();
                            beat.Notes[stringIndex] = new Note()
                            {
                                Fret     = gpBeat.Notes[noteIndex].FretNumber.ToString(),
                                IsLegato = effects.HammerOnPullOff,
                                Bend     = effects.Bend == null ? null : new Bend(),
                                Slide    = effects.Slide ==
                                           PhoneGuitarTab.Tablature.GuitarPro.Slide.NoSlide ? null : new Slide()
                            };
                            noteIndex++;
                        }

                        measure.Beats.Add(beat);
                    }
                    track.Measures.Add(measure);
                }
                file.Tracks.Add(track);
            }
            return(file);
        }