示例#1
0
 //
 // <MasterTrack>...</MasterTrack>
 //
 private void ParseMasterTrackNode(XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Automations":
                     ParseAutomations(c);
                     break;
                 case "Tracks":
                     _tracksMapping = GetValue(c).Split(' ');
                     break;
             }
         }
     });
 }
示例#2
0
        private void ParseNoteProperties(XmlNode node, Note note, string noteId)
        {
            bool isBended = false;
            BendPoint bendOrigin = null;
            int? bendMiddleValue = null;
            int? bendMiddleOffset1 = null;
            int? bendMiddleOffset2 = null;
            BendPoint bendDestination = null;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    XmlElement e = (XmlElement) c;
                    switch (c.LocalName)
                    {
                        case "Property":
                            var name = e.Attributes["name"].Value;
                            switch (name)
                            {
                                case "String":
                                    note.String = Std.ParseInt(GetValue(FindChildElement(c, "String"))) + 1;
                                    break;
                                case "Fret":
                                    note.Fret = Std.ParseInt(GetValue(FindChildElement(c, "Fret")));
                                    break;
                                case "Tapped":
                                    _tappedNotes[noteId] = true;
                                    break;
                                case "HarmonicType":
                                    var htype = FindChildElement(c, "HType");
                                    if (htype != null)
                                    {
                                        switch (GetValue(htype))
                                        {
                                            case "NoHarmonic":
                                                note.HarmonicType = HarmonicType.None;
                                                break;
                                            case "Natural":
                                                note.HarmonicType = HarmonicType.Natural;
                                                break;
                                            case "Artificial":
                                                note.HarmonicType = HarmonicType.Artificial;
                                                break;
                                            case "Pinch":
                                                note.HarmonicType = HarmonicType.Pinch;
                                                break;
                                            case "Tap":
                                                note.HarmonicType = HarmonicType.Tap;
                                                break;
                                            case "Semi":
                                                note.HarmonicType = HarmonicType.Semi;
                                                break;
                                            case "Feedback":
                                                note.HarmonicType = HarmonicType.Feedback;
                                                break;
                                        }
                                    }
                                    break;
                                case "HarmonicFret":
                                    var hfret = FindChildElement(c, "HFret");
                                    if (hfret != null)
                                    {
                                        note.HarmonicValue = Std.ParseFloat(GetValue(hfret));
                                    }
                                    break;
                                // case "Muted":
                                case "PalmMuted":
                                    if (FindChildElement(c, "Enable") != null)
                                        note.IsPalmMute = true;
                                    break;
                                // case "Element":
                                // case "Variation":
                                // case "Tone":
                                case "Octave":
                                    note.Octave = Std.ParseInt(GetValue(FindChildElement(c, "Number"))) - 1;
                                    break;
                                case "Tone":
                                    note.Tone = Std.ParseInt(GetValue(FindChildElement(c, "Step")));
                                    break;
                                case "Bended":
                                    isBended = true;
                                    break;

                                case "BendOriginValue":
                                    if (bendOrigin == null) bendOrigin = new BendPoint();
                                    bendOrigin.Value = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointValueFactor);
                                    break;
                                case "BendOriginOffset":
                                    if (bendOrigin == null) bendOrigin = new BendPoint();
                                    bendOrigin.Offset = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointPositionFactor);
                                    break;

                                case "BendMiddleValue":
                                    bendMiddleValue = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointValueFactor);
                                    break;

                                case "BendMiddleOffset1":
                                    bendMiddleOffset1 = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointPositionFactor);
                                    break;
                                case "BendMiddleOffset2":
                                    bendMiddleOffset2 = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointPositionFactor);
                                    break;

                                case "BendDestinationValue":
                                    if (bendDestination == null) bendDestination = new BendPoint(BendPoint.MaxPosition);
                                    bendDestination.Value = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointValueFactor);
                                    break;

                                case "BendDestinationOffset":
                                    if (bendDestination == null) bendDestination = new BendPoint();
                                    bendDestination.Offset = (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointPositionFactor);
                                    break;

                                case "HopoOrigin":
                                    if (FindChildElement(c, "Enable") != null)
                                        note.IsHammerPullOrigin = true;
                                    break;
                                case "HopoDestination":
                                // NOTE: gets automatically calculated
                                // if (FindChildElement(node, "Enable") != null)
                                //     note.isHammerPullDestination = true;
                                    break;
                                case "Slide":
                                    var slideFlags = Std.ParseInt(GetValue(FindChildElement(c, "Flags")));
                                    if ((slideFlags & 0x01) != 0)
                                        note.SlideType = SlideType.Shift;
                                    if ((slideFlags & 0x02) != 0)
                                        note.SlideType = SlideType.Legato;
                                    if ((slideFlags & 0x04) != 0)
                                        note.SlideType = SlideType.OutDown;
                                    if ((slideFlags & 0x08) != 0)
                                        note.SlideType = SlideType.OutUp;
                                    if ((slideFlags & 0x10) != 0)
                                        note.SlideType = SlideType.IntoFromBelow;
                                    if ((slideFlags & 0x20) != 0)
                                        note.SlideType = SlideType.IntoFromAbove;
                                    break;
                            }
                            break;
                    }
                }
            });

            if (isBended)
            {
                if (bendOrigin == null) bendOrigin = new BendPoint();
                if (bendDestination == null) bendDestination = new BendPoint(BendPoint.MaxPosition);
                var bend = new FastList<BendPoint>();
                bend.Add(bendOrigin);
                if (bendMiddleOffset1 != null && bendMiddleValue != null)
                {
                    bend.Add(new BendPoint(bendMiddleOffset1.Value, bendMiddleValue.Value));
                }
                if (bendMiddleOffset2 != null && bendMiddleValue != null)
                {
                    bend.Add(new BendPoint(bendMiddleOffset2.Value, bendMiddleValue.Value));
                }

                if (bendMiddleOffset1 == null && bendMiddleOffset2 == null && bendMiddleValue != null)
                {
                    bend.Add(new BendPoint(BendPoint.MaxPosition / 2, bendMiddleValue.Value));
                }
                bend.Add(bendDestination);
                note.BendPoints = bend;
            }
        }
