コード例 #1
0
ファイル: MusicXml2Importer.cs プロジェクト: eriser/alphaTab
        private void ParsePartwise(IXmlNode element)
        {
            var version = element.GetAttribute("version");
            if (!string.IsNullOrEmpty(version) && version != "2.0")
            {
                throw new UnsupportedFormatException();
            }

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "movement-title":
                            _score.Title = Std.GetNodeValue(c.FirstChild);
                            break;
                        case "identification":
                            ParseIdentification(c);
                            break;
                        case "part-list":
                            ParsePartList(c);
                            break;
                        case "part":
                            ParsePart(c);
                            break;
                    }
                }
            });
        }
コード例 #2
0
ファイル: Std.cs プロジェクト: piotrwarzocha/alphaTab
 public static string GetNodeValue(IXmlNode n)
 {
     if (n.NodeType == XmlNodeType.Element || n.NodeType == XmlNodeType.Document)
     {
         var txt = new StringBuilder();
         n.IterateChildren(c =>
         {
             txt.Append(GetNodeValue(c));
         });
         return txt.ToString().Trim();
     }
     return n.Value;
 }
コード例 #3
0
        private void ParseClef(IXmlNode element, Bar bar)
        {
            string sign = null;
            string line = null;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "sign":
                        sign = Std.GetNodeValue(c);
                        break;

                    case "line":
                        line = Std.GetNodeValue(c);
                        break;
                    }
                }
            });

            var clef = sign + line;

            switch (clef)
            {
            case "G2":
                bar.Clef = Clef.G2;
                break;

            case "F4":
                bar.Clef = Clef.F4;
                break;

            case "C3":
                bar.Clef = Clef.C3;
                break;

            case "C4":
                bar.Clef = Clef.C4;
                break;
            }
        }
コード例 #4
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;
                    }
                }
            });
        }
コード例 #5
0
 private void ParseDirection(IXmlNode element, MasterBar masterBar)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
             case "sound":
                 var tempoAutomation       = new Automation();
                 tempoAutomation.IsLinear  = true;
                 tempoAutomation.Type      = AutomationType.Tempo;
                 tempoAutomation.Value     = Std.ParseInt(c.GetAttribute("tempo"));
                 masterBar.TempoAutomation = tempoAutomation;
                 break;
             }
         }
     });
 }
コード例 #6
0
        private void ParseBarline(IXmlNode element, MasterBar masterBar)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "repeat":
                        ParseRepeat(c, masterBar);
                        break;

                    case "ending":
                        ParseEnding(c, masterBar);
                        break;
                    }
                }
            });
        }
コード例 #7
0
        private void ParseTime(IXmlNode element, MasterBar masterBar)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "beats":
                        masterBar.TimeSignatureNumerator = Std.ParseInt(Std.GetNodeValue(c));
                        break;

                    case "beats-type":
                        masterBar.TimeSignatureDenominator = Std.ParseInt(Std.GetNodeValue(c));
                        break;
                    }
                }
            });
        }
コード例 #8
0
        private void ParsePart(IXmlNode element)
        {
            var id             = element.GetAttribute("id");
            var track          = _trackById[id];
            var isFirstMeasure = true;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "measure":
                        ParseMeasure(c, track, isFirstMeasure);
                        isFirstMeasure = false;
                        break;
                    }
                }
            });
        }
コード例 #9
0
        private void ParseArticulations(IXmlNode element, Note note)
        {
            element.IterateChildren(c =>
            {
                switch (c.LocalName)
                {
                case "accent":
                    note.Accentuated = AccentuationType.Normal;
                    break;

                case "strong-accent":
                    note.Accentuated = AccentuationType.Heavy;
                    break;

                case "staccato":
                case "detached-legato":
                    note.IsStaccato = true;
                    break;
                }
            });
        }
コード例 #10
0
 private void ParseLyric(IXmlNode element, Beat beat)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
             case "text":
                 if (!string.IsNullOrEmpty(beat.Text))
                 {
                     beat.Text += " " + Std.GetNodeValue(c);
                 }
                 else
                 {
                     beat.Text = Std.GetNodeValue(c);
                 }
                 break;
             }
         }
     });
 }
コード例 #11
0
        private void ParseIdentification(IXmlNode element)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "creator":
                        if (c.GetAttribute("type") == "composer")
                        {
                            _score.Music = Std.GetNodeValue(c.FirstChild);
                        }
                        break;

                    case "rights":
                        _score.Artist = Std.GetNodeValue(c.FirstChild);
                        break;
                    }
                }
            });
        }
