Commit Graph

99 Commits

Author SHA1 Message Date
Anna Schumaker ab6eb556ad db: Fix track_adjusts_current() when the track has been removed
In this case, the call to get_track_index() returns None which can't be
used for the comparisons we're doing. Make sure we handle the None
result explicitely.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2022-02-22 10:08:34 -05:00
Anna Schumaker 0c7a4a4a4c db: Use the new match / case statement in user.py:do_factory()
This is cleaner than using a bunch of elif-s to pick the right playlist
type

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-12-28 17:23:57 -05:00
Anna Schumaker a85ac03517 db: Occasionally optimize the database
I do this whenever we commit during scanning, and during application
shutdown.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-12-09 22:09:40 -05:00
Anna Schumaker 853594fc26 db: Remove indexes
They aren't doing anything useful to help speed up sorting, so remove
for now and reevaluate later

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-12-09 22:05:42 -05:00
Anna Schumaker 8f26cf9fee db: Fix random next_track() on playlists with only one track
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-12-09 17:51:02 -05:00
Anna Schumaker 574d03bad6 db: Make it easy to know if we can delete tracks from playlists
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-12-05 13:49:22 -05:00
Anna Schumaker 6913cf992d db: Fix Playlist.get_track_index()
We need to limit the OVER () clause to just pick tracks that are
actually on the requested playlist.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-26 17:26:15 -05:00
Anna Schumaker b4daf0e48c db: Set check_same_thread=False
Apparently, the about-to-finish signal is called in a different thread
than the main thread. SQLite complains about the connection getting used
from a different thread, so we need to set this check to False so the
code skips it.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-26 17:26:15 -05:00
Anna Schumaker 20e4ab4ba5 db: Update icons for the Previous and QueuedTracks playlists
So they match the next and previous button icons

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker cc88dcab0a db: Give QueuedTracks a custom next_track() function
So we can remove tracks from the queue as they are played.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 2e57e1fe0a db: Preserve the current track when removing tracks
Again, we have to be careful not to check positions against playlists
where current == -1 for performance reasons.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 2f747ccaa6 db: Preserve the current track when adding tracks
We have to be careful not to check track positions against playlists
where current == -1, because this could drastically slow down adding new
tracks because SQLite would need to find the position for every track

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker e94a737718 db: Provide a passthrough for playlist_state.rowid
So the audio layer can easily access it when saving the current
playlist.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker ee6bf059c1 db: Replace years.year with albums.release in the default sort order
And remove the INNER JOIN with the years table since it is no longer
needed.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 0b818bc067 db: Attach release information to albums
This lets us sort albums by original release date, so if an artist
releases multiple albums in a year we can sort by month too.
Additionally, this helps us better handle albums with the same name that
were released in different years.

Implements: #40 (Store the full date in the year table)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 050a930376 db: Give the Previous playlist special next and previous functions
previous_track() moves deeper into the previous tracks list while
next_track() moves us closer to the start. I also make sure we reset
current track when new tracks are added to the playlist.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 7a46ffdf47 db: Give playlists a next_track() function
For picking the next track (with or without random enabled)

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 8a4590f0ed db: Preserve the current track when sorting
Implements: #39 (Preserve current track when sorting)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 23699a601d db: Have playlists clamp the current track value
And add a get_current_track() function to make it easier to get the
currently selected track. Clamping behaves differently if random or loop
are enabled to ensure a track is still picked.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker c658e873a6 db: Create a function to find playlists based on state id
So we can write the current playlist stateid to the settings file and
look it up later.

Implements: #36 (Find playlists based on playlist state id)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 6b5b2a745e db: Create a function for checking if this is a new database
So the tagdb can attempt to import tracks if none have been added to the
sql database yet.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker f82e299736 db: Add tracks.trackid ASC as a fallback sort option
This keeps us from ever completely clearing the sort field in the
playlist state, since that would lead to an incomplete SQL query error.

Fixes: #38 (PlaylistStates should not allow completely clearing sort)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker d8dbba0960 db: Commit after deleting a User playlist
Fixes: Issue #35 (Commit when creating or deleting new User playlists)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker adfbf8fdbc db: Give Discs a "number" property
So we can access the disc number when displaying tracks in the tracklist

Implements: Issue #34 (Give Discs a "number" property)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-11-18 10:20:24 -05:00
Anna Schumaker 14724aa81e db: Give Playlists a passthrough for PlaylistState properties
This lets us handle changes easier, since we'll catch them as they
happen. This lets us emit the "refreshed" signal when sorting changes,
for example.

