A beat is a single block within a bar. A beat is a combination of several notes played at the same time.
Example #1
0
 public void AddBeat(Beat beat)
 {
     // chaining
     beat.Voice = this;
     beat.Index = Beats.Count;
     Beats.Add(beat);
 }
Example #2
0
        private int FindStringForValue(Track track, Beat beat, int value)
        {
            // find strings which are already taken
            var takenStrings = new FastDictionary<int, bool>();
            for (int i = 0; i < beat.Notes.Count; i++)
            {
                var note = beat.Notes[i];
                takenStrings[note.String] = true;
            }

            // find a string where the note matches into 0 to <upperbound>

            // first try to find a string from 0-14 (more handy to play)
            // then try from 0-20 (guitars with high frets)
            // then unlimited
            int[] steps = { 14, 20, int.MaxValue };
            for (int i = 0; i < steps.Length; i++)
            {
                for (int j = 0; j < track.Tuning.Length; j++)
                {
                    if (!takenStrings.ContainsKey(j))
                    {
                        var min = track.Tuning[j];
                        var max = track.Tuning[j] + steps[i];

                        if (value >= min && value <= max)
                        {
                            return track.Tuning.Length - j;
                        }
                    }
                }
            }
            // will not happen
            return 1;
        }
Example #3
0
 public BeatContainerGlyph(Beat beat, VoiceContainerGlyph voiceContainer, bool useLayoutingInfo = false)
     : base(0, 0)
 {
     Beat = beat;
     Ties = new FastList<Glyph>();
     VoiceContainer = voiceContainer;
     UseLayoutingInfo = useLayoutingInfo;
 }
 public bool ShouldCreateGlyph(EffectBarRenderer renderer, Beat beat)
 {
     return beat.Index == 0 &&
         (
             (beat.Voice.Bar.MasterBar.Index == 0 && beat.Voice.Bar.MasterBar.TripletFeel != TripletFeel.NoTripletFeel)
             || (beat.Voice.Bar.MasterBar.Index > 0 && beat.Voice.Bar.MasterBar.TripletFeel != beat.Voice.Bar.MasterBar.PreviousMasterBar.TripletFeel)
         );
 }
Example #5
0
 public BeamDirection GetBeatDirection(Beat beat)
 {
     ScoreBeatGlyph g = (ScoreBeatGlyph)GetOnNotesPosition(beat.Voice.Index, beat.Index);
     if (g != null)
     {
         return g.NoteHeads.Direction;
     }
     return BeamDirection.Up;
 }
Example #6
0
 public float GetBeatX(Beat beat)
 {
     var bg = (TabBeatGlyph)GetPreNotesPosition(beat.Voice.Index, beat.Index);
     if (bg != null)
     {
         return bg.Container.X + bg.X;
     }
     return 0;
 }
 protected override bool ShouldCreateGlyphForNote(EffectBarRenderer renderer, Note note)
 {
     if (!note.IsHarmonic) return false;
     if (note.Beat != _beat || note.HarmonicType > _beatType)
     {
         _beat = note.Beat;
         _beatType = note.HarmonicType;
     }
     return true;
 }
Example #8
0
 public virtual bool ShouldCreateGlyph(EffectBarRenderer renderer, Beat beat)
 {
     LastCreateInfo = new FastList<Note>();
     for (int i = 0, j = beat.Notes.Count; i < j; i++)
     {
         var n = beat.Notes[i];
         if (ShouldCreateGlyphForNote(renderer, n))
         {
             LastCreateInfo.Add(n);
         }
     }
     return LastCreateInfo.Count > 0;
 }
Example #9
0
 public EffectGlyph CreateNewGlyph(EffectBarRenderer renderer, Beat beat)
 {
     int tempo;
     if (beat.Voice.Bar.MasterBar.TempoAutomation != null)
     {
         tempo = (int)(beat.Voice.Bar.MasterBar.TempoAutomation.Value);
     }
     else
     {
         tempo = beat.Voice.Bar.Staff.Track.Score.Tempo;
     }
     return new TempoGlyph(0, 0, tempo);
 }
Example #10
0
 public EffectGlyph CreateNewGlyph(EffectBarRenderer renderer, Beat beat)
 {
     var res = renderer.Resources;
     if (beat.Slap)
     {
         return new TextGlyph(0, 0, "S", res.EffectFont);
     }
     if (beat.Pop)
     {
         return new TextGlyph(0, 0, "P", res.EffectFont);
     }
     return new TextGlyph(0, 0, "T", res.EffectFont);
 }
Example #11
0
 public bool Check(Beat beat)
 {
     if (Beats.Count == 0)
     {
         Tuplet = beat.TupletNumerator;
     }
     else if (beat.Voice.Index != VoiceIndex || beat.TupletNumerator != Tuplet || IsFull || _isFinished)
     {
         return false;
     }
     Beats.Add(beat);
     return true;
 }
Example #12
0
        public void AddGraceBeat(Beat beat)
        {
            if (Beats.Count == 0)
            {
                AddBeat(beat);
                return;
            }

            // remove last beat
            var lastBeat = Beats[Beats.Count - 1];
            Beats.RemoveAt(Beats.Count - 1);

            // insert grace beat
            AddBeat(beat);
            // reinsert last beat
            AddBeat(lastBeat);
        }
Example #13
0
 private void Chain(Beat beat)
 {
     if (Bar == null) return;
     if (Bar.Index == 0 && beat.Index == 0)
     {
         // very first beat
         beat.PreviousBeat = null; 
     }
     else if (beat.Index == 0)
     {
         // first beat of bar
         var previousVoice = Bar.PreviousBar.Voices[Index];
         beat.PreviousBeat = previousVoice.Beats[previousVoice.Beats.Count - 1];
         beat.PreviousBeat.NextBeat = beat;
     }
     else
     {
         // other beats of bar
         beat.PreviousBeat = Beats[beat.Index - 1];
         beat.PreviousBeat.NextBeat = beat;
     }
 }
