Skip to content

Commit

Permalink
Nokia: Sound: Return a pause when a sequence uses a reserved note
Browse files Browse the repository at this point in the history
This should actually result in undefined behavior, but since CaveCab
does this and has midi playback hampered by this, simply return a
pause and keep parsing the tone as if nothing happened.

Warn about it though.
  • Loading branch information
AShiningRay committed Dec 2, 2024
1 parent 6eb05b8 commit 8fed7eb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/com/nokia/mid/sound/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public static byte[] convertToMidi(byte[] data) throws MidiUnavailableException,
{
parsePos = 0; // Reset the parsePos counter
noteScale = 1f; // Reset scale as well
noteStyle = NATURAL_STYLE; // Reset note style too
curTick = 0; // Also move curTick to the beginning
toneBitArray = new boolean[data.length * 8];

Expand Down Expand Up @@ -429,7 +430,7 @@ else if (noteStyle == CONTINUOUS_STYLE) // Try to add a small overlap between no

curTick += ticks;
}
catch (InvalidMidiDataException e) { Mobile.log(Mobile.LOG_ERROR, Sound.class.getPackage().getName() + "." + Sound.class.getSimpleName() + ": " + "Couldn't parse note instruction" + e.getMessage()); }
catch (InvalidMidiDataException e) { Mobile.log(Mobile.LOG_ERROR, Sound.class.getPackage().getName() + "." + Sound.class.getSimpleName() + ": " + "Couldn't parse note instruction:" + e.getMessage()); }
}

private static void parseScaleInstruction()
Expand Down Expand Up @@ -631,7 +632,9 @@ private static int convertNoteValueToMidi(int noteValue)
case 0b1010: baseFrequency = 880; break;// A1
case 0b1011: baseFrequency = 932; break;// A#1
case 0b1100: baseFrequency = 988; break;// B(or H)1
default: return -1; // Invalid note, shall make the midi fail
default:
Mobile.log(Mobile.LOG_WARNING, Sound.class.getPackage().getName() + "." + Sound.class.getSimpleName() + ": " + "Parsed Note: " + noteStrings[noteValue] + ". Returning a pause instead.");
return 0; // Invalid note, but CaveCab tries to add notes with reserved values. Let's just return a pause instead of causing issues for midi playback.
}

/*
Expand Down

0 comments on commit 8fed7eb

Please sign in to comment.