From 7add329360057c40fbb7be3b5a4d175b72f715f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Waldisp=C3=BChl?= Date: Thu, 16 Nov 2017 19:28:57 +0100 Subject: [PATCH] Improved debug logging. --- .../compilation/Compilation.java | 2 +- .../playlist/Playlist.java | 34 +++++---------- .../playlist/PlaylistItem.java | 42 ++++++++++++++----- .../playlist/PlaylistTest.java | 19 +++++---- 4 files changed, 55 insertions(+), 42 deletions(-) diff --git a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/compilation/Compilation.java b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/compilation/Compilation.java index 04798c2..043b07e 100644 --- a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/compilation/Compilation.java +++ b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/compilation/Compilation.java @@ -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); } diff --git a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/Playlist.java b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/Playlist.java index 79b3d03..7f331ed 100644 --- a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/Playlist.java +++ b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/Playlist.java @@ -260,35 +260,21 @@ private PlaylistItemFragment createPlaylistItem(IAudioFile audioFile, Long start return new PlaylistItemFragment(audioFile, startInMilliseconds, endInMilliseconds); } - long getTotalLength(List 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 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() { @@ -308,7 +294,7 @@ private boolean isShuffleMode() { } private long getTotalLength() { - return getTotalLength(playlistItems); + return getTotalLength(this, playlistItems); } public int getTotalLengthInSeconds() { diff --git a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistItem.java b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistItem.java index 09757b4..745b53e 100644 --- a/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistItem.java +++ b/intervalmusiccompositor.core/src/main/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistItem.java @@ -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; @@ -61,14 +60,37 @@ public List 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(); + } } } diff --git a/intervalmusiccompositor.core/src/test/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistTest.java b/intervalmusiccompositor.core/src/test/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistTest.java index 396cd55..e6bd366 100644 --- a/intervalmusiccompositor.core/src/test/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistTest.java +++ b/intervalmusiccompositor.core/src/test/java/ch/retorte/intervalmusiccompositor/playlist/PlaylistTest.java @@ -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 @@ -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 @@ -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 @@ -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)); @@ -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); } @@ -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)); } @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -402,8 +407,8 @@ private void assertTrackLength(List tracks, int... seconds) { } } - private void assertTotalLength(List tracks, int seconds) { - assertThat(new Playlist(msgPrd).getTotalLength(tracks), is(sec(seconds))); + private void assertTotalLength(Playlist p, List tracks, int seconds) { + assertThat(new Playlist(msgPrd).getTotalLength(p, tracks), is(sec(seconds))); } private List pattern(Integer... patternItems) {