コード例 #12
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;
                    }
                }
            });
        }
コード例 #13
0
        private void ParseMidiInstrument(IXmlNode element, Track track)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "midi-channel":
                        track.PlaybackInfo.PrimaryChannel = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                        break;

                    case "midi-program":
                        track.PlaybackInfo.Program = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                        break;

                    case "midi-volume":
                        track.PlaybackInfo.Volume = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                        break;
                    }
                }
            });
        }
コード例 #14
0
        private void ParseAttributes(IXmlNode element, Bar bar, MasterBar masterBar)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "key":
                        ParseKey(c, masterBar);
                        break;

                    case "time":
                        ParseTime(c, masterBar);
                        break;

                    case "clef":
                        ParseClef(c, bar);
                        break;
                    }
                }
            });
        }
コード例 #15
0
        private void ParsePitch(IXmlNode element, Note note)
        {
            string step      = null;
            float  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.ParseFloat(Std.GetNodeValue(c));
                        if (float.IsNaN(semitones))
                        {
                            semitones = 0;
                        }
                        break;

                    case "octave":
                        // 0-9, 4 for middle C
                        octave = Std.ParseInt(Std.GetNodeValue(c));
                        break;
                    }
                }
            });

            var value = octave * 12 + TuningParser.GetToneForText(step) + (int)semitones;

            note.Octave = (value / 12);
            note.Tone   = value - (note.Octave * 12);
        }
コード例 #16
0
        private void ParseKey(IXmlNode element, MasterBar masterBar)
        {
            int fifths   = int.MinValue;
            int keyStep  = int.MinValue;
            int keyAlter = int.MinValue;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "fifths":
                        fifths = Std.ParseInt(Std.GetNodeValue(c));
                        break;

                    case "key-step":
                        keyStep = Std.ParseInt(Std.GetNodeValue(c));
                        break;

                    case "key-alter":
                        keyAlter = Std.ParseInt(Std.GetNodeValue(c));
                        break;
                    }
                }
            });

            if (fifths != int.MinValue)
            {
                // TODO: check if this is conrrect
                masterBar.KeySignature = fifths;
            }
            else
            {
                // TODO: map keyStep/keyAlter to internal keysignature
            }
        }
コード例 #17
0
        private void ParseStaffDetails(IXmlNode element, Track track)
        {
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "staff-lines":
                        track.Tuning = new int[Std.ParseInt(Std.GetNodeValue(c))];
                        break;

                    case "staff-tuning":
                        ParseStaffTuning(c, track);
                        break;
                    }
                }
            });

            if (IsEmptyTuning(track.Tuning))
            {
                track.Tuning = new int[0];
            }
        }
コード例 #18
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        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;
            }
        }
コード例 #19
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        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;
        }
コード例 #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.Count > 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":
                        //    break;
                        //case "128th":
                        //    break;
                        //case "breve":
                        //    break;
                        //case "long":
                        //    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);
        }
コード例 #21
0
 private void ParseAttributes(IXmlNode element, Bar bar, MasterBar masterBar)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "key":
                     ParseKey(c, masterBar);
                     break;
                 case "time":
                     ParseTime(c, masterBar);
                     break;
                 case "clef":
                     ParseClef(c, bar);
                     break;
             }
         }
     });
 }
