@@ -231,8 +231,109 @@ int main(int argc, char* argv[])
231231 chart_store cs;// store the chart
232232 try {
233233 int fail_read = cs.readfile (filename);// open file
234+ // fixing stage
235+ // missing barpm
236+ if (fail_read & BARPM_MISSING) {
237+ double new_barpm = 0 ;
238+ string ll;
239+ istringstream istr;
240+ cout << " Illegal Barpm! Please enter a valid Barpm:" << endl;;
241+ getline (cin, ll);
242+ istr.str (ll);
243+ istr >> new_barpm;
234244
235- if (fail_read != 1 ) {
245+ while (new_barpm <= 0 ) {
246+ cout << " Illegal Barpm! Please re-enter a valid Barpm:" << endl;
247+ getline (cin, ll);
248+ istr.clear ();
249+ istr.str (ll);
250+ istr >> new_barpm;
251+ }
252+ char new_barpm_string[64 ];
253+ sprintf_s (new_barpm_string, " %f" , new_barpm);
254+ cs.set_barpm (new_barpm);
255+ cout << " Barpm is set to " + string (new_barpm_string) + " ." << endl;
256+ cout << " ===============================" << endl;
257+
258+ fail_read &= (~(int )BARPM_MISSING);
259+ }
260+ // missing left side
261+ if (fail_read & LEFT_SIDE_MISSING) {
262+ sides s = sides::UNKNOWN;
263+ string side_string;
264+ cout << " Left side type is not specified! Please enter a valid side type:" << endl;
265+ while (s == sides::UNKNOWN) {
266+ cin >> side_string;
267+ // lowercase
268+ transform (side_string.begin (), side_string.end (), side_string.begin (), tolower);
269+ if (side_string == " pad" ) {
270+ s = sides::PAD;
271+ }
272+ else if (side_string == " mixer" ) {
273+ s = sides::MIXER;
274+ }
275+ else if (side_string == " multi" ) {
276+ s = sides::MULTI;
277+ }
278+ else {
279+ cout << " Invalid side type! Please enter again!" << endl;
280+ }
281+ }
282+ cs.set_lside (s);
283+ cout << " Left side fixed." << endl;
284+ cout << " ===============================" << endl;
285+ fail_read &= (~(int )LEFT_SIDE_MISSING);
286+ }
287+ // missing right side
288+ if (fail_read & RIGHT_SIDE_MISSING) {
289+ sides s = sides::UNKNOWN;
290+ string side_string;
291+ cout << " Right side type is not specified! Please enter a valid side type:" << endl;
292+ while (s == sides::UNKNOWN) {
293+ cin >> side_string;
294+ // lowercase
295+ transform (side_string.begin (), side_string.end (), side_string.begin (), tolower);
296+ if (side_string == " pad" ) {
297+ s = sides::PAD;
298+ }
299+ else if (side_string == " mixer" ) {
300+ s = sides::MIXER;
301+ }
302+ else if (side_string == " multi" ) {
303+ s = sides::MULTI;
304+ }
305+ else {
306+ cout << " Invalid side type! Please enter again!" << endl;
307+ }
308+ }
309+ cs.set_rside (s);
310+ cout << " Right side fixed." << endl;
311+ cout << " ===============================" << endl;
312+ fail_read &= (~(int )RIGHT_SIDE_MISSING);
313+ }
314+ // Hold-sub mismatch autofix
315+ if (fail_read & HOLD_SUB_MISMATCH) {
316+ cout << " mismatched notes found:" << endl;
317+ for (auto & ii : cs.mismatched_notes ) {
318+ cout << ii.first << ' \t ' << ii.second << endl;
319+ // fix
320+ if (ii.second == " middle" ) {
321+ cs.m_notes .erase (ii.first );
322+ }
323+ else if (ii.second == " left" ) {
324+ cs.m_left .erase (ii.first );
325+ }
326+ else if (ii.second == " right" ) {
327+ cs.m_right .erase (ii.first );
328+ }
329+ }
330+ cout << " \n The mismatching Holds and Subs have been fixed automatically." << endl;
331+ cout << " ===============================" << endl;
332+ // set status to success
333+ fail_read &= (~(int )HOLD_SUB_MISMATCH);
334+ }
335+
336+ if (fail_read == 0 ) {
236337
237338 // this function now only processes chart store class
238339 int success = width_change (cs, width, start_time, end_time, side_mask, random_trigger);// width=1 as default width multiplier
@@ -290,6 +391,9 @@ int main(int argc, char* argv[])
290391 }
291392 }
292393 }
394+ else {
395+ cout << " Unknown error" << endl;
396+ }
293397 }
294398 catch (exception& ex) {
295399 cout << ex.what () << endl;
0 commit comments