Skip to content

Commit

Permalink
in-progress interpreter refactor
Browse files Browse the repository at this point in the history
Will force-rewrite at several points.
  • Loading branch information
OxygenCobalt committed Nov 10, 2024
1 parent 85bd1f0 commit a784f73
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 369 deletions.
42 changes: 42 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/music/device/ArtistTree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.oxycblt.auxio.music.device


interface AlbumTree {
fun register(linkedSong: ArtistTree.LinkedSong): LinkedSong
fun resolve(): Collection<AlbumImpl>

data class LinkedSong(
val linkedArtistSong: ArtistTree.LinkedSong,
val album: Linked<AlbumImpl, SongImpl>
)
}

interface ArtistTree {
fun register(preSong: GenreTree.LinkedSong): LinkedSong
fun resolve(): Collection<ArtistImpl>

data class LinkedSong(
val linkedGenreSong: GenreTree.LinkedSong,
val linkedAlbum: LinkedAlbum,
val artists: Linked<List<ArtistImpl>, SongImpl>
)

data class LinkedAlbum(
val preAlbum: PreAlbum,
val artists: Linked<List<ArtistImpl>, AlbumImpl>
)
}

interface GenreTree {
fun register(preSong: PreSong): LinkedSong
fun resolve(): Collection<GenreImpl>

data class LinkedSong(
val preSong: PreSong,
val genres: Linked<List<GenreImpl>, SongImpl>
)
}

interface Linked<P, C> {
fun resolve(child: C): P
}
28 changes: 22 additions & 6 deletions app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,25 @@ interface DeviceLibrary {
processedSongs: Channel<RawSong>,
separators: Separators,
nameFactory: Name.Known.Factory
): DeviceLibraryImpl
): DeviceLibrary
}
}

class DeviceLibraryFactoryImpl2 @Inject constructor(
val interpreterFactory: Interpreter.Factory
) : DeviceLibrary.Factory {
override suspend fun create(
rawSongs: Channel<RawSong>,
processedSongs: Channel<RawSong>,
separators: Separators,
nameFactory: Name.Known.Factory
): DeviceLibrary {
val interpreter = interpreterFactory.create(nameFactory, separators)
rawSongs.forEachWithTimeout { rawSong ->
interpreter.consume(rawSong)
processedSongs.sendWithTimeout(rawSong)
}
return interpreter.resolve()
}
}

Expand All @@ -137,7 +155,7 @@ class DeviceLibraryFactoryImpl @Inject constructor() : DeviceLibrary.Factory {
processedSongs: Channel<RawSong>,
separators: Separators,
nameFactory: Name.Known.Factory
): DeviceLibraryImpl {
): DeviceLibrary {
val songGrouping = mutableMapOf<Music.UID, SongImpl>()
val albumGrouping = mutableMapOf<String?, MutableMap<UUID?, Grouping<RawAlbum, SongImpl>>>()
val artistGrouping = mutableMapOf<String?, MutableMap<UUID?, Grouping<RawArtist, Music>>>()
Expand Down Expand Up @@ -185,9 +203,7 @@ class DeviceLibraryFactoryImpl @Inject constructor() : DeviceLibrary.Factory {

// Now that all songs are processed, also process albums and group them into their
// respective artists.
pruneMusicBrainzIdTree(albumGrouping) { old, new ->
compareSongTracks(old, new)
}
pruneMusicBrainzIdTree(albumGrouping) { old, new -> compareSongTracks(old, new) }
val albums = flattenMusicBrainzIdTree(albumGrouping) { AlbumImpl(it, nameFactory) }
for (album in albums) {
for (rawArtist in album.rawArtists) {
Expand All @@ -214,7 +230,7 @@ class DeviceLibraryFactoryImpl @Inject constructor() : DeviceLibrary.Factory {
compareSongDates(old, new)
}
old is AlbumImpl && new is AlbumImpl -> {
compareAlbumDates(old, new)
compareAlbumDates(old, new)
}
else -> throw IllegalStateException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
interface DeviceModule {
@Binds fun deviceLibraryFactory(factory: DeviceLibraryFactoryImpl): DeviceLibrary.Factory
@Binds fun deviceLibraryFactory(factory: DeviceLibraryFactoryImpl2): DeviceLibrary.Factory
@Binds fun interpreterFactory(factory: InterpreterFactoryImpl): Interpreter.Factory
}
Loading

0 comments on commit a784f73

Please sign in to comment.