-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f63710
commit a16a0ce
Showing
9 changed files
with
166 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using MIDIKeyboard.dataFolder; | ||
using static MIDIKeyboard.miscellaneous.Miscellaneous; | ||
|
||
namespace MIDIKeyboard.Run | ||
{ | ||
class LoadData | ||
{ | ||
public static bool Load() => LoadFile() && SendOutputData() & LoadKeyData(); | ||
|
||
static string[] array; | ||
|
||
static bool LoadFile(string path = "data.txt") | ||
{ | ||
Console.Write("Loading data from path \"{0}\"...", path); | ||
if (File.Exists(path) && (array = File.ReadAllLines(path)).Length > 2) { | ||
Console.WriteLine(" Done."); | ||
return true; | ||
} | ||
Console.WriteLine(" Error."); | ||
Error("Error -> No data."); | ||
return false; | ||
} | ||
|
||
static bool SendOutputData() | ||
{ | ||
if (array[0].Split(',').Length > 1) { | ||
Console.Write("Sending output data..."); | ||
string[] ColorArray = array[0].Split(','); | ||
|
||
InputPort midiOut = new InputPort(); | ||
midiOut.OpenOut(int.Parse(ColorArray[1].Trim())); | ||
|
||
//send output | ||
for (int i = 2; i + 1 < ColorArray.Length; i += 2) { | ||
midiOut.MidiOutMsg((byte)int.Parse(ColorArray[i].Trim()), (byte)int.Parse(ColorArray[i + 1].Trim())); | ||
} | ||
|
||
midiOut.CloseOut(); | ||
Console.WriteLine(" Done."); | ||
return true; | ||
} | ||
Console.WriteLine("No output data detected."); | ||
return true; | ||
} | ||
|
||
static bool LoadKeyData() | ||
{ | ||
bool noErrors = true; | ||
Console.WriteLine("loading from file..."); | ||
int chanel = int.Parse(array[0].Split(',')[0]); | ||
|
||
for (int lineID = 0; lineID < array.Length; lineID++) { | ||
if (array[lineID] != string.Concat(chanel)) { | ||
string[] loadedValues = array[lineID].Split(new char[] { ',' }); | ||
int[] tempValues = new int[loadedValues.Length]; | ||
StringBuilder log = new StringBuilder(); | ||
for (int i = 0; i < tempValues.Length; i++) { | ||
string value = loadedValues[i].Trim(); | ||
if (!int.TryParse(value, out tempValues[i])) { | ||
string[] convertValue; | ||
if ((convertValue = value.Split('\'')).Length > 1) { | ||
tempValues[i] = GetID(convertValue[1][0]); | ||
if (convertValue[0][convertValue[0].Length - 1] == '-') { | ||
if (i < 2 || i > 1 && tempValues[1] != 1) { | ||
noErrors = false; | ||
Error("Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, array[lineID], value); | ||
} else | ||
tempValues[i] = -tempValues[i]; | ||
} | ||
} else if ((convertValue = value.Split('"')).Length > 1) { | ||
tempValues[i] = GetID(convertValue[1][0]); | ||
if (convertValue[0][convertValue[0].Length - 1] == '-') { | ||
if (i < 2 || i > 1 && tempValues[1] != 1) { | ||
noErrors = false; | ||
Error("Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, array[lineID], value); | ||
} else | ||
tempValues[i] = -tempValues[i]; | ||
} | ||
} else if (value.Length == 1) { | ||
tempValues[i] = GetID(value[0]); | ||
} else { | ||
if (value.Length == 2 && value[0] == '-') { | ||
tempValues[i] = -GetID(value[1]); | ||
} else { | ||
noErrors = false; | ||
Error("Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineID, array[lineID], value.Length > 1 ? "s" : "", value); | ||
} | ||
} | ||
} | ||
log.Append(value); | ||
log.Append(' '); | ||
} | ||
Program.values.Add(tempValues); | ||
Console.WriteLine(log); | ||
} | ||
} | ||
return noErrors; | ||
} | ||
} | ||
} |
Oops, something went wrong.