public void TestRendering() { var currentResults = new ScoreRenderingTestResultsRepository(GetDirectoryPath(inProgressPath)); var previousResults = GetPreviousResults(outputPath); var renderer = new UnitTestScoreRenderer(currentResults); foreach (var file in Directory.EnumerateFiles(inputPath, "*.xml", SearchOption.AllDirectories)) { var xDocument = XDocument.Load(file); var parser = new MusicXmlParser(); var score = parser.Parse(xDocument); foreach (var staff in score.Staves) { Assert.IsTrue(staff.Measures.Where(m => m.Number.HasValue).GroupBy(m => m.Number.Value).All(g => g.Count() == 1), "Duplicate measure numbers detected."); } renderer.Render(score); Assert.IsTrue(!renderer.Exceptions.Any(), "Exceptions occured while rendering."); currentResults.Persist(Path.GetFileName(file)); if (previousResults != null) { previousResults.Load(Path.GetFileName(file)); PerformAssertions(currentResults, previousResults, Path.GetFileName(file)); } } var successPath = Path.Combine(outputPath, Path.GetFileName(currentResults.DataPath)); Directory.Move(currentResults.DataPath, successPath); }
//protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint) //{ // return new SizeRequest(new Size(widthConstraint, heightConstraint)); //} private static void XmlSourceChanged(BindableObject obj, string oldValue, string newValue) { NoteViewer viewer = obj as NoteViewer; if (string.IsNullOrWhiteSpace(newValue)) { if (!string.IsNullOrWhiteSpace(oldValue)) { viewer.Children.Clear(); } return; } XDocument xmlDocument = XDocument.Parse(newValue); //Apply transformations: if (viewer.XmlTransformations != null) { foreach (var transformation in viewer.XmlTransformations) { xmlDocument = transformation.Parse(xmlDocument); } } MusicXmlParser parser = new MusicXmlParser(); var score = parser.Parse(xmlDocument); score.MeasureInvalidated -= viewer.Score_MeasureInvalidated; viewer.RenderOnCanvas(score); score.MeasureInvalidated += viewer.Score_MeasureInvalidated; }
private static MvcHtmlString NoteViewerHelper(HtmlHelper htmlHelper, string musicXml, HtmlScoreRendererSettings settings) { MusicXmlParser parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Parse(musicXml)); return(NoteViewerHelper(htmlHelper, score, settings)); }
/// <summary> /// Loads the viewer with a Score object generated from the specified MusicXml file. /// </summary> public void loadFile(string fileName) { this.fileName = fileName; if (File.Exists(fileName)) { // Parser instance converts between Score object and MusicXML var parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Load(fileName)); // Load the content of the specified file into Data Data = score; keySig = (Key)score.FirstStaff.Elements.First(k => k.GetType() == typeof(Key)); if (KeySig == null) { KeySig = new Key(0); } timeSig = (TimeSignature)score.FirstStaff.Elements.First(k => k.GetType() == typeof(TimeSignature)); if (timeSig == null) { timeSig = TimeSignature.CommonTime; } } else { throw new FileNotFoundException(fileName + " not found."); //This and any parser exceptions will be caught by the calling function } }
private string ParseMusicXmlFile(string path) { string xml = File.ReadAllText(path); var patternBuilder = new StaccatoPatternBuilder(xmlParser); xmlParser.Parse(xml); return(patternBuilder.Pattern.ToString()); }
/// <summary> /// Reads a score from MusicXml document with specific XTransformerParser. /// </summary> /// <param name="document"></param> /// <param name="transformer"></param> /// <returns></returns> public static Score ToScore(this XDocument document, XTransformerParser transformer) { MusicXmlParser parser = new MusicXmlParser(); if (transformer != null) { document = transformer.Parse(document); } return(parser.Parse(document)); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "MusicXml (*.xml)|*.xml"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { MusicXmlParser parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Parse(File.ReadAllText(dialog.FileName))); noteViewer1.DataSource = score; noteViewer1.Refresh(); } }
/// <summary> /// Loads the viewer with a Score object generated from the specified MusicXml file. /// </summary> public void loadFile(string fileName) { this.fileName = fileName; if (File.Exists(fileName)) { // Parser instance converts between Score object and MusicXML var parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Load(fileName)); // Load the content of the specified file into Data Data = score; } else { throw new FileNotFoundException(fileName + " not found."); //This and any parser exceptions will be caught by the calling function } }
/// <summary> /// Loads the viewer with a Score object generated from the specified MusicXml file. /// </summary> public void loadFile(string fileName) { this.fileName = fileName; if (File.Exists(fileName)) { // Parser instance converts between Score object and MusicXML var parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Load(fileName)); // Load the content of the specified file into Data data = null; Data = score; // Get the key signature keySig = (Key)score.FirstStaff.Elements.First(k => k.GetType() == typeof(Key)); if (KeySig == null) { KeySig = new Key(0); } // Get the time signature timeSig = (TimeSignature)score.FirstStaff.Elements.First(k => k.GetType() == typeof(TimeSignature)); if (timeSig == null) { timeSig = TimeSignature.CommonTime; } // Set up the back end data model staves = null; staves = new List <LStaff>(); foreach (var staff in score.Staves) { LStaff ls = null; List <LMeasure> measures = new List <LMeasure>(); foreach (var measure in staff.Measures) { LMeasure m = new LMeasure(measure.Elements, ls, timeSig.WholeNoteCapacity); measures.Add(m); } ls = new LStaff(staff, measures); this.staves.Add(ls); } player = new MidiTaskScorePlayer(data); updateView(); } else { throw new FileNotFoundException(fileName + " not found."); //This and any parser exceptions will be caught by the calling function } }
private static void XmlSourceChanged(NoteViewer contol, string oldValue, string newValue) { XDocument xmlDocument = XDocument.Parse(newValue); //Apply transformations: if (contol.XmlTransformations != null) { foreach (var transformation in contol.XmlTransformations) { xmlDocument = transformation.Parse(xmlDocument); } } MusicXmlParser parser = new MusicXmlParser(); var score = parser.Parse(xmlDocument); contol.RenderOnCanvas(score); }
private static void XmlSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { NoteViewer contol = (NoteViewer)obj; string oldValue = args.OldValue as string; string newValue = args.NewValue as string; var xmlDocument = XDocument.Parse(newValue); //Apply transformations: if (contol.XmlTransformations != null) { //foreach (var transformation in contol.XmlTransformations) xmlDocument = transformation.Parse(xmlDocument); } MusicXmlParser parser = new MusicXmlParser(); var score = parser.Parse(xmlDocument); contol.RenderOnCanvas(score); }
public static void XmlSourceChanged(IXamlNoteViewer viewer, string oldValue, string newValue) { XDocument xmlDocument = XDocument.Parse(newValue); //Apply transformations: if (viewer.XmlTransformations != null) { foreach (var transformation in viewer.XmlTransformations) { xmlDocument = transformation.Parse(xmlDocument); } } MusicXmlParser parser = new MusicXmlParser(); var score = parser.Parse(xmlDocument); score.MeasureInvalidated -= viewer.Score_MeasureInvalidated; viewer.RenderOnCanvas(score); score.MeasureInvalidated += viewer.Score_MeasureInvalidated; }
private static void XmlSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { NoteViewer viewer = obj as NoteViewer; string xmlSource = args.NewValue as string; XDocument xmlDocument = XDocument.Parse(xmlSource); //Apply transformations: if (viewer.XmlTransformations != null) { foreach (var transformation in viewer.XmlTransformations) { xmlDocument = transformation.Parse(xmlDocument); } } MusicXmlParser parser = new MusicXmlParser(); var score = parser.Parse(xmlDocument); viewer.RenderOnCanvas(score); }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "MusicXml (*.xml)|*.xml"; if (dialog.ShowDialog().Value) { string xml = File.ReadAllText(dialog.FileName); noteViewer1.XmlSource = xml; var testViewModel = DataContext as TestViewModel; if (testViewModel.Player != null) { ((IDisposable)testViewModel.Player).Dispose(); } testViewModel.Player = new MidiTaskScorePlayer(noteViewer1.InnerScore); ((MidiTaskScorePlayer)testViewModel.Player).SetInstrument(GeneralMidiInstrument.AcousticGrandPiano); var devices = MidiTaskScorePlayer.AvailableDevices; MusicXmlParser parser = new MusicXmlParser(); noteViewer2.ScoreSource = parser.Parse(XDocument.Parse(xml)); } }
private void Button_Click(object sender, RoutedEventArgs e) { string scoreXml = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?> <!DOCTYPE score-partwise PUBLIC ""-//Recordare//DTD MusicXML 3.0 Partwise//EN"" ""http://www.musicxml.org/dtds/partwise.dtd""> <score-partwise version=""3.0""> <identification> <rights>©</rights> <encoding> <software>Finale NotePad 2012 for Windows</software> <software>Dolet Light for Finale NotePad 2012</software> <encoding-date>2014-06-10</encoding-date> <supports attribute=""new-system"" element=""print"" type=""yes"" value=""yes""/> <supports attribute=""new-page"" element=""print"" type=""yes"" value=""yes""/> </encoding> </identification> <defaults> <scaling> <millimeters>7.2319</millimeters> <tenths>40</tenths> </scaling> <page-layout> <page-height>1545</page-height> <page-width>1194</page-width> <page-margins type=""both""> <left-margin>140</left-margin> <right-margin>70</right-margin> <top-margin>88</top-margin> <bottom-margin>88</bottom-margin> </page-margins> </page-layout> <system-layout> <system-margins> <left-margin>0</left-margin> <right-margin>0</right-margin> </system-margins> <system-distance>121</system-distance> <top-system-distance>70</top-system-distance> </system-layout> <appearance> <line-width type=""stem"">0.7487</line-width> <line-width type=""beam"">5</line-width> <line-width type=""staff"">0.7487</line-width> <line-width type=""light barline"">0.7487</line-width> <line-width type=""heavy barline"">5</line-width> <line-width type=""leger"">0.7487</line-width> <line-width type=""ending"">0.7487</line-width> <line-width type=""wedge"">0.7487</line-width> <line-width type=""enclosure"">0.7487</line-width> <line-width type=""tuplet bracket"">0.7487</line-width> <note-size type=""grace"">60</note-size> <note-size type=""cue"">60</note-size> <distance type=""hyphen"">120</distance> <distance type=""beam"">8</distance> </appearance> <music-font font-family=""Maestro,engraved"" font-size=""20.5""/> <word-font font-family=""Times New Roman"" font-size=""10.25""/> </defaults> <part-list> <score-part id=""P1""> <part-name>Violin</part-name> <part-abbreviation>Vln.</part-abbreviation> <score-instrument id=""P1-I1""> <instrument-name>SmartMusic SoftSynth 1</instrument-name> <instrument-sound>strings.violin</instrument-sound> <solo/> </score-instrument> <midi-instrument id=""P1-I1""> <midi-channel>1</midi-channel> <midi-bank>15489</midi-bank> <midi-program>41</midi-program> <volume>80</volume> <pan>0</pan> </midi-instrument> </score-part> </part-list> <!--=========================================================--> <part id=""P1""> <measure number=""1"" width=""236""> <print> <system-layout> <system-margins> <left-margin>70</left-margin> <right-margin>0</right-margin> </system-margins> <top-system-distance>167</top-system-distance> </system-layout> <measure-numbering>none</measure-numbering> </print> <attributes> <divisions>2</divisions> <key> <fifths>-1</fifths> <mode>major</mode> </key> <time> <beats>2</beats> <beat-type>4</beat-type> </time> <clef> <sign>G</sign> <line>2</line> </clef> </attributes> <sound tempo=""120""/> <note default-x=""111""> <pitch> <step>A</step> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-60"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""111""> <chord/> <pitch> <step>A</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""142""> <pitch> <step>A</step> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-60"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""142""> <chord/> <pitch> <step>A</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""174""> <pitch> <step>B</step> <alter>-1</alter> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""174""> <chord/> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""204""> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-50"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""204""> <chord/> <pitch> <step>C</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> </measure> <!--=======================================================--> <measure number=""2"" width=""135""> <note default-x=""16""> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-60"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""16""> <chord/> <pitch> <step>C</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""46""> <pitch> <step>G</step> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-65"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""46""> <chord/> <pitch> <step>G</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""75""> <pitch> <step>A</step> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-60"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""75""> <chord/> <pitch> <step>A</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""105""> <pitch> <step>B</step> <alter>-1</alter> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""105""> <chord/> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> </measure> <!--=======================================================--> <measure number=""3"" width=""141""> <note default-x=""17""> <pitch> <step>B</step> <alter>-1</alter> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""17""> <chord/> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""47""> <pitch> <step>B</step> <alter>-1</alter> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""47""> <chord/> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""78""> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-50"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""78""> <chord/> <pitch> <step>C</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""109""> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-45"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""109""> <chord/> <pitch> <step>D</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> </measure> <!--=======================================================--> <measure number=""4"" width=""141""> <note default-x=""16""> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""16""> <chord/> <pitch> <step>D</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""47""> <pitch> <step>A</step> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-60"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""47""> <chord/> <pitch> <step>A</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""79""> <pitch> <step>B</step> <alter>-1</alter> <octave>4</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-55"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""79""> <chord/> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""109""> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-50"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""109""> <chord/> <pitch> <step>C</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> </measure> <!--=======================================================--> <measure number=""5"" width=""141""> <note default-x=""16""> <pitch> <step>F</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-35"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""16""> <chord/> <pitch> <step>F</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""47""> <pitch> <step>F</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-35"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""47""> <chord/> <pitch> <step>F</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""78""> <pitch> <step>E</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-40"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""78""> <chord/> <pitch> <step>E</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""109""> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-42.5"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""109""> <chord/> <pitch> <step>D</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> </measure> <!--=======================================================--> <measure number=""6"" width=""119""> <note default-x=""14""> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-45"">down</stem> <beam number=""1"">begin</beam> </note> <note default-x=""14""> <chord/> <pitch> <step>G</step> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""40""> <pitch> <step>B</step> <alter>-1</alter> <octave>5</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem default-y=""-40"">down</stem> <beam number=""1"">end</beam> </note> <note default-x=""40""> <chord/> <pitch> <step>D</step> <octave>6</octave> </pitch> <duration>1</duration> <voice>1</voice> <type>eighth</type> <stem>down</stem> </note> <note default-x=""67""> <rest/> <duration>2</duration> <voice>1</voice> <type>quarter</type> </note> <barline location=""right""> <bar-style>light-heavy</bar-style> </barline> </measure> </part> <!--=========================================================--> </score-partwise> "; MusicXmlParser parser = new MusicXmlParser(); Score score = parser.Parse(XDocument.Parse(scoreXml)); noteViewer1.XmlSource = scoreXml; noteViewer2.ScoreSource = score; }