Exemplo n.º 1
0
 public VGFont(IOpenVG vg, FontHandle fontHandle, Dictionary <uint, float[]> escapements, float height)
 {
     this.vg          = vg;
     this.fontHandle  = fontHandle;
     this.escapements = escapements;
     Height           = height;
 }
Exemplo n.º 2
0
 protected Component(IPlatform platform)
 {
     this.platform = platform;
     this.vg       = platform.VG;
     this.children = new List <Component>();
     Point         = EMinor.Point.Zero;
     Bounds        = platform.Bounds;
 }
Exemplo n.º 3
0
 public RoundRect(IOpenVG vg, Bounds bounds, float arcWidth, float arcHeight)
     : base(vg)
 {
     this.Bounds = bounds;
     ArcWidth    = arcWidth;
     ArcHeight   = arcHeight;
     vg.RoundRect(path, 0, 0, bounds.W - 1.0f, bounds.H - 1.0f, arcWidth, arcHeight);
 }
Exemplo n.º 4
0
        protected Shape(IOpenVG vg)
        {
            this.vg              = vg;
            this.PaintModes      = PaintMode.VG_STROKE_PATH;
            this.StrokeLineWidth = 1.0f;

            // Create an OpenVG path resource:
            this.path = vg.CreatePathStandardFloat();
        }
Exemplo n.º 5
0
        public static void ThrowIfError(this IOpenVG vg)
        {
            int err = vg.GetError();

            if (err != 0)
            {
                throw new Exception(String.Format("VG error {0:X04}", err));
            }
        }
Exemplo n.º 6
0
        public PaintColor(IOpenVG vg, float[] color) : base(vg)
        {
            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }
            if (color.Length != 4)
            {
                throw new ArgumentOutOfRangeException(nameof(color));
            }

            vg.SetParameteri(paint, (int)PaintParamType.VG_PAINT_TYPE, (int)PaintType.VG_PAINT_TYPE_COLOR);
            vg.SetParameterfv(paint, (int)PaintParamType.VG_PAINT_COLOR, color);
        }
Exemplo n.º 7
0
 public Ellipse(IOpenVG vg, float w, float h) : base(vg)
 {
     this.Bounds = new Bounds(w, h);
     vg.Ellipse(this.path, 0, 0, w, h);
 }
Exemplo n.º 8
0
 protected Paint(IOpenVG vg)
 {
     this.vg    = vg;
     this.paint = vg.CreatePaint();
 }
Exemplo n.º 9
0
 public VGFontConverter(IOpenVG vg)
 {
     this.vg = vg;
 }
