Skip to content

Commit

Permalink
Improved debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaldispuehl committed Nov 16, 2017
1 parent f828f6f commit 7add329
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private byte[] getPlaylistItemDataFrom(Playlist playlist, PlaylistItem playlistI
}

for (SoundEffectOccurrence effect : playlistItem.getSoundEffects()) {
addDebugMessage("Adding sound effect " + effect.getSoundEffect().getId() + " at " + (timeSoFarMs + effect.getTimeMillis()) + " ms");
addDebugMessage("Adding sound effect " + effect.getSoundEffect() + " at " + (timeSoFarMs + effect.getTimeMillis()) + " ms");
addSoundEffectTo(playlistItemData, effect);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,35 +260,21 @@ private PlaylistItemFragment createPlaylistItem(IAudioFile audioFile, Long start
return new PlaylistItemFragment(audioFile, startInMilliseconds, endInMilliseconds);
}

long getTotalLength(List<PlaylistItem> playlistItems) {
long result = 0L;
for (PlaylistItem playlistItem : playlistItems) {
PlaylistItemFragment musicFragment = playlistItem.getMusicFragment();

result += musicFragment.getExtractDurationInMilliseconds();

if (isCrossFadingMode()) {
// Removing 1/2 of the blend time due to overlapping between the tracks.
result -= (blendTime * 500);
}
long getTotalLength(Playlist playlist, List<PlaylistItem> playlistItems) {
long resultMs = 0L;

PlaylistItemFragment breakFragment = playlistItem.getBreakFragment();
if (breakFragment != null) {
result += breakFragment.getExtractDurationInMilliseconds();

if (isCrossFadingMode()) {
// Removing 1/2 of the blend time due to overlapping between the tracks.
result -= (blendTime * 500);
}
}
long blendTimeMs = playlist.getBlendTimeMs();
boolean isCrossFadingMode = playlist.isCrossFadingMode();

for (PlaylistItem playlistItem : playlistItems) {
resultMs += playlistItem.getStrictItemLengthMs();
}

if (isCrossFadingMode()) {
result += (blendTime * 1000);
if (isCrossFadingMode) {
resultMs += blendTimeMs;
}

return result;
return resultMs;
}

public boolean isCrossFadingMode() {
Expand All @@ -308,7 +294,7 @@ private boolean isShuffleMode() {
}

private long getTotalLength() {
return getTotalLength(playlistItems);
return getTotalLength(this, playlistItems);
}

public int getTotalLengthInSeconds() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ch.retorte.intervalmusiccompositor.playlist;

import ch.retorte.intervalmusiccompositor.soundeffect.SoundEffectOccurrence;
import com.google.common.collect.Lists;

import java.util.List;

Expand Down Expand Up @@ -61,14 +60,37 @@ public List<SoundEffectOccurrence> getSoundEffects() {
* Returns the length of the single segment, that is, the length without overlapping parts.
*/
public long getStrictItemLengthMs() {
long musicLengthMs = getMusicFragment().getExtractDurationInMilliseconds();
long breakLengthMs = hasBreakFragment() ? getBreakFragment().getExtractDurationInMilliseconds() : 0;

if (playlist.isCrossFadingMode()) {
return musicLengthMs - playlist.getBlendTimeMs() + breakLengthMs - (hasBreakFragment() ? playlist.getBlendTimeMs() : 0);
}
else {
return musicLengthMs + breakLengthMs;
}
return getStrictMusicLengthMs() + getStrictBreakLengthMs();
}

public long getMusicLengthMs() {
return getMusicFragment().getExtractDurationInMilliseconds();
}

public long getStrictMusicLengthMs() {
if (playlist.isCrossFadingMode()) {
return getMusicLengthMs() - playlist.getBlendTimeMs();
}
else {
return getMusicLengthMs();
}
}

public long getBreakLengthMs() {
if (hasBreakFragment()) {
return getBreakFragment().getExtractDurationInMilliseconds();
}
else {
return 0L;
}
}

public long getStrictBreakLengthMs() {
if (hasBreakFragment() && playlist.isCrossFadingMode()) {
return getBreakLengthMs() - playlist.getBlendTimeMs();
}
else {
return getBreakLengthMs();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void shouldGenerateTracksOfRightLength() {
// then
Assert.assertThat(tracks.size(), CoreMatchers.is(2));
assertTrackLength(tracks, 5, 10);
assertTotalLength(tracks, 15);
assertTotalLength(playlist, tracks, 15);
}

@Test
Expand All @@ -124,7 +124,7 @@ public void shouldGenerateBreaksOfRightLength() {
// then
assertThat(tracks.size(), is(2));
assertTrackLength(tracks, 5, 2, 10, 2);
assertTotalLength(tracks, 19);
assertTotalLength(playlist, tracks, 19);
}

@Test
Expand All @@ -143,7 +143,7 @@ public void shouldIgnoreSurplusBreakPatterns() {
// then
assertThat(tracks.size(), is(6));
assertTrackLength(tracks, 9, 1, 7, 2, 9, 1, 7, 2, 9, 1, 7, 2);
assertTotalLength(tracks, 57);
assertTotalLength(playlist, tracks, 57);
}

@Test
Expand All @@ -163,7 +163,7 @@ public void shouldPutTracksInOrder() {

// then
assertThat(tracks.size(), is(6));
assertTotalLength(tracks, 30);
assertTotalLength(playlist, tracks, 30);
assertTrackLength(tracks, 2, 1, 4, 1, 6, 1, 2, 1, 4, 1, 6, 1);
assertThat(tracks.get(0).getMusicFragment().getAudioFile(), is(musicTrack20s));
assertThat(tracks.get(1).getMusicFragment().getAudioFile(), is(musicTrack40s));
Expand All @@ -187,7 +187,7 @@ public void shouldIncreaseExtractLengthOnCrossFadeByTransitionDuration() {

// then
assertThat(tracks.size(), is(3));
assertTotalLength(tracks, 43);
assertTotalLength(playlist, tracks, 33);
assertTrackLength(tracks, 4, 5, 9, 5, 15, 5);
}

Expand Down Expand Up @@ -219,6 +219,7 @@ public void shouldUseExtractFromInsideTheBoundaries() {
// then
assertThat(tracks.size(), is(1));
assertTrackLength(tracks, 25);
assertTotalLength(playlist, tracks, 25);
assertTrue(sec(10) <= tracks.get(0).getMusicFragment().getExtractStartInMilliseconds());
assertTrue(tracks.get(0).getMusicFragment().getExtractEndInMilliseconds() <= musicTrack60s.getDuration() - sec(10));
}
Expand All @@ -242,6 +243,7 @@ public void shouldSkipTooShortTracksButNeverthelessCompletelyFillPattern() {
// then
assertThat(tracks.size(), is(3));
assertTrackLength(tracks, 11, 1, 11, 1, 11, 1);
assertTotalLength(playlist, tracks, 36);
assertThat(tracks.get(0).getMusicFragment().getAudioFile(), is(musicTrack60s));
assertThat(tracks.get(1).getMusicFragment().getAudioFile(), is(musicTrack40s));
assertThat(tracks.get(2).getMusicFragment().getAudioFile(), is(musicTrack60s));
Expand All @@ -266,6 +268,7 @@ public void shouldTakeTheSameTrackInContinuousMode() {
// then
assertThat(tracks.size(), is(10));
assertTrackLength(tracks, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
assertTotalLength(playlist, tracks, 100);
assertThat(tracks.get(0).getMusicFragment().getAudioFile(), is(musicTrack60s));
assertThat(tracks.get(1).getMusicFragment().getAudioFile(), is(musicTrack60s));
assertThat(tracks.get(2).getMusicFragment().getAudioFile(), is(musicTrack60s));
Expand Down Expand Up @@ -296,6 +299,7 @@ public void shouldTakeTheSameTrackInContinuousShuffleMode() {
// then
assertThat(tracks.size(), is(9));
assertTrackLength(tracks, 10, 10, 10, 10, 10, 10, 10, 10, 10);
assertTotalLength(playlist, tracks, 90);
assertThat(tracks.get(0).getMusicFragment().getAudioFile(), is(musicTrack60s));
assertThat(tracks.get(1).getMusicFragment().getAudioFile(), is(musicTrack60s));
assertThat(tracks.get(2).getMusicFragment().getAudioFile(), is(musicTrack60s));
Expand Down Expand Up @@ -378,6 +382,7 @@ public void shouldNotThrowExceptionInContinuousShuffleMode() {
// then
assertThat(tracks.size(), is(3));
assertTrackLength(tracks, 10, 10, 10);
assertTotalLength(playlist, tracks, 30);
assertThat(tracks.get(0).getMusicFragment().getAudioFile(), is(musicTrack20s));
assertThat(tracks.get(1).getMusicFragment().getAudioFile(), is(musicTrack20s));
assertThat(tracks.get(2).getMusicFragment().getAudioFile(), is(musicTrack20s));
Expand All @@ -402,8 +407,8 @@ private void assertTrackLength(List<PlaylistItem> tracks, int... seconds) {
}
}

private void assertTotalLength(List<PlaylistItem> tracks, int seconds) {
assertThat(new Playlist(msgPrd).getTotalLength(tracks), is(sec(seconds)));
private void assertTotalLength(Playlist p, List<PlaylistItem> tracks, int seconds) {
assertThat(new Playlist(msgPrd).getTotalLength(p, tracks), is(sec(seconds)));
}

private List<Integer> pattern(Integer... patternItems) {
Expand Down

0 comments on commit 7add329

Please sign in to comment.