Example #14
0
 private void ParseDynamics(IXmlNode element, Beat beat)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "p":
                     beat.Dynamic = DynamicValue.P;
                     break;
                 case "pp":
                     beat.Dynamic = DynamicValue.PP;
                     break;
                 case "ppp":
                     beat.Dynamic = DynamicValue.PPP;
                     break;
                 case "f":
                     beat.Dynamic = DynamicValue.F;
                     break;
                 case "ff":
                     beat.Dynamic = DynamicValue.FF;
                     break;
                 case "fff":
                     beat.Dynamic = DynamicValue.FFF;
                     break;
                 case "mp":
                     beat.Dynamic = DynamicValue.MP;
                     break;
                 case "mf":
                     beat.Dynamic = DynamicValue.MF;
                     break;
             }
         }
     });
 }
Example #15
0
 public override void ExpandTo(Beat beat)
 {
     _isExpanded = true;
 }
Example #16
0
        public Score JsObjectToScore(Score score)
        {
            var score2 = new Score();

            Score.CopyTo(score, score2);

            #region MasterBars

            for (var i = 0; i < score.MasterBars.Count; i++)
            {
                var masterBar  = score.MasterBars[i];
                var masterBar2 = new MasterBar();
                MasterBar.CopyTo(masterBar, masterBar2);
                if (masterBar.TempoAutomation != null)
                {
                    masterBar2.TempoAutomation = new Automation();
                    Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation);
                }
                if (masterBar.VolumeAutomation != null)
                {
                    masterBar2.VolumeAutomation = new Automation();
                    Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation);
                }
                if (masterBar.Section != null)
                {
                    masterBar2.Section = new Section();
                    Section.CopyTo(masterBar.Section, masterBar2.Section);
                }
                score2.AddMasterBar(masterBar2);
            }

            #endregion

            #region Tracks

            for (int t = 0; t < score.Tracks.Count; t++)
            {
                var track  = score.Tracks[t];
                var track2 = new Track();
                Track.CopyTo(track, track2);
                score2.AddTrack(track2);

                PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo);

                foreach (var key in track.Chords.Keys)
                {
                    var chord  = track.Chords[key];
                    var chord2 = new Chord();
                    Chord.CopyTo(chord, chord2);
                    track2.Chords[key] = chord2;
                }

                #region Bars

                for (int b = 0; b < track.Bars.Count; b++)
                {
                    var bar  = track.Bars[b];
                    var bar2 = new Bar();
                    Bar.CopyTo(bar, bar2);
                    track2.AddBar(bar2);

                    #region Voices

                    for (int v = 0; v < bar.Voices.Count; v++)
                    {
                        var voice  = bar.Voices[v];
                        var voice2 = new Voice();
                        Voice.CopyTo(voice, voice2);
                        bar2.AddVoice(voice2);

                        #region Beats

                        for (int bb = 0; bb < voice.Beats.Count; bb++)
                        {
                            var beat  = voice.Beats[bb];
                            var beat2 = new Beat();
                            Beat.CopyTo(beat, beat2);
                            voice2.AddBeat(beat2);

                            for (int a = 0; a < beat.Automations.Count; a++)
                            {
                                var automation = new Automation();
                                Automation.CopyTo(beat.Automations[a], automation);
                                beat2.Automations.Add(automation);
                            }

                            for (int i = 0; i < beat.WhammyBarPoints.Count; i++)
                            {
                                var point = new BendPoint();
                                BendPoint.CopyTo(beat.WhammyBarPoints[i], point);
                                beat2.WhammyBarPoints.Add(point);
                            }

                            #region Notes

                            for (int n = 0; n < beat.Notes.Count; n++)
                            {
                                var note  = beat.Notes[n];
                                var note2 = new Note();
                                Note.CopyTo(note, note2);
                                beat2.AddNote(note2);

                                for (int i = 0; i < note.BendPoints.Count; i++)
                                {
                                    var point = new BendPoint();
                                    BendPoint.CopyTo(note.BendPoints[i], point);
                                    note2.BendPoints.Add(point);
                                }
                            }

                            #endregion
                        }

                        #endregion
                    }

                    #endregion
                }

                #endregion
            }

            #endregion

            score2.Finish();
            return(score2);
        }
