public void ImportDocumentTest2()
        {
            MeiDocument testDoc = MeiImport.ImportDocument("..\\..\\files\\MeiImportTest2.xml");

            Assert.IsNotNull(testDoc.SchemaLocation);
            Assert.IsNotNull(from node in testDoc.Nodes().OfType <XProcessingInstruction>() select node.Target != "xml-model");
        }
Example #2
0
        /// <summary>
        /// Reads Mei-File and generates sequences per panel.
        /// </summary>
        /// <param name="_filedir">Path to Mei file</param>
        /// <returns>List of sequence objects</returns>
        public static List <Sequence> GetSequences(string _filedir)
        {
            MeiDocument doc  = MeiImport.ImportDocument(_filedir);
            MeiElement  root = doc.Root;

            List <Sequence> sequences = new List <Sequence>();

            string piece;

            //Get name of piece
            try
            {
                piece = root.Element <MeiHead>().Element <FileDesc>().Descendants <Title>().FirstOrDefault().Value;
            }
            catch
            {
                string[] splitUri = doc.BaseUri.Split('/');
                piece = splitUri[splitUri.Length - 1];
            }

            foreach (Panel panel in root.Descendants <Panel>())
            {
                List <Sequence> sequencesPerPart = SequenceHandler.GetPreConversionSequence(panel, piece);

                foreach (Sequence stateSequence in sequencesPerPart)
                {
                    sequences.Add(stateSequence);
                }
            }

            return(sequences);
        }
        public void ConvertBrevePositionChord()
        {
            Sequence metricSequence = SequenceHandler.CreateNewSequence("kind of test", "Breve position Chord", "noPage", "Tenor", 3);
            Panel    metricPanel    = MeiImport.ImportDocument("..\\..\\files\\tests\\MetricSequenceChord.xml").Root.Descendants <Panel>().FirstOrDefault();

            SequenceHandler.FlattenMeiToSequence(metricPanel, metricSequence);
            Controller.BuildSequence(metricSequence);

            SequenceConversion.ConvertBrevePosition(metricSequence);

            foreach (ObjectInSequence obj in metricSequence.ObjectsInSequence)
            {
                IAttCommon corresp = (IAttCommon)metricPanel.Descendants().FirstOrDefault(element => element.GetId() == obj.ID);

                if (corresp.HasN())
                {
                    Fraction exp = new Fraction(corresp.GetNValue());

                    if (obj is Model.Rest rest)
                    {
                        //Check if expected value is not null and then compare
                        Assert.IsNotNull(exp);
                        Assert.AreEqual(exp, rest.BrevePosition);
                    }
                }
            }

            metricPanel    = null;
            metricSequence = null;
        }
        public void ConvertAbsolutePitchTest()
        {
            Sequence aPitchSeq   = SequenceHandler.CreateNewSequence("Test", "Absolute Pitch", "noPage", "AbsolutePitch", 1);
            Panel    aPitchPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\AbsolutePitch.xml").Root.Descendants <Panel>().FirstOrDefault();

            SequenceHandler.FlattenMeiToSequence(aPitchPanel, aPitchSeq);
            Controller.BuildSequence(aPitchSeq);
            SequenceConversion.ConvertAbsolutePitch(aPitchSeq);

            foreach (Model.Note note in aPitchSeq.ObjectsInSequence.Where(item => item is Model.Note))
            {
                Assert.IsNotNull(note.WrittenPitch);

                mei.Note corresp = (mei.Note)aPitchPanel.Descendants().FirstOrDefault(element => element.GetId() == note.ID);

                if (corresp.HasPnum())
                {
                    if (Int32.TryParse(corresp.GetPnumValue(), out int pnum))
                    {
                        Assert.AreEqual(pnum, note.PitchWithAccid);
                    }
                    else
                    {
                        throw new ArgumentNullException("Pnum could not be parsed!");
                    }
                }
            }
        }
        public void ConvertLigatureTest()
        {
            Sequence ligSequence = SequenceHandler.CreateNewSequence("Test", "Ligature", "noPage", "Tenor", 3);
            Panel    ligPanel    = MeiImport.ImportDocument("..\\..\\files\\tests\\LigatureTest.xml").Root.Descendants <Panel>().FirstOrDefault();

            SequenceHandler.FlattenMeiToSequence(ligPanel, ligSequence);
            Controller.BuildSequence(ligSequence);

            foreach (Model.Note note in ligSequence.ObjectsInSequence.Where(item => item is Model.Note))
            {
                Assert.IsNotNull(note.LigaturePosition);
                Assert.IsNotNull(note.LigatureForm);

                if (note.LigaturePosition == 1)
                {
                    Assert.AreEqual(StemDesc.LeftUp, note.Stem);
                }

                if (note.Position == 3 || note.Position == 4 || note.Position == 10 || note.Position == 11)
                {
                    Assert.AreEqual(LigatureForm.Obliqua, note.LigatureForm);
                }
                else
                {
                    Assert.AreEqual(LigatureForm.Recta, note.LigatureForm);
                }
            }
        }
        public void GetSequencesTest()
        {
            int countSequences = this.testList.Count();

            MeiElement root       = MeiImport.ImportDocument("..\\..\\files\\VatS-13a-TuSolus.xml").Root;
            int        countPanel = root.Descendants <Panel>().Count();

            Assert.AreEqual(countPanel, countSequences);
        }
        public void ImportExportCompare()
        {
            XDocument   xDoc   = XDocument.Load("..\\..\\files\\MeiImportTest2.xml");
            MeiDocument meiDoc = MeiImport.ImportDocument("..\\..\\files\\MeiImportTest2.xml");

            string xString   = xDoc.ToString();
            string meiString = meiDoc.ToString();

            Equals(xString, meiString);
        }
        public void Init()
        {
            //this.testSequence = SequenceHandler.CreateNewSequence("kind of mass", "Kyrie", "Tenor", 3);
            //this.testPanel = MeiImport.ImportDocument("..\\..\\files\\Capp.Sist.41-13a-TuSous_clean.xml").Root.Descendants<Panel>().FirstOrDefault(panel => panel.GetNValue() == "2");

            //SequenceHandler.FlattenMeiToSequence(this.testPanel, this.testSequence);
            //Controller.BuildSequence(this.testSequence);

            testPanels = MeiImport.ImportDocument("..\\..\\files\\VatS-13a-TuSolus.xml").Root.Descendants <Panel>();

            this.testList = Controller.GetSequences("..\\..\\files\\VatS-13a-TuSolus.xml");
            foreach (Sequence sequence in testList)
            {
                Controller.BuildSequence(sequence);
            }
        }
        public void ConvertBrevePositionGap()
        {
            Sequence metricSequence = SequenceHandler.CreateNewSequence("kind of test", "Breve position with gaps", "noPage", "Tenor", 3);
            Panel    metricPanel    = MeiImport.ImportDocument("..\\..\\files\\tests\\MetricSequenceDamage.xml").Root.Descendants <Panel>().FirstOrDefault();

            SequenceHandler.FlattenMeiToSequence(metricPanel, metricSequence);
            Controller.BuildSequence(metricSequence);

            SequenceConversion.ConvertBrevePosition(metricSequence);

            foreach (ObjectInSequence obj in metricSequence.ObjectsInSequence)
            {
                if (obj is Model.Rest rest)
                {
                    IAttCommon corresp = (IAttCommon)metricPanel.Descendants().FirstOrDefault(element => element.GetId() == obj.ID);

                    Fraction expBP  = 0;
                    Fraction expPaG = 0;

                    if (corresp.HasN())
                    {
                        expBP = new Fraction(corresp.GetNValue());
                    }
                    else if (corresp.HasLabel())
                    {
                        expPaG = new Fraction(corresp.GetLabelValue());
                    }

                    //Check if expected value is not null and then compare
                    if (expBP != 0)
                    {
                        Assert.AreEqual(expBP, rest.BrevePosition);
                    }
                    else if (expPaG != 0)
                    {
                        Assert.AreEqual(expPaG, rest.AfterGapPosition);
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }

            metricPanel    = null;
            metricSequence = null;
        }
        public void ImportDocumentTest3()
        {
            MeiDocument testDoc = MeiImport.ImportDocument("..\\..\\files\\MeiImportTest3.xml");

            IEnumerable <XProcessingInstruction> models = from node in testDoc.Nodes().OfType <XProcessingInstruction>().Where(node => node.Target == "xml-model") select node;

            List <string> href_compare = new List <string>();

            Match hrefs;

            foreach (XProcessingInstruction model in models)
            {
                //Get schemaLocation from pImodel.Data
                //See example here: https://msdn.microsoft.com/de-de/library/t9e807fx(v=vs.110).aspx

                string HRefPattern = "href\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))";

                try
                {
                    hrefs = Regex.Match(model.Data, HRefPattern,
                                        RegexOptions.IgnoreCase | RegexOptions.Compiled,
                                        TimeSpan.FromSeconds(1));
                    while (hrefs.Success)
                    {
                        href_compare.Add(hrefs.Groups[1].ToString());
                        hrefs = hrefs.NextMatch();
                    }
                }

                catch (RegexMatchTimeoutException)
                {
                    break;
                }
            }

            Assert.AreEqual(testDoc.SchemaLocation, string.Empty);
            CollectionAssert.AllItemsAreUnique(href_compare);
        }
        public void ConvertGapTest()
        {
            Sequence gapSequence = SequenceHandler.CreateNewSequence("Test", "Gap", "noPage", "Tenor", 3);
            Panel    gapPanel    = MeiImport.ImportDocument("..\\..\\files\\tests\\DamageTest.xml").Root.Descendants <Panel>().FirstOrDefault();

            SequenceHandler.FlattenMeiToSequence(gapPanel, gapSequence);
            Controller.BuildSequence(gapSequence);

            Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[4], typeof(Model.Gap));
            Model.Gap gap1 = (Model.Gap)gapSequence.ObjectsInSequence[4];
            Assert.AreEqual(gap1.GapType, GapType.Damage);

            Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[6], typeof(Model.Gap));
            Model.Gap gap2 = (Model.Gap)gapSequence.ObjectsInSequence[6];
            Assert.AreEqual(gap2.GapType, GapType.Damage);

            Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[7], typeof(Model.Gap));
            Model.Gap gap3 = (Model.Gap)gapSequence.ObjectsInSequence[7];
            Assert.AreEqual(gap3.GapType, GapType.Damage);

            Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[20], typeof(Model.Gap));
            Model.Gap gap4 = (Model.Gap)gapSequence.ObjectsInSequence[20];
            Assert.AreEqual(gap4.GapType, GapType.Gap);
        }
        public void ImportDocumentTest1()
        {
            MeiDocument testDoc = MeiImport.ImportDocument("..\\..\\files\\MeiImportTest1.xml");

            Assert.IsNotNull(testDoc);
        }