Пример #1
0
 /// <summary>
 /// Returns the current instance of the PIN2DMD API. In any case,
 /// the instance get (re-)initialized.
 /// </summary>
 /// <returns></returns>
 public static Pin2DmdHd GetInstance(int outputDelay)
 {
     if (_instance == null)
     {
         _instance = new Pin2DmdHd {
             Delay = outputDelay
         };
     }
     _instance.Init();
     return(_instance);
 }
Пример #2
0
        /// <summary>
        /// Kreiärt ä Render-Graph fir jedä Input-Tip und bindet si as
        /// virtueuä DMD.
        /// </summary>
        private void SetupGraphs()
        {
            _graphs.Dispose();

            ReportingTags.Clear();
            ReportingTags.Add(Process.GetCurrentProcess().ProcessName);
#if PLATFORM_X86
            ReportingTags.Add("x86");
#elif PLATFORM_X64
            ReportingTags.Add("x64");
#endif
            ReportingTags.Add("In:DmdDevice");
            ReportingTags.Add("Game:" + _gameName);


            var renderers = new List <IDestination>();
            if (_config.PinDmd1.Enabled)
            {
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Logger.Info("Added PinDMDv1 renderer.");
                    ReportingTags.Add("Out:PinDMDv1");
                }
            }
            if (_config.PinDmd2.Enabled)
            {
                var pinDmd2 = PinDmd2.GetInstance();
                if (pinDmd2.IsAvailable)
                {
                    renderers.Add(pinDmd2);
                    Logger.Info("Added PinDMDv2 renderer.");
                    ReportingTags.Add("Out:PinDMDv2");
                }
            }
            if (_config.PinDmd3.Enabled)
            {
                var pinDmd3 = PinDmd3.GetInstance(_config.PinDmd3.Port);
                if (pinDmd3.IsAvailable)
                {
                    renderers.Add(pinDmd3);
                    Logger.Info("Added PinDMDv3 renderer.");
                    ReportingTags.Add("Out:PinDMDv3");
                }
            }
            if (_config.ZeDMD.Enabled)
            {
                var zeDmd = ZeDMD.GetInstance();
                if (zeDmd.IsAvailable)
                {
                    renderers.Add(zeDmd);
                    Logger.Info("Added ZeDMD renderer.");
                    ReportingTags.Add("Out:ZeDMD");
                }
            }
            if (_config.Pin2Dmd.Enabled)
            {
                var pin2Dmd = Pin2Dmd.GetInstance(_config.Pin2Dmd.Delay);
                if (pin2Dmd.IsAvailable)
                {
                    renderers.Add(pin2Dmd);
                    Logger.Info("Added PIN2DMD renderer.");
                    ReportingTags.Add("Out:PIN2DMD");
                }

                var pin2DmdXl = Pin2DmdXl.GetInstance(_config.Pin2Dmd.Delay);
                if (pin2DmdXl.IsAvailable)
                {
                    renderers.Add(pin2DmdXl);
                    Logger.Info("Added PIN2DMD XL renderer.");
                    ReportingTags.Add("Out:PIN2DMDXL");
                }

                var pin2DmdHd = Pin2DmdHd.GetInstance(_config.Pin2Dmd.Delay);
                if (pin2DmdHd.IsAvailable)
                {
                    renderers.Add(pin2DmdHd);
                    Logger.Info("Added PIN2DMD HD renderer.");
                    ReportingTags.Add("Out:PIN2DMDHD");
                }
            }
            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.");
                    ReportingTags.Add("Out:Pixelcade");
                }
            }
            if (_config.VirtualDmd.Enabled)
            {
                renderers.Add(_virtualDmd.Dmd);
                Logger.Info("Added VirtualDMD renderer.");
                ReportingTags.Add("Out:VirtualDMD");
            }
            if (_config.VirtualAlphaNumericDisplay.Enabled)
            {
                _alphaNumericDest = VirtualAlphanumericDestination.GetInstance(Dispatcher.CurrentDispatcher, _config.VirtualAlphaNumericDisplay.Style, _config);
                renderers.Add(_alphaNumericDest);
                Logger.Info("Added virtual alphanumeric renderer.");
                ReportingTags.Add("Out:VirtualAlphaNum");
            }
            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"), _config.Global.ScaleToHd));
                    Logger.Info("Added video renderer.");
                    ReportingTags.Add("Out:Video");
                }
                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), _config.Global.ScaleToHd));
                    Logger.Info("Added video renderer.");
                    ReportingTags.Add("Out:Video");
                }
                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.");
                        ReportingTags.Add("Out:PinUP");
                    }
                } 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);
                    ReportingTags.Add("Out:GIF");
                }
                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
                });
                Logger.Info("Added VPDB stream renderer.");
                ReportingTags.Add("Out:VpdbStream");
            }
            if (_config.BrowserStream.Enabled)
            {
                renderers.Add(new BrowserStream(_config.BrowserStream.Port, _gameName));
                Logger.Info("Added browser stream renderer.");
                ReportingTags.Add("Out:BrowserStream");
            }
            if (_config.NetworkStream.Enabled)
            {
                renderers.Add(NetworkStream.GetInstance(_config.NetworkStream, _gameName));
                Logger.Info("Added network stream renderer.");
                ReportingTags.Add("Out:NetworkStream");
            }

            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,
                    ScalerMode       = _config.Global.ScalerMode
                });
                ReportingTags.Add("Color:Gray2");
            }
            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,
                    ScalerMode       = _config.Global.ScalerMode
                });
            }

            // 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,
                    ScalerMode       = _config.Global.ScalerMode
                });
                ReportingTags.Add("Color:Gray4");
            }
            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,
                    ScalerMode       = _config.Global.ScalerMode
                });
            }

            // 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,
                ScalerMode       = _config.Global.ScalerMode
            });

            // 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,
                ScalerMode       = _config.Global.ScalerMode
            });

            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();
        }