Example #17
0
        private void Beat(Voice voice)
        {
            // duration specifier?
            if (_sy == AlphaTexSymbols.DoubleDot)
            {
                NewSy();
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("duration", AlphaTexSymbols.Number);
                }

                var duration = (int)_syData;
                switch (duration)
                {
                    case 1:
                    case 2:
                    case 4:
                    case 8:
                    case 16:
                    case 32:
                    case 64:
                        _currentDuration = ParseDuration((int)_syData);
                        break;
                    default:
                        Error("duration", AlphaTexSymbols.Number, false);
                        break;
                }

                NewSy();
                return;
            }

            var beat = new Beat();
            voice.AddBeat(beat);

            if (voice.Bar.MasterBar.TempoAutomation != null && voice.Beats.Count == 1)
            {
                beat.Automations.Add(voice.Bar.MasterBar.TempoAutomation);
            }

            // notes
            if (_sy == AlphaTexSymbols.LParensis)
            {
                NewSy();

                Note(beat);
                while (_sy != AlphaTexSymbols.RParensis && _sy != AlphaTexSymbols.Eof)
                {
                    Note(beat);
                }

                if (_sy != AlphaTexSymbols.RParensis)
                {
                    Error("note-list", AlphaTexSymbols.RParensis);
                }
                NewSy();
            }
            // rest 
            else if (_sy == AlphaTexSymbols.String && _syData.ToString().ToLower() == "r")
            {
                // rest voice -> no notes 
                NewSy();
            }
            else
            {
                Note(beat);
            }

            // new duration
            if (_sy == AlphaTexSymbols.Dot)
            {
                NewSy();
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("duration", AlphaTexSymbols.Number);
                }

                var duration = (int)_syData;
                switch (duration)
                {
                    case 1:
                    case 2:
                    case 4:
                    case 8:
                    case 16:
                    case 32:
                    case 64:
                        _currentDuration = ParseDuration((int)_syData);
                        break;
                    default:
                        Error("duration", AlphaTexSymbols.Number, false);
                        break;
                }

                NewSy();
            }
            beat.Duration = _currentDuration;

            // beat multiplier (repeat beat n times)
            var beatRepeat = 1;
            if (_sy == AlphaTexSymbols.Multiply)
            {
                NewSy();

                // multiplier count
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("multiplier", AlphaTexSymbols.Number);
                }
                else
                {
                    beatRepeat = (int)_syData;
                }
                NewSy();
            }

            BeatEffects(beat);

            for (var i = 0; i < beatRepeat - 1; i++)
            {
                voice.AddBeat(beat.Clone());
            }
        }
Example #18
0
 private void ParseTimeModification(IXmlNode element, Beat beat)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "actual-notes":
                     beat.TupletNumerator = Std.ParseInt(Std.GetNodeValue(c));
                     break;
                 case "normal-notes":
                     beat.TupletDenominator = Std.ParseInt(Std.GetNodeValue(c));
                     break;
                     //case "normal-type":
                     //    break;
                     //case "normal-dot":
                     //    break;
             }
         }
     });
 }
Example #19
0
 /// <summary>
 /// Checks whether the current beat is timewise before the given beat.
 /// </summary>
 /// <param name="beat"></param>
 /// <returns></returns>
 internal bool IsBefore(Beat beat)
 {
     return(Voice.Bar.Index < beat.Voice.Bar.Index ||
            (beat.Voice.Bar.Index == Voice.Bar.Index && Index < beat.Index));
 }
Example #20
0
        private bool ParseNoteBeat(IXmlNode element, Track track, Bar bar, bool chord, bool isFirstBeat)
        {
            int voiceIndex = 0;
            var voiceNodes = element.GetElementsByTagName("voice");
            if (voiceNodes.Length > 0)
            {
                voiceIndex = Std.ParseInt(Std.GetNodeValue(voiceNodes[0])) - 1;
            }

            Beat beat;
            var voice = GetOrCreateVoice(bar, voiceIndex);
            if (chord || (isFirstBeat && voice.Beats.Count == 1))
            {
                beat = voice.Beats[voice.Beats.Count - 1];
            }
            else
            {
                beat = new Beat();
                voice.AddBeat(beat);
            }

            var note = new Note();
            beat.AddNote(note);
            beat.IsEmpty = false;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "grace":
                            //var slash = e.GetAttribute("slash");
                            //var makeTime = Std.ParseInt(e.GetAttribute("make-time"));
                            //var stealTimePrevious = Std.ParseInt(e.GetAttribute("steal-time-previous"));
                            //var stealTimeFollowing = Std.ParseInt(e.GetAttribute("steal-time-following"));
                            beat.GraceType = GraceType.BeforeBeat;
                            beat.Duration = Duration.ThirtySecond;
                            break;
                        case "duration":
                            beat.Duration = (Duration)Std.ParseInt(Std.GetNodeValue(c));
                            break;
                        case "tie":
                            ParseTied(c, note);
                            break;
                        case "cue":
                            // not supported
                            break;
                        case "instrument":
                            // not supported
                            break;
                        case "type":
                            switch (Std.GetNodeValue(c))
                            {
                                case "256th":
                                    beat.Duration = Duration.TwoHundredFiftySixth;
                                    break;
                                case "128th":
                                    beat.Duration = Duration.OneHundredTwentyEighth;
                                    break;
                                case "breve":
                                    beat.Duration = Duration.DoubleWhole;
                                    break;
                                case "long":
                                    beat.Duration = Duration.QuadrupleWhole;
                                    break;
                                case "64th":
                                    beat.Duration = Duration.SixtyFourth;
                                    break;
                                case "32nd":
                                    beat.Duration = Duration.ThirtySecond;
                                    break;
                                case "16th":
                                    beat.Duration = Duration.Sixteenth;
                                    break;
                                case "eighth":
                                    beat.Duration = Duration.Eighth;
                                    break;
                                case "quarter":
                                    beat.Duration = Duration.Quarter;
                                    break;
                                case "half":
                                    beat.Duration = Duration.Half;
                                    break;
                                case "whole":
                                    beat.Duration = Duration.Whole;
                                    break;
                            }
                            break;
                        case "dot":
                            note.IsStaccato = true;
                            break;
                        case "accidental":
                            ParseAccidental(c, note);
                            break;
                        case "time-modification":
                            ParseTimeModification(c, beat);
                            break;
                        case "stem":
                            // not supported
                            break;
                        case "notehead":
                            if (c.GetAttribute("parentheses") == "yes")
                            {
                                note.IsGhost = true;
                            }
                            break;
                        case "beam":
                            // not supported
                            break;
                        case "notations":
                            ParseNotations(c, beat, note);
                            break;
                        case "lyric":
                            // not supported
                            break;
                        // "full-note"
                        case "chord":
                            chord = true;
                            break;
                        case "pitch":
                            ParsePitch(c, track, beat, note);
                            break;
                        case "unpitched":
                            // TODO: not yet fully supported
                            note.String = 0;
                            note.Fret = 0;
                            break;
                        case "rest":
                            beat.IsEmpty = false;
                            break;
                    }
                }
            });

            return chord;
        }
