aboutsummaryrefslogtreecommitdiff
path: root/patches/0003-yp3-next-chapter-title-in-the-next-track-tokens.patch
blob: 2613f360e237c961f54d7bb268209345dc870e45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From 4a31d205984cb0ffa1d2381213b09d695adbd49d Mon Sep 17 00:00:00 2001
From: YP3 Audiobook <noreply@example.invalid>
Date: Wed, 25 Nov 2026 20:39:34 +0000
Subject: [PATCH 3/3] yp3: next chapter title in the next-track tokens

---
 apps/chapters.c                    | 18 ++++++++++++++++++
 apps/chapters.h                    |  2 ++
 apps/gui/skin_engine/skin_tokens.c |  9 +++++++++
 3 files changed, 29 insertions(+)

diff --git a/apps/chapters.c b/apps/chapters.c
index 9b483653..d8306f5b 100644
--- a/apps/chapters.c
+++ b/apps/chapters.c
@@ -47,6 +47,8 @@ static char ch_path[MAX_PATH];            /* the file they are from */
 static int ch_last_index = -1;            /* chapters_changed() */
 static int ch_title_index = -1;           /* cur_title holds this one */
 static char cur_title[TITLE_MAX + 1];
+static int ch_next_index = -1;            /* next_title holds this one */
+static char next_title[TITLE_MAX + 1];
 
 /* --- a small buffered reader: the atoms are walked with many tiny reads --- */
 
@@ -418,6 +420,7 @@ int chapters_update(const struct mp3entry *id3)
     ch_count = 0;
     ch_last_index = -1;
     ch_title_index = -1;
+    ch_next_index = -1;
     switch (id3->codectype)
     {
         case AFMT_MP4_AAC:
@@ -537,6 +540,21 @@ const char *chapters_current_title(const struct mp3entry *id3)
     return cur_title;
 }
 
+const char *chapters_next_title(const struct mp3entry *id3)
+{
+    if (chapters_update(id3) <= 0)
+        return NULL;
+    int i = chapters_index(id3->elapsed) + 1;
+    if (i >= ch_count)
+        return NULL;
+    if (i != ch_next_index)
+    {
+        chapters_title(i, next_title, sizeof(next_title));
+        ch_next_index = i;
+    }
+    return next_title;
+}
+
 bool chapters_changed(const struct mp3entry *id3)
 {
     if (chapters_update(id3) <= 0)
diff --git a/apps/chapters.h b/apps/chapters.h
index 14e4d709..3bc633c6 100644
--- a/apps/chapters.h
+++ b/apps/chapters.h
@@ -21,6 +21,8 @@ unsigned long chapters_start(int i);
 const char *chapters_title(int i, char *buf, size_t size);
 /* The playing chapter's title, cached. */
 const char *chapters_current_title(const struct mp3entry *id3);
+/* The next chapter's title, cached; NULL in the last chapter. */
+const char *chapters_next_title(const struct mp3entry *id3);
 /* True once each time the playing chapter changes (skin refresh). */
 bool chapters_changed(const struct mp3entry *id3);
 /* Ticks at the chapter starts on a progress bar. */
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index 98d854ce..4c1fbffb 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -878,6 +878,15 @@ static const char *try_id3_token(struct wps_token *token, int offset,
         if (out_text)
             goto free_id3_outtext;
     }
+    /* "next track" title: the next chapter's, until the last chapter */
+    else if ((token->next || offset == 1) && state->id3 &&
+             token->type == SKIN_TOKEN_METADATA_TRACK_TITLE &&
+             chapters_update(state->id3) > 0)
+    {
+        out_text = chapters_next_title(state->id3);
+        if (out_text)
+            goto free_id3_outtext;
+    }
 #endif
     if (id3 && id3 == state->id3 && id3->cuesheet)
     {
-- 
2.56.1