Created
August 6, 2020 20:45
-
-
Save zallanx/9c12acc9625579ae1707b98b093369bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func generateForSleep(_ playlist: Playlist) -> Playlist { | |
var remainingDurationInMs: Int = self.getDurationInMsFromNow() | |
let maxRemainderLength = 90 * 60 * 1000 * 2 | |
let firstChunks = [1,3,4,6,8,9,13,14,16] | |
var thenChunks = [2,4,7,8,9,10,12,14,15] | |
let endChunks = [5,6,11,16] | |
let ultEndChunks = [17] | |
//if no Grace Davidson, must get rid of 2, 7, 12 | |
if AppDataManager.shared.includeVocals == false { | |
thenChunks = [4,8,9,10,14,15] | |
} | |
var chunks: [PlayChunk] = [] | |
var resultTracks: [Track] = [] | |
while remainingDurationInMs > maxRemainderLength { | |
let resultChunks: [PlayChunk] = self.generateClustersFor(playlist: playlist, duration: 90 * 60 * 1000, | |
chunkDefinition:[firstChunks, thenChunks, endChunks]) | |
remainingDurationInMs -= (90 * 60 * 1000) | |
chunks.append(contentsOf: resultChunks) | |
print("Chunk for \(90*60)s limit -") // \(resultChunks.debugDescription())") | |
for chunk in resultChunks { | |
print("Chunk - \(chunk.debugDescription())") | |
} | |
resultTracks.append(contentsOf: PlayChunk.serializeChunk(chunks: resultChunks)) | |
} | |
// Do the ULT END | |
let resultChunks: [PlayChunk] = self.generateClustersFor(playlist: playlist, duration: remainingDurationInMs, | |
chunkDefinition:[firstChunks, thenChunks, ultEndChunks]) | |
chunks.append(contentsOf: resultChunks) | |
print("Chunk for \(remainingDurationInMs)ms limit -") | |
for chunk in resultChunks { | |
print("Chunk - \(chunk.debugDescription())") | |
} | |
resultTracks.append(contentsOf: PlayChunk.serializeChunk(chunks: resultChunks)) | |
playlist.tracks = resultTracks | |
return playlist | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment