Example #1
0
        public List <IUniqueDef> GetIUniqueDefs()
        {
            var         rval        = new List <IUniqueDef>();
            OctaveShift octaveShift = null;

            // SequenceComponents includes the SequenceDirectionComponents (see the Sequence constructor above)
            foreach (var seqObj in Components)
            {
                if (seqObj is SequenceDirections d)
                {
                    if (d.Clef != null)
                    {
                        rval.Add(d.Clef as IUniqueDef); // mid staff clef change
                    }
                    //if(d.Cresc != null)
                    //{
                    //    rval.Add(d.Cresc as IUniqueDef);
                    //}
                    //if(d.Dim != null)
                    //{
                    //    rval.Add(d.Cim as IUniqueDef);
                    //}
                    //if(d.Dynamic != null)
                    //{
                    //    rval.Add(d.Dynamic as IUniqueDef);
                    //}
                    //if(d.Expression != null)
                    //{
                    //    rval.Add(d.Expression as IUniqueDef);
                    //}
                    //if(d.Instruction != null)
                    //{
                    //    rval.Add(d.Instruction as IUniqueDef);
                    //}
                    if (d.OctaveShift != null)
                    {
                        rval.Add(d.OctaveShift as IUniqueDef);
                    }
                    //if(d.Wedge != null)
                    //{
                    //    rval.Add(d.Wedge as IUniqueDef);
                    //}
                }
                else if (seqObj is Event evt)
                {
                    evt.OctaveShift = octaveShift;
                    octaveShift     = null;
                    rval.Add(evt as IUniqueDef);
                }
                else if (seqObj is Grace g)
                {
                    var graceComponents = g.Components;
                    foreach (var graceCompt in graceComponents)
                    {
                        // Assuming that Grace groups can only contain Events and Directions...
                        if (graceCompt is Event graceEvt)
                        {
                            graceEvt.OctaveShift = octaveShift;
                            octaveShift          = null;
                            rval.Add(graceEvt as IUniqueDef);
                        }
                    }
                }
                else if (seqObj is TupletDef t)
                {
                    octaveShift = GetTupletComponents(t, rval, octaveShift);
                }
                else if (seqObj is BeamBlocks beamBlocks)
                {
                    //foreach(var beamBlock in beamBlocks.Blocks)
                    //{
                    //    rval.Add(beamBlock as IUniqueDef);
                    //}
                }
                else
                {
                    throw new ApplicationException("unhandled SequenceComponent type.");
                    //rval.Add(seqObj as IUniqueDef);
                }
            }
            return(rval);
        }
Example #2
0
        /// <summary>
        /// recursive function (for nested tuplets)
        /// </summary>
        /// <param name="tupletDef"></param>
        /// <param name="iuds"></param>
        /// <param name="octaveShift"></param>
        /// <returns>current octave shift (can be null)</returns>
        private OctaveShift GetTupletComponents(TupletDef tupletDef, List <IUniqueDef> iuds, OctaveShift octaveShift)
        {
            var   tupletComponents = tupletDef.Components;
            Event firstEvent       = (Event)tupletComponents.Find(e => e is Event);

            if (firstEvent.TupletDefs == null)
            {
                firstEvent.TupletDefs = new List <TupletDef>();
            }
            firstEvent.TupletDefs.Add(tupletDef);
            foreach (var component in tupletComponents)
            {
                if (component is Event tupletEvt)
                {
                    tupletEvt.OctaveShift = octaveShift;
                    octaveShift           = null;
                    iuds.Add(tupletEvt as IUniqueDef);
                }
                else if (component is Grace g)
                {
                    var graceComponents = g.Components;
                    foreach (var graceCompt in graceComponents)
                    {
                        // Assuming that Grace groups can only contain Events and Directions...
                        if (graceCompt is Event graceEvt)
                        {
                            graceEvt.OctaveShift = octaveShift;
                            octaveShift          = null;
                            iuds.Add(graceEvt as IUniqueDef);
                        }
                    }
                }
                else if (component is TupletDef tplet)
                {
                    // recursive call
                    octaveShift = GetTupletComponents(tplet, iuds, octaveShift);
                }
            }

            return(octaveShift);
        }
Example #3
0
        public SequenceDirections(XmlReader r, TimeSignature currentTimeSignature)
        {
            M.Assert(r.Name == "directions");

            M.ReadToXmlElementTag(r, "clef", "cresc", "dim", "dynamics", "expression", "instruction", "octave-shift", "wedge", "text-block");

            while (r.Name == "clef" || r.Name == "cresc" || r.Name == "dim" || r.Name == "dynamics" ||
                   r.Name == "expression" || r.Name == "instruction" || r.Name == "octave-shift" || r.Name == "wedge" || r.Name == "text-block")
            {
                if (r.NodeType != XmlNodeType.EndElement)
                {
                    switch (r.Name)
                    {
                    case "clef":
                        Clef = new Clef(r);
                        Components.Add(Clef);
                        break;

                    case "cresc":
                        // TODO
                        break;

                    case "dim":
                        // TODO
                        break;

                    case "dynamics":
                        // TODO
                        break;

                    case "expression":
                        // TODO
                        break;

                    case "instruction":
                        // TODO
                        break;

                    case "octave-shift":
                        OctaveShift = new OctaveShift(r);
                        Components.Add(OctaveShift);
                        break;

                    case "wedge":
                        // TODO
                        break;

                    case "text-block":
                        TextBlock = new TextBlock(r);
                        Components.Add(TextBlock);
                        break;
                    }
                }
                M.ReadToXmlElementTag(r, "clef", "cresc", "dim", "dynamics", "expression", "instruction", "octave-shift", "wedge", "text-block", "directions");
            }

            if (Repeats != null)
            {
                SetDefaultRepeatPositions(Repeats, currentTimeSignature);
            }

            M.Assert(r.Name == "directions"); // end of "directions"
        }