using System; using System.Collections.Generic; using System.Linq; using System.IO; using IntelOrca.Launchpad; namespace IntelOrca.LaunchpadTests { public struct virtualButton { public int PosX; public int PosY; public ButtonBrightness IntensityGreen; public ButtonBrightness IntensityRed; } public class PWGenerator { private LaunchpadDevice mLaunchpadDevice; private long mCurrentTicks = 0; private bool appFrozen = false; private bool appEnd = false; private int screenSaverTimer = 0; //Default speed is 4, valid speed frame is 1 - 9 private int speed = 4; long delay; virtualButton[,] virtualGrid = new virtualButton[8, 8]; Random NoiseRandomizer; Random FieldValRandomizer; //Default Seed int Seed = 12345; //Default Private Key int privateKey = 54321; Random CharValRandomizer; List currentRaisingActiveGroup = new List(); int refreshIndexer; int decayIndexer; Point[] refreshGroup; Point[] decayGroup; Point ChosenPoint; int[,] FieldValues; Point currentTrailPoint; Point TargetPoint; bool isDigitalDevice = true; bool screenSaverWasKilled = false; bool setUpNewRound = true; // Building a trail is 0 = inactive, 1 = initializing, 2 = in process int buildingTrail = 0; string currentPasswordChunk = ""; string finalPassword = ""; Queue ImageList; private string processMode = "Horizontal_Green"; //Default Codepage private string codePage = "65001 Unicode"; // codepageMode activates a certain codepage to be used as characters private string characterSet = "CharsOnly"; // in combination with codepage gives the range of chars that are private bool screensaverOn = false; public enum animationColorMode { Green2Red, Red2Green, Green2Green, Red2Red }; animationColorMode currentMode = animationColorMode.Green2Green; public enum animationStyle { CenteredIn, CenteredOut, HorizontalDown, HorizontalUp, VerticalRight, VerticalLeft, Noise, SmoothNoise, Matrix, WaveHorizontal, WaveVertical }; animationStyle currentStyle = animationStyle.VerticalRight; public PWGenerator(LaunchpadDevice device) { if (device != null) { mLaunchpadDevice = device; mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed; mLaunchpadDevice.GetButton(SideButton.Arm).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice.GetButton(SideButton.Solo).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full); mLaunchpadDevice.GetButton(SideButton.TrackOn).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); isDigitalDevice = false; } //Randomizer with always different Timestamp NoiseRandomizer = new Random(Convert.ToInt32((new TimeSpan(DateTime.UtcNow.Ticks - new DateTime(2013, 06, 08).Ticks).TotalMinutes))); //Randomizer to always generate different chars from the current field value depending on the current chunk CharValRandomizer = new Random(privateKey); //Set field Values depending on given private Key FieldValues = new int[8, 8]; fillFieldValues(Seed); ImageList = new Queue(); } public PWGenerator(LaunchpadDevice device, int Seed, int privateKey, string charSet = "Nur Buchstaben", string codePage = "65001 Unicode") { if (device != null) {//if no launchpad is available use a virtual field logic mLaunchpadDevice = device; mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed; mLaunchpadDevice.GetButton(SideButton.Arm).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice.GetButton(SideButton.Solo).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full); mLaunchpadDevice.GetButton(SideButton.TrackOn).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); isDigitalDevice = false; } else { mLaunchpadDevice = null; fillVirtualGrid(); } this.Seed = Seed; this.privateKey = privateKey; this.characterSet = charSet; this.codePage = codePage; //Randomizer with always different Timestamp NoiseRandomizer = new Random(Convert.ToInt32((new TimeSpan(DateTime.UtcNow.Ticks - new DateTime(2013, 06, 08).Ticks).TotalMinutes))); //Randomizer to always generate different chars from the current field value depending on the current chunk CharValRandomizer = new Random(privateKey); //Set field Values depending on given private Key FieldValues = new int[8, 8]; fillFieldValues(Seed); ImageList = new Queue(); } private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e) { if (e.Type == ButtonType.Grid) { if (screensaverOn) { screensaverOn = false; screenSaverTimer = 0; screenSaverWasKilled = true; speed = 2; } else { // to prevent multiinput buttonpress while trailing Proccess has no use if (buildingTrail == 0 && !appFrozen) { mLaunchpadDevice[e.X, e.Y].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full); ChosenPoint.X = e.X; ChosenPoint.Y = e.Y; buildingTrail = 1; createImageFromPoint(ChosenPoint); } //Reset Screensavertimer screensaverOn = false; screenSaverTimer = 0; } } if (e.Type == ButtonType.Toolbar) { if (e.ToolbarButton == ToolbarButton.Session && buildingTrail == 0) { if (mLaunchpadDevice.GetButton(ToolbarButton.Session).RedBrightness == ButtonBrightness.Full) { mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); //Enlight Targetpoints in corresponding Color mLaunchpadDevice[3, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[3, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[4, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[4, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); processMode = "Horizontal_Green"; currentMode = animationColorMode.Green2Green; } else { mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); //Enlight Targetpoints in corresponding Color mLaunchpadDevice[3, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice[3, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice[4, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice[4, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); processMode = "Vertical_Red"; currentMode = animationColorMode.Red2Red; } mLaunchpadDevice.Refresh(); } } if (e.Type == ButtonType.Side) { if (e.SidebarButton == SideButton.TrackOn) { mLaunchpadDevice.Reset(); appEnd = true; } } if (e.Type == ButtonType.Side) { // Disable freezing the calculating process to prevent aborting a pathcalculation with a screensaver if (e.SidebarButton == SideButton.Solo && buildingTrail == 0) { if (appFrozen) appFrozen = false; else appFrozen = true; } } if (e.Type == ButtonType.Side) { if (e.SidebarButton == SideButton.Arm) { clearAllFields(); finalPassword = ""; appEnd = true; } } } public void virtualButtonPress(string buttonType, int buttonX, int buttonY) { switch (buttonType) { case "Grid": // to prevent multiinput buttonpress while trailing Proccess has no use if (buildingTrail == 0 && !appFrozen) { virtualGrid[buttonX, buttonY].IntensityGreen = ButtonBrightness.Full; virtualGrid[buttonX, buttonY].IntensityRed = ButtonBrightness.Full; ChosenPoint.X = buttonX; ChosenPoint.Y = buttonY; buildingTrail = 1; createImageFromPoint(ChosenPoint); } break; case "Enter": appEnd = true; break; case "ChangeProcessMode": if (buildingTrail == 0) { if (processMode == "VerticalRed") { //If change to Horizontal green is imminent, change center field colors to red virtualGrid[3, 3].IntensityGreen = ButtonBrightness.Off; virtualGrid[3, 3].IntensityRed = ButtonBrightness.Full; virtualGrid[3, 4].IntensityGreen = ButtonBrightness.Off; virtualGrid[3, 4].IntensityRed = ButtonBrightness.Full; virtualGrid[4, 3].IntensityGreen = ButtonBrightness.Off; virtualGrid[4, 3].IntensityRed = ButtonBrightness.Full; virtualGrid[4, 4].IntensityGreen = ButtonBrightness.Off; virtualGrid[4, 4].IntensityRed = ButtonBrightness.Full; processMode = "Horizontal_Green"; currentMode = animationColorMode.Green2Green; } else { virtualGrid[3, 3].IntensityGreen = ButtonBrightness.Full; virtualGrid[3, 3].IntensityRed = ButtonBrightness.Off; virtualGrid[3, 4].IntensityGreen = ButtonBrightness.Full; virtualGrid[3, 4].IntensityRed = ButtonBrightness.Off; virtualGrid[4, 3].IntensityGreen = ButtonBrightness.Full; virtualGrid[4, 3].IntensityRed = ButtonBrightness.Off; virtualGrid[4, 4].IntensityGreen = ButtonBrightness.Full; virtualGrid[4, 4].IntensityRed = ButtonBrightness.Off; processMode = "Vertical_Red"; currentMode = animationColorMode.Red2Red; } } break; case "Cancel": finalPassword = ""; appEnd = true; break; } } public bool Run() { //Function for external operation (with device) // controll over internal tick clock (6*12 Frames are skipped until next action to achieve a viewable result) long last_tick = Environment.TickCount; // main processing loop while (true && !appEnd) { delay = 24 * speed; if (Environment.TickCount - last_tick < delay) continue; screenSaverTimer++; if (screenSaverWasKilled || setUpNewRound) { // Kill all screensaver lights for (int xPos = 0; xPos < 8; xPos++) { for (int yPos = 0; yPos < 8; yPos++) { mLaunchpadDevice[xPos, yPos].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off); } } // Restore the regular lights setUpNewEntry(); screenSaverWasKilled = false; setUpNewRound = false; } if (screenSaverTimer >= 300) { screensaverOn = true; speed = 6; } mCurrentTicks += Environment.TickCount - last_tick; last_tick = Environment.TickCount; // Basic update-routine with integrated "freeze" function if (!appFrozen) { // Update aller Positionen Update(); // Neu Zeichnen des Brettes Draw(); } } if (finalPassword == "") { return true; } else { return false; } } private void Update() { //TODO // Methode zum setzen von virtuellem oder launchpad feld erstellen und hier integrieren //Features to implement: //- CodePages integrieren //- Externes Inputdevice in eigenem Window integrieren //- Prüfungen ob alle Konfig-Felder gefüllt sind bevor PW-Generierung gestartet wird //- Prüfungen, ob alle Konfig-Felder legitime Inhalte haben -> Seed und Key müssen int sein //- Scale der Icons dynamisch an Eingabemenge anpassen (Egal wie viele Buttons gedrückt werden Icons müssen immer in die Groupbox passen) //- Mehrzeilen Finales Passwort muss bei mehr als 2 Stellen Scrollbar sein // If screensaver is active display the noise light pattern if (screensaverOn) { while (currentRaisingActiveGroup.Count() < 32) { //create new Random point Point TempPoint = new Point(NoiseRandomizer.Next(0, 8), NoiseRandomizer.Next(0, 8)); //check if new Point is allready in the current group if (currentRaisingActiveGroup.Contains(TempPoint)) { continue; } else { //if its not in the activeGroup it must be added currentRaisingActiveGroup.Add(TempPoint); } } //check if maxed ListEntries need to be put to decay again List RemoveList = new List(); foreach (Point P in currentRaisingActiveGroup) { if (checkIfMaxedPoint(P)) { RemoveList.Add(P); } } foreach (Point P in RemoveList) { currentRaisingActiveGroup.Remove(P); } //technicly no Tiles are directly refreshed-> all will first be set to increase slowly refreshGroup = new Point[currentRaisingActiveGroup.Count()]; refreshIndexer = 0; //An Point not in the List of RaisingPoints will decay decayGroup = new Point[64 - currentRaisingActiveGroup.Count()]; decayIndexer = 0; //When the new group is picked, they shall be refreshed while the rest decays for (int yPos = 0; yPos < 8; yPos++) { for (int xPos = 0; xPos < 8; xPos++) { Point TempPoint = new Point(xPos, yPos); if (currentRaisingActiveGroup.Contains(TempPoint)) { refreshGroup[refreshIndexer++] = new Point(TempPoint.X, TempPoint.Y); } else { decayGroup[decayIndexer++] = new Point(TempPoint.X, TempPoint.Y); } } } //after groups are sorted update their lightinformation increaseGroupColors(refreshGroup); decayGroupColors(decayGroup); } else { //if a Trail needs to be build, don't set a new Target if (buildingTrail == 1) { //Check to whitch of the middle ref fields it is closest to switch (checkQuadrantOfPoint(ChosenPoint)) { case "UpLeft": TargetPoint.X = 3; TargetPoint.Y = 3; break; case "UpRight": TargetPoint.X = 4; TargetPoint.Y = 3; break; case "DownLeft": TargetPoint.X = 3; TargetPoint.Y = 4; break; case "DownRight": TargetPoint.X = 4; TargetPoint.Y = 4; break; } //Building a trail is initiated currentTrailPoint = ChosenPoint; buildingTrail = 2; //Chosenpoint will also be picked for the pw-char currentPasswordChunk = createPathChar("UTF-16"); } else { if (buildingTrail == 2) { //before stepping on in the trail, old trailpoint needs to be turned off setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Off); //Depending on process mode horizontal or vertical path is prefered switch (processMode) { case "Horizontal_Green": if (currentTrailPoint.X != TargetPoint.X) {//Currentpoint needs to make a step to the side depending on quarter it is in switch (checkQuadrantOfPoint(ChosenPoint)) { case "UpLeft": case "DownLeft": currentTrailPoint.X++; break; case "UpRight": case "DownRight": currentTrailPoint.X--; break; } //Depending on ColorMode enlight current processed Button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); break; case animationColorMode.Red2Red: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); break; } //next char needs to be read from the field and calculated currentPasswordChunk += createPathChar("UTF-16"); break; } if (currentTrailPoint.Y != TargetPoint.Y) {// Currentpoint needs to make a step verticaly depending on quadrant switch (checkQuadrantOfPoint(ChosenPoint)) { case "UpLeft": case "UpRight": currentTrailPoint.Y++; break; case "DownLeft": case "DownRight": currentTrailPoint.Y--; break; } //Depending on ColorMode enlight current processed Button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); break; case animationColorMode.Red2Red: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); break; } //next char needs to be read from the field and calculated currentPasswordChunk += createPathChar("UTF-16"); break; } //if end of trail is reached, close trailbuilding process and initiate new field pic if (currentTrailPoint.X == TargetPoint.X && currentTrailPoint.Y == TargetPoint.Y) { //Initialize all temporal Points buildingTrail = 0; setFieldColor(ChosenPoint.X, ChosenPoint.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Off); setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Off); currentTrailPoint.X = -1; currentTrailPoint.Y = -1; //Depending on ColorMode reset target button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(TargetPoint.X, TargetPoint.Y, "Green", ButtonBrightness.Full, ButtonBrightness.Off); break; case animationColorMode.Red2Red: setFieldColor(TargetPoint.X, TargetPoint.Y, "Red", ButtonBrightness.Off, ButtonBrightness.Full); break; } TargetPoint.X = -1; TargetPoint.Y = -1; ChosenPoint.X = -1; ChosenPoint.Y = -1; finalPassword += currentPasswordChunk; Console.WriteLine(finalPassword); } break; case "Vertical_Red": if (currentTrailPoint.Y != TargetPoint.Y) {// Currentpoint needs to make a step verticaly depending on quadrant switch (checkQuadrantOfPoint(ChosenPoint)) { case "UpLeft": case "UpRight": currentTrailPoint.Y++; break; case "DownLeft": case "DownRight": currentTrailPoint.Y--; break; } //Depending on ColorMode enlight current processed Button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); break; case animationColorMode.Red2Red: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); break; } //next char needs to be read from the field and calculated currentPasswordChunk += createPathChar("UTF-16"); break; } if (currentTrailPoint.X != TargetPoint.X) {//Currentpoint needs to make a step to the side depending on quarter it is in switch (checkQuadrantOfPoint(ChosenPoint)) { case "UpLeft": case "DownLeft": currentTrailPoint.X++; break; case "UpRight": case "DownRight": currentTrailPoint.X--; break; } //Depending on ColorMode enlight current processed Button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); break; case animationColorMode.Red2Red: setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[currentTrailPoint.X, currentTrailPoint.Y].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); break; } //next char needs to be read from the field and calculated currentPasswordChunk += createPathChar("UTF-16"); break; } if (currentTrailPoint.X == TargetPoint.X && currentTrailPoint.Y == TargetPoint.Y) { //Initialize all temporal Points buildingTrail = 0; setFieldColor(ChosenPoint.X, ChosenPoint.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Off); setFieldColor(currentTrailPoint.X, currentTrailPoint.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Off); currentTrailPoint.X = -1; currentTrailPoint.Y = -1; //Depending on ColorMode reset target button in corresponding color switch (currentMode) { case animationColorMode.Green2Green: setFieldColor(TargetPoint.X, TargetPoint.Y, "Green", ButtonBrightness.Full, ButtonBrightness.Off); break; case animationColorMode.Red2Red: setFieldColor(TargetPoint.X, TargetPoint.Y, "Red", ButtonBrightness.Off, ButtonBrightness.Full); break; } TargetPoint.X = -1; TargetPoint.Y = -1; ChosenPoint.X = -1; ChosenPoint.Y = -1; finalPassword += currentPasswordChunk; Console.WriteLine(finalPassword); } break; } } } } } private string checkQuadrantOfPoint(Point p) { // Check in whitch quater the point is in if (p.X < 4 && p.Y < 4) { return "UpLeft"; } if (p.X < 4 && p.Y > 3) { return "DownLeft"; } if (p.X > 3 && p.Y < 4) { return "UpRight"; } if (p.X > 3 && p.Y > 3) { return "DownRight"; } return "Error"; } private void setUpNewEntry() { //clear all current active buttons clearAllFields(); //Set up Reference Fields mLaunchpadDevice[3, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[4, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[3, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice[4, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); //Set up ConfigButtons mLaunchpadDevice.GetButton(SideButton.Arm).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off); mLaunchpadDevice.GetButton(SideButton.Solo).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full); mLaunchpadDevice.GetButton(SideButton.TrackOn).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full); } private bool checkIfMaxedPoint(Point p) { switch (currentMode) { case animationColorMode.Green2Green: if (getFieldColor(p.X, p.Y, "Green") == ButtonBrightness.Full) return true; else return false; case animationColorMode.Green2Red: if (getFieldColor(p.X, p.Y, "Green") == ButtonBrightness.Full) return true; else return false; case animationColorMode.Red2Red: if (getFieldColor(p.X, p.Y, "Red") == ButtonBrightness.Full) return true; else return false; case animationColorMode.Red2Green: if (getFieldColor(p.X, p.Y, "Red") == ButtonBrightness.Full) return true; else return false; default: return false; } } private void refreshGroupColors(Point[] currentGroup) { //Depending on Colormode refresh the Brightness of that button group switch (currentMode) { case animationColorMode.Green2Green: foreach (Point Tile in currentGroup) { setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); } break; case animationColorMode.Green2Red: foreach (Point Tile in currentGroup) { setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Full); } break; case animationColorMode.Red2Green: foreach (Point Tile in currentGroup) { setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Full, ButtonBrightness.Off); } break; case animationColorMode.Red2Red: foreach (Point Tile in currentGroup) { setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); } break; } } private void increaseGroupColors(Point[] currentGroup) { // Depending on colormode decay switch (currentMode) { case animationColorMode.Green2Green: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Green")) { case ButtonBrightness.Off: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Low); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Full); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Medium); break; } } break; case animationColorMode.Green2Red: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Green")) { case ButtonBrightness.Off: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Medium, ButtonBrightness.Low); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Off, ButtonBrightness.Full); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Low, ButtonBrightness.Medium); break; } } break; case animationColorMode.Red2Green: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Red")) { case ButtonBrightness.Off: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Low, ButtonBrightness.Medium); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Full, ButtonBrightness.Off); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Medium, ButtonBrightness.Low); break; } } break; case animationColorMode.Red2Red: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Red")) { case ButtonBrightness.Off: setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Low, ButtonBrightness.Off); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Full, ButtonBrightness.Off); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Medium, ButtonBrightness.Off); break; } } break; } } private void decayGroupColors(Point[] currentGroup) { // Depending on colormode decay switch (currentMode) { case animationColorMode.Green2Green: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Green")) { case ButtonBrightness.Full: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Medium); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Low); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Green", ButtonBrightness.Off, ButtonBrightness.Off); break; } } break; case animationColorMode.Green2Red: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Green")) { case ButtonBrightness.Full: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Low, ButtonBrightness.Medium); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Medium, ButtonBrightness.Low); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Green2Red", ButtonBrightness.Full, ButtonBrightness.Off); break; } } break; case animationColorMode.Red2Green: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Red")) { case ButtonBrightness.Full: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Medium, ButtonBrightness.Low); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Low, ButtonBrightness.Medium); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Red2Green", ButtonBrightness.Off, ButtonBrightness.Full); break; } } break; case animationColorMode.Red2Red: foreach (Point Tile in currentGroup) { switch (getFieldColor(Tile.X, Tile.Y, "Red")) { case ButtonBrightness.Full: setFieldColor(Tile.X, Tile.Y,"Red", ButtonBrightness.Medium, ButtonBrightness.Off); break; case ButtonBrightness.Medium: setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Low, ButtonBrightness.Off); break; case ButtonBrightness.Low: setFieldColor(Tile.X, Tile.Y, "Red", ButtonBrightness.Off, ButtonBrightness.Off); break; } } break; } } private void fillFieldValues(int Seed) { // This method sets up the values behind all fields to build paths on; every field is unique // and stays the same per private key FieldValRandomizer = new Random(Seed); for (int yPos = 0; yPos < 8; yPos++) { for (int xPos = 0; xPos < 8; xPos++) { FieldValues[xPos, yPos] = FieldValRandomizer.Next(0, 100); Console.Write(FieldValues[xPos, yPos] + " |"); } Console.WriteLine(""); } } private void fillVirtualGrid() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { virtualButton tempButton = new virtualButton(); tempButton.PosX = i; tempButton.PosY = j; tempButton.IntensityGreen = ButtonBrightness.Off; tempButton.IntensityRed = ButtonBrightness.Off; virtualGrid[i, j] = tempButton; } } switch (currentMode) { case animationColorMode.Green2Green: case animationColorMode.Green2Red: virtualGrid[3, 3].IntensityRed = ButtonBrightness.Full; virtualGrid[3, 3].IntensityGreen = ButtonBrightness.Off; virtualGrid[3, 4].IntensityRed = ButtonBrightness.Full; virtualGrid[3, 4].IntensityGreen = ButtonBrightness.Off; virtualGrid[4, 3].IntensityRed = ButtonBrightness.Full; virtualGrid[4, 3].IntensityGreen = ButtonBrightness.Off; virtualGrid[4, 4].IntensityRed = ButtonBrightness.Full; virtualGrid[4, 4].IntensityGreen = ButtonBrightness.Off; break; case animationColorMode.Red2Green: case animationColorMode.Red2Red: virtualGrid[3, 3].IntensityRed = ButtonBrightness.Off; virtualGrid[3, 3].IntensityGreen = ButtonBrightness.Full; virtualGrid[3, 4].IntensityRed = ButtonBrightness.Off; virtualGrid[3, 4].IntensityGreen = ButtonBrightness.Full; virtualGrid[4, 3].IntensityRed = ButtonBrightness.Off; virtualGrid[4, 3].IntensityGreen = ButtonBrightness.Full; virtualGrid[4, 4].IntensityRed = ButtonBrightness.Off; virtualGrid[4, 4].IntensityGreen = ButtonBrightness.Full; break; } } private void setFieldColor(int PosX, int PosY, string color, ButtonBrightness intensityR,ButtonBrightness intensityG ) { if (mLaunchpadDevice == null) {//no device was given so virtualBoard is used virtualGrid[PosX, PosY].IntensityGreen = intensityG; virtualGrid[PosX, PosY].IntensityRed = intensityR; } else { mLaunchpadDevice[PosX, PosY].SetBrightness(intensityR, intensityG); } } public ButtonBrightness getFieldColor(int PosX, int PosY, string neededColor) { ButtonBrightness TempColor; if (mLaunchpadDevice == null) {//no device was given so virtualBoard is used switch (neededColor) { case "Red": TempColor = virtualGrid[PosX, PosY].IntensityRed; break; case "Green": TempColor = virtualGrid[PosX, PosY].IntensityGreen; break; default: TempColor = ButtonBrightness.Off; break; } return TempColor; } else { switch (neededColor) { case "Red": TempColor = mLaunchpadDevice[PosX, PosY].RedBrightness; break; case "Green": TempColor = mLaunchpadDevice[PosX, PosY].GreenBrightness; break; default: TempColor = ButtonBrightness.Off; break; } return TempColor; } } private string createPathChar(string codepage) { //This method creates a codepage char to add it to the current path int tempValue = 0; string tempString; int lowerCap = 0; int upperCap = 0; char c = ' '; switch (codepage) { // ToDo: Insert Codepage specific caps + find out how to cast INTs to them case "ASCII": case "UTF-16": case "65001 UTF-8 (Unicode)": switch (characterSet) { case "Nur Buchstaben": lowerCap = 65; upperCap = 121; break; case "Nur Zahlen": lowerCap = 48; upperCap = 58; break; case "Keine Steuerzeichen": default: lowerCap = 32; upperCap = 126; break; } break; } //Pick a valid codepage-value which is allowed by target system (needs to be ensured beforehand!!) //because 0 can be a FieldValue too, at least 1 charactervalue needs to be generated if (characterSet == "Nur Buchstaben") { //in characters only mode there are codepages (like ascii/Unicode) which do not have all chars grouped together //for such codepages there must be a special tempValue-Calc procedure bool characterIsInvalid = true; switch (codePage) { case "65001 UTF-8 (Unicode)": default: for (int indexer = -1; indexer < FieldValues[currentTrailPoint.X, currentTrailPoint.Y] || characterIsInvalid; indexer++) { //lower and uppder cap have all chars implemented but only valid chars need allow for continuing of the process tempValue = CharValRandomizer.Next(lowerCap, upperCap); c = (char)tempValue; switch (c) { case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': characterIsInvalid = false; break; default: characterIsInvalid = true; break; } } break; } } else { // If searched chars are grouped together this process is enough to determine all needed chars for (int indexer = -1; indexer < FieldValues[currentTrailPoint.X, currentTrailPoint.Y]; indexer++) { tempValue = CharValRandomizer.Next(lowerCap, upperCap); } c = (char)tempValue; } if (c == '\\') { tempString = c.ToString(); tempString += c.ToString(); } return c.ToString(); } private void createImageFromPoint(Point nextImage) { string Tempstring = nextImage.X.ToString() + "_" + nextImage.Y.ToString(); string PathString = "../../Assets/Graphics/"; string extension = ".png"; string proccessString; if (processMode == "Horizontal_Green") proccessString = "Hor_"; else proccessString = "Ver_"; string finalPath = PathString + proccessString + Tempstring + extension; ImageList.Enqueue(finalPath); } private void Draw() { // Refresh devices light information mLaunchpadDevice.Refresh(); } public string GetFinalPassword() { return finalPassword; } public Queue GetInstructionList() { return ImageList; } public void clearAllFields() { //Clear all Grid Fields for (int yPos = 0; yPos < 8; yPos++) { for (int xPos = 0; xPos < 8; xPos++) { mLaunchpadDevice[xPos, xPos].TurnOffLight(); } } //ToolbarButtons mLaunchpadDevice.GetButton(ToolbarButton.Down).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.Left).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.Mixer).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.Right).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.Session).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.Up).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.User1).TurnOffLight(); mLaunchpadDevice.GetButton(ToolbarButton.User2).TurnOffLight(); //SidebarButtons mLaunchpadDevice.GetButton(SideButton.Arm).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.Pan).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.Solo).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.SoundA).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.SoundB).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.Stop).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.TrackOn).TurnOffLight(); mLaunchpadDevice.GetButton(SideButton.Volume).TurnOffLight(); } } }