/// <summary> /// Adds properties to a Mensur object. /// </summary> /// <param name="_mensobj">Empty mensur object</param> /// <param name="_meimensur">MEI mensur element</param> /// <returns>Mensur object with data</returns> public static Model.Mensur ConvertMensur(Model.Mensur _mensobj, mei.Mensur _meimensur) { //Convert logic mensural values //If Modus and modusmaior are null, set value to 2 _mensobj.Maximodus = ConvertLogicMensurAttribute(_meimensur.GetModusmaiorAttribute(), false, 2); _mensobj.Modus = ConvertLogicMensurAttribute(_meimensur.GetModusminorAttribute(), false, 2); //Tempus and Prolatio are not allowed to be null _mensobj.Tempus = ConvertLogicMensurAttribute(_meimensur.GetTempusAttribute()); _mensobj.Prolatio = ConvertLogicMensurAttribute(_meimensur.GetProlatioAttribute()); //Get sign _mensobj.Sign = GetSign(_meimensur); return(_mensobj); }
/// <summary> /// Initializes metric system according to mensur /// </summary> /// <param name="_mensur">Mensur Object</param> private static void InitMetricTable(Model.Mensur _mensur) { if (MetricTable == null) { MetricTable = new Dictionary <Duration, Fraction> { { Duration.Longa, 1 * _mensur.Modus }, { Duration.Brevis, 1 }, { Duration.Semibrevis, new Fraction(1, _mensur.Tempus) }, }; //Add Maximodus and Prolatio MetricTable.Add(Duration.Minima, MetricTable[Duration.Semibrevis] / _mensur.Prolatio); MetricTable.Add(Duration.Maxima, MetricTable[Duration.Longa] * _mensur.Maximodus); //Add small values always as binary MetricTable.Add(Duration.Semiminima, MetricTable[Duration.Minima] / 2); MetricTable.Add(Duration.Fusa, MetricTable[Duration.Semiminima] / 2); MetricTable.Add(Duration.Semifusa, MetricTable[Duration.Fusa] / 2); } //For changes of mensuration, rewrite dictionary. else { //Change modus and tempus MetricTable[Duration.Longa] = 1 * _mensur.Modus; MetricTable[Duration.Semibrevis] = new Fraction(1, _mensur.Tempus); //Change Maximodus and Prolatio MetricTable[Duration.Maxima] = MetricTable[Duration.Longa] * _mensur.Maximodus; MetricTable[Duration.Minima] = MetricTable[Duration.Semibrevis] / _mensur.Prolatio; //Reset small values to binary MetricTable[Duration.Semiminima] = MetricTable[Duration.Minima] / 2; MetricTable[Duration.Fusa] = MetricTable[Duration.Semiminima] / 2; MetricTable[Duration.Semifusa] = MetricTable[Duration.Fusa] / 2; } if (InterNoteQuotient == null) { InterNoteQuotient = new Dictionary <Duration, int> { { Duration.Maxima, 1 }, { Duration.Longa, _mensur.Maximodus }, { Duration.Brevis, _mensur.Modus }, { Duration.Semibrevis, _mensur.Tempus }, { Duration.Minima, _mensur.Prolatio }, { Duration.Semiminima, 2 }, { Duration.Fusa, 2 }, { Duration.Semifusa, 2 } }; } //For changes of mensuration, rewrite also this. else { InterNoteQuotient[Duration.Longa] = _mensur.Maximodus; InterNoteQuotient[Duration.Brevis] = _mensur.Modus; InterNoteQuotient[Duration.Semibrevis] = _mensur.Tempus; InterNoteQuotient[Duration.Minima] = _mensur.Prolatio; InterNoteQuotient[Duration.Semiminima] = 2; InterNoteQuotient[Duration.Fusa] = 2; InterNoteQuotient[Duration.Semifusa] = 2; } }
/// <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); }