Пример #3
0
        protected List <IDestination> GetRenderers(IConfiguration config, HashSet <string> reportingTags, int[] position = null)
        {
            var renderers = new List <IDestination>();

            if (config.PinDmd1.Enabled)
            {
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Logger.Info("Added PinDMDv1 renderer.");
                    reportingTags.Add("Out:PinDMDv1");
                }
                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.");
                    reportingTags.Add("Out:PinDMDv2");
                }
                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.");
                    reportingTags.Add("Out:PinDMDv3");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PinDMDv3);
                }
            }

            if (config.ZeDMD.Enabled)
            {
                var zeDMD = ZeDMD.GetInstance();
                if (zeDMD.IsAvailable)
                {
                    renderers.Add(zeDMD);
                    Logger.Info("Added ZeDMD renderer.");
                    reportingTags.Add("Out:ZeDMD");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", zeDMD);
                }
            }

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

            if (config.Pin2Dmd.Enabled)
            {
                var pin2DmdXl = Pin2DmdXl.GetInstance(config.Pin2Dmd.Delay);
                if (pin2DmdXl.IsAvailable)
                {
                    renderers.Add(pin2DmdXl);
                    Logger.Info("Added PIN2DMD XL renderer.");
                    reportingTags.Add("Out:PIN2DMDXL");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PIN2DMDXL);
                }
            }

            if (config.Pin2Dmd.Enabled)
            {
                var pin2DmdHd = Pin2DmdHd.GetInstance(config.Pin2Dmd.Delay);
                if (pin2DmdHd.IsAvailable)
                {
                    renderers.Add(pin2DmdHd);
                    Logger.Info("Added PIN2DMD HD renderer.");
                    reportingTags.Add("Out:PIN2DMDHD");
                }
                else
                {
                    Logger.Warn("Device {0} is not available.", PIN2DMDHD);
                }
            }

            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.");
                    reportingTags.Add("Out:Pixelcade");
                }
                else
                {
                    Logger.Warn("Device Pixelcade is not available.");
                }
            }

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

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

            if (config.NetworkStream.Enabled)
            {
                try {
                    renderers.Add(NetworkStream.GetInstance(config.NetworkStream));
                    Logger.Info("Added websocket client renderer.");
                    reportingTags.Add("Out:NetworkStream");
                } 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);
        }