Example #21
0
 /// <summary>
 /// Checks whether the current beat is timewise after the given beat.
 /// </summary>
 /// <param name="beat"></param>
 /// <returns></returns>
 internal bool IsAfter(Beat beat)
 {
     return(Voice.Bar.Index > beat.Voice.Bar.Index ||
            (beat.Voice.Bar.Index == Voice.Bar.Index && Index > beat.Index));
 }
Example #22
0
        public Score ScoreToJsObject(Score score)
        {
            Score score2 = NewObject();

            Score.CopyTo(score, score2);
            score2.MasterBars = new FastList <MasterBar>();
            score2.Tracks     = new FastList <Track>();

            #region MasterBars

            for (var i = 0; i < score.MasterBars.Count; i++)
            {
                MasterBar masterBar  = score.MasterBars[i];
                MasterBar masterBar2 = NewObject();
                MasterBar.CopyTo(masterBar, masterBar2);
                if (masterBar.TempoAutomation != null)
                {
                    masterBar2.TempoAutomation = NewObject();
                    Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation);
                }
                if (masterBar.VolumeAutomation != null)
                {
                    masterBar2.VolumeAutomation = NewObject();
                    Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation);
                }
                if (masterBar.Section != null)
                {
                    masterBar2.Section = NewObject();
                    Section.CopyTo(masterBar.Section, masterBar2.Section);
                }
                score2.MasterBars.Add(masterBar2);
            }

            #endregion

            #region Tracks

            for (int t = 0; t < score.Tracks.Count; t++)
            {
                var   track  = score.Tracks[t];
                Track track2 = NewObject();
                track2.Color = NewObject();
                Track.CopyTo(track, track2);

                track2.PlaybackInfo = NewObject();
                PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo);

                track2.Chords = new FastDictionary <string, Chord>();
                foreach (var key in track.Chords.Keys)
                {
                    var   chord  = track.Chords[key];
                    Chord chord2 = NewObject();
                    Chord.CopyTo(chord, chord2);
                    track2.Chords[key] = chord;
                }

                #region Bars

                track2.Bars = new FastList <Bar>();
                for (int b = 0; b < track.Bars.Count; b++)
                {
                    var bar  = track.Bars[b];
                    Bar bar2 = NewObject();
                    Bar.CopyTo(bar, bar2);

                    #region Voices

                    bar2.Voices = new FastList <Voice>();
                    for (int v = 0; v < bar.Voices.Count; v++)
                    {
                        var   voice  = bar.Voices[v];
                        Voice voice2 = NewObject();
                        Voice.CopyTo(voice, voice2);

                        #region Beats

                        voice2.Beats = new FastList <Beat>();
                        for (int bb = 0; bb < voice.Beats.Count; bb++)
                        {
                            var  beat  = voice.Beats[bb];
                            Beat beat2 = NewObject();
                            Beat.CopyTo(beat, beat2);

                            beat2.Automations = new FastList <Automation>();
                            for (int a = 0; a < beat.Automations.Count; a++)
                            {
                                Automation automation = NewObject();
                                Automation.CopyTo(beat.Automations[a], automation);
                                beat2.Automations.Add(automation);
                            }

                            beat2.WhammyBarPoints = new FastList <BendPoint>();
                            for (int i = 0; i < beat.WhammyBarPoints.Count; i++)
                            {
                                BendPoint point = NewObject();
                                BendPoint.CopyTo(beat.WhammyBarPoints[i], point);
                                beat2.WhammyBarPoints.Add(point);
                            }

                            #region Notes

                            beat2.Notes = new FastList <Note>();
                            for (int n = 0; n < beat.Notes.Count; n++)
                            {
                                var  note  = beat.Notes[n];
                                Note note2 = NewObject();
                                Note.CopyTo(note, note2);

                                note2.BendPoints = new FastList <BendPoint>();
                                for (int i = 0; i < note.BendPoints.Count; i++)
                                {
                                    BendPoint point = NewObject();
                                    BendPoint.CopyTo(note.BendPoints[i], point);
                                    note2.BendPoints.Add(point);
                                }

                                beat2.Notes.Add(note2);
                            }

                            #endregion

                            voice2.Beats.Add(beat2);
                        }

                        #endregion

                        bar2.Voices.Add(voice2);
                    }

                    #endregion

                    track2.Bars.Add(bar2);
                }

                #endregion

                score2.Tracks.Add(track2);
            }

            #endregion

            return(score2);
        }
Example #23
0
        private void ParseMeasure(IXmlNode element, Track track, bool isFirstMeasure)
        {
            var barIndex = 0;
            if (isFirstMeasure)
            {
                _trackFirstMeasureNumber = Std.ParseInt(element.GetAttribute("number"));
                barIndex = 0;
            }
            else
            {
                barIndex = Std.ParseInt(element.GetAttribute("number")) - _trackFirstMeasureNumber;
            }

            // create empty bars to the current index
            Bar bar = null;
            MasterBar masterBar = null;
            for (int i = track.Staves[0].Bars.Count; i <= barIndex; i++)
            {
                bar = new Bar();
                masterBar = GetOrCreateMasterBar(barIndex);
                track.AddBarToStaff(0, bar);

                for (int j = 0; j < _maxVoices; j++)
                {
                    var emptyVoice = new Voice();
                    bar.AddVoice(emptyVoice);
                    var emptyBeat = new Beat { IsEmpty = true };
                    emptyVoice.AddBeat(emptyBeat);
                }
            }

            bool chord = false;
            bool isFirstBeat = true;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "note":
                            chord = ParseNoteBeat(c, track, bar, chord, isFirstBeat);
                            isFirstBeat = false;
                            break;
                        case "forward":
                            break;
                        case "direction":
                            ParseDirection(c, masterBar);
                            break;
                        case "attributes":
                            ParseAttributes(c, bar, masterBar);
                            break;
                        case "harmony":
                            // TODO
                            break;
                        case "sound":
                            // TODO
                            break;
                        case "barline":
                            // TODO
                            break;
                    }
                }
            });
        }