コード例 #22
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        private void ParseNote(IXmlNode node)
        {
            var note = new Note();
            var noteId = node.Attributes.Get("id").Value;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Properties":
                            ParseNoteProperties(c, note, noteId);
                            break;
                        case "AntiAccent":
                            if (GetValue(c).ToLower() == "normal")
                            {
                                note.IsGhost = true;
                            }
                            break;
                        case "LetRing":
                            note.IsLetRing = true;
                            break;
                        case "Trill":
                            note.TrillValue = Std.ParseInt(GetValue(c));
                            note.TrillSpeed = Duration.Sixteenth;
                            break;
                        case "Accent":
                            var accentFlags = Std.ParseInt(GetValue(c));
                            if ((accentFlags & 0x01) != 0)
                                note.IsStaccato = true;
                            if ((accentFlags & 0x04) != 0)
                                note.Accentuated = AccentuationType.Heavy;
                            if ((accentFlags & 0x08) != 0)
                                note.Accentuated = AccentuationType.Normal;
                            break;
                        case "Tie":
                            if (c.Attributes.Get("origin").Value.ToLower() == "true")
                            {
                                note.IsTieOrigin = true;
                            }
                            if (c.Attributes.Get("destination").Value.ToLower() == "true")
                            {
                                note.IsTieDestination = true;
                            }
                            break;
                        case "Vibrato":
                            switch (GetValue(c))
                            {
                                case "Slight":
                                    note.Vibrato = VibratoType.Slight;
                                    break;
                                case "Wide":
                                    note.Vibrato = VibratoType.Wide;
                                    break;
                            }
                            break;
                        case "LeftFingering":
                            note.IsFingering = true;
                            switch (GetValue(c))
                            {
                                case "P":
                                    note.LeftHandFinger = Fingers.Thumb;
                                    break;
                                case "I":
                                    note.LeftHandFinger = Fingers.IndexFinger;
                                    break;
                                case "M":
                                    note.LeftHandFinger = Fingers.MiddleFinger;
                                    break;
                                case "A":
                                    note.LeftHandFinger = Fingers.AnnularFinger;
                                    break;
                                case "C":
                                    note.LeftHandFinger = Fingers.LittleFinger;
                                    break;
                            }
                            break;
                        case "RightFingering":
                            note.IsFingering = true;
                            switch (GetValue(c))
                            {
                                case "P":
                                    note.RightHandFinger = Fingers.Thumb;
                                    break;
                                case "I":
                                    note.RightHandFinger = Fingers.IndexFinger;
                                    break;
                                case "M":
                                    note.RightHandFinger = Fingers.MiddleFinger;
                                    break;
                                case "A":
                                    note.RightHandFinger = Fingers.AnnularFinger;
                                    break;
                                case "C":
                                    note.RightHandFinger = Fingers.LittleFinger;
                                    break;
                            }
                            break;
                    }
                }
            });

            _noteById[noteId] = note;
        }
コード例 #23
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
 //
 // <MasterBars>...</MasterBars>
 //
 private void ParseMasterBarsNode(IXmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "MasterBar":
                     ParseMasterBar(c);
                     break;
             }
         }
     });
 }
コード例 #24
0
 private void ParseIdentification(IXmlNode element)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "creator":
                     if (c.GetAttribute("type") == "composer")
                     {
                         _score.Music = Std.GetNodeValue(c.FirstChild);
                     }
                     break;
                 case "rights":
                     _score.Artist = Std.GetNodeValue(c.FirstChild);
                     break;
             }
         }
     });
 }
コード例 #25
0
 private void ParseDirection(IXmlNode element, MasterBar masterBar)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "sound":
                     var tempoAutomation = new Automation();
                     tempoAutomation.IsLinear = true;
                     tempoAutomation.Type = AutomationType.Tempo;
                     tempoAutomation.Value = Std.ParseInt(c.GetAttribute("tempo"));
                     masterBar.TempoAutomation = tempoAutomation;
                     break;
             }
         }
     });
 }
コード例 #26
0
        private void ParseNoteBeat(IXmlNode element, Bar[] bars)
        {
            var chord = element.GetElementsByTagName("chord").Length > 0;
            var beat  = GetOrCreateBeat(element, bars, chord);

            beat.ChordId  = _currentChord;
            _currentChord = null;

            var note = new Note();

            beat.AddNote(note);
            beat.IsEmpty = false;

            beat.Dots = 0;
            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":
                        if (beat.IsRest)
                        {
                            // unit: divisions per quarter note
                            var duration = Std.ParseInt(Std.GetNodeValue(c));
                            switch (duration)
                            {
                            case 1:
                                beat.Duration = Duration.Whole;
                                break;

                            case 2:
                                beat.Duration = Duration.Half;
                                break;

                            case 4:
                                beat.Duration = Duration.Quarter;
                                break;

                            case 8:
                                beat.Duration = Duration.Eighth;
                                break;

                            case 16:
                                beat.Duration = Duration.Sixteenth;
                                break;

                            case 32:
                                beat.Duration = Duration.ThirtySecond;
                                break;

                            case 64:
                                beat.Duration = Duration.SixtyFourth;
                                break;

                            default:
                                beat.Duration = Duration.Quarter;
                                break;
                            }
                        }
                        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":
                        case "128th":
                        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 "long":
                        case "breve":
                        case "whole":
                            beat.Duration = Duration.Whole;
                            break;
                        }
                        if (beat.GraceType != GraceType.None && beat.Duration < Duration.Sixteenth)
                        {
                            beat.Duration = Duration.Eighth;
                        }
                        break;

                    case "dot":
                        beat.Dots++;
                        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":
                        var beamMode = Std.GetNodeValue(c);
                        if (beamMode == "continue")
                        {
                            _isBeamContinue = true;
                        }
                        break;

                    case "notations":
                        ParseNotations(c, beat, note);
                        break;

                    case "lyric":
                        ParseLyric(c, beat);
                        break;

                    // "full-note"
                    case "pitch":
                        ParsePitch(c, note);
                        break;

                    case "unpitched":
                        ParseUnpitched(c, note);
                        break;

                    case "rest":
                        beat.IsEmpty = false;
                        beat.Notes.Clear();
                        break;
                    }
                }
            });

            // check if new note is duplicate on string
            if (note.IsStringed)
            {
                for (int i = 0; i < beat.Notes.Count; i++)
                {
                    if (beat.Notes[i].String == note.String && beat.Notes[i] != note)
                    {
                        beat.RemoveNote(note);
                        break;
                    }
                }
            }
        }
