@@ -51,23 +51,21 @@ void readFromSD() {
51
51
}
52
52
53
53
void readSongParameters () {
54
- for (byte i = 0 ; i < 2 ; i++) {
55
- String line = " " ;
56
- while (textFile.available ()) {
57
- char c = textFile.read ();
58
- if (c == ' \n ' )
59
- break ;
60
- line.concat (c);
61
- }
62
- if (i == 0 )
63
- songLines = line.toInt ();
64
- else
65
- noteLength = floor ((double )1000 * (double )60 / (double )line.toInt ());
54
+ String line = " " ;
55
+ while (textFile.available ()) {;
56
+ char c = textFile.read ();
57
+ if (c == ' \n ' )
58
+ break ;
59
+ line.concat (c);
66
60
}
61
+ noteLength = floor ((double )1000 * (double )60 / (double )line.toInt ());
62
+
63
+ inferLineSize ();
64
+ inferLineCount ();
67
65
}
68
66
69
- void initializeArray (){
70
- int file_pos = textFile.position ();
67
+ void inferLineSize (){
68
+ unsigned long file_pos = textFile.position ();
71
69
String token = " " ;
72
70
while (textFile.available ()) {
73
71
char c = textFile.read ();
@@ -80,9 +78,20 @@ void initializeArray(){
80
78
else if (c != ' ' )
81
79
token.concat (c);
82
80
}
83
- songLength += 1 ;
84
- textFile. seek (file_pos);
81
+ textFile. seek (file_pos - 1 ) ;
82
+ }
85
83
84
+ void inferLineCount (){
85
+ unsigned long file_pos = textFile.position ();
86
+ while (textFile.available ()) {
87
+ char c = textFile.read ();
88
+ if (c == ' \n ' )
89
+ songLines++;
90
+ }
91
+ textFile.seek (file_pos+1 );
92
+ }
93
+
94
+ void initializeArray (){
86
95
score = new byte*[songLines];
87
96
for (byte i = 0 ; i < songLines; i++)
88
97
score[i] = new byte[songLength];
@@ -92,7 +101,6 @@ void readSong() {
92
101
byte pos = 0 ;
93
102
String token = " " ;
94
103
byte melodicLine = 0 ;
95
-
96
104
while (textFile.available ()) {
97
105
char c = textFile.read ();
98
106
if (c == ' \n ' ) {
0 commit comments