Skip to content

Commit e48e84e

Browse files
committed
ordered track list; jukebox mode
1 parent 6181c4a commit e48e84e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

util.c

+58
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
11

22
#include "util.h"
33

4+
struct Track *track_add (struct Track **entries, const char *uri, int idx, int st)
5+
{
6+
if (!uri)
7+
return NULL;
8+
// Allocate memory for new node;
9+
struct Track *list = *entries;
10+
struct Track *link = (struct Track*) malloc (sizeof (struct Track));
11+
if (!link)
12+
{
13+
//NPrintf ("!fm_job_add malloc failed for %d>%s\n", dir, fn);
14+
return NULL;
15+
}
16+
//
17+
//Nprintf("adding %s\n", uri);
18+
link->uri = strdup (uri);
19+
link->index = idx;
20+
link->streamType = st;
21+
//
22+
link->prev = NULL;
23+
link->next = NULL;
24+
// If head is empty, create new list
25+
if (list == NULL)
26+
{
27+
*entries = link;
28+
}
29+
else
30+
{
31+
struct Track *current = list;
32+
while (current->next && strcasecmp (current->uri, uri) < 0)
33+
current = current->next;
34+
//
35+
if (strcasecmp (current->uri, uri) < 0)
36+
{
37+
//Nprintf ("adding after %s\n", current->uri);
38+
struct Track *next = current->next;
39+
if (next)
40+
next->prev = link;
41+
current->next = link;
42+
link->prev = current;
43+
link->next = next;
44+
}
45+
else
46+
{
47+
//Nprintf ("adding before %s\n", current->uri);
48+
struct Track *prev = current->prev;
49+
if (prev)
50+
prev->next = link;
51+
else
52+
//new head
53+
*entries = link;
54+
current->prev = link;
55+
link->prev = prev;
56+
link->next = current;
57+
}
58+
}
59+
return link;
60+
}
61+
462
struct Subs *subs_get (struct Subs *head, long cts)
563
{
664
struct Subs *node;

util.h

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef __UTIL_H__
33
#define __UTIL_H__
44

5+
void Nprintf (const char* fmt, ...);
6+
57
struct Subs {
68
struct Subs *prev, *next; //chaining refs
79
int idx; //sub index
@@ -14,4 +16,15 @@ struct Subs *subs_load (char *path);
1416
struct Subs * subs_clear (struct Subs *subs);
1517
struct Subs *subs_get (struct Subs *head, long cts);
1618

19+
20+
struct Track {
21+
struct Track *prev, *next; //chaining refs
22+
//
23+
const char *uri;
24+
int index;
25+
int streamType;
26+
};
27+
28+
struct Track *track_add (struct Track **entries, const char *uri, int idx, int st);
29+
1730
#endif

0 commit comments

Comments
 (0)