コード例 #27
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
 //
 // <Beats>...</Beats>
 //
 private void ParseBeats(IXmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Beat":
                     ParseBeat(c);
                     break;
             }
         }
     });
 }
コード例 #28
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;
                    }
                }
            });
        }
コード例 #29
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
 private void ParseMasterBar(IXmlNode node)
 {
     var masterBar = new MasterBar();
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             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 (c.Attributes.Get("start").Value.ToLower() == "true")
                     {
                         masterBar.IsRepeatStart = true;
                     }
                     if (c.Attributes.Get("end").Value.ToLower() == "true" && c.Attributes.Get("count").Value != null)
                     {
                         masterBar.RepeatCount = Std.ParseInt(c.Attributes.Get("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);
 }
コード例 #30
0
        private bool ParseMeasure(IXmlNode element, Track track, bool isFirstMeasure)
        {
            if (element.GetAttribute("implicit") == "yes" && element.GetElementsByTagName("note").Length == 0)
            {
                return(false);
            }

            var barIndex = 0;

            if (isFirstMeasure)
            {
                _divisionsPerQuarterNote = 0;
                _trackFirstMeasureNumber = Std.ParseInt(element.GetAttribute("number"));
                if (_trackFirstMeasureNumber == int.MinValue)
                {
                    _trackFirstMeasureNumber = 0;
                }
                barIndex = 0;
            }
            else
            {
                barIndex = Std.ParseInt(element.GetAttribute("number"));
                if (barIndex == int.MinValue)
                {
                    return(false);
                }
                barIndex -= _trackFirstMeasureNumber;
            }

            // try to find out the number of staffs required
            if (isFirstMeasure)
            {
                var attributes = element.GetElementsByTagName("attributes");
                if (attributes.Length > 0)
                {
                    var stavesElements = attributes[0].GetElementsByTagName("staves");
                    if (stavesElements.Length > 0)
                    {
                        var staves = Std.ParseInt(Std.GetNodeValue(stavesElements[0]));
                        track.EnsureStaveCount(staves);
                    }
                }
            }


            // create empty bars to the current index
            Bar[]     bars      = new Bar[track.Staves.Count];
            MasterBar masterBar = null;

            for (int b = track.Staves[0].Bars.Count; b <= barIndex; b++)
            {
                for (int s = 0; s < track.Staves.Count; s++)
                {
                    var bar = bars[s] = new Bar();
                    if (track.Staves[s].Bars.Count > 0)
                    {
                        var previousBar = track.Staves[s].Bars[track.Staves[s].Bars.Count - 1];
                        bar.Clef = previousBar.Clef;
                    }
                    masterBar = GetOrCreateMasterBar(barIndex);
                    track.AddBarToStaff(s, bar);

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

            var attributesParsed = false;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "note":
                        ParseNoteBeat(c, bars);
                        break;

                    case "forward":
                        ParseForward(c, bars);
                        break;

                    case "direction":
                        ParseDirection(c, masterBar);
                        break;

                    case "attributes":
                        if (!attributesParsed)
                        {
                            ParseAttributes(c, bars, masterBar);
                            attributesParsed = true;
                        }
                        break;

                    case "harmony":
                        ParseHarmony(c, track);
                        break;

                    case "sound":
                        // TODO
                        break;

                    case "barline":
                        ParseBarline(c, masterBar);
                        break;
                    }
                }
            });

            return(true);
        }
コード例 #31
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
 //
 // <MasterTrack>...</MasterTrack>
 //
 private void ParseMasterTrackNode(IXmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Automations":
                     ParseAutomations(c);
                     break;
                 case "Tracks":
                     _tracksMapping = GetValue(c).Split(' ');
                     break;
             }
         }
     });
 }
