This is the main wrapper of the rendering engine which can render a single track of a score object into a notation sheet.
Inheritance: IScoreRenderer
コード例 #1
0
ファイル: BarRendererBase.cs プロジェクト: zwdesigns/alphaTab
 public BarRendererBase(ScoreRenderer renderer, Bar bar)
 {
     Bar           = bar;
     ScoreRenderer = renderer;
     Helpers       = new BarHelpers(bar);
     CanWrap       = true;
 }
コード例 #2
0
ファイル: AlphaTabControl.cs プロジェクト: eriser/alphaTab
        public AlphaTabControl()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ContainerControl, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            var settings = Settings.Defaults;
            settings.Engine = "gdi";
            Settings = settings;
            _renderer = new ScoreRenderer(settings, this);
            _renderer.PreRender += () =>
            {
                lock (this)
                {
                    _images = new List<Image>();
                }
            };
            _renderer.PartialRenderFinished += result =>
            {
                lock (this)
                {
                    BeginInvoke(new Action(() =>
                    {
                        AddPartialResult(result);
                    }));
                }
            };
            _renderer.RenderFinished += OnRenderFinished;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: eriser/alphaTab
        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);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: CoderLine/alphaTab
        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);
                }
            }
        }
コード例 #5
0
        public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, StaveSettings staveSettings)
        {
            var tabBarRenderer = new TabBarRenderer(renderer, bar);

            tabBarRenderer.RenderRhythm = staveSettings.Get("rhythm", tabBarRenderer.RenderRhythm);
            tabBarRenderer.RhythmHeight = staveSettings.Get("rhythm-height", tabBarRenderer.RhythmHeight);
            tabBarRenderer.RhythmBeams  = staveSettings.Get("rhythm-beams", tabBarRenderer.RhythmBeams);

            return(tabBarRenderer);
        }
コード例 #6
0
ファイル: JsWorkerApi.cs プロジェクト: CoderLine/alphaTab
 public JsWorker(SharpKit.Html.workers.WorkerContext main, object options)
 {
     _main = main;
     _main.addEventListener("message", HandleMessage, false);
     Settings settings = Settings.FromJson(options);
     _renderer = new ScoreRenderer(settings);
     _renderer.PartialRenderFinished += result => PostMessage(new { cmd = "partialRenderFinished", result = result });
     _renderer.RenderFinished += result => PostMessage(new { cmd = "renderFinished", result = result });
     _renderer.PostRenderFinished += () => PostMessage(new { cmd = "postRenderFinished", boundsLookup = _renderer.BoundsLookup.ToJson() });
     _renderer.PreRender += result => PostMessage(new { cmd = "preRender", result = result  });
 }
コード例 #7
0
        public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, StaveSettings staveSettings)
        {
            var tabBarRenderer = new TabBarRenderer(renderer, bar);

            tabBarRenderer.ShowRests         = _showRests;
            tabBarRenderer.ShowTimeSignature = _showTimeSignature;
            tabBarRenderer.ShowTiedNotes     = _showTiedNotes;
            tabBarRenderer.RenderRhythm      = staveSettings.Get("rhythm", tabBarRenderer.RenderRhythm);
            tabBarRenderer.RhythmHeight      = staveSettings.Get("rhythmHeight", tabBarRenderer.RhythmHeight);
            tabBarRenderer.RhythmBeams       = staveSettings.Get("rhythmBeams", tabBarRenderer.RhythmBeams);

            return(tabBarRenderer);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, FastDictionary <string, object> additionalSettings)
        {
            var tabBarRenderer = new TabBarRenderer(renderer, bar);

            if (additionalSettings.ContainsKey("rhythm"))
            {
                tabBarRenderer.RenderRhythm = (bool)additionalSettings["rhythm"];
            }

            if (additionalSettings.ContainsKey("rhythm-height"))
            {
                tabBarRenderer.RhythmHeight = (float)additionalSettings["rhythm-height"];
            }

            if (additionalSettings.ContainsKey("rhythm-beams"))
            {
                tabBarRenderer.RhythmBeams = (bool)additionalSettings["rhythm-beams"];
            }

            return(tabBarRenderer);
        }
