Ejemplo n.º 1
0
        public void Initialise(int striplength = 0, bool isDebug = false, LightsConfiguration inputConfig = null)
        {
            debugmode = isDebug;

            if (inputConfig != null)
            {
                SetCurrentConfig(inputConfig);
            }

            if (striplength < 1)
            {
                foreach (LightChannel lc in LightChannels)
                {
                    striplength = Math.Max(striplength, lc.StripRangeEnd + 1);
                }
            }

            stripStack = new Colour[striplength];

            if (!debugmode)
            {
                strip = new LedStripOutput(striplength);
                strip.SetStrip(Colour.Blank());
            }

            currentPatternLayer = PatternLayers[0];

            fixedUpdateTimeDelta = (1000 / updatesPerSecond);
            Console.WriteLine($"Running at {updatesPerSecond} updates/sec ({fixedUpdateTimeDelta}ms frametime)");
            var bgtask = Task.Run(UpdateValues);
        }
Ejemplo n.º 2
0
        public static void SaveConfigToFile(LightsConfiguration input, string filepath)
        {
            Console.WriteLine($"Writing to {filepath}");
            XmlSerializer configSerializer = new XmlSerializer(typeof(LightsConfiguration));
            TextWriter    writer           = new StreamWriter(filepath);

            configSerializer.Serialize(writer, input);
            writer.Close();
            Console.WriteLine("Save successful.");
        }
Ejemplo n.º 3
0
        private void SetCurrentConfig(LightsConfiguration conf)
        {
            this.KeysMode                   = conf.KeysMode;
            this.updatesPerSecond           = conf.UpdatesPerSecond;
            this.LightChannels              = conf.DefinedChannels;
            this.PatternLayers              = conf.DefinedPatternLayers;
            this.FastNotesDetection         = conf.FastNotesDetection;
            this.FastNoteTimeThreshold      = conf.FastNotesTimeThreshold;
            this.FastNoteVelocityThreshold  = conf.FastNotesVelocityThreshold;
            this.FlamNotesDetection         = conf.FlamNotesDetection;
            this.FlamNotesTimeThreshold     = conf.FlamNotesTimeThreshold;
            this.FlamNotesVelocityThreshold = conf.FlamNotesVelocityThreshold;
            this.GlobalBrightnessValue      = Math.Clamp(conf.GlobalBrightnessValue, 1, 255);
            this.decayValue                 = conf.HitDecayRate;
            this.intensityDecayRate         = conf.IntensityDecayRate;
            this.c_IntensityColour          = conf.ColourIntensityHighlight;

            this.intensityGain  = conf.IntensityGain;
            this.decayCurveType = conf.HitDecayCurveType;
            Console.WriteLine("Set lights config");
        }
Ejemplo n.º 4
0
        //Params
        public LightsConfiguration GetCurrentConfig()
        {
            LightsConfiguration outLc = new LightsConfiguration();

            outLc.KeysMode                   = KeysMode;
            outLc.UpdatesPerSecond           = updatesPerSecond;
            outLc.DefinedChannels            = LightChannels;
            outLc.FastNotesDetection         = FastNotesDetection;
            outLc.FastNotesTimeThreshold     = FastNoteTimeThreshold;
            outLc.FastNotesVelocityThreshold = FastNoteVelocityThreshold;
            outLc.FlamNotesDetection         = FlamNotesDetection;
            outLc.FlamNotesTimeThreshold     = FlamNotesTimeThreshold;
            outLc.FlamNotesVelocityThreshold = FlamNotesVelocityThreshold;
            outLc.GlobalBrightnessValue      = GlobalBrightnessValue;
            outLc.HitDecayRate               = decayValue;
            outLc.IntensityDecayRate         = intensityDecayRate;
            outLc.IntensityGain              = intensityGain;
            outLc.ColourIntensityHighlight   = c_IntensityColour;
            outLc.DefinedPatternLayers       = PatternLayers;

            return(outLc);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Light FX Server");
            string targetAddress  = "127.0.0.1";
            int    targetPort     = 5005;
            bool   debug          = false;
            bool   running        = true;
            string targetFilepath = "";

            if (args.Length > 0)
            {
                if (args[0] == "testmode")
                {
                    debug = true;
                }
                else
                {
                    if (args[0] != null)
                    {
                        targetAddress = args[0];
                    }
                    if (args[1] != null)
                    {
                        int.TryParse(args[1], out targetPort);
                    }
                }
            }

            if (Directory.Exists(configPath))
            {
                foreach (string fname in Directory.GetFiles(configPath))
                {
                    if (fname.EndsWith(".xml"))
                    {
                        //todo: multiple files, just load the first one for now
                        targetFilepath = fname;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("No config available!");
            }


            LightControl control = new LightControl(isDebug: debug, inputConfig: LightsConfiguration.LoadConfigFromFile(targetFilepath));

            //Inputs over TCP
            //Todo: gracefully shut down, instruct connected clients when it happens
            InputTcpServer listenServer = new InputTcpServer(targetAddress, targetPort);

            //Deal with messages
            MidiEvent curEvent;

            try
            {
                while (running)
                {
                    while (MidiMessageList.TryDequeue(out curEvent))
                    {
                        if (curEvent == null)
                        {
                            Console.WriteLine("Null event?");
                        }
                        else
                        {
                            //Todo: extra special event to perform a program-change?
                            if (debug)
                            {
                                Console.WriteLine($"MIDI Event: {curEvent.ToString()}");
                            }
                            if (curEvent.EventType == 999)
                            {
                                running = false;
                            }                                                   //special event to close server
                            control.ProcessEvent(curEvent);
                        }
                    }
                }
            }
            finally
            {
                listenServer.StopListener();
            }
        }
Ejemplo n.º 6
0
 public LightControl(int striplength = 0, bool isDebug = false, LightsConfiguration inputConfig = null)
 {
     Initialise(striplength, isDebug, inputConfig);
 }