Ejemplo n.º 1
0
		public void SetUp()
		{
			_scoreWithStaffValues = MusicXmlParser.GetScore("TestData/MusicXmlWithStaffValues.xml");
		}
Ejemplo n.º 2
0
		public static Score GetScore(string filename)
		{
			var document = GetXmlDocument(filename);

			var score = new Score();

			var movementTitleNode = document.SelectSingleNode("score-partwise/movement-title");
			if (movementTitleNode != null)
				score.MovementTitle = movementTitleNode.InnerText;

			score.Identification = GetIdentification(document);
			
			var partNodes = document.SelectNodes("score-partwise/part-list/score-part");
			
			if (partNodes != null)
			{
				foreach (XmlNode partNode in partNodes)
				{
					var part = new Part();
					score.Parts.Add(part);

					if (partNode.Attributes != null)
						part.Id = partNode.Attributes["id"].InnerText;
					
					var partNameNode = partNode.SelectSingleNode("part-name");
					
					if (partNameNode != null)
						part.Name = partNameNode.InnerText;

					var measuresXpath = string.Format("//part[@id='{0}']/measure", part.Id);

					var measureNodes = partNode.SelectNodes(measuresXpath);

					if (measureNodes != null)
					{
						foreach (XmlNode measureNode in measureNodes)
						{
							var measure = new Measure();

							if (measureNode.Attributes != null)
							{
								var measureWidthAttribute = measureNode.Attributes["width"];
								if (measureWidthAttribute != null)
									measure.Width = Convert.ToInt32(measureWidthAttribute.InnerText);
							}

							var attributesNode = measureNode.SelectSingleNode("attributes");

							if (attributesNode != null)
							{
								measure.Attributes = new MeasureAttributes();

								var divisionsNode = attributesNode.SelectSingleNode("divisions");
								if (divisionsNode != null)
									measure.Attributes.Divisions = Convert.ToInt32(divisionsNode.InnerText);

								var keyNode = attributesNode.SelectSingleNode("key");

								if (keyNode != null)
								{
									measure.Attributes.Key = new Key();

									var fifthsNode = keyNode.SelectSingleNode("fifths");
									if (fifthsNode != null)
										measure.Attributes.Key.Fifths = Convert.ToInt32(fifthsNode.InnerText);

									var modeNode = keyNode.SelectSingleNode("mode");
									if (modeNode != null)
										measure.Attributes.Key.Mode = modeNode.InnerText;
								}
								
								measure.Attributes.Time = GetTime(attributesNode);

								measure.Attributes.Clef = GetClef(attributesNode);
							}

							var childNodes = measureNode.ChildNodes;

							foreach (XmlNode node in childNodes)
							{
								MeasureElement measureElement = null;

								if (node.Name == "note")
								{
									var newNote = GetNote(node);
									measureElement = new MeasureElement {Type = MeasureElementType.Note, Element = newNote};
								}
								else if (node.Name == "backup")
								{
									measureElement = new MeasureElement {Type = MeasureElementType.Backup, Element = GetBackupElement(node)};
								}
								else if (node.Name == "forward")
								{
									measureElement = new MeasureElement {Type = MeasureElementType.Forward, Element = GetForwardElement(node)};
								}

								if (measureElement != null)
									measure.MeasureElements.Add(measureElement);
							}
							
							part.Measures.Add(measure);
						}
					}
				}
			}

			return score;
		}