コード例 #10
0
ファイル: AlphaTab.cs プロジェクト: stefan-j/alphaTab
        public AlphaTab()
        {
            SnapsToDevicePixels = true;
            var settings = Settings.Defaults;
            settings.Engine = "gdi";
            settings.Layout.Mode = "horizontal";
            Settings = settings;

            PartialResults = new ObservableCollection<ImageSource>();
            _renderer = new ScoreRenderer(settings, this);

            _renderer.PreRender += () =>
            {
                lock (this)
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        PartialResults.Clear();
                    }));
                }
            };
            _renderer.PartialRenderFinished += result =>
            {
                lock (this)
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        AddPartialResult(result);
                    }));
                }
            };
            _renderer.RenderFinished += result =>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    OnRenderFinished(result);
                }));
            };
        }
コード例 #11
0
ファイル: GpImporterTestBase.cs プロジェクト: eriser/alphaTab
        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);
            }
        }
コード例 #12
0
 public TabBarRenderer(ScoreRenderer renderer, Bar bar)
     : base(renderer, bar)
 {
     RhythmHeight = 15 * renderer.Layout.Scale;
     RhythmBeams  = true;
 }
コード例 #13
0
 public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, FastDictionary <string, object> additionalSettings)
 {
     return(new ScoreBarRenderer(renderer, bar));
 }
コード例 #14
0
 public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, StaveSettings staveSettings)
 {
     return(new EffectBarRenderer(renderer, bar, _infos));
 }
コード例 #15
0
 public EffectBarRenderer(ScoreRenderer renderer, Bar bar, IEffectBarRendererInfo[] infos)
     : base(renderer, bar)
 {
     _infos = infos;
 }
コード例 #16
0
 public abstract BarRendererBase Create(ScoreRenderer renderer, Bar bar, StaveSettings staveSettings);
コード例 #17
0
 public ScoreBarRenderer(ScoreRenderer renderer, Bar bar)
     : base(renderer, bar)
 {
     AccidentalHelper = new AccidentalHelper();
 }
コード例 #18
0
ファイル: JsWorkerApi.cs プロジェクト: eriser/alphaTab
 public JsWorker(SharpKit.Html.workers.WorkerContext main, object options)
 {
     _main = main;
     _includeScoreInLoadedEvent = options.Member("scoreInLoadedEvent").As<bool>();
     _main.addEventListener("message", HandleMessage, false);
     Settings settings = Settings.FromJson(options);
     _renderer = new ScoreRenderer(settings, null);
     _renderer.PartialRenderFinished += result => PostMessage(new { cmd = "partialRenderFinished", result = result });
     _renderer.RenderFinished += result => PostMessage(new { cmd = "renderFinished", result = result });
     _renderer.PostRenderFinished += () => PostMessage(new { cmd = "postRenderFinished" });
     _renderer.PreRender += () => PostMessage(new {cmd = "preRender"});
 }
コード例 #19
0
        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))));
        }
コード例 #20
0
 public abstract BarRendererBase Create(ScoreRenderer renderer, Bar bar, FastDictionary <string, object> additionalSettings);
コード例 #21
0
        void Init()
        {
            SnapsToDevicePixels = true;
            var settings = Settings.Defaults;
            settings.Engine = "gdi";
            settings.Layout.Mode = "horizontal";
            Settings = settings;

            _renderer = new ScoreRenderer(settings, this);

            _renderer.PartialRenderFinished += result =>
            {
                lock (this)
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        DrawResult(result);
                        //AddPartialResult(result);
                    }));
                }
            };
            _renderer.RenderFinished += result =>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    OnRenderFinished(result);
                }));
            };
            ThreadPool.SetMinThreads(1, 1);
            ThreadPool.SetMaxThreads(2, 2);
        }
コード例 #22
0
        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());
            }
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: CoderLine/alphaTab
        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());
            }
        }