コード例 #32
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);
        }
コード例 #33
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        private void ParseNoteProperties(IXmlNode 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)
                {
                    switch (c.LocalName)
                    {
                        case "Property":
                            var name = c.Attributes.Get("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":
                                    if (FindChildElement(c, "Enable") != null)
                                        note.IsDead = true;
                                    break;
                                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 = ToBendValue(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;
                                case "BendOriginOffset":
                                    if (bendOrigin == null) bendOrigin = new BendPoint();
                                    bendOrigin.Offset = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

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

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

                                case "BendDestinationValue":
                                    if (bendDestination == null) bendDestination = new BendPoint(BendPoint.MaxPosition);
                                    // NOTE: If we directly cast the expression of value to (int) it is 3 instead of 4, strange compiler
                                    // optimizations happening here:
                                    // (int)(Std.ParseFloat(GetValue(FindChildElement(c, "Float")))* BendPointValueFactor) => (int)(100f * 0.04f) => 3
                                    // (Std.ParseFloat(GetValue(FindChildElement(c, "Float")))* BendPointValueFactor) => (100f * 0.04f) => 4.0
                                    bendDestination.Value = ToBendValue(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    break;

                                case "BendDestinationOffset":
                                    if (bendDestination == null) bendDestination = new BendPoint();
                                    bendDestination.Offset = ToBendOffset(Std.ParseFloat(GetValue(FindChildElement(c, "Float"))));
                                    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;
            }
        }
コード例 #34
0
 private void ParseTime(IXmlNode element, MasterBar masterBar)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "beats":
                     masterBar.TimeSignatureNumerator = Std.ParseInt(Std.GetNodeValue(c));
                     break;
                 case "beats-type":
                     masterBar.TimeSignatureDenominator = Std.ParseInt(Std.GetNodeValue(c));
                     break;
             }
         }
     });
 }
コード例 #35
0
        private void ParseClef(IXmlNode element, Bar bar)
        {
            string sign = null;
            string line = null;
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "sign":
                            sign = Std.GetNodeValue(c);
                            break;
                        case "line":
                            line = Std.GetNodeValue(c);
                            break;
                    }
                }
            });

            var clef = sign + line;
            switch (clef)
            {
                case "G2":
                    bar.Clef = Clef.G2;
                    break;
                case "F4":
                    bar.Clef = Clef.F4;
                    break;
                case "C3":
                    bar.Clef = Clef.C3;
                    break;
                case "C4":
                    bar.Clef = Clef.C4;
                    break;
            }
        }
コード例 #36
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.Bars.Count; i <= barIndex; i++)
            {
                bar       = new Bar();
                masterBar = GetOrCreateMasterBar(barIndex);
                track.AddBar(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;
                    }
                }
            });
        }
コード例 #37
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;
             }
         }
     });
 }
コード例 #38
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;
             }
         }
     });
 }
コード例 #39
0
        private void ParseKey(IXmlNode element, MasterBar masterBar)
        {
            int fifths = int.MinValue;
            int keyStep = int.MinValue;
            int keyAlter = int.MinValue;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "fifths":
                            fifths = Std.ParseInt(Std.GetNodeValue(c));
                            break;
                        case "key-step":
                            keyStep = Std.ParseInt(Std.GetNodeValue(c));
                            break;
                        case "key-alter":
                            keyAlter = Std.ParseInt(Std.GetNodeValue(c));
                            break;
                    }
                }
            });

            if (fifths != int.MinValue)
            {
                // TODO: check if this is conrrect
                masterBar.KeySignature = fifths;
            }
            else
            {
                // TODO: map keyStep/keyAlter to internal keysignature
            }
        }
コード例 #40
0
 private void ParsePart(IXmlNode element)
 {
     var id = element.GetAttribute("id");
     var track = _trackById[id];
     var isFirstMeasure = true;
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "measure":
                     ParseMeasure(c, track, isFirstMeasure);
                     isFirstMeasure = false;
                     break;
             }
         }
     });
 }
