]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce VSS_NEW_AUDIO_FILE to fix playlist updates.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 19 Mar 2025 21:05:16 +0000 (22:05 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 25 May 2025 17:00:27 +0000 (19:00 +0200)
The playlist event handler handles afsi change events by moving the affected
entry to the end of the playlist. This is the right thing to do if the
event was triggered by virtual streaming system streaming a new file. It is
incorrect, however, if the event was triggered by a subcommand such as touch.

This commit introduces the new afs event type VSS_NEW_AUDIO_FILE to distinguish
between the two different use cases. The audio file table event handler
ignores the VSS_NEW_AUDIO_FILE event while the playlist event handler ignores
the AFSI_CHANGE event. The moods event handler treats both events equally,

Get rid of a pointless static one-liner function in playlist.c while at it.

afs.h
aft.c
m4/lls/server_cmd.suite.m4
mood.c
playlist.c

diff --git a/afs.h b/afs.h
index 622ac70f304ef9051a9d4ec063713059192ab492..b46aeed1e9c107405cc717dfed236309ef551763 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -39,6 +39,8 @@ enum afs_events {
        AFSI_CHANGE,
        /** The afh info struct of an audio file changed. */
        AFHI_CHANGE,
+       /** The vss streams a new file, implies afsi and afhi change */
+       VSS_NEW_AUDIO_FILE,
        /** An audio file was renamed. */
        AUDIO_FILE_RENAME,
        /** An audio file was added. */
diff --git a/aft.c b/aft.c
index 383439d08256a4a245e2b6de5b4ff46a479438d5..8abfbc94fe5a9afd7352528987d8e453f33228c4 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1108,6 +1108,7 @@ again:
                ret = -E_HASH_MISMATCH;
                goto out;
        }
+
        old_afsi = d->afsi;
        d->afsi.num_played++;
        d->afsi.last_played = time(NULL);
@@ -1115,14 +1116,11 @@ again:
        d->afsi.last_played = old_afsi.last_played;
        aced.aft_row = current_aft_row;
        aced.old_afsi = &old_afsi;
-
        afd.audio_format_id = d->afsi.audio_format_id;
        load_chunk_table(&afd.afhi, &chunk_table_obj);
-       /*
-        * No need to update the status items as the AFSI_CHANGE event will
-        * recreate them.
-        */
-       ret = afs_event(AFSI_CHANGE, NULL, &aced);
+       make_status_items();
+
+       ret = afs_event(VSS_NEW_AUDIO_FILE, NULL, &aced);
        if (ret < 0)
                goto out;
        ret = save_afd(&afd);
index 6056541c1a73af8e9863bb9cfe8c79be6deea07e..1b282f3aabe97b73e4b3a76224f6ef29cad8870e 100644 (file)
@@ -553,9 +553,7 @@ m4_include(`com_ll.m4')
                all other fields are left unchanged. This mimics what happens when
                the virtual streaming system selects the file for streaming.
 
-               If the file is admissible for the current mood (or contained in the
-               current playlist), its score is recomputed according to the changed
-               values.
+               If the file is admissible for the current mood, its score is recomputed.
        [/description]
        [option numplayed]
                short_opt = n
diff --git a/mood.c b/mood.c
index 01ef2c8ab38c2ad18e42cf0a00117c33069f87e7..c697b168265e9bbd094333cf3c823ff5e6334594 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -756,6 +756,7 @@ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb
        case ATTRIBUTE_RENAME:
                return reload_current_mood();
        /* changes to the aft only require to re-examine the audio file */
+       case VSS_NEW_AUDIO_FILE:
        case AFSI_CHANGE: {
                struct afsi_change_event_data *aced = data;
                return mood_update_audio_file(aced->aft_row, aced->old_afsi);
index 3a7df149189df5052875d626314e85d8ad402cf6..93acf7744b898b685f49b561de5a8f841b1d9490 100644 (file)
@@ -28,19 +28,6 @@ struct playlist_instance {
 };
 static struct playlist_instance current_playlist;
 
-/**
- * Re-insert an audio file into the tree of admissible files.
- *
- * \param aft_row Determines the audio file.
- *
- * \return The return value of score_update().
- */
-static int playlist_update_audio_file(const struct osl_row *aft_row)
-{
-       /* always re-insert to the top of the tree */
-       return score_update(aft_row, 0);
-}
-
 static int add_playlist_entry(char *path, void *data)
 {
        struct playlist_instance *pi = data;
@@ -263,13 +250,13 @@ static int handle_audio_file_event(enum afs_events event, void *data)
 int playlists_event_handler(enum afs_events event,
        __a_unused struct para_buffer *pb, void *data)
 {
-       struct afsi_change_event_data *aced = data;
-
        if (!current_playlist.name)
                return 1;
        switch (event) {
-       case AFSI_CHANGE:
-               return playlist_update_audio_file(aced->aft_row);
+       case VSS_NEW_AUDIO_FILE: { /* move the row to the end of the playlist */
+               struct afsi_change_event_data *aced = data;
+               return score_update(aced->aft_row, 0);
+               }
        case AUDIO_FILE_RENAME:
        case AUDIO_FILE_ADD:
                return handle_audio_file_event(event, data);