Implements: Issue #32 (Passthrough PlaylistState properties)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 13:29:09 -04:00
Anna Schumaker edb6857292 db: Give playlists a get_tracks() function
So the UI's Gio.ListModel can get the list of tracks when it is created,
instead of needing to look up individual tracks by index through a sql
query.

Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:08 -04:00
Anna Schumaker 01de88f474 db: Give playlists a refresh() function
The Collection playlist uses this to emit the "refreshed" signal to
notify higher layers that the contents of the playlist has changed.
Eventually, this will also be used to update playlists when sorting.

Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:05 -04:00
Anna Schumaker 0c3afb9d56 db: Give playlists a remove_track() function
And emit a "track-removed" signal to notify the higher layers.

Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:04 -04:00
Anna Schumaker 9b4153737b db: Give playlists an add_track() function
And emit a "track-added" signal to notify higher layers

Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:02 -04:00
Anna Schumaker 32dcd83865 db: Give Tracks a Decade property and genres() function
For accessing a Track's Decade playlist or list of genres

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:02 -04:00
Anna Schumaker f6c72ed081 db: Remove the now unused objects.py file
Implements: Issue #18 (Remove the db.objects.Map class)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:02 -04:00
Anna Schumaker 932663f872 db: Remove the PlaylistMap objects
We can now do everything it did and more through the various user
playlist objects.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:02 -04:00
Anna Schumaker bba00b3d27 db: Remove the GenreMap object
We can now do everything it did and more through the Genre playlist
object.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:25:02 -04:00
Anna Schumaker 847f182173 db: Give playlists a get_track_index() function
So we can send an "items-changed" signal once Playlists have been
converted to a Gio.ListModel

Implements: Issue #3 (Sort playlists through SQLite)
Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:24:59 -04:00
Anna Schumaker 1d5f88f080 db: Give playlists a get_track() function
For finding a single track at a given index into the select query
results, ordered by the configured sort order.

Implements: Issue #3 (Sort playlists through SQLite)
Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:24:56 -04:00
Anna Schumaker 8917600970 db: Clear MappedPlaylists before deleting
Otherwise we end up with a bunch of (playlistid, trackid) pairs in the
map table that don't refer to a valid playlist anymore.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:24:56 -04:00
Anna Schumaker 729b1efc9a db: Give playlists a get_n_tracks() function
For finding the number of tracks in the specific playlist.

Implements: Issue #15 (Convert Playlists into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-27 11:24:22 -04:00
Anna Schumaker 5ff03cf33f db: Give MappedPlaylists add_track() and remove_track() functions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-18 15:50:07 -04:00
Anna Schumaker 0688088318 db: Create a MappedPlaylist type
For genre and most user playlists that rely on an extra map table to
figure out which tracks they have.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-18 15:50:07 -04:00
Anna Schumaker 72f654508c initial sort squash
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-18 15:50:07 -04:00
Anna Schumaker 0851aeb0cf db: Give playlists a default sort order
Most playlists sort by artist -> album -> year -> discno -> trackno, but
the Previous playlist sorts by rowid with the most recently added
tracks first, and the Up Next playlist sorts by rowid with the most
recently added tracks last.

Implements: Issue #13 (Give most playlists a default sort order)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-18 15:50:07 -04:00
Anna Schumaker a52a815338 db: Give Playlists a "rowkey" property
Most playlists will use this to look up their tracks in the track table

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-18 15:50:07 -04:00
Anna Schumaker 6f9fb34792 db: Give playlists a delete() function
So we can remove playlists from the database when needed.

Implemets: Issue #29 (Give playlists a delete() function)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-16 17:37:23 -04:00
Anna Schumaker 2aad28f708 db: Give Playlists an "icon-name" property
This will be used by the sidebar to display playlist rows

Implements: Issue #20 (Give Playlist database items a icon-name property)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-15 16:11:34 -04:00
Anna Schumaker 063b93b66f db: Convert the TrackTable into a table.Table
Implements: Issue #11 (Cache database items fields)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-15 16:09:59 -04:00
Anna Schumaker 4235e794bd db: Convert the UserTable to a playlist.Model
Implements: Issue #11 (Cache database items fields)
Implements: Issue #14 (Convert Tables into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-15 16:09:58 -04:00
Anna Schumaker 67238ed385 db: Give Albums a find_disc() function
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-14 17:03:19 -04:00
Anna Schumaker 44a002ecac db: Convert the DiscTable into a playlist.ChildModel
Implements: Issue #11 (Cache database items fields)
Implements: Issue #14 (Convert Tables into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-14 17:02:04 -04:00
Anna Schumaker 737d135d41 db: Give Artists a find_album() function
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-14 13:22:57 -04:00
Anna Schumaker a1f54839bb db: Convert the AlbumTable into a playlist.ChildModel
Implements: Issue #11 (Cache database items fields)
Implements: Issue #14 (Convert Tables into Gio.ListModels)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-10-14 13:22:57 -04:00