Example #24
0
 private void ParseNotations(IXmlNode element, Beat beat, Note note)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "tied":
                     ParseTied(c, note);
                     break;
                 case "slide":
                     if (c.GetAttribute("type") == "start")
                     {
                         note.SlideType = SlideType.Legato;
                     }
                     break;
                 case "dynamics":
                     ParseDynamics(c, beat);
                     break;
             }
         }
     });
 }
Example #25
0
        /// <summary>
        /// Tries to apply a beat effect to the given beat.
        /// </summary>
        /// <returns>true if a effect could be applied, otherwise false</returns>
        private bool ApplyBeatEffect(Beat beat)
        {
            var syData = _syData.ToString().ToLower();
            if (syData == "f")
            {
                beat.FadeIn = true;
                NewSy();
                return true;
            }
            if (syData == "v")
            {
                beat.Vibrato = VibratoType.Slight;
                NewSy();
                return true;
            }
            if (syData == "s")
            {
                beat.Slap = true;
                NewSy();
                return true;
            }
            if (syData == "p")
            {
                beat.Pop = true;
                NewSy();
                return true;
            }
            if (syData == "dd")
            {
                beat.Dots = 2;
                NewSy();
                return true;
            }
            if (syData == "d")
            {
                beat.Dots = 1;
                NewSy();
                return true;
            }
            if (syData == "su")
            {
                beat.PickStroke = PickStrokeType.Up;
                NewSy();
                return true;
            }
            if (syData == "sd")
            {
                beat.PickStroke = PickStrokeType.Down;
                NewSy();
                return true;
            }
            if (syData == "tu")
            {
                NewSy();
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("tuplet", AlphaTexSymbols.Number);
                    return false;
                }
                var tuplet = (int)_syData;
                switch (tuplet)
                {
                    case 3:
                        beat.TupletDenominator = 3;
                        beat.TupletNumerator = 2;
                        break;
                    case 5:
                        beat.TupletDenominator = 5;
                        beat.TupletNumerator = 4;
                        break;
                    case 6:
                        beat.TupletDenominator = 6;
                        beat.TupletNumerator = 4;
                        break;
                    case 7:
                        beat.TupletDenominator = 7;
                        beat.TupletNumerator = 4;
                        break;
                    case 9:
                        beat.TupletDenominator = 9;
                        beat.TupletNumerator = 8;
                        break;
                    case 10:
                        beat.TupletDenominator = 10;
                        beat.TupletNumerator = 8;
                        break;
                    case 11:
                        beat.TupletDenominator = 11;
                        beat.TupletNumerator = 8;
                        break;
                    case 12:
                        beat.TupletDenominator = 12;
                        beat.TupletNumerator = 8;
                        break;
                }
                NewSy();
                return true;
            }
            if (syData == "tb")
            {
                // read points
                NewSy();
                if (_sy != AlphaTexSymbols.LParensis)
                {
                    Error("tremolobar-effect", AlphaTexSymbols.LParensis);
                    return false;
                }
                _allowNegatives = true;
                NewSy();

                while (_sy != AlphaTexSymbols.RParensis && _sy != AlphaTexSymbols.Eof)
                {
                    if (_sy != AlphaTexSymbols.Number)
                    {
                        Error("tremolobar-effect", AlphaTexSymbols.Number);
                        return false;
                    }
                    beat.WhammyBarPoints.Add(new BendPoint(0, (int)_syData));
                    NewSy();
                }

                while (beat.WhammyBarPoints.Count > 60)
                {
                    beat.WhammyBarPoints.RemoveAt(beat.WhammyBarPoints.Count - 1);
                }

                // set positions
                var count = beat.WhammyBarPoints.Count;
                var step = (60 / count);
                var i = 0;
                while (i < count)
                {
                    beat.WhammyBarPoints[i].Offset = Math.Min(60, (i * step));
                    i++;
                }
                _allowNegatives = false;

                if (_sy != AlphaTexSymbols.RParensis)
                {
                    Error("tremolobar-effect", AlphaTexSymbols.RParensis);
                    return false;
                }
                NewSy();
                return true;
            }
            return false;
        }
Example #26
0
 private void ApplyNoteStringFrets(Track track, Beat beat, Note note, int fullNoteValue)
 {
     note.String = FindStringForValue(track, beat, fullNoteValue);
     note.Fret = fullNoteValue - Note.GetStringTuning(track, note.String);
 }