コード例 #41
0
 private void ParseMidiInstrument(IXmlNode element, Track track)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "midi-channel":
                     track.PlaybackInfo.PrimaryChannel = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                     break;
                 case "midi-program":
                     track.PlaybackInfo.Program = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                     break;
                 case "midi-volume":
                     track.PlaybackInfo.Volume = Std.ParseInt(Std.GetNodeValue(c.FirstChild));
                     break;
             }
         }
     });
 }
コード例 #42
0
        private void ParseClef(IXmlNode element, Bar bar)
        {
            string sign         = null;
            int    line         = 0;
            int    octaveChange = 0;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "sign":
                        sign = Std.GetNodeValue(c);
                        break;

                    case "line":
                        line = Std.ParseInt(Std.GetNodeValue(c));
                        break;

                    case "clef-octave-change":
                        switch (Std.ParseInt(Std.GetNodeValue(c)))
                        {
                        case -2:
                            bar.ClefOttavia = ClefOttavia._15mb;
                            break;

                        case -1:
                            bar.ClefOttavia = ClefOttavia._8vb;
                            break;

                        case 1:
                            bar.ClefOttavia = ClefOttavia._8va;
                            break;

                        case 2:
                            bar.ClefOttavia = ClefOttavia._15mb;
                            break;
                        }
                        break;
                    }
                }
            });

            switch (sign)
            {
            case "G":
                bar.Clef = Clef.G2;
                break;

            case "F":
                bar.Clef = Clef.F4;
                break;

            case "C":
                if (line == 3)
                {
                    bar.Clef = Clef.C3;
                }
                else
                {
                    bar.Clef = Clef.C4;
                }
                break;

            case "percussion":
                bar.Clef = Clef.Neutral;
                break;

            default:
                bar.Clef = Clef.G2;
                break;
            }
        }
コード例 #43
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;
        }
コード例 #44
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        private void ParseVoice(IXmlNode node)
        {
            var voice = new Voice();
            var voiceId = node.Attributes.Get("id").Value;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Beats":
                            _beatsOfVoice[voiceId] = GetValue(c).Split(' ');
                            break;
                    }
                }
            });

            _voiceById[voiceId] = voice;
        }
コード例 #45
0
 private void ParsePartList(IXmlNode element)
 {
     element.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "score-part":
                     ParseScorePart(c);
                     break;
             }
         }
     });
 }
コード例 #46
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        private void ParseAutomation(IXmlNode 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);
            }
        }
コード例 #47
0
        private void ParseScorePart(IXmlNode element)
        {
            string id = element.GetAttribute("id");
            var track = new Track(1);
            _trackById[id] = track;
            _score.AddTrack(track);
            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "part-name":
                            track.Name = Std.GetNodeValue(c.FirstChild);
                            break;
                        case "part-abbreviation":
                            track.ShortName = Std.GetNodeValue(c.FirstChild);
                            break;
                        case "midi-instrument":
                            ParseMidiInstrument(c, track);
                            break;
                    }
                }
            });

            if (track.Tuning == null || track.Tuning.Length == 0)
            {
                track.Tuning = Tuning.GetDefaultTuningFor(6).Tunings;
            }
        }
コード例 #48
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
 private void ParseAutomations(IXmlNode node)
 {
     node.IterateChildren(c =>
     {
         if (c.NodeType == XmlNodeType.Element)
         {
             switch (c.LocalName)
             {
                 case "Automation":
                     ParseAutomation(c);
                     break;
             }
         }
     });
 }
コード例 #49
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;
             }
         }
     });
 }
コード例 #50
0
ファイル: GpxParser.cs プロジェクト: rkenning/alphaTab
        private void ParseBar(IXmlNode node)
        {
            var bar = new Bar();
            var barId = node.Attributes.Get("id").Value;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Voices":
                            _voicesOfBar[barId] = GetValue(c).Split(' ');
                            break;
                        case "Clef":
                            switch (GetValue(c))
                            {
                                case "Neutral":
                                    bar.Clef = Clef.Neutral;
                                    break;
                                case "G2":
                                    bar.Clef = Clef.G2;
                                    break;
                                case "F4":
                                    bar.Clef = Clef.F4;
                                    break;
                                case "C4":
                                    bar.Clef = Clef.C4;
                                    break;
                                case "C3":
                                    bar.Clef = Clef.C3;
                                    break;
                            }
                            break;
                            // case "SimileMark":
                    }
                }
            });

            _barsById[barId] = bar;
        }