Exemplo n.º 10
0
        public VGUI(IPlatform platform, Controller controller)
        {
            this.controller = controller;
            this.platform   = platform;
            vg = platform.VG;
            footswitchMapping = FootSwitchScene(controller);
            selectedComponent = null;

            needFrame  = new AutoResetEvent(false);
            frameReady = new AutoResetEvent(false);

            vg.ClearColor = new float[] { 0.0f, 0.0f, 0.2f, 1.0f };

            platform.InputEvent += Platform_InputEvent;

            Debug.WriteLine("Set rendering quality and pixel layout");
            //vg.Seti(ParamType.VG_PIXEL_LAYOUT, (int)PixelLayout.VG_PIXEL_LAYOUT_RGB_HORIZONTAL);

            //vg.Seti(ParamType.VG_RENDERING_QUALITY, (int)RenderingQuality.VG_RENDERING_QUALITY_BETTER);
            vg.Seti(ParamType.VG_RENDERING_QUALITY, (int)RenderingQuality.VG_RENDERING_QUALITY_FASTER);
            //vg.Seti(ParamType.VG_RENDERING_QUALITY, (int)RenderingQuality.VG_RENDERING_QUALITY_NONANTIALIASED);

            //vg.Seti(ParamType.VG_IMAGE_QUALITY, (int)ImageQuality.VG_IMAGE_QUALITY_BETTER);
            vg.Seti(ParamType.VG_IMAGE_QUALITY, (int)ImageQuality.VG_IMAGE_QUALITY_FASTER);

            vg.Seti(ParamType.VG_BLEND_MODE, (int)BlendMode.VG_BLEND_SRC_OVER);

            // Load TTF font:
            Debug.WriteLine("Load Vera.ttf");
            var fontConverter = new VGFontConverter(vg);

            //vera = fontConverter.FromTTF("Vera.ttf");
            //vera = fontConverter.FromTTF("DroidSans.ttf");
            vera = fontConverter.FromODX("Verdana.json");

            this.disposalContainer = new DisposalContainer(
                white = new PaintColor(vg, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }),
                // For the touch point:
                pointColor            = new PaintColor(vg, new float[] { 0.0f, 1.0f, 0.0f, 0.5f }),
                point                 = new Ellipse(vg, 24, 24),
                clrBtnOutline         = new PaintColor(vg, new float[] { 0.6f, 0.6f, 0.6f, 1.0f }),
                clrBtnBg              = new PaintColor(vg, new float[] { 0.3f, 0.3f, 0.3f, 1.0f }),
                clrBtnBgSelected      = new PaintColor(vg, new float[] { 0.3f, 0.3f, 0.6f, 1.0f }),
                clrBtnOutlineSelected = new PaintColor(vg, new float[] { 1.0f, 1.0f, 0.0f, 1.0f })
                );

            // Root of component tree:
            this.root = new Panel(platform)
            {
                Children =
                {
                    new VerticalStack(platform)
                    {
                        Children =
                        {
                            new HorizontalStack(platform)
                            {
                                Dock     = Dock.Top,
                                Height   = 32,
                                Children =
                                {
                                    // MIDI button:
                                    new Button(platform)
                                    {
                                        Dock          = Dock.Left,
                                        Width         = 60,
                                        Stroke        = clrBtnOutline,
                                        Fill          = clrBtnBg,
                                        StrokePressed = clrBtnBg,
                                        FillPressed   = clrBtnOutline,
                                        OnRelease     = (cmp, p) => {
                                            controller.MidiResend();
                                            return(true);
                                        },
                                        Children =
                                        {
                                            new Label(platform)
                                            {
                                                TextFont   = vera,
                                                TextColor  = white,
                                                TextHAlign = HAlign.Center,
                                                TextVAlign = VAlign.Middle,
                                                Text       = () => "MIDI"
                                            }
                                        }
                                    },
                                    // Song display:
                                    new Button(platform)
                                    {
                                        Stroke          = clrBtnOutline,
                                        Fill            = clrBtnBg,
                                        StrokeLineWidth = 3.0f,
                                        OnPress         = (cmp, p) => {
                                            var btn = (Button)cmp;

                                            // Footswitch controls song prev/next.
                                            footswitchMapping = FootSwitchSong(controller);
                                            if (selectedComponent is Button selectedBtn)
                                            {
                                                selectedBtn.Stroke = clrBtnOutline;
                                                selectedBtn.Fill   = clrBtnBg;
                                            }
                                            btn.Stroke        = clrBtnOutlineSelected;
                                            btn.Fill          = clrBtnBgSelected;
                                            selectedComponent = cmp;
                                            return(true);
                                        },
                                        Children =
                                        {
                                            new Label(platform)
                                            {
                                                TextFont  = vera,
                                                TextColor = white,
                                                Text      = () => $"SONG: {controller.CurrentSongName}"
                                            }
                                        }
                                    },
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            bool benchmark = false;

            if (args.Length != 0)
            {
                if (args[0] == "translate")
                {
                    Console.WriteLine("Running v5 to v6 translator...");
                    var translator = new Translator();
                    translator.Translate();
                    return;
                }
                else if (args[0] == "benchmark")
                {
                    Console.WriteLine("Benchmark mode ON");
                    benchmark = true;
                }
            }

            try
            {
                // Select appropriate device implementation classes depending on build configuration
                // Use 'pi-debug' configuration to enable RPI.
#if RPI
                Console.WriteLine("RPI platform");
                using (IPlatform platform = new RpiPlatform(0))
#else
                Console.WriteLine("GLFW platform");
                using (IPlatform platform = new GlfwPlatform(800, 480))
#endif
                {
                    Console.WriteLine($"Display[0] = {platform.Width}x{platform.Height} ({platform.FramebufferWidth}x{platform.FramebufferHeight})");

                    var controller = new Controller(platform.MIDI, channel: 2);
                    controller.LoadData();

                    Console.WriteLine();
                    foreach (var midiProgram in controller.MidiPrograms)
                    {
                        Console.WriteLine("midi: {0}", midiProgram.ProgramNumber);
                        foreach (var song in midiProgram.Songs)
                        {
                            Console.WriteLine("  {0}", song.Name);
                        }
                    }
                    Console.WriteLine();
                    Console.WriteLine("all songs alphabetical:");
                    for (int i = 0; i < controller.Songs.Count; i++)
                    {
                        var song = controller.Songs[i];
                        Console.WriteLine("  {0}. {1}", i + 1, song.Name);
                    }
                    Console.WriteLine();

                    // Use latest active setlist:
                    var setlist = (
                        from sl in controller.Setlists
                        where sl.Active
                        select sl
                        ).Last();

                    Console.WriteLine("Setlist for {0} on {1}", setlist.Venue, setlist.Date);
                    Console.WriteLine("{0} songs", setlist.Songs.Count);
                    for (int i = 0; i < setlist.Songs.Count; i++)
                    {
                        var song = setlist.Songs[i];
                        Console.WriteLine("  {0}. {1}", i + 1, song.Name);
                    }

                    // Activate the first song in the setlist:
                    controller.StartMidiBatch();
                    controller.ActivateSetlist(setlist);
                    controller.EndMidiBatch();

                    // Initialize UI:
                    IOpenVG vg = platform.VG;

                    List <double> benchmarkPoints = null;
                    if (benchmark)
                    {
                        benchmarkPoints = new List <double>(totalBenchmarkPoints);
                    }

                    VGUI ui = null;
#if THREADS
                    ManualResetEvent uiInitialized = new ManualResetEvent(false);

                    // Start a new thread to handle rendering:
                    var renderThread = platform.NewRenderThread(() =>
                    {
                        using (ui = new VGUI(platform, controller))
                        {
                            uiInitialized.Set();

                            if (benchmark)
                            {
                                var sw = new Stopwatch();
                                sw.Start();

                                while (true)
                                {
                                    double start = sw.Elapsed.TotalMilliseconds;

                                    // Render UI screen:
                                    ui.Render();

                                    var elapsed = sw.Elapsed.TotalMilliseconds - start;
                                    benchmarkPoints.Add(elapsed);

                                    ui.FrameReady();
#if TIMING
                                    Console.Out.WriteLineAsync($"{elapsed:N2} ms");
#endif

                                    // Wait for next frame:
                                    ui.WaitForNextFrame();
                                }
                            }
                            else
                            {
#if TIMING
                                var sw = new Stopwatch();
                                sw.Start();
#endif
                                while (true)
                                {
#if TIMING
                                    double start = sw.Elapsed.TotalMilliseconds;
#endif
                                    // Render UI screen:
                                    ui.Render();

#if TIMING
                                    Console.Out.WriteLineAsync($"{sw.Elapsed.TotalMilliseconds - start:N2} ms");
#endif

                                    // Wait for next frame:
                                    ui.WaitForNextFrame();
                                }
                            }
                        }
                    });
                    renderThread.Start();

                    // Wait for renderer thread to initialize:
                    uiInitialized.WaitOne();
                    if (benchmark)
                    {
                        // Toss out 20 frames to warm up JIT:
                        for (int i = 0; i < 20; i++)
                        {
                            platform.PollEvents();
                            ui.AllowFrame();
                            ui.WaitForFrameReady();
                        }
                        benchmarkPoints.Clear();
                        // Start the benchmark:
                        Console.WriteLine("Benchmark started");
                        for (int i = 0; i < totalBenchmarkPoints; i++)
                        {
                            platform.PollEvents();
                            ui.AllowFrame();
                            ui.WaitForFrameReady();
                        }
                        Console.WriteLine("Benchmark complete");
                        Console.WriteLine($"Min   time: {benchmarkPoints.Min():N2} ms");
                        Console.WriteLine($"Max   time: {benchmarkPoints.Max():N2} ms");
                        Console.WriteLine($"Avg   time: {benchmarkPoints.Average():N2} ms");
                        Console.WriteLine($"Total time: {benchmarkPoints.Sum():N2} ms");
                        return;
                    }

                    // Main thread:
                    bool quit = false;
                    do
                    {
                        platform.WaitEvents();

                        // Check with the GUI if user indicated app should quit:
                        quit |= platform.ShouldQuit();
                    } while (!quit);
#else
                    // Non-threaded version:
                    platform.InitRenderThread();
                    using (ui = new VGUI(platform, controller))
                    {
                        Stopwatch sw;

                        if (benchmark)
                        {
                            // Toss out 20 frames to warm up JIT:
                            for (int i = 0; i < 20; i++)
                            {
                                ui.Render();
                                platform.PollEvents();
                            }

                            // Start the benchmark:
                            Console.WriteLine("Benchmark started");
                            sw = new Stopwatch();
                            sw.Start();
                            for (int i = 0; i < totalBenchmarkPoints; i++)
                            {
                                double start = sw.Elapsed.TotalMilliseconds;

                                ui.Render();
                                platform.PollEvents();

                                var elapsed = sw.Elapsed.TotalMilliseconds - start;
                                benchmarkPoints.Add(elapsed);
#if TIMING
                                Console.Out.WriteLineAsync($"{elapsed:N2} ms");
#endif
                            }

                            Console.WriteLine("Benchmark complete");
                            Console.WriteLine($"Min   time: {benchmarkPoints.Min():N2} ms");
                            Console.WriteLine($"Max   time: {benchmarkPoints.Max():N2} ms");
                            Console.WriteLine($"Avg   time: {benchmarkPoints.Average():N2} ms");
                            Console.WriteLine($"Total time: {benchmarkPoints.Sum():N2} ms");
                            return;
                        }

                        // Main thread:
                        bool quit = false;
#if TIMING
                        sw = new Stopwatch();
                        sw.Start();
#endif
                        do
                        {
#if TIMING
                            double start = sw.Elapsed.TotalMilliseconds;
#endif
                            ui.Render();

#if TIMING
                            Console.Out.WriteLineAsync($"{sw.Elapsed.TotalMilliseconds - start:N2} ms");
#endif

                            platform.WaitEvents();

                            // Check with the GUI if user indicated app should quit:
                            quit |= platform.ShouldQuit();
                        } while (!quit);
                    }
#endif
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine(ex);
            }
        }