Example #27
0
        internal void Finish(Settings settings)
        {
            _beatLookup = new FastDictionary <int, Beat>();
            for (var index = 0; index < Beats.Count; index++)
            {
                var beat = Beats[index];
                beat.Index = index;
                Chain(beat);
            }

            var currentDisplayTick  = 0;
            var currentPlaybackTick = 0;

            for (var i = 0; i < Beats.Count; i++)
            {
                var beat = Beats[i];
                beat.Index = i;
                beat.Finish(settings);

                if (beat.GraceType == GraceType.None || beat.GraceType == GraceType.BendGrace)
                {
                    beat.DisplayStart    = currentDisplayTick;
                    beat.PlaybackStart   = currentPlaybackTick;
                    currentDisplayTick  += beat.DisplayDuration;
                    currentPlaybackTick += beat.PlaybackDuration;
                }
                else
                {
                    // find note which is not a grace note
                    Beat nonGrace           = beat;
                    int  numberOfGraceBeats = 0;
                    while (nonGrace != null && nonGrace.GraceType != GraceType.None)
                    {
                        nonGrace = nonGrace.NextBeat;
                        numberOfGraceBeats++;
                    }

                    var graceDuration  = Duration.Eighth;
                    int stolenDuration = 0;
                    if (numberOfGraceBeats == 1)
                    {
                        graceDuration  = Duration.Eighth;
                        stolenDuration = Duration.ThirtySecond.ToTicks();
                    }
                    else if (numberOfGraceBeats == 2)
                    {
                        graceDuration  = Duration.Sixteenth;
                        stolenDuration = Duration.SixtyFourth.ToTicks();
                    }
                    else
                    {
                        graceDuration  = Duration.ThirtySecond;
                        stolenDuration = Duration.OneHundredTwentyEighth.ToTicks();
                    }


                    // grace beats have 1/4 size of the non grace beat following them
                    var perGraceDuration = nonGrace == null?Duration.ThirtySecond.ToTicks() : (nonGrace.DisplayDuration / 4) / numberOfGraceBeats;

                    // move all grace beats
                    for (int j = 0; j < numberOfGraceBeats; j++)
                    {
                        var graceBeat = Beats[j + i];
                        if (beat.PreviousBeat == null || beat.PreviousBeat.GraceType == GraceType.None)
                        {
                            graceBeat.Duration = graceDuration;
                            graceBeat.UpdateDurations();
                        }
                        graceBeat.DisplayStart    = currentDisplayTick - (numberOfGraceBeats - j + 1) * perGraceDuration;
                        graceBeat.DisplayDuration = perGraceDuration;
                    }

                    if (beat.PreviousBeat != null && beat.GraceType == GraceType.BeforeBeat)
                    {
                        beat.PreviousBeat.PlaybackDuration -= stolenDuration;
                    }

                    beat.PlaybackStart = currentPlaybackTick;
                    switch (beat.GraceType)
                    {
                    case GraceType.BeforeBeat:
                        beat.PlaybackStart -= beat.PlaybackDuration;
                        break;

                    case GraceType.OnBeat:
                        currentPlaybackTick += beat.PlaybackDuration;
                        break;
                    }
                }

                _beatLookup[beat.DisplayStart] = beat;
            }
        }
Example #28
0
        private void ParsePitch(IXmlNode element, Track track, Beat beat, Note note)
        {
            string step = null;
            int semitones = 0;
            int octave = 0;
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "step":
                            step = Std.GetNodeValue(c);
                            break;
                        case "alter":
                            semitones = Std.ParseInt(Std.GetNodeValue(c));
                            break;
                        case "octave":
                            // 0-9, 4 for middle C
                            octave = Std.ParseInt(Std.GetNodeValue(c));
                            break;
                    }
                }
            });

            var fullNoteName = step + octave;
            var fullNoteValue = TuningParser.GetTuningForText(fullNoteName) + semitones;

            ApplyNoteStringFrets(track, beat, note, fullNoteValue);
        }
Example #29
0
        private void ParseBeat(IXmlNode node)
        {
            var beat = new Beat();
            var beatId = node.Attributes.Get("id").Value;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Notes":
                            _notesOfBeat[beatId] = GetValue(c).Split(' ');
                            break;
                        case "Rhythm":
                            _rhythmOfBeat[beatId] = c.Attributes.Get("ref").Value;
                            break;
                        case "Fadding":
                            if (GetValue(c) == "FadeIn")
                            {
                                beat.FadeIn = true;
                            }
                            break;
                        case "Tremolo":
                            switch (GetValue(c))
                            {
                                case "1/2":
                                    beat.TremoloSpeed = Duration.Eighth;
                                    break;
                                case "1/4":
                                    beat.TremoloSpeed = Duration.Sixteenth;
                                    break;
                                case "1/8":
                                    beat.TremoloSpeed = Duration.ThirtySecond;
                                    break;
                            }
                            break;
                        case "Chord":
                            beat.ChordId = GetValue(c);
                            break;
                        case "Hairpin":
                            switch (GetValue(c))
                            {
                                case "Crescendo":
                                    beat.Crescendo = CrescendoType.Crescendo;
                                    break;
                                case "Decrescendo":
                                    beat.Crescendo = CrescendoType.Decrescendo;
                                    break;
                            }
                            break;
                        case "Arpeggio":
                            if (GetValue(c) == "Up")
                            {
                                beat.BrushType = BrushType.ArpeggioUp;
                            }
                            else
                            {
                                beat.BrushType = BrushType.ArpeggioDown;
                            }
                            break;
                        // TODO: brushDuration
                        case "Properties":
                            ParseBeatProperties(c, beat);
                            break;
                        case "FreeText":
                            beat.Text = GetValue(c);
                            break;
                        case "Dynamic":
                            switch (GetValue(c))
                            {
                                case "PPP":
                                    beat.Dynamic = DynamicValue.PPP;
                                    break;
                                case "PP":
                                    beat.Dynamic = DynamicValue.PP;
                                    break;
                                case "P":
                                    beat.Dynamic = DynamicValue.P;
                                    break;
                                case "MP":
                                    beat.Dynamic = DynamicValue.MP;
                                    break;
                                case "MF":
                                    beat.Dynamic = DynamicValue.MF;
                                    break;
                                case "F":
                                    beat.Dynamic = DynamicValue.F;
                                    break;
                                case "FF":
                                    beat.Dynamic = DynamicValue.FF;
                                    break;
                                case "FFF":
                                    beat.Dynamic = DynamicValue.FFF;
                                    break;
                            }
                            break;
                        case "GraceNotes":
                            switch (GetValue(c))
                            {
                                case "OnBeat":
                                    beat.GraceType = GraceType.OnBeat;
                                    break;
                                case "BeforeBeat":
                                    beat.GraceType = GraceType.BeforeBeat;
                                    break;
                            }
                            break;
                    }
                }
            });

            _beatById[beatId] = beat;
        }