示例#3
0
 private void ParseMasterBar(XmlNode node)
 {
     var masterBar = new MasterBar();
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             XmlElement e = (XmlElement) c;
             switch (c.LocalName)
             {
                 case "Time":
                     var timeParts = GetValue(c).Split('/');
                     masterBar.TimeSignatureNumerator = Std.ParseInt(timeParts[0]);
                     masterBar.TimeSignatureDenominator = Std.ParseInt(timeParts[1]);
                     break;
                 case "DoubleBar":
                     masterBar.IsDoubleBar = true;
                     break;
                 case "Section":
                     masterBar.Section = new Section();
                     masterBar.Section.Marker = GetValue(FindChildElement(c, "Letter"));
                     masterBar.Section.Text = GetValue(FindChildElement(c, "Text"));
                     break;
                 case "Repeat":
                     if (e.Attributes["start"].Value.ToLower() == "true")
                     {
                         masterBar.IsRepeatStart = true;
                     }
                     if (e.Attributes["end"].Value.ToLower() == "true" && e.Attributes["count"].Value != null)
                     {
                         masterBar.RepeatCount = Std.ParseInt(e.Attributes["count"].Value);
                     }
                     break;
                 // TODO case "Directions": // Coda segno etc.
                 case "AlternateEndings":
                     var alternateEndings = GetValue(c).Split(' ');
                     var i = 0;
                     for (int k = 0; k < alternateEndings.Length; k++)
                     {
                         i |= 1 << (-1 + Std.ParseInt(alternateEndings[i]));
                     }
                     masterBar.AlternateEndings = (byte)i;
                     break;
                 case "Bars":
                     _barsOfMasterBar.Add(GetValue(c).Split(' '));
                     break;
                 case "TripletFeel":
                     switch (GetValue(c))
                     {
                         case "NoTripletFeel":
                             masterBar.TripletFeel = TripletFeel.NoTripletFeel;
                             break;
                         case "Triplet8th":
                             masterBar.TripletFeel = TripletFeel.Triplet8th;
                             break;
                         case "Triplet16th":
                             masterBar.TripletFeel = TripletFeel.Triplet16th;
                             break;
                         case "Dotted8th":
                             masterBar.TripletFeel = TripletFeel.Dotted8th;
                             break;
                         case "Dotted16th":
                             masterBar.TripletFeel = TripletFeel.Dotted16th;
                             break;
                         case "Scottish8th":
                             masterBar.TripletFeel = TripletFeel.Scottish8th;
                             break;
                         case "Scottish16th":
                             masterBar.TripletFeel = TripletFeel.Scottish16th;
                             break;
                     }
                     break;
                 case "Key":
                     masterBar.KeySignature = Std.ParseInt(GetValue(FindChildElement(c, "AccidentalCount")));
                     break;
             }
         }
     });
     _masterBars.Add(masterBar);
 }
