Skip to content

Commit

Permalink
fixed Note parsing when statements other than i- or comments are foun…
Browse files Browse the repository at this point in the history
…d (was duplicating notes) [fixes #345]
  • Loading branch information
kunstmusik committed May 4, 2017
1 parent 8b54d24 commit 6102594
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ FIX
* Fixed Code Repository Dialog to ensure it is in sync with repository changes.
Also fixed drag/drop when editing repository within dialog.

* Issue #345 - Parsing output from nGen revealed issue with parsing score
statements that were not i- or comments (notes would repeat)

INTERNAL

* Replaced use of Cloneable and Serializable with copy constructors and new
Expand Down
2 changes: 1 addition & 1 deletion blue-core/src/blue/utility/ScoreUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum ParseState {
public static NoteList getNotes(String in) throws NoteParseException {
NoteList notes = new NoteList();
Note previousNote = null;
Note tempNote = null;
int start = -1, end = -1, lineNumber = 1, len, lastIndex;
ParseState state = ParseState.STARTING;

Expand Down Expand Up @@ -153,6 +152,7 @@ public static NoteList getNotes(String in) throws NoteParseException {
String noteText = TextUtilities.stripMultiLineComments(
in.substring(start, end + 1));

Note tempNote = null;
try {
if (noteText.charAt(0) == 'i') {
tempNote = Note.createNote(noteText,
Expand Down
46 changes: 37 additions & 9 deletions blue-core/test/unit/src/blue/utility/ScoreUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public void testGetNotes() {
testScore.append("i1 0 2 3 4 5 ;garbage\n");
testScore.append("i1 + 2 3 4 5\n");

for(int i = 0; i < 200000; i++) {
for (int i = 0; i < 200000; i++) {
testScore.append("i1 + 2 3 4 5 6 7 8 [ 1.34 + 34 ] \n");
}

NoteList nl = null;

// System.out.println(testScore.toString());
Expand Down Expand Up @@ -83,7 +83,7 @@ public void testCommentAtEnd() {
String testScore = "i1 0 2 3 4 5 ; comment";

String testScore2 = "i1 0 2 3 4 5 /* comment \n test test */i";

NoteList nl = null;

try {
Expand All @@ -95,7 +95,7 @@ public void testCommentAtEnd() {
assertNotNull(nl);
assertEquals(1, nl.size());
assertEquals(6, nl.get(0).getPCount());
assertEquals("5", nl.get(0).getPField(6));
assertEquals("5", nl.get(0).getPField(6));

try {
nl = ScoreUtilities.getNotes(testScore2);
Expand All @@ -106,16 +106,15 @@ public void testCommentAtEnd() {
assertNotNull(nl);
assertEquals(1, nl.size());
assertEquals(6, nl.get(0).getPCount());
assertEquals("5", nl.get(0).getPField(6));
assertEquals("5", nl.get(0).getPField(6));
}

public void testScoreCarry() {

String testScore = "i1 0 2 3 4 5\n"
+ "i1.1 0 .\n"
+ "i1 0 .";

String testScore = "i1 0 2 3 4 5\n" +
"i1.1 0 .\n" +
"i1 0 .";

NoteList nl = null;

try {
Expand All @@ -130,4 +129,33 @@ public void testScoreCarry() {
assertEquals(6, nl.get(2).getPCount());

}

public void testNGenScore() {
String testScore = ";I-block #1 (i1):\n"
+ "i1 0.000 0.010 0.000 100.000\n"
+ "i1 0.010 0.010 0.111 100.000\n"
+ "i1 0.020 0.010 0.222 100.000\n"
+ "i1 0.030 0.010 0.333 100.000\n"
+ "i1 0.040 0.010 0.444 100.000\n"
+ "i1 0.050 0.010 0.556 100.000\n"
+ "i1 0.060 0.010 0.667 100.000\n"
+ "i1 0.070 0.010 0.778 100.000\n"
+ "i1 0.080 0.010 0.889 100.000\n"
+ "i1 0.090 0.010 1.000 100.000\n"
+ "\n"
+ "e\n";


NoteList nl = null;

try {
nl = ScoreUtilities.getNotes(testScore);
} catch (NoteParseException ex) {
ex.printStackTrace();
}

assertNotNull(nl);
assertEquals(10, nl.size());
assertEquals(5, nl.get(0).getPCount());
}
}

0 comments on commit 6102594

Please sign in to comment.