Example #30
0
        private void Bar()
        {
            var master = new MasterBar();
            _score.AddMasterBar(master);

            var bar = new Bar();
            _track.AddBar(bar);

            if (master.Index > 0)
            {
                master.KeySignature = master.PreviousMasterBar.KeySignature;
                master.TimeSignatureDenominator = master.PreviousMasterBar.TimeSignatureDenominator;
                master.TimeSignatureNumerator = master.PreviousMasterBar.TimeSignatureNumerator;
                bar.Clef = bar.PreviousBar.Clef;
            }
            BarMeta(bar);

            var voice = new Voice();
            bar.AddVoice(voice);

            while (_sy != AlphaTexSymbols.Pipe && _sy != AlphaTexSymbols.Eof)
            {
                Beat(voice);
            }

            if (voice.Beats.Count == 0)
            {
                var emptyBeat = new Beat();
                emptyBeat.IsEmpty = true;
                voice.AddBeat(emptyBeat);
            }
        }
Example #31
0
        private void ParseBeatProperties(IXmlNode node, Beat beat)
        {
            bool isWhammy = false;
            BendPoint whammyOrigin = null;
            int? whammyMiddleValue = null;
            int? whammyMiddleOffset1 = null;
            int? whammyMiddleOffset2 = null;
            BendPoint whammyDestination = null;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Property":
                            var name = c.Attributes.Get("name").Value;
                            switch (name)
                            {
                                case "Brush":
                                    if (GetValue(FindChildElement(c, "Direction")) == "Up")
                                    {
                                        beat.BrushType = BrushType.BrushUp;
                                    }
                                    else
                                    {
                                        beat.BrushType = BrushType.BrushDown;
                                    }
                                    break;
                                // TODO: brush duration
                                case "PickStroke":
                                    if (GetValue(FindChildElement(c, "Direction")) == "Up")
                                    {
                                        beat.PickStroke = PickStrokeType.Up;
                                    }
                                    else
                                    {
                                        beat.PickStroke = PickStrokeType.Down;
                                    }
                                    break;
                                // TODO: brush duration
                                case "Slapped":
                                    if (FindChildElement(c, "Enable") != null)
                                        beat.Slap = true;
                                    break;
                                case "Popped":
                                    if (FindChildElement(c, "Enable") != null)
                                        beat.Pop = true;
                                    break;
                                case "VibratoWTremBar":
                                    switch (GetValue(FindChildElement(c, "Strength")))
                                    {
                                        case "Wide":
                                            beat.Vibrato = VibratoType.Wide;
                                            break;
                                        case "Slight":
                                            beat.Vibrato = VibratoType.Slight;
                                            break;
                                    }
                                    break;
                                case "WhammyBar":
                                    isWhammy = true;
                                    break;
                                case "WhammyBarExtend":

                                case "WhammyBarOriginValue":
                                    if (whammyOrigin == null) whammyOrigin = new BendPoint();
                                    whammyOrigin.Value = ToBendValue(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;
                                case "WhammyBarOriginOffset":
                                    if (whammyOrigin == null) whammyOrigin = new BendPoint();
                                    whammyOrigin.Offset = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

                                case "WhammyBarMiddleValue":
                                    whammyMiddleValue = ToBendValue(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

                                case "WhammyBarMiddleOffset1":
                                    whammyMiddleOffset1 = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;
                                case "WhammyBarMiddleOffset2":
                                    whammyMiddleOffset2 = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

                                case "WhammyBarDestinationValue":
                                    if (whammyDestination == null)
                                        whammyDestination = new BendPoint(BendPoint.MaxPosition);
                                    whammyDestination.Value = ToBendValue(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

                                case "WhammyBarDestinationOffset":
                                    if (whammyDestination == null) whammyDestination = new BendPoint();
                                    whammyDestination.Offset = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));

                                    break;
                            }
                            break;
                    }
                }
            });

            if (isWhammy)
            {
                if (whammyOrigin == null) whammyOrigin = new BendPoint();
                if (whammyDestination == null) whammyDestination = new BendPoint(BendPoint.MaxPosition);
                var whammy = new FastList<BendPoint>();
                whammy.Add(whammyOrigin);

                if (whammyMiddleOffset1 != null && whammyMiddleValue != null)
                {
                    whammy.Add(new BendPoint(whammyMiddleOffset1.Value, whammyMiddleValue.Value));
                }
                if (whammyMiddleOffset2 != null && whammyMiddleValue != null)
                {
                    whammy.Add(new BendPoint(whammyMiddleOffset2.Value, whammyMiddleValue.Value));
                }

                if (whammyMiddleOffset1 == null && whammyMiddleOffset2 == null && whammyMiddleValue != null)
                {
                    whammy.Add(new BendPoint(BendPoint.MaxPosition / 2, whammyMiddleValue.Value));
                }
                whammy.Add(whammyDestination);
                beat.WhammyBarPoints = whammy;
            }
        }
Example #32
0
        private void BeatEffects(Beat beat)
        {
            if (_sy != AlphaTexSymbols.LBrace)
            {
                return;
            }
            NewSy();

            while (_sy == AlphaTexSymbols.String)
            {
                _syData = _syData.ToString().ToLower();
                if (!ApplyBeatEffect(beat))
                {
                    Error("beat-effects", AlphaTexSymbols.String, false);
                }
            }

            if (_sy != AlphaTexSymbols.RBrace)
            {
                Error("beat-effects", AlphaTexSymbols.RBrace);
            }
            NewSy();
        }
