예제 #1
0
        /// <summary>
        /// Kreiärt ä Render-Graph fir jedä Input-Tip und bindet si as
        /// virtueuä DMD.
        /// </summary>
        private void SetupGraphs()
        {
            _graphs.Dispose();

            var renderers = new List <IDestination>();

            if (_config.PinDmd1.Enabled)
            {
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Logger.Info("Added PinDMDv1 renderer.");
                }
            }
            if (_config.PinDmd2.Enabled)
            {
                var pinDmd2 = PinDmd2.GetInstance();
                if (pinDmd2.IsAvailable)
                {
                    renderers.Add(pinDmd2);
                    Logger.Info("Added PinDMDv2 renderer.");
                }
            }
            if (_config.PinDmd3.Enabled)
            {
                var pinDmd3 = PinDmd3.GetInstance(_config.PinDmd3.Port);
                if (pinDmd3.IsAvailable)
                {
                    renderers.Add(pinDmd3);
                    Logger.Info("Added PinDMDv3 renderer.");
                }
            }
            if (_config.Pin2Dmd.Enabled)
            {
                var pin2Dmd = Output.Pin2Dmd.Pin2Dmd.GetInstance(_config.Pin2Dmd.Delay);
                if (pin2Dmd.IsAvailable)
                {
                    renderers.Add(pin2Dmd);
                    if (_coloring != null)
                    {
                        pin2Dmd.PreloadPalettes(_coloring);
                    }
                    Logger.Info("Added PIN2DMD renderer.");
                }
            }
            if (_config.Pixelcade.Enabled)
            {
                var pixelcade = Pixelcade.GetInstance(_config.Pixelcade.Port, _config.Pixelcade.ColorMatrix);
                if (pixelcade.IsAvailable)
                {
                    renderers.Add(pixelcade);
                    Logger.Info("Added Pixelcade renderer.");
                }
            }
            if (_config.VirtualDmd.Enabled)
            {
                renderers.Add(_virtualDmd.Dmd);
                Logger.Info("Added VirtualDMD renderer.");
            }
            if (_config.VirtualAlphaNumericDisplay.Enabled)
            {
                _alphaNumericDest = VirtualAlphanumericDestination.GetInstance(Dispatcher.CurrentDispatcher, _config.VirtualAlphaNumericDisplay.Style, _config);
                renderers.Add(_alphaNumericDest);
                Logger.Info("Added virtual alphanumeric renderer.");
            }
            if (_config.Video.Enabled)
            {
                var rootPath = "";
                if (_config.Video.Path.Length == 0 || !Path.IsPathRooted(_config.Video.Path))
                {
                    rootPath = AssemblyPath;
                }
                if (Directory.Exists(Path.Combine(rootPath, _config.Video.Path)))
                {
                    renderers.Add(new VideoOutput(Path.Combine(rootPath, _config.Video.Path, _gameName + ".avi")));
                    Logger.Info("Added video renderer.");
                }
                else if (Directory.Exists(Path.GetDirectoryName(Path.Combine(rootPath, _config.Video.Path))) && _config.Video.Path.Length > 4 && _config.Video.Path.EndsWith(".avi"))
                {
                    renderers.Add(new VideoOutput(Path.Combine(rootPath, _config.Video.Path)));
                    Logger.Info("Added video renderer.");
                }
                else
                {
                    Logger.Warn("Ignoring video renderer for non-existing path \"{0}\"", _config.Video.Path);
                }
            }
            if (_config.PinUp.Enabled)
            {
                try {
                    var pinupOutput = new PinUpOutput(_gameName);
                    if (pinupOutput.IsAvailable)
                    {
                        renderers.Add(pinupOutput);
                        Logger.Info("Added PinUP renderer.");
                    }
                } catch (Exception e) {
                    Logger.Warn("Error opening PinUP output: {0}", e.Message);
                }
            }
            if (_config.Gif.Enabled)
            {
                var rootPath = "";
                var dirPath  = Path.GetDirectoryName(_config.Gif.Path);
                if (string.IsNullOrEmpty(dirPath) || !Path.IsPathRooted(_config.Video.Path))
                {
                    rootPath = AssemblyPath;
                }
                var path = Path.Combine(rootPath, _config.Gif.Path);
                if (Directory.Exists(Path.GetDirectoryName(path)))
                {
                    renderers.Add(new GifOutput(path));
                    Logger.Info("Added animated GIF renderer, saving to {0}", path);
                }
                else
                {
                    Logger.Warn("Ignoring animated GIF renderer for non-existing path \"{0}\"", Path.GetDirectoryName(path));
                }
            }
            if (_config.VpdbStream.Enabled)
            {
                renderers.Add(new VpdbStream {
                    EndPoint = _config.VpdbStream.EndPoint
                });
            }
            if (_config.BrowserStream.Enabled)
            {
                renderers.Add(new BrowserStream(_config.BrowserStream.Port, _gameName));
            }
            if (_config.NetworkStream.Enabled)
            {
                renderers.Add(NetworkStream.GetInstance(new Uri(_config.NetworkStream.Url), _gameName));
            }

            if (renderers.Count == 0)
            {
                Logger.Error("No renderers found, exiting.");
                return;
            }

            Logger.Info("Transformation options: Resize={0}, HFlip={1}, VFlip={2}", _config.Global.Resize, _config.Global.FlipHorizontally, _config.Global.FlipVertically);

            // 2-bit graph
            if (_colorize && _gray2Colorizer != null)
            {
                _graphs.Add(new RenderGraph {
                    Name             = "2-bit Colored VPM Graph",
                    Source           = _vpmGray2Source,
                    Destinations     = renderers,
                    Converter        = _gray2Colorizer,
                    Resize           = _config.Global.Resize,
                    FlipHorizontally = _config.Global.FlipHorizontally,
                    FlipVertically   = _config.Global.FlipVertically
                });
            }
            else
            {
                _graphs.Add(new RenderGraph {
                    Name             = "2-bit VPM Graph",
                    Source           = _vpmGray2Source,
                    Destinations     = renderers,
                    Resize           = _config.Global.Resize,
                    FlipHorizontally = _config.Global.FlipHorizontally,
                    FlipVertically   = _config.Global.FlipVertically
                });
            }

            // 4-bit graph
            if (_colorize && _gray4Colorizer != null)
            {
                _graphs.Add(new RenderGraph {
                    Name             = "4-bit Colored VPM Graph",
                    Source           = _vpmGray4Source,
                    Destinations     = renderers,
                    Converter        = _gray4Colorizer,
                    Resize           = _config.Global.Resize,
                    FlipHorizontally = _config.Global.FlipHorizontally,
                    FlipVertically   = _config.Global.FlipVertically
                });
            }
            else
            {
                _graphs.Add(new RenderGraph {
                    Name             = "4-bit VPM Graph",
                    Source           = _vpmGray4Source,
                    Destinations     = renderers,
                    Resize           = _config.Global.Resize,
                    FlipHorizontally = _config.Global.FlipHorizontally,
                    FlipVertically   = _config.Global.FlipVertically
                });
            }

            // rgb24 graph
            _graphs.Add(new RenderGraph {
                Name             = "RGB24-bit VPM Graph",
                Source           = _vpmRgb24Source,
                Destinations     = renderers,
                Resize           = _config.Global.Resize,
                FlipHorizontally = _config.Global.FlipHorizontally,
                FlipVertically   = _config.Global.FlipVertically
            });

            // alphanumeric graph
            _graphs.Add(new RenderGraph {
                Name             = "Alphanumeric VPM Graph",
                Source           = _vpmAlphaNumericSource,
                Destinations     = renderers,
                Resize           = _config.Global.Resize,
                FlipHorizontally = _config.Global.FlipHorizontally,
                FlipVertically   = _config.Global.FlipVertically
            });

            if (_colorize && (_gray2Colorizer != null || _gray4Colorizer != null))
            {
                Logger.Info("Just clearing palette, colorization is done by converter.");
                _graphs.ClearColor();
            }
            else if (_colorize && _palette != null)
            {
                Logger.Info("Applying palette to render graphs.");
                _graphs.ClearColor();
                if (_coloring != null)
                {
                    _graphs.SetPalette(_palette, _coloring.DefaultPaletteIndex);
                }
                else
                {
                    _graphs.SetPalette(_palette, -1);
                }
            }
            else
            {
                Logger.Info("Applying default color to render graphs ({0}).", _color);
                _graphs.ClearPalette();
                _graphs.SetColor(_color);
            }

            _graphs.Init().StartRendering();
        }
