1
1
using System ;
2
2
using System . IO ;
3
+ using System . Linq ;
3
4
using System . Text ;
4
5
using MIDIKeyboard . dataFolder ;
6
+ using MIDIKeyboard . Miscellaneous ;
5
7
using static MIDIKeyboard . Miscellaneous . Miscellaneous ;
6
8
7
9
namespace MIDIKeyboard . Run
@@ -46,7 +48,7 @@ private static bool SendOutputData()
46
48
}
47
49
48
50
Console . WriteLine ( "No output data detected." ) ;
49
- return true ;
51
+ return false ;
50
52
}
51
53
52
54
public static bool SendOutputDataZero ( )
@@ -73,159 +75,182 @@ private static bool LoadKeyData()
73
75
{
74
76
bool noErrors = true ;
75
77
Console . WriteLine ( "loading from file..." ) ;
76
- int chanel = int . Parse ( rawData [ 0 ] . Split ( ',' ) [ 0 ] ) ;
77
-
78
- for ( int lineId = 1 ; lineId < rawData . Length ; lineId ++ )
79
- if ( rawData [ lineId ] != string . Concat ( chanel ) ) {
80
- string [ ] loadedValues = rawData [ lineId ] . Split ( ',' ) ;
81
- if ( loadedValues . Length == 2 ) //add missing mode id
82
- loadedValues = new [ ]
83
- { loadedValues [ 0 ] , loadedValues [ 1 ] . Contains ( "\" " ) ? "1" : "0" , loadedValues [ 1 ] } ;
84
- else if ( loadedValues [ 1 ] . Contains ( "\" " ) ) { //if mode is a string, assume it as a macro argument
85
- string [ ] newLoadedValues = new string [ loadedValues . Length + 1 ] ;
86
- newLoadedValues [ 0 ] = loadedValues [ 0 ] ;
87
- newLoadedValues [ 1 ] = "1" ;
88
- for ( int i = 1 ; i < loadedValues . Length ; i ++ )
89
- newLoadedValues [ i + 1 ] = loadedValues [ i ] ;
90
- }
78
+ //int chanel = int.Parse(rawData[0].Split(',')[0]);
79
+
80
+ int lineId = 1 ;
81
+ //Settings.data.visual_profiles_path
82
+ if ( ! rawData [ 1 ] . Contains ( "," ) ) {
83
+ lineId = 2 ;
84
+ if ( ! File . Exists ( Settings . data . visual_profiles_path + rawData [ 1 ] . Trim ( ) ) ) {
85
+ Error ( "Error at line 1 -> \" {0}\" , Cannot find target profile." , rawData [ 1 ] ) ;
86
+ return false ;
87
+ }
88
+
89
+ string [ ] res = new string [ rawData . Length - 2 ] ;
90
+ Array . Copy ( rawData , 2 , res , 0 , res . Length ) ;
91
+ string [ ] profileStringArray = string . Join ( "," , File . ReadAllLines ( Settings . data . visual_profiles_path + rawData [ 1 ] . Trim ( ) , Encoding . UTF8 ) ) . Split ( ',' ) ;
92
+ string [ ] dataArray = string . Join ( "," , res ) . Split ( ',' ) ;
93
+ string [ ] newRawData = new string [ profileStringArray . Length + 2 ] ;
94
+ newRawData [ 0 ] = rawData [ 0 ] ;
95
+ newRawData [ 1 ] = rawData [ 1 ] ;
96
+ for ( int i = 0 ; i < profileStringArray . Length ; i ++ ) {
97
+ newRawData [ i + 2 ] = profileStringArray [ i ] + ( dataArray [ i ] . Trim ( ) . Length > 0 ? "," + dataArray [ i ] : "" ) ;
98
+ }
91
99
92
- int [ ] tempValues = new int [ loadedValues . Length ] ;
93
- var log = new StringBuilder ( ) ;
94
- bool error = false ;
95
- for ( int i = 0 ; i < tempValues . Length ; i ++ ) {
96
- string value = loadedValues [ i ] . Trim ( ) ;
97
- if ( ! int . TryParse ( value , out tempValues [ i ] ) ) {
98
- if ( i < 2 ) {
100
+ rawData = newRawData ;
101
+ }
102
+
103
+ for ( ; lineId < rawData . Length ; lineId ++ ) {
104
+ string [ ] loadedValues = rawData [ lineId ] . Split ( ',' ) ;
105
+ if ( loadedValues . Length == 1 ) continue ;
106
+ if ( loadedValues . Length == 2 ) //add missing mode id
107
+ loadedValues = new [ ]
108
+ { loadedValues [ 0 ] , loadedValues [ 1 ] . Contains ( "\" " ) ? "1" : "0" , loadedValues [ 1 ] } ;
109
+ else if ( loadedValues [ 1 ] . Contains ( "\" " ) ) { //if mode is a string, assume it as a macro argument
110
+ string [ ] newLoadedValues = new string [ loadedValues . Length + 1 ] ;
111
+ newLoadedValues [ 0 ] = loadedValues [ 0 ] ;
112
+ newLoadedValues [ 1 ] = "1" ;
113
+ for ( int i = 1 ; i < loadedValues . Length ; i ++ )
114
+ newLoadedValues [ i + 1 ] = loadedValues [ i ] ;
115
+ }
116
+
117
+ int [ ] tempValues = new int [ loadedValues . Length ] ;
118
+ var log = new StringBuilder ( ) ;
119
+ bool error = false ;
120
+ for ( int i = 0 ; i < tempValues . Length ; i ++ ) {
121
+ string value = loadedValues [ i ] . Trim ( ) ;
122
+ if ( ! int . TryParse ( value , out tempValues [ i ] ) ) {
123
+ if ( i < 2 ) {
124
+ noErrors = false ;
125
+ error = true ;
126
+ Error (
127
+ "Error at line {0} -> \" {1}\" , Value must be a full number: \" {2}\" ." , lineId ,
128
+ rawData [ lineId ] , value ) ;
129
+ break ;
130
+ }
131
+
132
+ string [ ] convertValue ;
133
+ if ( ( convertValue = value . Split ( '\' ' ) ) . Length > 1 ) { //'a' -> GetId("a")
134
+ tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ;
135
+ if ( convertValue [ 0 ] . Length > 0 && convertValue [ 0 ] [ 0 ] == '-' ) {
136
+ if ( tempValues [ 1 ] != 1 ) {
137
+ noErrors = false ;
138
+ error = true ;
139
+ Error (
140
+ "Error at line {0} -> \" {1}\" , Negative value not allowed: \" {2}\" ." ,
141
+ lineId ,
142
+ rawData [ lineId ] , value ) ;
143
+ break ;
144
+ }
145
+
146
+ tempValues [ i ] = - tempValues [ i ] ;
147
+ }
148
+ } else if ( ( convertValue = value . Split ( '"' ) ) . Length > 1 ) {
149
+ //"a" -> GetId("a") //"abc" -> GetId("a"), GetId("b"), GetId("c")
150
+
151
+ if ( convertValue . Length > 4 ) {
99
152
noErrors = false ;
100
153
error = true ;
101
154
Error (
102
- "Error at line {0} -> \" {1}\" , Value must be a full number : \" {2}\" ." , lineId ,
103
- rawData [ lineId ] , value ) ;
155
+ "Error at line {0} -> \" {1}\" , Multiple strings not allowed : \" {2}\" ." , lineId ,
156
+ rawData [ lineId ] , value ) ;
104
157
break ;
105
158
}
106
159
107
- string [ ] convertValue ;
108
- if ( ( convertValue = value . Split ( '\' ' ) ) . Length > 1 ) { //'a' -> GetId("a")
109
- tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ;
110
- if ( convertValue [ 0 ] [ convertValue [ 0 ] . Length - 1 ] == '-' ) {
111
- if ( tempValues [ 1 ] != 1 ) {
112
- noErrors = false ;
113
- error = true ;
114
- Error (
115
- "Error at line {0} -> \" {1}\" , Negative value not allowed: \" {2}\" ." ,
116
- lineId ,
117
- rawData [ lineId ] , value ) ;
118
- break ;
119
- }
120
-
121
- tempValues [ i ] = - tempValues [ i ] ;
160
+ if ( tempValues [ 1 ] != 1 ) {
161
+ if ( convertValue [ 0 ] . Length != 0 ) {
162
+ noErrors = false ;
163
+ error = true ;
164
+ Error (
165
+ "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineId ,
166
+ rawData [ lineId ] , convertValue [ 0 ] . Length > 1 ? "s" : "" , convertValue [ 0 ] ) ;
167
+ break ;
122
168
}
123
- } else if ( ( convertValue = value . Split ( '"' ) ) . Length > 1 ) {
124
- //"a" -> GetId("a") //"abc" -> GetId("a"), GetId("b"), GetId("c")
125
169
126
- if ( convertValue . Length > 4 ) {
170
+ if ( convertValue [ 1 ] . Length == 1 ) { tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ; }
171
+ } else {
172
+ if ( convertValue [ 0 ] . Length > 1 || ( convertValue [ 0 ] . Length != 0 &&
173
+ ( convertValue [ 0 ] [ 0 ] != '-' &&
174
+ convertValue [ 0 ] [ 0 ] != '+' ) ) ) {
127
175
noErrors = false ;
128
176
error = true ;
129
177
Error (
130
- "Error at line {0} -> \" {1}\" , Multiple strings not allowed : \" {2 }\" ." , lineId ,
131
- rawData [ lineId ] , value ) ;
178
+ "Error at line {0} -> \" {1}\" , Unexpected character{2} : \" {3 }\" ." , lineId ,
179
+ rawData [ lineId ] , convertValue [ 0 ] . Length > 1 ? "s" : "" , convertValue [ 0 ] ) ;
132
180
break ;
133
181
}
134
182
135
- if ( tempValues [ 1 ] != 1 ) {
136
- if ( convertValue [ 0 ] . Length != 0 ) {
137
- noErrors = false ;
138
- error = true ;
139
- Error (
140
- "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineId ,
141
- rawData [ lineId ] , convertValue [ 0 ] . Length > 1 ? "s" : "" , convertValue [ 0 ] ) ;
142
- break ;
143
- }
144
-
145
- if ( convertValue [ 1 ] . Length == 1 ) { tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ; }
183
+ if ( convertValue [ 0 ] . Length == 1 && convertValue [ 1 ] . Length == 1 ) {
184
+ tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ;
185
+ if ( convertValue [ 0 ] [ 0 ] != '-' )
186
+ tempValues [ i ] = - tempValues [ i ] ;
146
187
} else {
147
- if ( convertValue [ 0 ] . Length > 1 || ( convertValue [ 0 ] . Length != 0 &&
148
- ( convertValue [ 0 ] [ 0 ] != '-' &&
149
- convertValue [ 0 ] [ 0 ] != '+' ) ) ) {
150
- noErrors = false ;
151
- error = true ;
152
- Error (
153
- "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineId ,
154
- rawData [ lineId ] , convertValue [ 0 ] . Length > 1 ? "s" : "" , convertValue [ 0 ] ) ;
155
- break ;
156
- }
188
+ int length = convertValue [ 0 ] . Length == 1
189
+ ? convertValue [ 1 ] . Length - 1
190
+ : convertValue [ 1 ] . Length + convertValue [ 1 ] . Length - 1 ;
157
191
158
- if ( convertValue [ 0 ] . Length == 1 && convertValue [ 1 ] . Length == 1 ) {
159
- tempValues [ i ] = GetId ( convertValue [ 1 ] [ 0 ] ) ;
160
- if ( convertValue [ 0 ] [ 0 ] != '-' )
161
- tempValues [ i ] = - tempValues [ i ] ;
162
- } else {
163
- int length = convertValue [ 0 ] . Length == 1
164
- ? convertValue [ 1 ] . Length - 1
165
- : convertValue [ 1 ] . Length + convertValue [ 1 ] . Length - 1 ;
166
-
167
- //copy old values to new array with a gap for the new values.
168
- int [ ] newTempV = new int [ tempValues . Length + length ] ;
169
- for ( int j = 0 ; j < tempValues . Length ; j ++ ) {
170
- if ( j < i ) { newTempV [ j ] = tempValues [ j ] ; } else if ( j > i ) {
171
- newTempV [ j + length ] = tempValues [ j ] ;
172
- }
192
+ //copy old values to new array with a gap for the new values.
193
+ int [ ] newTempV = new int [ tempValues . Length + length ] ;
194
+ for ( int j = 0 ; j < tempValues . Length ; j ++ ) {
195
+ if ( j < i ) { newTempV [ j ] = tempValues [ j ] ; } else if ( j > i ) {
196
+ newTempV [ j + length ] = tempValues [ j ] ;
173
197
}
198
+ }
174
199
175
- // insert new values
176
- if ( convertValue [ 0 ] . Length == 1 ) {
177
- if ( convertValue [ 0 ] [ 0 ] == '-' )
178
- for ( int j = 0 ; j < convertValue [ 1 ] . Length ; j ++ ) {
179
- newTempV [ j + i ] = - GetId ( convertValue [ 1 ] [ j ] ) ;
180
- }
181
- else
182
- for ( int j = 0 ; j < convertValue [ 1 ] . Length ; j ++ ) {
183
- newTempV [ j + i ] = GetId ( convertValue [ 1 ] [ j ] ) ;
184
- }
185
- } else
200
+ // insert new values
201
+ if ( convertValue [ 0 ] . Length == 1 ) {
202
+ if ( convertValue [ 0 ] [ 0 ] == '-' )
186
203
for ( int j = 0 ; j < convertValue [ 1 ] . Length ; j ++ ) {
187
- newTempV [ j * 2 + i ] = GetId ( convertValue [ 1 ] [ j ] ) ;
188
- newTempV [ j * 2 + i + 1 ] = - GetId ( convertValue [ 1 ] [ j ] ) ;
204
+ newTempV [ j + i ] = - GetId ( convertValue [ 1 ] [ j ] ) ;
189
205
}
206
+ else
207
+ for ( int j = 0 ; j < convertValue [ 1 ] . Length ; j ++ ) {
208
+ newTempV [ j + i ] = GetId ( convertValue [ 1 ] [ j ] ) ;
209
+ }
210
+ } else
211
+ for ( int j = 0 ; j < convertValue [ 1 ] . Length ; j ++ ) {
212
+ newTempV [ j * 2 + i ] = GetId ( convertValue [ 1 ] [ j ] ) ;
213
+ newTempV [ j * 2 + i + 1 ] = - GetId ( convertValue [ 1 ] [ j ] ) ;
214
+ }
190
215
191
- //apply new values
192
- tempValues = newTempV ;
193
- i += length ;
194
- }
195
- }
196
- } else if ( value . Length == 1 ) //a -> GetId("a")
197
- tempValues [ i ] = GetId ( value [ 0 ] ) ;
198
- else { //-a -> -GetId("a")
199
- if ( value . Length == 2 && value [ 0 ] == '-' )
200
- tempValues [ i ] = - GetId ( value [ 1 ] ) ;
201
- else {
202
- noErrors = false ;
203
- error = true ;
204
- Error (
205
- "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineId ,
206
- rawData [ lineId ] , value . Length > 1 ? "s" : "" , value ) ;
207
- break ;
216
+ //apply new values
217
+ tempValues = newTempV ;
218
+ i += length ;
208
219
}
209
220
}
221
+ } else if ( value . Length == 1 ) //a -> GetId("a")
222
+ tempValues [ i ] = GetId ( value [ 0 ] ) ;
223
+ else { //-a -> -GetId("a")
224
+ if ( value . Length == 2 && value [ 0 ] == '-' )
225
+ tempValues [ i ] = - GetId ( value [ 1 ] ) ;
226
+ else {
227
+ noErrors = false ;
228
+ error = true ;
229
+ Error (
230
+ "Error at line {0} -> \" {1}\" , Unexpected character{2}: \" {3}\" ." , lineId ,
231
+ rawData [ lineId ] , value . Length > 1 ? "s" : "" , value ) ;
232
+ break ;
233
+ }
210
234
}
211
-
212
- log . Append ( value ) ;
213
- log . Append ( ' ' ) ;
214
235
}
215
236
216
- if ( ! error )
217
- Program . values . Add ( tempValues ) ;
218
-
219
- log . Append ( "-> " ) ;
220
- foreach ( int item in tempValues ) {
221
- log . Append ( item ) ;
222
- log . Append ( ' ' ) ;
223
- }
237
+ log . Append ( value ) ;
238
+ log . Append ( ' ' ) ;
239
+ }
224
240
241
+ if ( ! error )
242
+ Program . values . Add ( tempValues ) ;
225
243
226
- Console . WriteLine ( log ) ;
244
+ log . Append ( "-> " ) ;
245
+ foreach ( int item in tempValues ) {
246
+ log . Append ( item ) ;
247
+ log . Append ( ' ' ) ;
227
248
}
228
249
250
+
251
+ Console . WriteLine ( log ) ;
252
+ }
253
+
229
254
return noErrors ;
230
255
}
231
256
}
0 commit comments