示例#1
0
        public Segno(XmlReader r)
        {
            M.Assert(r.Name == "segno");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "location":
                {
                    PositionInMeasure = new PositionInMeasure(r.Value);
                    break;
                }

                case "glyph":
                    SMuFLGlyphName = r.Value;
                    break;

                default:
                    M.ThrowError("Unknown segno attribute.");
                    break;
                }
            }
            // r.Name is now the name of the last jump attribute that has been read.
        }
示例#2
0
        public Clef(XmlReader r)
        {
            // https://w3c.github.io/mnx/specification/common/#the-clef-element
            M.Assert(r.Name == "clef");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "line":
                    int.TryParse(r.Value, out Line);
                    M.Assert(Line > 0);
                    break;

                case "sign":
                    Sign = GetMNXClefSign(r.Value);
                    break;

                case "octave":
                    int.TryParse(r.Value, out Octave);
                    break;

                // Instruction attributes
                case "location":
                    Location = new PositionInMeasure(r.Value);
                    break;

                case "staff-index":
                    int staffIndex;
                    int.TryParse(r.Value, out staffIndex);
                    StaffIndex = staffIndex;
                    break;

                case "orient":
                    switch (r.Value)
                    {
                    case "up":
                        Orient = Orientation.up;
                        break;

                    case "down":
                        Orient = Orientation.down;
                        break;
                    }
                    break;

                default:
                    M.ThrowError("Unknown clef attribute.");
                    break;
                }
            }

            M.Assert(Sign != null && Line > 0);

            // r.Name is now the name of the last clef attribute that has been read.
        }
示例#3
0
文件: Tied.cs 项目: notator/MNXtoSVG
        public Tied(XmlReader r)
        {
            M.Assert(r.Name == "tied");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                // Span attribute
                case "target":
                    TargetID = r.Value;
                    break;

                case "end":
                    End = new PositionInMeasure(r.Value);
                    break;

                // Instruction attributes
                case "location":
                    Location = new PositionInMeasure(r.Value);
                    break;

                case "staff-index":
                    int staffIndex = 0;
                    int.TryParse(r.Value, out staffIndex);
                    StaffIndex = staffIndex;
                    break;

                case "side":
                    switch (r.Value)
                    {
                    case "up":
                        Side = Orientation.up;
                        break;

                    case "down":
                        Side = Orientation.down;
                        break;
                    }
                    break;
                }
            }
        }
示例#4
0
        public Jump(XmlReader r)
        {
            M.Assert(r.Name == "jump");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "location":
                {
                    PositionInMeasure = new PositionInMeasure(r.Value);
                    break;
                }

                case "type":
                    switch (r.Value)
                    {
                    case "segno":
                        JumpType = JumpType.segno;
                        break;

                    case "dsalfine":
                        JumpType = JumpType.dsalfine;
                        break;

                    default:
                        JumpType = JumpType.unknown;
                        break;
                    }
                    break;

                default:
                    M.ThrowError("Unknown jump attribute.");
                    break;
                }
            }
            // r.Name is now the name of the last jump attribute that has been read.
        }
示例#5
0
        public Fine(XmlReader r)
        {
            M.Assert(r.Name == "fine");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "location":
                {
                    PositionInMeasure = new PositionInMeasure(r.Value);
                    break;
                }

                default:
                    M.ThrowError("Unknown fine attribute.");
                    break;
                }
            }
            // r.Name is now the name of the last fine attribute that has been read.
        }
示例#6
0
        public OctaveShift(XmlReader r)
            : base()
        {
            M.Assert(r.Name == "octave-shift");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "type":
                    _octaveShiftType = GetOctaveShiftType(r.Value);
                    break;

                // Span attribute
                case "target":
                    TargetID = r.Value;
                    break;

                case "end":
                    End = new PositionInMeasure(r.Value);
                    break;

                // Instruction attributes
                case "location":
                    Location = new PositionInMeasure(r.Value);
                    break;

                case "staff-index":
                    int staffIndex;
                    int.TryParse(r.Value, out staffIndex);
                    StaffIndex = staffIndex;
                    break;

                case "orient":
                    switch (r.Value)
                    {
                    case "up":
                        Orient = Orientation.up;
                        break;

                    case "down":
                        Orient = Orientation.down;
                        break;
                    }
                    break;

                default:
                    M.ThrowError("Error: Unknown attribute name.");
                    break;
                }
            }

            M.Assert(_octaveShiftType != null);

            if (Orient == null)
            {
                switch (_octaveShiftType)
                {
                case OctaveShiftType.down1Oct:
                case OctaveShiftType.down2Oct:
                case OctaveShiftType.down3Oct:
                    Orient = Orientation.up;
                    break;

                case OctaveShiftType.up1Oct:
                case OctaveShiftType.up2Oct:
                case OctaveShiftType.up3Oct:
                    Orient = Orientation.down;
                    break;
                }
            }

            // r.Name is now the name of the last octave-shift attribute that has been read.
        }
