static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // we need to use english culture to have correct string variants of floating points (dot as decimal separator) Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); // load score Score score = ScoreLoader.LoadScore(args[0]); // render score with svg engine Settings settings = Settings.Defaults; settings.Engine = "svg"; ScoreRenderer renderer = new ScoreRenderer(settings, null); // get iterate tracks for (int i = 0; i < score.Tracks.Count; i++) { Track track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var totalWidth = 0; var totalHeight = 0; var merged = XDocument.Parse("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1px\" height=\"1px\"></svg>"); var currentY = 0f; renderer.PartialRenderFinished += r => { var subSvg = XDocument.Parse(r.RenderResult.ToString()); var subRoot = subSvg.Root; subRoot.SetAttributeValue("x", "0px"); subRoot.SetAttributeValue("y", ((int)currentY) + "px"); merged.Root.Add(subRoot); currentY += r.Height; }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(track); merged.Root.Attribute("width").Value = totalWidth + "px"; merged.Root.Attribute("height").Value = totalHeight + "px"; string svg = merged.ToString(); FileInfo info = new FileInfo(args[0]); string path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".svg"); File.WriteAllText(path, svg); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // load score var score = ScoreLoader.LoadScore(args[0]); // render score with svg engine var settings = Settings.Defaults; settings.Engine = "gdi"; var renderer = new ScoreRenderer(settings); // iterate tracks for (int i = 0, j = score.Tracks.Count; i < j; i++) { var track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var images = new List<Image>(); var totalWidth = 0; var totalHeight = 0; renderer.PartialRenderFinished += r => { images.Add((Image) r.RenderResult); }; renderer.RenderFinished += r => { totalWidth = (int) r.TotalWidth; totalHeight = (int) r.TotalHeight; }; renderer.Render(track); // write png var info = new FileInfo(args[0]); var path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".png"); using (var bmp = new Bitmap(totalWidth, totalHeight)) { int y = 0; using (var g = Graphics.FromImage(bmp)) { foreach (var image in images) { g.DrawImage(image, new Rectangle(0, y, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); y += image.Height; } } bmp.Save(path, ImageFormat.Png); } } }
public void BendRendering_Issue79() { var tex = @":4 15.6{b(0 4)} 18.6{b(0 6)} 17.6{b(0 8)} 16.6{b(0 3 0)} | 15.6{b(0 8 4)} 14.6{b(4 4)} 13.6{b(4 6)} 14.6{b(4 0)}"; var score = ParseTex(tex); var settings = Settings.Defaults; settings.Engine = "svg"; settings.Staves = new FastList<StaveSettings> { new StaveSettings("tab") }; var renderer = new ScoreRenderer(settings); var partials = new List<string>(); renderer.PartialRenderFinished += r => { partials.Add(r.RenderResult.ToString()); }; renderer.Render(score.Tracks[0]); var tab = XDocument.Parse(partials[1]); var texts = tab.Descendants(XName.Get("text", "http://www.w3.org/2000/svg")).ToArray(); var expectedTexts = new[] { "T", "A", "B", // clef "1", // bar number "15", "full", "18", "1½", "17", "2", "16", "¾", "2", // bar number "15", "2", "-1", "14", "full", "13", "full", "1½", "14", "full" }; Assert.Inconclusive("There must be a better way of testing the rendered values"); for (int i = 0; i < expectedTexts.Length; i++) { var text = texts[i].Value.Trim(); Assert.AreEqual(expectedTexts[i], text, "Mismatch at index {0}", i); } }
public void LoadScore(string fileName = null) { //test if (fileName == null) fileName = @"C:\Work\SVN\webprofusion\scalex\trunk\FileFormats\Testing\Fade To Black.gp4"; try { // load the score from the filesystem _score = ScoreLoader.LoadScore(fileName); Log(_score.Title); CurrentTrackIndex = 0; AlphaTab.Platform.CSharp.WpfCanvas canvas = new Platform.CSharp.WpfCanvas(); var settings = Settings.Defaults; settings.Engine = "wpf"; _diagramCanvasList = new List<Canvas>(); var _renderer = new ScoreRenderer(settings, this); _renderer.PartialRenderFinished += _renderer_PartialRenderFinished; _renderer.RenderFinished += _renderer_RenderFinished; ; _renderer.Render(CurrentTrack); /*_renderer.PreRender += () => { lock (this) { Dispatcher.BeginInvoke(new Action(() => { PartialResults.Clear(); })); } };*/ } catch (Exception exp) { Log("Failed to load score: " + exp.ToString()); } }
public void HamonicsRenderingText_Issue79() { var tex = @":8 3.3{nh} 3.3{ah} 3.3{th} 3.3{ph} 3.3{sh}"; var score = ParseTex(tex); var settings = Settings.Defaults; settings.Engine = "svg"; settings.Staves = new FastList<StaveSettings> { new StaveSettings("harmonics") }; var renderer = new ScoreRenderer(settings, null); var svg = ""; renderer.PartialRenderFinished += r => { svg += r.RenderResult.ToString(); }; renderer.Render(score.Tracks[0]); var regexTemplate = @"<text[^>]+>\s*{0}\s*</text>"; Assert.IsTrue(Regex.IsMatch(svg, string.Format(regexTemplate, HarmonicsEffectInfo.HarmonicToString(HarmonicType.Natural)))); Assert.IsTrue(Regex.IsMatch(svg, string.Format(regexTemplate, HarmonicsEffectInfo.HarmonicToString(HarmonicType.Artificial)))); Assert.IsTrue(Regex.IsMatch(svg, string.Format(regexTemplate, HarmonicsEffectInfo.HarmonicToString(HarmonicType.Tap)))); Assert.IsTrue(Regex.IsMatch(svg, string.Format(regexTemplate, HarmonicsEffectInfo.HarmonicToString(HarmonicType.Pinch)))); Assert.IsTrue(Regex.IsMatch(svg, string.Format(regexTemplate, HarmonicsEffectInfo.HarmonicToString(HarmonicType.Semi)))); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // we need to use english culture to have correct string variants of floating points (dot as decimal separator) Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); // load score Score score = ScoreLoader.LoadScore(args[0]); // render score with svg engine Settings settings = Settings.Defaults; settings.Engine = "svg"; ScoreRenderer renderer = new ScoreRenderer(settings); // get iterate tracks for (int i = 0; i < 1; i++) { Track track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var totalWidth = 0; var totalHeight = 0; XDocument merged = null; var currentY = 0f; renderer.PreRender += r => { // append the svg close tag which would be part of the RenderFinished event var svgString = r.RenderResult.ToString() + "</svg>"; merged = XDocument.Parse(svgString); }; renderer.PartialRenderFinished += r => { var subSvg = XDocument.Parse(r.RenderResult.ToString()); var subRoot = subSvg.Root; subRoot.SetAttributeValue("x", "0px"); subRoot.SetAttributeValue("y", ((int)currentY) + "px"); merged.Root.Add(subRoot); currentY += r.Height; }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(track); merged.Root.SetAttributeValue("width", totalWidth + "px"); merged.Root.SetAttributeValue("height", totalHeight + "px"); var svg = new StringWriter(); var xmlWriter = new EntitizingXmlWriter(svg); merged.Save(xmlWriter); FileInfo info = new FileInfo(args[0]); string path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".svg"); File.WriteAllText(path, svg.ToString()); } }
protected void Render(Score score, [CallerFilePath] string callerFile = null, [CallerMemberName] string caller = null) { if (caller == null) { throw new ArgumentNullException("caller", "svg rendering failed because caller info was missing"); } var settings = Settings.Defaults; settings.Engine = "svg"; var renderer = new ScoreRenderer(settings, null); for (int i = 0; i < score.Tracks.Count; i++) { Track track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var totalWidth = 0; var totalHeight = 0; var merged = XDocument.Parse("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1px\" height=\"1px\"></svg>"); var currentY = 0f; renderer.PartialRenderFinished += r => { var subSvg = XDocument.Parse(r.RenderResult.ToString()); var subRoot = subSvg.Root; subRoot.SetAttributeValue("x", "0px"); subRoot.SetAttributeValue("y", ((int)currentY) + "px"); merged.Root.Add(subRoot); currentY += r.Height; }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(track); merged.Root.Attribute("width").Value = totalWidth + "px"; merged.Root.Attribute("height").Value = totalHeight + "px"; var svg = merged.ToString(); var dirName = Path.GetFileNameWithoutExtension(callerFile); var path = Path.Combine(dirName, caller + "-" + i + ".svg"); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } File.WriteAllText(path, svg); } }