Skip to content

Commit

Permalink
Fix Issue #135 Regression 2.2: assertion error when opening a song fi…
Browse files Browse the repository at this point in the history
…le with a rhythm not available
  • Loading branch information
Jerome Lelasseux committed Sep 6, 2020
1 parent 96a7d68 commit 99bd513
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions MidiMix/src/org/jjazz/midimix/MidiMix.java
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,10 @@ public RvStorage(RhythmVoice rv)
this.rvName = rv.getName();
}

/**
*
* @return Can be null
*/
public RhythmVoice rebuildRhythmVoice()
{
if (rhythmId.equals(SP_USER_CHANNEL_RHYTHM_ID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,32 +303,48 @@ public Rhythm getRhythmInstance(String rId) throws UnavailableRhythmException
{
String rpId = strs[0];
String rIdOriginal = strs[1];
TimeSignature newTs;
TimeSignature newTs = null;

// Parse time signature and try to get a cached instance of the AdaptedRhythm
try
{
newTs = TimeSignature.parse(strs[2]);
newTs = TimeSignature.parse(strs[2]); // Possible ParseException
r = mapAdaptedRhythms.get(getAdaptedRhythmKey(r, newTs)); // Can be null if first time request
} catch (ParseException ex)
{
LOGGER.warning("getRhythm() Invalid time signature in AdaptedRhythm rId=" + rId);
return null;
LOGGER.warning("getRhythmInstance() Invalid time signature in AdaptedRhythm rId=" + rId);
}
RhythmProvider rp = getRhythmProviders().stream().filter(rhp -> rhp.getInfo().getUniqueId().equals(rpId)).findAny().orElse(null);
if (rp == null)


// Create the AdaptedRhythm if possible
if (r == null && newTs != null)
{
LOGGER.warning("getRhythm() Unknown rhythm provider id in AdaptedRhythm rId=" + rId);
return null;
Rhythm rOriginal = getRhythmInstance(rIdOriginal); // Possible exception here
RhythmProvider rp = getRhythmProviders().stream().filter(rhp -> rhp.getInfo().getUniqueId().equals(rpId)).findAny().orElse(null);
if (rp == null)
{
LOGGER.warning("getRhythmInstance() Unknown rhythm provider id in AdaptedRhythm rId=" + rId);
} else
{
r = rp.getAdaptedRhythm(rOriginal, newTs); // Can be null!
}
}
Rhythm rOriginal = getRhythmInstance(rIdOriginal); // Possible exception here
r = getAdaptedRhythmInstance(rOriginal, newTs); // Can be null
}
} else
{
RhythmInfo ri = getRhythm(rId);
RhythmInfo ri = getRhythm(rId); // Can be null
if (ri != null)
{
r = getRhythmInstance(ri);
r = getRhythmInstance(ri); // Possible UnavailableRhythmException here
}
}


if (r == null)
{
throw new UnavailableRhythmException("No rhythm found for id=" + rId);
}

return r;
}

Expand Down

0 comments on commit 99bd513

Please sign in to comment.