コード例 #1
0
        internal static string[] GetStringData(ObjectInSequence _obj)
        {
            object[] objData      = WriteToDataRow(_obj);
            string[] strArrReturn = new string[objData.Length];
            for (int intIndex = 0; intIndex < objData.Length; intIndex++)
            {
                strArrReturn[intIndex] = objData[intIndex]?.ToString();
            }

            return(strArrReturn);
        }
コード例 #2
0
 /// <summary>
 /// Returns the classification of an ObjectInSequence
 /// </summary>
 /// <param name="_obj">ObjectInSequence</param>
 /// <returns>Classification value</returns>
 public static string GetClassification(ObjectInSequence _obj)
 {
     if (_obj is Rest rest)
     {
         if (rest is Note note && note.Coloration == true)
         {
             return("colored" + rest.Duration.ToString());
         }
         else
         {
             return(rest.Duration.ToString());
         }
     }
コード例 #3
0
        internal static object[] WriteToDataRow(ObjectInSequence _obj)
        {
            //Get Evidence value
            decimal evidence = ConvertEvidence(_obj.Evidence);
            //Get Classification
            string classification = GetClassification(_obj);
            //Get Pitch Position
            int?pitchPos = GetPitchPosition(_obj);
            //Get Visual Features
            string visual = GetVisualFeatures(_obj);
            //Get Breve Position
            string strBrevePos = GetBrevePos(_obj);
            //Get inflected Pitch
            int?infPitch = GetInflectedPitch(_obj);

            //Position  ObjectType  Evidence  Classification  PitchPosition  VisualFeatures   BrevePosition   InflectedPitch
            object[] sequenceObj = { _obj.Position, _obj.Type, evidence, classification, pitchPos, visual, strBrevePos, infPitch };

            return(sequenceObj);
        }
コード例 #4
0
        public void BuildSequence_TestPosition()
        {
            foreach (Sequence testSequence in testList)
            {
                List <MeiElement> testList = new List <MeiElement>();

                int countPos = 0;

                foreach (MeiElement meiElement in testSequence.MeiObjects.Values)
                {
                    if (meiElement is KeySig)
                    {
                        foreach (KeyAccid keyacc in meiElement.Elements <KeyAccid>())
                        {
                            keyacc.SetAttributeValue("n", countPos);
                            testList.Add(keyacc);
                        }
                        countPos++;
                    }
                    else if (meiElement is Chord)
                    {
                        foreach (MeiElement chordDesc in meiElement.Descendants())
                        {
                            if (chordDesc.Name.LocalName == "note" || chordDesc.Name.LocalName == "rest")
                            {
                                chordDesc.SetAttributeValue("n", countPos);
                                testList.Add(chordDesc);
                            }
                        }
                        countPos++;
                    }
                    else if (meiElement is Ligature)
                    {
                        foreach (MeiElement ligchild in meiElement.Elements())
                        {
                            ligchild.SetAttributeValue("n", countPos);
                            testList.Add(ligchild);
                            countPos++;
                        }
                    }
                    else if (meiElement is Unclear)
                    {
                        foreach (MeiElement unclearChild in meiElement.Elements())
                        {
                            unclearChild.SetAttributeValue("n", countPos);
                            testList.Add(unclearChild);
                            countPos++;
                        }
                    }
                    else
                    {
                        meiElement.SetAttributeValue("n", countPos);
                        testList.Add(meiElement);
                        countPos++;
                    }
                }

                foreach (MeiElement compare in testList)
                {
                    ObjectInSequence comparison = testSequence.ObjectsInSequence.FirstOrDefault(obj => obj.ID == compare.GetId());
                    if (Int32.TryParse(compare.Attribute("n").Value, out int position) == true)
                    {
                        Assert.AreEqual(position, comparison.Position);
                    }
                }
            }
        }
コード例 #5
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);
        }