Example #33
0
        private void BuildModel()
        {
            // build score
            for (int i = 0, j = _masterBars.Count; i < j; i++)
            {
                var masterBar = _masterBars[i];
                Score.AddMasterBar(masterBar);
            }

            // build tracks (not all, only those used by the score)
            var trackIndex = 0;
            foreach (var trackId in _tracksMapping)
            {
                var track = _tracksById[trackId];
                Score.AddTrack(track);

                // iterate all bar definitions for the masterbars
                // and add the correct bar to the track
                for (int i = 0, j = _barsOfMasterBar.Count; i < j; i++)
                {
                    var barIds = _barsOfMasterBar[i];
                    var barId = barIds[trackIndex];
                    if (barId != InvalidId)
                    {
                        track.AddBar(_barsById[barId]);
                    }
                }

                trackIndex++;
            }

            // build bars
            foreach (var barId in _barsById.Keys)
            {
                var bar = _barsById[barId];
                if (_voicesOfBar.ContainsKey(barId))
                {
                    // add voices to bars
                    foreach (var voiceId in _voicesOfBar[barId])
                    {
                        if (voiceId != InvalidId)
                        {
                            bar.AddVoice(_voiceById[voiceId]);
                        }
                        else
                        {
                            // invalid voice -> empty voice
                            var voice = new Voice();
                            bar.AddVoice(voice);

                            var beat = new Beat();
                            beat.IsEmpty = true;
                            beat.Duration = Duration.Quarter;
                            voice.AddBeat(beat);
                        }
                    }
                }
            }

            // build beats
            foreach (var beatId in _beatById.Keys)
            {
                var beat = _beatById[beatId];
                var rhythmId = _rhythmOfBeat[beatId];
                var rhythm = _rhythmById[rhythmId];

                // set beat duration
                beat.Duration = rhythm.Value;
                beat.Dots = rhythm.Dots;
                beat.TupletNumerator = rhythm.TupletNumerator;
                beat.TupletDenominator = rhythm.TupletDenominator;

                // add notes to beat
                if (_notesOfBeat.ContainsKey(beatId))
                {
                    foreach (var noteId in _notesOfBeat[beatId])
                    {
                        if (noteId != InvalidId)
                        {
                            beat.AddNote(_noteById[noteId]);
                            if (_tappedNotes.ContainsKey(noteId))
                            {
                                beat.Tap = true;
                            }
                        }
                    }
                }
            }

            // build voices
            foreach (var voiceId in _voiceById.Keys)
            {
                var voice = _voiceById[voiceId];
                if (_beatsOfVoice.ContainsKey(voiceId))
                {
                    // add beats to voices
                    foreach (var beatId in _beatsOfVoice[voiceId])
                    {
                        if (beatId != InvalidId)
                        {
                            // important! we clone the beat because beats get reused
                            // in gp6, our model needs to have unique beats.
                            voice.AddBeat(_beatById[beatId].Clone());
                        }
                    }
                }
            }

            // build automations
            foreach (var barId in _automations.Keys)
            {
                var bar = _barsById[barId];
                for (int i = 0, j = bar.Voices.Count; i < j; i++)
                {
                    var v = bar.Voices[i];
                    if (v.Beats.Count > 0)
                    {
                        for (int k = 0, l = _automations[barId].Count; k < l; k++)
                        {
                            var automation = _automations[barId][k];
                            v.Beats[0].Automations.Add(automation);
                        }
                    }
                }
            }

            // build automations
            foreach (var barId in _automations.Keys)
            {
                var automations = _automations[barId];
                var bar = _barsById[barId];
                for (int i = 0, j = automations.Count; i < j; i++)
                {
                    var automation = automations[i];
                    if (automation.Type == AutomationType.Tempo)
                    {
                        if (barId == "0") // // TODO find the correct first bar id
                        {
                            Score.Tempo = (int)(automation.Value);
                            Score.TempoLabel = automation.Text;
                        }

                        bar.MasterBar.TempoAutomation = automation;
                    }
                }
            }
        }
Example #34
0
        private void Note(Beat beat)
        {
            // fret.string
            var syData = _syData.ToString().ToLower();
            if (_sy != AlphaTexSymbols.Number && !(_sy == AlphaTexSymbols.String
                && (syData == "x" || syData == "-")))
            {
                Error("note-fret", AlphaTexSymbols.Number);
            }

            var isDead = syData == "x";
            var isTie = syData == "-";
            int fret = (int)(isDead || isTie ? 0 : _syData);
            NewSy(); // Fret done

            if (_sy != AlphaTexSymbols.Dot)
            {
                Error("note", AlphaTexSymbols.Dot);
            }
            NewSy(); // dot done

            if (_sy != AlphaTexSymbols.Number)
            {
                Error("note-string", AlphaTexSymbols.Number);
            }
            int @string = (int)_syData;
            if (@string < 1 || @string > _track.Tuning.Length)
            {
                Error("note-string", AlphaTexSymbols.Number, false);
            }
            NewSy(); // string done

            // read effects
            var note = new Note();
            beat.AddNote(note);
            note.String = _track.Tuning.Length - (@string - 1);
            note.IsDead = isDead;
            note.IsTieDestination = isTie;
            if (!isTie)
            {
                note.Fret = fret;
            }

            NoteEffects(note);

        }
Example #35
0
 private void ParseBeatXProperties(IXmlNode node, Beat beat)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "XProperty":
                     var id = c.GetAttribute("id");
                     switch (id)
                     {
                         case "1124204545":
                             var val = Std.ParseInt(GetValue(FindChildElement(c, "Int")));
                             beat.InvertBeamDirection = val == 1;
                             break;
                     }
                     break;
             }
         }
     });
 }