@@ -23,78 +23,77 @@ public static bool Run_(bool runPogram)
23
23
24
24
//load data
25
25
if ( Program . values . Count < 1 ) {
26
- Console . WriteLine ( "loading from file..." ) ;
27
- array = File . ReadAllLines ( "data.txt ") ;
28
- chanel = int . Parse ( array [ 0 ] . Split ( ',' ) [ 0 ] ) ;
26
+ if ( File . Exists ( "data.txt" ) && ( array = File . ReadAllLines ( "data.txt" ) ) . Length > 2 ) {
27
+ Console . WriteLine ( "loading from file... ") ;
28
+ chanel = int . Parse ( array [ 0 ] . Split ( ',' ) [ 0 ] ) ;
29
29
30
- //color
31
- if ( array [ 0 ] . Split ( ',' ) . Length > 1 ) {
32
- string [ ] ColorArray = array [ 0 ] . Split ( ',' ) ;
30
+ //color
31
+ if ( array [ 0 ] . Split ( ',' ) . Length > 1 ) {
32
+ string [ ] ColorArray = array [ 0 ] . Split ( ',' ) ;
33
33
34
- InputPort midiOut = new InputPort ( ) ;
35
- midiOut . OpenOut ( int . Parse ( ColorArray [ 1 ] . Trim ( ) ) ) ;
34
+ InputPort midiOut = new InputPort ( ) ;
35
+ midiOut . OpenOut ( int . Parse ( ColorArray [ 1 ] . Trim ( ) ) ) ;
36
36
37
- //send output
38
- for ( int i = 2 ; i + 1 < ColorArray . Length ; i += 2 ) {
39
- midiOut . MidiOutMsg ( ( byte ) int . Parse ( ColorArray [ i ] . Trim ( ) ) , ( byte ) int . Parse ( ColorArray [ i + 1 ] . Trim ( ) ) ) ;
40
- }
37
+ //send output
38
+ for ( int i = 2 ; i + 1 < ColorArray . Length ; i += 2 ) {
39
+ midiOut . MidiOutMsg ( ( byte ) int . Parse ( ColorArray [ i ] . Trim ( ) ) , ( byte ) int . Parse ( ColorArray [ i + 1 ] . Trim ( ) ) ) ;
40
+ }
41
41
42
- midiOut . CloseOut ( ) ;
43
- }
42
+ midiOut . CloseOut ( ) ;
43
+ }
44
44
45
- //load keys
46
- for ( int lineID = 0 ; lineID < array . Length ; lineID ++ ) {
47
- if ( array [ lineID ] != string . Concat ( chanel ) ) {
48
- string [ ] loadedValues = array [ lineID ] . Split ( new char [ ] { ',' } ) ;
49
- int [ ] tempValues = new int [ loadedValues . Length ] ;
50
- StringBuilder log = new StringBuilder ( ) ;
51
- for ( int i = 0 ; i < tempValues . Length ; i ++ ) {
52
- string value = loadedValues [ i ] . Trim ( ) ;
53
- if ( ! int . TryParse ( value , out tempValues [ i ] ) ) {
54
- string [ ] convertValue ;
55
- if ( ( convertValue = value . Split ( '\' ' ) ) . Length > 1 ) {
56
- tempValues [ i ] = GetID ( convertValue [ 1 ] [ 0 ] ) ;
57
- if ( convertValue [ 0 ] [ convertValue [ 0 ] . Length - 1 ] == '-' ) {
58
- if ( i < 2 || i > 1 && tempValues [ 1 ] != 1 ) {
59
- error = true ;
60
- Error ( "Error at line {0} -> \" {1}\" , Negativ value not allowed: \" {2}\" ." , lineID , array [ lineID ] , value ) ;
61
- } else
62
- tempValues [ i ] = - tempValues [ i ] ;
63
- }
64
- } else if ( ( convertValue = value . Split ( '"' ) ) . Length > 1 ) {
65
- tempValues [ i ] = GetID ( convertValue [ 1 ] [ 0 ] ) ;
66
- if ( convertValue [ 0 ] [ convertValue [ 0 ] . Length - 1 ] == '-' ) {
67
- if ( i < 2 || i > 1 && tempValues [ 1 ] != 1 ) {
68
- error = true ;
69
- Error ( "Error at line {0} -> \" {1}\" , Negativ value not allowed: \" {2}\" ." , lineID , array [ lineID ] , value ) ;
70
- } else
71
- tempValues [ i ] = - tempValues [ i ] ;
72
- }
73
- } else if ( value . Length == 1 ) {
74
- tempValues [ i ] = GetID ( value [ 0 ] ) ;
75
- } else {
76
- if ( value . Length == 2 && value [ 0 ] == '-' ) {
77
- tempValues [ i ] = - GetID ( value [ 1 ] ) ;
45
+ //load keys
46
+ for ( int lineID = 0 ; lineID < array . Length ; lineID ++ ) {
47
+ if ( array [ lineID ] != string . Concat ( chanel ) ) {
48
+ string [ ] loadedValues = array [ lineID ] . Split ( new char [ ] { ',' } ) ;
49
+ int [ ] tempValues = new int [ loadedValues . Length ] ;
50
+ StringBuilder log = new StringBuilder ( ) ;
51
+ for ( int i = 0 ; i < tempValues . Length ; i ++ ) {
52
+ string value = loadedValues [ i ] . Trim ( ) ;
53
+ if ( ! int . TryParse ( value , out tempValues [ i ] ) ) {
54
+ string [ ] convertValue ;
55
+ if ( ( convertValue = value . Split ( '\' ' ) ) . Length > 1 ) {
56
+ tempValues [ i ] = GetID ( convertValue [ 1 ] [ 0 ] ) ;
57
+ if ( convertValue [ 0 ] [ convertValue [ 0 ] . Length - 1 ] == '-' ) {
58
+ if ( i < 2 || i > 1 && tempValues [ 1 ] != 1 ) {
59
+ error = true ;
60
+ Error ( "Error at line {0} -> \" {1}\" , Negativ value not allowed: \" {2}\" ." , lineID , array [ lineID ] , value ) ;
61
+ } else
62
+ tempValues [ i ] = - tempValues [ i ] ;
63
+ }
64
+ } else if ( ( convertValue = value . Split ( '"' ) ) . Length > 1 ) {
65
+ tempValues [ i ] = GetID ( convertValue [ 1 ] [ 0 ] ) ;
66
+ if ( convertValue [ 0 ] [ convertValue [ 0 ] . Length - 1 ] == '-' ) {
67
+ if ( i < 2 || i > 1 && tempValues [ 1 ] != 1 ) {
68
+ error = true ;
69
+ Error ( "Error at line {0} -> \" {1}\" , Negativ value not allowed: \" {2}\" ." , lineID , array [ lineID ] , value ) ;
70
+ } else
71
+ tempValues [ i ] = - tempValues [ i ] ;
72
+ }
73
+ } else if ( value . Length == 1 ) {
74
+ tempValues [ i ] = GetID ( value [ 0 ] ) ;
78
75
} else {
79
- error = true ;
80
- Error ( "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineID , array [ lineID ] , value . Length > 1 ? "s" : "" , value ) ;
76
+ if ( value . Length == 2 && value [ 0 ] == '-' ) {
77
+ tempValues [ i ] = - GetID ( value [ 1 ] ) ;
78
+ } else {
79
+ error = true ;
80
+ Error ( "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineID , array [ lineID ] , value . Length > 1 ? "s" : "" , value ) ;
81
+ }
81
82
}
82
83
}
84
+ log . Append ( value ) ;
85
+ log . Append ( ' ' ) ;
83
86
}
84
- log . Append ( value ) ;
85
- log . Append ( ' ' ) ;
87
+ Program . values . Add ( tempValues ) ;
88
+ Console . WriteLine ( log ) ;
86
89
}
87
- Program . values . Add ( tempValues ) ;
88
- Console . WriteLine ( log ) ;
89
90
}
91
+ } else {
92
+ error = true ;
93
+ Error ( "Error -> No data." ) ;
90
94
}
91
95
} else {
92
- error = true ;
93
- Console . ForegroundColor = ConsoleColor . Red ;
94
- Console . WriteLine ( "Error -> No data." ) ;
95
- Console . ResetColor ( ) ;
96
- Console . WriteLine ( "Press any key to continue..." ) ;
97
- Console . ReadKey ( ) ;
96
+ Console . WriteLine ( "Data already loaded in memory..." ) ;
98
97
}
99
98
100
99
string [ ] valuesHex = new string [ Program . values . Count ] ;
@@ -187,8 +186,6 @@ public static bool Run_(bool runPogram)
187
186
}
188
187
Console . WriteLine ( valueHex + "\n " ) ;
189
188
old2 = value ;
190
-
191
-
192
189
}
193
190
Program . waitHandle . Reset ( ) ;
194
191
}
@@ -249,21 +246,10 @@ private static void Error(string s, object[] os)
249
246
Console . WriteLine ( "Press any key to ignore and continue..." ) ;
250
247
Console . ReadKey ( ) ;
251
248
}
252
- private static void Error ( string s , object o1 )
253
- {
254
- Error ( s , new object [ ] { o1 } ) ;
255
- }
256
- private static void Error ( string s , object o1 , object o2 )
257
- {
258
- Error ( s , new object [ ] { o1 , o2 } ) ;
259
- }
260
- private static void Error ( string s , object o1 , object o2 , object o3 )
261
- {
262
- Error ( s , new object [ ] { o1 , o2 , o3 } ) ;
263
- }
264
- private static void Error ( string s , object o1 , object o2 , object o3 , object o4 )
265
- {
266
- Error ( s , new object [ ] { o1 , o2 , o3 , o4 } ) ;
267
- }
249
+ private static void Error ( string s , object o1 ) => Error ( s , new object [ ] { o1 } ) ;
250
+ private static void Error ( string s , object o1 , object o2 ) => Error ( s , new object [ ] { o1 , o2 } ) ;
251
+ private static void Error ( string s , object o1 , object o2 , object o3 ) => Error ( s , new object [ ] { o1 , o2 , o3 } ) ;
252
+ private static void Error ( string s , object o1 , object o2 , object o3 , object o4 ) => Error ( s , new object [ ] { o1 , o2 , o3 , o4 } ) ;
253
+
268
254
}
269
255
}
0 commit comments