示例#4
0
 //
 // <MasterBars>...</MasterBars>
 //
 private void ParseMasterBarsNode(XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "MasterBar":
                     ParseMasterBar(c);
                     break;
             }
         }
     });
 }
示例#5
0
        private void ParseBeatProperties(XmlNode 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)
                {
                    XmlElement e = (XmlElement) c;
                    switch (c.LocalName)
                    {
                        case "Property":
                            var name = e.Attributes["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 =
                                        (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointValueFactor);
                                    break;
                                case "WhammyBarOriginOffset":
                                    if (whammyOrigin == null) whammyOrigin = new BendPoint();
                                    whammyOrigin.Offset =
                                        (int)
                                            (Std.ParseFloat(GetValue(FindChildElement(c, "Float"))) * BendPointPositionFactor);
                                    break;

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

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

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

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

                                    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;
            }
        }
示例#6
0
 //
 // <Beats>...</Beats>
 //
 private void ParseBeats(XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Beat":
                     ParseBeat((XmlElement)c);
                     break;
             }
         }
     });
 }
示例#7
0
 private void ParseAutomations(XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Automation":
                     ParseAutomation(c);
                     break;
             }
         }
     });
 }
示例#8
0
        private void ParseAutomation(XmlNode node)
        {
            string type = null;
            bool isLinear = false;
            string barId = null;
            float ratioPosition = 0;
            float value = 0;
            int reference = 0;
            string text = null;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Type":
                            type = GetValue(c);
                            break;
                        case "Linear":
                            isLinear = GetValue(c).ToLower() == "true";
                            break;
                        case "Bar":
                            barId = GetValue(c);
                            break;
                        case "Position":
                            ratioPosition = Std.ParseFloat(GetValue(c));
                            break;
                        case "Value":
                            var parts = GetValue(c).Split(' ');
                            value = Std.ParseFloat(parts[0]);
                            reference = Std.ParseInt(parts[1]);
                            break;
                        case "Text":
                            text = GetValue(c);
                            break;
                    }
                }
            });

            if (type == null) return;
            Automation automation = null;
            switch (type)
            {
                case "Tempo":
                    automation = Automation.BuildTempoAutomation(isLinear, ratioPosition, value, reference);
                    break;
                // TODO: other automations
            }

            if (automation != null)
            {
                automation.Text = text;
            }

            if (barId != null)
            {
                if (!_automations.ContainsKey(barId))
                {
                    _automations[barId] = new FastList<Automation>();
                }
                _automations[barId].Add(automation);
            }
        }
示例#9
0
 //
 // <Tracks>...</Tracks>
 //
 private void ParseTracksNode(XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Track":
                     ParseTrack((XmlElement)c);
                     break;
             }
         }
     });
 }
示例#10
0
 private void ParseTrackProperties(Track track, XmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Property":
                     ParseTrackProperty(track, (XmlElement)c);
                     break;
             }
         }
     });
 }
示例#11
0
 //
 // <Score>...</Score>
 //
 private void ParseScoreNode(XmlNode element)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Title":
                     Score.Title = GetValue(c.FirstChild);
                     break;
                 case "SubTitle":
                     Score.SubTitle = GetValue(c.FirstChild);
                     break;
                 case "Artist":
                     Score.Artist = GetValue(c.FirstChild);
                     break;
                 case "Album":
                     Score.Album = GetValue(c.FirstChild);
                     break;
                 case "Words":
                     Score.Words = GetValue(c.FirstChild);
                     break;
                 case "Music":
                     Score.Music = GetValue(c.FirstChild);
                     break;
                 case "WordsAndMusic":
                     if (c.FirstChild != null && c.FirstChild.ToString() != "")
                     {
                         Score.Words = GetValue(c.FirstChild);
                         Score.Music = GetValue(c.FirstChild);
                     }
                     break;
                 case "Copyright":
                     Score.Copyright = GetValue(c.FirstChild);
                     break;
                 case "Tabber":
                     Score.Tab = GetValue(c.FirstChild);
                     break;
             }
         }
     });
 }