/// <summary>
        /// Adds properties to a Proportion object.
        /// </summary>
        /// <param name="_propobj">Empty proportion object</param>
        /// <param name="_meiprop">MEI proport element</param>
        /// <returns>Proportion object with data</returns>
        public static Model.Proportion ConvertProportion(Model.Proportion _propobj, mei.Proport _meiprop)
        {
            _propobj.Sign     = GetSign(_meiprop);
            _propobj.Affected = ConvertAffected(_meiprop);

            if (_meiprop.HasNum() && _meiprop.HasNumbase())
            {
                _propobj.Num     = ConverterHelper.ConvertNumNumbase(_meiprop.GetNumAttribute());
                _propobj.Numbase = ConverterHelper.ConvertNumNumbase(_meiprop.GetNumbaseAttribute());
            }
            else
            {
                throw new NullReferenceException($"<proport> doesn't have @num or @numbase!");
            }

            return(_propobj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Changes metric system according to proportion
        /// </summary>
        /// <param name="_prop">Proportion object</param>
        private static void SetProportion(Model.Proportion _prop)
        {
            if (MetricTable == null)
            {
                throw new Exception("Proportion without preceding mensur!");
            }
            else
            {
                //Get index value of duration enum
                int affectedInt = (int)_prop.Affected;

                //Affected duration needs to be a valid duration, so the index of the affected duration needs to be at least the value of Maxima
                if ((int)_prop.Affected >= (int)Duration.Maxima)
                {
                    for (int i = (int)Duration.Maxima; i <= (int)Duration.Semifusa; i++)
                    {
                        //Gets index of the next greater note value, if there is no greater value (in case of Maxima), set the actual note value
                        int nextGreater = MetricTable.ContainsKey((Duration)i - 1) ? i - 1 : i;

                        //Calculate relative duration of actual note value based on the next greater
                        MetricTable[(Duration)i] = (MetricTable[(Duration)nextGreater] / InterNoteQuotient[(Duration)i]);

                        //If proportion affects the actual note value, modify the relative duration by the proportion ratio.
                        if (i == affectedInt)
                        {
                            MetricTable[(Duration)i] = MetricTable[(Duration)i] * _prop.Ratio;
                        }
                        //By calculating a duration relative to the duration of the next greater note value, proportion changes are passed to smaller note values.
                    }
                }
                else if (_prop.Affected == Duration.Null)
                {
                    //if Affected is empty, apply proportion to every value of metric table
                    foreach (KeyValuePair <Duration, Fraction> metricPair in MetricTable)
                    {
                        MetricTable[metricPair.Key] = metricPair.Value * _prop.Ratio;
                    }
                }
                else
                {
                    throw new Exception("Proportion cannot be applied!");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invokes a Sequence object for the given MEI element
        /// </summary>
        /// <param name="_sequence">Sequence</param>
        /// <param name="layerElement">MEI Element to process</param>
        internal static ObjectInSequence InvokeSequenceObject(Sequence _sequence, MeiElement layerElement, Evidence evidence = Evidence.Clear, int ligaturePos = 0, string ligForm = null)
        {
            ObjectInSequence obj = null;

            if (layerElement is mei.Note note)
            {
                obj = new Model.Note();
                NoteConverter.ConvertNote((Model.Note)obj, note);

                //check for @lig attribute
                if (note.HasLig())
                {
                    ligForm = note.GetLigValue();
                }

                TinyConverters.LigatureHandler((Model.Note)obj, ligaturePos, ligForm);
            }
            // Ligatures needs to be be handled recursively to get their elements and store related data
            else if (layerElement is mei.Ligature ligature)
            {
                foreach (MeiElement ligaturChild in ligature.Elements())
                {
                    ligaturePos++;
                    InvokeSequenceObject(_sequence, ligaturChild, evidence, ligaturePos, ligature.GetFormValue());
                }
                ligaturePos = 0;
            }
            else if (layerElement is mei.Rest)
            {
                obj = new Model.Rest();
                RestConverter.ConvertRest((Model.Rest)obj, (mei.Rest)layerElement);
            }
            else if (layerElement is Chord)
            {
                // We need a List of all objects in the Chord to add them to the sequence at the same position
                List <ObjectInSequence> lstChordEvents = new List <ObjectInSequence>();
                foreach (MeiElement noteRest in layerElement.Descendants())
                {
                    ObjectInSequence objNoteRest = InvokeSequenceObject(null, noteRest);
                    if (objNoteRest != null)
                    {
                        lstChordEvents.Add(objNoteRest);
                    }
                }

                _sequence?.AddToSequence(lstChordEvents.ToArray());
            }
            else if (layerElement is mei.KeySig)
            {
                // We need a List of all KeyAccids in the KeySig to add them to the sequence at the same position
                List <ObjectInSequence> lstAcids = new List <ObjectInSequence>();
                foreach (KeyAccid keyAccid in layerElement.Elements())
                {
                    lstAcids.Add(InvokeSequenceObject(null, keyAccid));
                }

                _sequence?.AddToSequence(lstAcids.ToArray());
            }
            else if (layerElement is KeyAccid)
            {
                obj = new Model.KeyAccidental();
                AccidentalConverter.ConvertKeyAccidental((Model.KeyAccidental)obj, (mei.KeyAccid)layerElement);
            }
            else if (layerElement is mei.Accid)
            {
                obj = new Model.Accidental();
                AccidentalConverter.ConvertAccidental((Model.Accidental)obj, (mei.Accid)layerElement);
            }
            else if (layerElement is mei.Mensur)
            {
                obj = new Model.Mensur();
                MensurProportionConverter.ConvertMensur((Model.Mensur)obj, (mei.Mensur)layerElement);
            }
            else if (layerElement is mei.Proport)
            {
                obj = new Model.Proportion();
                MensurProportionConverter.ConvertProportion((Model.Proportion)obj, (mei.Proport)layerElement);
            }
            else if (layerElement is mei.BarLine)
            {
                obj = new Model.Barline();
                TinyConverters.ConvertBarline((Model.Barline)obj, (mei.BarLine)layerElement);
            }
            else if (layerElement is mei.Dot)
            {
                obj = new Model.Dot();
            }
            else if (layerElement is mei.Clef)
            {
                obj = new Model.Clef();
                TinyConverters.ConvertClef((Model.Clef)obj, (mei.Clef)layerElement);
            }
            else if (layerElement is mei.Custos)
            {
                obj = new Model.Custos();
                TinyConverters.ConvertCustos((Model.Custos)obj, (mei.Custos)layerElement);
            }
            else if (layerElement is mei.Unclear || layerElement is mei.Supplied)
            {
                Evidence evd = TinyConverters.GetEvidence(layerElement);
                foreach (MeiElement evdChild in layerElement.Elements())
                {
                    InvokeSequenceObject(_sequence, evdChild, evd);
                }
            }
            else if (layerElement is mei.Damage || layerElement is mei.Gap)
            {
                obj = new Model.Gap();
                TinyConverters.ConvertGap((Model.Gap)obj, layerElement);
            }

            if (obj != null)
            {
                //After type definition, add ID of MEI element
                obj.ID = layerElement.GetId();

                //Set Evidence
                obj.Evidence = evidence;

                //Add to sequence if defined
                _sequence?.AddToSequence(obj);
            }

            return(obj);
        }