示例#7
0
        public SlurDef(XmlReader r)
        {
            // https://w3c.github.io/mnx/specification/common/#the-slur-element
            M.Assert(r.Name == "slur");

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "start-note":
                    StartNoteID = r.Value;
                    break;

                case "end-note":
                    EndNoteID = r.Value;
                    break;

                case "line-type":
                    LineType = GetLineType(r.Value);
                    break;

                case "side":
                    if (r.Value == "up")
                    {
                        Side = Orientation.up;
                    }
                    else if (r.Value == "down")
                    {
                        Side = Orientation.down;
                    }
                    break;

                case "side-end":
                    if (r.Value == "up")
                    {
                        SideEnd = Orientation.up;
                    }
                    else if (r.Value == "down")
                    {
                        SideEnd = Orientation.down;
                    }
                    break;

                // Span attribute
                case "target":
                    TargetID = r.Value;
                    break;

                case "end":
                    End = new PositionInMeasure(r.Value);
                    break;

                // Instruction attributes
                case "location":
                    Location = new PositionInMeasure(r.Value);
                    break;

                case "staff-index":
                    int staffIndex = 0;
                    int.TryParse(r.Value, out staffIndex);
                    StaffIndex = staffIndex;
                    break;

                case "orient":
                    switch (r.Value)
                    {
                    case "up":
                        Orient = Orientation.up;
                        break;

                    case "down":
                        Orient = Orientation.down;
                        break;
                    }
                    break;
                }
            }
        }
示例#8
0
 public RepeatEnd(PositionInMeasure positionInMeasure, string times)
     : base()
 {
     PositionInMeasure = positionInMeasure; // can be null
     Times             = times;
 }
示例#9
0
 public RepeatBegin(PositionInMeasure positionInMeasure)
     : base()
 {
     PositionInMeasure = positionInMeasure; // can be null
 }
示例#10
0
        // returns either a RepeatBegin or RepeatEnd.
        private Repeat GetRepeat(XmlReader r)
        {
            M.Assert(r.Name == "cresc");

            bool?  IsBegin = null;
            string Times   = null;
            // when null, this defaults to 0 for RepeatBegin, and measure duration (= current time signature) for RepeatEnd.
            PositionInMeasure PositionInMeasure = null;

            int count = r.AttributeCount;

            for (int i = 0; i < count; i++)
            {
                r.MoveToAttribute(i);
                switch (r.Name)
                {
                case "type":
                {
                    switch (r.Value)
                    {
                    case "start":
                        IsBegin = true;
                        break;

                    case "end":
                        IsBegin = false;
                        break;

                    default:
                        M.ThrowError("Unknown repeat type.");
                        break;
                    }
                    break;
                }

                case "times":
                {
                    M.Assert(int.TryParse(r.Value, out _));
                    Times = r.Value;
                    break;
                }

                case "location":
                {
                    PositionInMeasure = new PositionInMeasure(r.Value);
                    break;
                }

                default:
                    M.ThrowError("Unknown repeat attribute.");
                    break;
                }
            }
            // r.Name is now the name of the last repeat attribute that has been read.

            Repeat rval = null;

            switch (IsBegin)
            {
            case true:
            {
                rval = new RepeatBegin(PositionInMeasure);
                break;
            }

            case false:
            {
                rval = new RepeatEnd(PositionInMeasure, Times);
                break;
            }

            default:     // null
            {
                M.ThrowError("Undefined repeat type.");
                break;
            }
            }

            return(rval);
        }