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); Environment.StaveProfiles["harmonics"] = new BarRendererFactory[] { new EffectBarRendererFactory("harmonics", new IEffectBarRendererInfo[] { new HarmonicsEffectInfo() }), }; var settings = Settings.Defaults; settings.Engine = "svg"; settings.Staves = new StaveSettings("harmonics"); var renderer = new ScoreRenderer(settings); var svg = ""; renderer.PartialRenderFinished += r => { svg += r.RenderResult.ToString(); }; renderer.Render(score, new[] { 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)))); }
private void InvalidateTracks() { if (Tracks == null) { return; } if (Width > 0) { _renderer.Settings.Width = (int)(Width / _displayDensity); _initialRenderCompleted = false; _isRendering = true; var tracks = Tracks.ToArray(); if (tracks.Length > 0) { ModelUtils.ApplyPitchOffsets(_renderer.Settings, tracks[0].Score); Task.Factory.StartNew(() => { _renderer.Render(tracks[0].Score, tracks.Select(t => t.Index).ToArray()); }); } } else { _initialRenderCompleted = false; _redrawPending = true; } }
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; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // render score with svg engine and desired rendering width var settings = Settings.Defaults; settings.Engine = "gdi"; settings.Width = 970; 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); Environment.StaveProfiles["tabOnly"] = new BarRendererFactory[] { new TabBarRendererFactory(false, false, false), }; var settings = Settings.Defaults; settings.Engine = "svg"; settings.Layout.Mode = "horizontal"; settings.Staves = new StaveSettings("tabOnly"); var renderer = new ScoreRenderer(settings); var partials = new FastList <string>(); renderer.Error += (o, e) => { Assert.Fail(e.Message); }; renderer.PartialRenderFinished += r => { partials.Add(r.RenderResult.ToString()); }; renderer.Render(score, new[] { 0 }); var tab = new XmlDocument(partials[0]); var texts = tab.GetElementsByTagName("text", true); var expectedTexts = new[] { Platform.Platform.StringFromCharCode((int)MusicFontSymbol.ClefTab), // clef "1", // bar number "15", "full", "18", "1½", "17", "2", "16", "¾", "2", // bar number "15", "2", "full", "14", "full", "13", "full", "1½", "14", "full" }; for (int i = 0; i < expectedTexts.Length; i++) { var text = texts[i].InnerText.Trim(); Assert.AreEqual(expectedTexts[i], text, "Mismatch at index {0}", i); } }
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); } }
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); Environment.StaveProfiles["tabOnly"] = new BarRendererFactory[] { new TabBarRendererFactory(), }; var settings = Settings.Defaults; settings.Engine = "svg"; settings.Staves = new StaveSettings("tabOnly"); 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); } }
private void RenderMultiple(Score score, int[] trackIndexes) { try { _renderer.Render(score, trackIndexes); } catch (Exception e) { Error("render", e); } }
public void InvalidateTrack() { if (Track == null) { return; } Task.Factory.StartNew(() => { _renderer.Render(Track); }); }
public void Render() { if (CheckAccess()) { _renderer.Render(); } else { _workerQueue.Add(Render); } }
protected void Render(Track[] tracks, string path, string renderLayout) { var settings = Settings.Defaults; settings.Engine = "gdi"; settings.Layout = new LayoutSettings { Mode = renderLayout }; settings.Width = 800; var renderer = new ScoreRenderer(settings); var images = new FastList <Image>(); var totalWidth = 0; var totalHeight = 0; renderer.Error += (s, exception) => { if (exception != null) { throw exception; } else { throw new Exception(s); } }; renderer.PartialRenderFinished += r => { images.Add((Image)r.RenderResult); }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(tracks[0].Score, tracks.Select(t => t.Index).ToArray()); using (var bmp = new Bitmap(totalWidth, totalHeight)) { int y = 0; using (var g = Graphics.FromImage(bmp)) { g.Clear(Color.White); 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 1)} 14.6{b(0 4)} 13.6{b(0 4 6)} 14.6{b(0 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, null); 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", "½", "14", "full" }; for (int i = 0; i < expectedTexts.Length; i++) { var text = texts[i].Value.Trim(); Assert.AreEqual(expectedTexts[i], text, "Mismatch at index {0}", i); } }
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); } }
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"); } #if !PHASE var settings = Settings.Defaults; settings.Engine = "svg"; var renderer = new ScoreRenderer(settings); for (int i = 0; i < score.Tracks.Count; i++) { Track track = score.Tracks[i]; // render track Logger.Info("Test", $"Rendering track {i + 1} - {track.Name}"); var totalWidth = 0; var totalHeight = 0; var merged = new StringBuilder(); var currentY = 0f; renderer.PartialRenderFinished += r => { var subSvg = r.RenderResult.ToString() .Replace("width=", "x=\"0px\" y=\"" + ((int)currentY) + "\" width="); merged.Append(subSvg); currentY += r.Height; }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(score, new[] { track.Index }); var final = new StringBuilder(); final.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"" + ((int)totalWidth) + "px\" height=\"" + ((int)totalHeight) + "px\">"); final.Append(merged.ToString()); final.Append("</svg>"); 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); } #endif }
public void InvalidateTracks(bool force) { var trackArray = Tracks?.ToArray(); if (trackArray == null || trackArray.Length == 0) { return; } var width = RenderWidth; if (width > 0) { if (trackArray == Renderer.Tracks && !force) { return; } var settings = Renderer.Settings; settings.Width = width; settings.Engine = RenderEngine; settings.Scale = Scale; settings.Layout.Mode = LayoutMode; settings.StretchForce = StretchForce; settings.Staves.Id = StavesMode; Renderer.UpdateSettings(settings); ModelUtils.ApplyPitchOffsets(settings, trackArray[0].Score); _initialRenderCompleted = false; _isRendering = 1; Task.Factory.StartNew(() => { Renderer.Render(trackArray[0].Score, trackArray.Select(t => t.Index).ToArray()); }); } else { _initialRenderCompleted = false; _redrawPending = true; _isRendering = 0; } }
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()); } }
public void RenderResult(IPresentationResult presentationResult) { ScoreRenderer.Render(presentationResult.Score); PlayerNameRenderer.Render(presentationResult.PlayerName); PlayedAtRenderer.Render(presentationResult.PlayedAt); }
protected override void OnRenderFrame(FrameEventArgs E) { base.OnRenderFrame(E); var Modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref Modelview); RenderBackground(); var PipeMarginY = (ProjectionHeight - MapHeight * SolidSize) / 2f; var PipeMarginX = (NominalHeight - MapHeight * SolidSize) / 2f; var Overwidth = ProjectionWidth - ProjectionHeight * (float)NominalWidth / NominalHeight; if (Overwidth > 0) { GL.Translate(Math.Min(Overwidth, (ProjectionWidth - MapWidth * SolidSize) / 2f), PipeMarginY, 0); } else { GL.Translate(PipeMarginX, PipeMarginY, 0); } RenderPipe(); for (var X = 0; X < MapWidth; X++) { for (var Y = 0; Y < MapHeight; Y++) { if (Map[X, Y] >= 0) { RenderSolid(X, Y + ImpactFallOffset[X, Y], Map[X, Y]); } } } if (GameStateEnum.Fall == GameState) { for (var i = 0; i < StickLength; i++) { if (StickColors[i] >= 0) { RenderSolid(StickPosition.X + i, StickPosition.Y, StickColors[i]); } } } GL.Translate(MapWidth * SolidSize + PipeMarginX, 0, 0); NextStickLabel.Render(); GL.Translate(0, NextStickLabel.Height, 0); RenderNextStick(); GL.Translate(0, -NextStickLabel.Height, 0); GL.Translate(0, MapHeight * SolidSize / 4f, 0); if (GameStateEnum.GameOver == GameState) { GameOverLabel.Render(); GL.Translate(0, GameOverLabel.Height, 0); GameOverHint.Render(); GL.Translate(0, -GameOverLabel.Height, 0); } else if (Paused) { PauseLabel.Render(); GL.Translate(0, PauseLabel.Height, 0); UnpauseHint.Render(); GL.Translate(0, -PauseLabel.Height, 0); } else { PlayingGameLabel.Render(); GL.Translate(0, PlayingGameLabel.Height, 0); PauseHint.Render(); GL.Translate(0, -PlayingGameLabel.Height, 0); } GL.Translate(0, MapHeight * SolidSize / 4f, 0); ScoreLabel.Render(); GL.Translate(0, ScoreLabel.Height, 0); ScoreRenderer.Label = Score.ToString(); ScoreRenderer.Render(); GL.Translate(0, -ScoreLabel.Height, 0); GL.Translate(0, MapHeight * SolidSize / 4f, 0); HighScoreLabel.Render(); GL.Translate(0, HighScoreLabel.Height, 0); HighScoreRenderer.Label = HighScore.ToString(); HighScoreRenderer.Render(); SwapBuffers(); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // render score with svg engine and desired rendering width var settings = Settings.Defaults; settings.Engine = "skia"; settings.Width = 970; 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 <SKImage>(); var totalWidth = 0; var totalHeight = 0; renderer.PartialRenderFinished += r => { images.Add((SKImage)r.RenderResult); }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(score, new[] { track.Index }); // write png var info = new FileInfo(args[0]); var path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".png"); using (var full = SKSurface.Create(totalWidth, totalHeight, SKImageInfo.PlatformColorType, SKAlphaType.Premul)) { int y = 0; foreach (var image in images) { full.Canvas.DrawImage(image, new SKRect(0, 0, image.Width, image.Height), new SKRect(0, y, image.Width, y + image.Height)); y += image.Height; } using (var fullImage = full.Snapshot()) { using (var data = fullImage.Encode(SKEncodedImageFormat.Png, 100).AsStream(true)) { using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write)) { data.CopyTo(fileStream); } } } } } }