예제 #2
0
        protected List <IDestination> GetRenderers(IConfiguration config)
        {
            var renderers = new List <IDestination>();

            if (config.PinDmd1.Enabled)
            {
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Logger.Info("Added PinDMDv1 renderer.");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PinDMDv1);
                }
            }

            if (config.PinDmd2.Enabled)
            {
                var pinDmd2 = PinDmd2.GetInstance();
                if (pinDmd2.IsAvailable)
                {
                    renderers.Add(pinDmd2);
                    Logger.Info("Added PinDMDv2 renderer.");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PinDMDv2);
                }
            }

            if (config.PinDmd3.Enabled)
            {
                var pinDmd3 = PinDmd3.GetInstance(config.PinDmd3.Port);
                if (pinDmd3.IsAvailable)
                {
                    renderers.Add(pinDmd3);
                    Logger.Info("Added PinDMDv3 renderer.");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PinDMDv3);
                }
            }

            if (config.Pin2Dmd.Enabled)
            {
                var pin2Dmd = Pin2Dmd.GetInstance(config.Pin2Dmd.Delay);
                if (pin2Dmd.IsAvailable)
                {
                    renderers.Add(pin2Dmd);
                    Logger.Info("Added PIN2DMD renderer.");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PIN2DMD);
                }
            }

            if (config.Pixelcade.Enabled)
            {
                var pixelcade = Pixelcade.GetInstance(config.Pixelcade.Port, config.Pixelcade.ColorMatrix);
                if (pixelcade.IsAvailable)
                {
                    renderers.Add(pixelcade);
                    Logger.Info("Added Pixelcade renderer.");
                }
                else
                {
                    Logger.Warn("Device Pixelcade is not available.");
                }
            }

            if (config.VirtualDmd.Enabled)
            {
                renderers.Add(ShowVirtualDmd(config.VirtualDmd));
                Logger.Info("Added virtual DMD renderer.");
            }

            if (config.VirtualAlphaNumericDisplay.Enabled)
            {
                renderers.Add(VirtualAlphanumericDestination.GetInstance(CurrentDispatcher, config.VirtualAlphaNumericDisplay.Style, config as Configuration));
                Logger.Info("Added virtual Alphanumeric renderer.");
            }

            if (config.NetworkStream.Enabled)
            {
                try {
                    renderers.Add(NetworkStream.GetInstance(config.NetworkStream));
                    Logger.Info("Added websocket client renderer.");
                } catch (Exception e) {
                    Logger.Warn("Network stream disabled: {0}", e.Message);
                }
            }

            if (renderers.Count == 0)
            {
                throw new NoRenderersAvailableException();
            }

            foreach (var renderer in renderers)
            {
                var rgb24 = renderer as IRgb24Destination;
                rgb24?.SetColor(config.Global.DmdColor);
            }
            _config = config;
            return(renderers);
        }