Skip to content

Commit c9654e4

Browse files
committed
Added note info integrity check
1 parent 38bba1c commit c9654e4

File tree

5 files changed

+195
-29
lines changed

5 files changed

+195
-29
lines changed

Dynamix_chart_width_control/chart_store.cpp

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ void chart_store::parse_elem() {
327327
tempnote->notetype = SUB;
328328
}
329329
else {
330-
char errnote[64];
330+
char errnote[64],lln[64];
331331
sprintf_s(errnote, "%d", tempnote->id);
332-
throw std::logic_error("Read notes error: Invalid note type at note #" + string(errnote));
332+
sprintf_s(lln, "%d.", lines);
333+
throw std::logic_error("Read notes error: Invalid note type at note #" + string(errnote)+".\n Please check line "+string(lln));
333334

334335
}
335336
}
@@ -386,14 +387,15 @@ void chart_store::parse_elem() {
386387
}
387388
else if (t_buf[buf_index] == '<') {
388389
if (t_buf[buf_index + 1] == '/') {
389-
//xml tag end:</...>
390+
//xml tag close:</...>
390391

391392
//scan
392393

393394
int buf_scan = buf_index + 2;//scan after "</"
394395
int pos_scan = buf_scan;
396+
int end_tag_line = lines;//the position of tag close
395397

396-
//scan for end tag
398+
//scan for tag close
397399
if (isalpha(t_buf[buf_scan]) || t_buf[buf_scan] == '_') {
398400
buf_scan++;
399401
while (isalnum(t_buf[buf_scan]) || t_buf[buf_scan] == '_' ||
@@ -421,7 +423,7 @@ void chart_store::parse_elem() {
421423
if (t_buf[buf_index] != '>') {
422424
//get error position
423425
char lln[64];
424-
sprintf_s(lln, "%d.", lines);
426+
sprintf_s(lln, "%d.", end_tag_line);
425427

426428
throw std::logic_error("expected \'>\' at line " + string(lln));
427429
return;
@@ -462,19 +464,92 @@ void chart_store::parse_elem() {
462464
}
463465
else if (tag == "CMapNoteAsset") {//end of a note
464466
if (note_reading) {
465-
int temp_id;//note id(temporary)
467+
char lln[64],id_string[64];
468+
int temp_id = tempnote->id;//note id(temporary)
469+
//checking note info integrity
470+
//id
471+
if (temp_id == -1) {
472+
473+
sprintf_s(lln, "%d", tag_line);
474+
475+
throw std::logic_error("Error: Note without id.\nThe note begins at line " + string(lln) + " in the XML.");
476+
}
477+
else {
478+
//note type
479+
if (tempnote->notetype == types::NULLTP) {
480+
sprintf_s(lln, "%d", tag_line);
481+
sprintf_s(id_string, "%d", temp_id);
482+
throw std::logic_error("Error: Note #"+string(id_string)+" type not specified.\nThe note begins at line " + string(lln) + " in the XML.");
483+
}
484+
//note position
485+
if (tempnote->position < -1e7) {
486+
sprintf_s(lln, "%d", tag_line);
487+
sprintf_s(id_string, "%d", temp_id);
488+
489+
throw std::logic_error("Error: Note #" + string(id_string) + " position not specified.\nThe note begins at line " + string(lln) + " in the XML.");
490+
}
491+
//note width
492+
if (tempnote->width < -1e7) {
493+
sprintf_s(lln, "%d", tag_line);
494+
sprintf_s(id_string, "%d", temp_id);
495+
496+
throw std::logic_error("Error: Note #" + string(id_string) + " width not specified.\nThe note begins at line " + string(lln) + " in the XML.");
497+
}
498+
//note time
499+
if (tempnote->time < -1e7) {
500+
sprintf_s(lln, "%d", tag_line);
501+
sprintf_s(id_string, "%d", temp_id);
502+
503+
throw std::logic_error("Error: Note #" + string(id_string) + " time not specified.\nThe note begins at line " + string(lln) + " in the XML.");
504+
}
505+
//sub id
506+
if (tempnote->subid == INT_MIN) {
507+
sprintf_s(lln, "%d", tag_line);
508+
sprintf_s(id_string, "%d", temp_id);
509+
510+
throw std::logic_error("Error: Note #" + string(id_string) + " subId not specified.\nThe note begins at line " + string(lln) + " in the XML.");
511+
}
512+
}
513+
//note info is complete
466514
switch (modes) {
467515
case 1:
468-
temp_id = tempnote->id;
469-
m_notes.insert(make_pair(temp_id, *tempnote));
516+
//scan for duplicated note id
517+
if (m_notes.find(temp_id) == m_notes.end()) {
518+
m_notes.insert(make_pair(temp_id, *tempnote));
519+
}
520+
//duplicated
521+
else {
522+
sprintf_s(lln, "%d", tag_line);
523+
sprintf_s(id_string, "%d", temp_id);
524+
525+
throw std::logic_error("Error: Duplicated note id: "+string(id_string)+".\nThe note begins at line " + string(lln) + " in the XML.");
526+
}
470527
break;
471528
case 2:
472-
temp_id = tempnote->id;
473-
m_left.insert(make_pair(temp_id, *tempnote));
529+
//scan for duplicated note id
530+
if (m_left.find(temp_id) == m_left.end()) {
531+
m_left.insert(make_pair(temp_id, *tempnote));
532+
}
533+
//duplicated
534+
else {
535+
sprintf_s(lln, "%d", tag_line);
536+
sprintf_s(id_string, "%d", temp_id);
537+
538+
throw std::logic_error("Error: Duplicated note id: " + string(id_string) + ".\nThe note begins at line " + string(lln) + " in the XML.");
539+
}
474540
break;
475541
case 3:
476-
temp_id = tempnote->id;
477-
m_right.insert(make_pair(temp_id, *tempnote));
542+
//scan for duplicated note id
543+
if (m_right.find(temp_id) == m_right.end()) {
544+
m_right.insert(make_pair(temp_id, *tempnote));
545+
}
546+
//duplicated
547+
else {
548+
sprintf_s(lln, "%d", tag_line);
549+
sprintf_s(id_string, "%d", temp_id);
550+
551+
throw std::logic_error("Error: Duplicated note id: " + string(id_string) + ".\nThe note begins at line " + string(lln) + " in the XML.");
552+
}
478553
break;
479554
default:
480555
delete tempnote;

Dynamix_chart_width_control/chart_store.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
#include<vector>
88
#include<string>
99
#include<sstream>
10+
#include<climits>
1011
#include<map>
1112

1213
using std::vector;
1314
using std::string;
1415
using std::ofstream;
1516
using std::pair;
1617
using std::map;
17-
18-
enum types { NORMAL = 1, CHAIN, HOLD, SUB };
18+
//added default note type: NULLTP
19+
enum types { NORMAL = 1, CHAIN, HOLD, SUB , NULLTP};
1920
//added default sides type: UNKNOWN
2021
enum sides { PAD, MIXER, MULTI, UNKNOWN };
2122
struct note {
@@ -25,6 +26,13 @@ struct note {
2526
double position;
2627
double width;
2728
int subid;
29+
//constructor
30+
note() :id(-1),
31+
notetype(types::NULLTP),
32+
time(-1e8),
33+
position(-1e8),
34+
width(-1e8),
35+
subid(INT_MIN) {}
2836
};
2937
class chart_store
3038
{

Dynamix_chart_width_control_GUI/chart_store.cpp

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ void chart_store::parse_elem() {
327327
tempnote->notetype = SUB;
328328
}
329329
else {
330-
char errnote[64];
330+
char errnote[64],lln[64];
331331
sprintf_s(errnote, "%d", tempnote->id);
332-
throw std::logic_error("Read notes error: Invalid note type at note #" + string(errnote));
332+
sprintf_s(lln, "%d.", lines);
333+
throw std::logic_error("Read notes error: Invalid note type at note #" + string(errnote)+".\n Please check line "+string(lln));
333334

334335
}
335336
}
@@ -386,14 +387,15 @@ void chart_store::parse_elem() {
386387
}
387388
else if (t_buf[buf_index] == '<') {
388389
if (t_buf[buf_index + 1] == '/') {
389-
//xml tag end:</...>
390+
//xml tag close:</...>
390391

391392
//scan
392393

393394
int buf_scan = buf_index + 2;//scan after "</"
394395
int pos_scan = buf_scan;
396+
int end_tag_line = lines;//the position of tag close
395397

396-
//scan for end tag
398+
//scan for tag close
397399
if (isalpha(t_buf[buf_scan]) || t_buf[buf_scan] == '_') {
398400
buf_scan++;
399401
while (isalnum(t_buf[buf_scan]) || t_buf[buf_scan] == '_' ||
@@ -421,7 +423,7 @@ void chart_store::parse_elem() {
421423
if (t_buf[buf_index] != '>') {
422424
//get error position
423425
char lln[64];
424-
sprintf_s(lln, "%d.", lines);
426+
sprintf_s(lln, "%d.", end_tag_line);
425427

426428
throw std::logic_error("expected \'>\' at line " + string(lln));
427429
return;
@@ -462,19 +464,92 @@ void chart_store::parse_elem() {
462464
}
463465
else if (tag == "CMapNoteAsset") {//end of a note
464466
if (note_reading) {
465-
int temp_id;//note id(temporary)
467+
char lln[64],id_string[64];
468+
int temp_id = tempnote->id;//note id(temporary)
469+
//checking note info integrity
470+
//id
471+
if (temp_id == -1) {
472+
473+
sprintf_s(lln, "%d", tag_line);
474+
475+
throw std::logic_error("Error: Note without id.\nThe note begins at line " + string(lln) + " in the XML.");
476+
}
477+
else {
478+
//note type
479+
if (tempnote->notetype == types::NULLTP) {
480+
sprintf_s(lln, "%d", tag_line);
481+
sprintf_s(id_string, "%d", temp_id);
482+
throw std::logic_error("Error: Note #"+string(id_string)+" type not specified.\nThe note begins at line " + string(lln) + " in the XML.");
483+
}
484+
//note position
485+
if (tempnote->position < -1e7) {
486+
sprintf_s(lln, "%d", tag_line);
487+
sprintf_s(id_string, "%d", temp_id);
488+
489+
throw std::logic_error("Error: Note #" + string(id_string) + " position not specified.\nThe note begins at line " + string(lln) + " in the XML.");
490+
}
491+
//note width
492+
if (tempnote->width < -1e7) {
493+
sprintf_s(lln, "%d", tag_line);
494+
sprintf_s(id_string, "%d", temp_id);
495+
496+
throw std::logic_error("Error: Note #" + string(id_string) + " width not specified.\nThe note begins at line " + string(lln) + " in the XML.");
497+
}
498+
//note time
499+
if (tempnote->time < -1e7) {
500+
sprintf_s(lln, "%d", tag_line);
501+
sprintf_s(id_string, "%d", temp_id);
502+
503+
throw std::logic_error("Error: Note #" + string(id_string) + " time not specified.\nThe note begins at line " + string(lln) + " in the XML.");
504+
}
505+
//sub id
506+
if (tempnote->subid == INT_MIN) {
507+
sprintf_s(lln, "%d", tag_line);
508+
sprintf_s(id_string, "%d", temp_id);
509+
510+
throw std::logic_error("Error: Note #" + string(id_string) + " subId not specified.\nThe note begins at line " + string(lln) + " in the XML.");
511+
}
512+
}
513+
//note info is complete
466514
switch (modes) {
467515
case 1:
468-
temp_id = tempnote->id;
469-
m_notes.insert(make_pair(temp_id, *tempnote));
516+
//scan for duplicated note id
517+
if (m_notes.find(temp_id) == m_notes.end()) {
518+
m_notes.insert(make_pair(temp_id, *tempnote));
519+
}
520+
//duplicated
521+
else {
522+
sprintf_s(lln, "%d", tag_line);
523+
sprintf_s(id_string, "%d", temp_id);
524+
525+
throw std::logic_error("Error: Duplicated note id: "+string(id_string)+".\nThe note begins at line " + string(lln) + " in the XML.");
526+
}
470527
break;
471528
case 2:
472-
temp_id = tempnote->id;
473-
m_left.insert(make_pair(temp_id, *tempnote));
529+
//scan for duplicated note id
530+
if (m_left.find(temp_id) == m_left.end()) {
531+
m_left.insert(make_pair(temp_id, *tempnote));
532+
}
533+
//duplicated
534+
else {
535+
sprintf_s(lln, "%d", tag_line);
536+
sprintf_s(id_string, "%d", temp_id);
537+
538+
throw std::logic_error("Error: Duplicated note id: " + string(id_string) + ".\nThe note begins at line " + string(lln) + " in the XML.");
539+
}
474540
break;
475541
case 3:
476-
temp_id = tempnote->id;
477-
m_right.insert(make_pair(temp_id, *tempnote));
542+
//scan for duplicated note id
543+
if (m_right.find(temp_id) == m_right.end()) {
544+
m_right.insert(make_pair(temp_id, *tempnote));
545+
}
546+
//duplicated
547+
else {
548+
sprintf_s(lln, "%d", tag_line);
549+
sprintf_s(id_string, "%d", temp_id);
550+
551+
throw std::logic_error("Error: Duplicated note id: " + string(id_string) + ".\nThe note begins at line " + string(lln) + " in the XML.");
552+
}
478553
break;
479554
default:
480555
delete tempnote;

Dynamix_chart_width_control_GUI/chart_store.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
#include<vector>
88
#include<string>
99
#include<sstream>
10+
#include<climits>
1011
#include<map>
1112

1213
using std::vector;
1314
using std::string;
1415
using std::ofstream;
1516
using std::pair;
1617
using std::map;
17-
18-
enum types { NORMAL = 1, CHAIN, HOLD, SUB };
18+
//added default note type: NULLTP
19+
enum types { NORMAL = 1, CHAIN, HOLD, SUB , NULLTP};
1920
//added default sides type: UNKNOWN
2021
enum sides { PAD, MIXER, MULTI, UNKNOWN };
2122
struct note {
@@ -25,6 +26,13 @@ struct note {
2526
double position;
2627
double width;
2728
int subid;
29+
//constructor
30+
note() :id(-1),
31+
notetype(types::NULLTP),
32+
time(-1e8),
33+
position(-1e8),
34+
width(-1e8),
35+
subid(INT_MIN) {}
2836
};
2937
class chart_store
3038
{

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
* The header that specifies the program version.
44
*
55
* */
6-
#define VERSION_H "v1.1.28"
6+
#define VERSION_H "v1.1.30"
77

88
#endif

0 commit comments

Comments
 (0)