SCTC
the soundcloud.com terminal client
track.h
Go to the documentation of this file.
1 /*
2  SCTC - the soundcloud.com client
3  Copyright (C) 2015 Christian Eichler
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>
17 */
18 
19 
24 #ifndef _TRACK_H
25  #define _TRACK_H
26 
27  //\cond
28  #include <stdbool.h>
29  #include <stdint.h>
30  #include <time.h>
31  //\endcond
32 
34  #define FLAG_PLAYING 1
35 
37  #define FLAG_PAUSED 2
38 
40  #define FLAG_BOOKMARKED 4
41 
43  #define FLAG_NEW 8
44 
46  #define FLAG_CACHED 16
47 
48  #define TRACK(LST, ID) (LST->entries[ID].name ? &LST->entries[ID] : LST->entries[ID].href)
49 
67  struct track {
68  char *name;
69  union {
70  struct {
71  char *stream_url;
72 
78 
79  char *download_url;
80  char *username;
81  char *description;
82  struct tm created_at;
83  int duration;
84  int user_id;
85  int track_id;
86 
87  /* these members are used for handling the playlist, they are not part of the data received from sc.com */
88  uint8_t flags;
90  };
91  struct track *href;
92  };
93  };
94 
95  struct track_list {
96  char *name;
97  size_t count;
98  struct track *entries;
99  };
100 
106  bool track_list_add(struct track_list *list, struct track *track);
107 
117  struct track_list* track_list_merge(struct track_list **lists);
118 
123  void track_list_sort(struct track_list *list);
124 
129  bool track_list_append(struct track_list *target, struct track_list *source);
130 
137  struct track* track_list_get(struct track_list *list, char *permalink);
138 
146  void track_list_destroy(struct track_list *list, bool free_trackdata);
147 
148  bool track_list_del(struct track_list *list, size_t track_id);
149  void track_destroy(struct track *track);
150 #endif /* _TRACK_H */
size_t count
Definition: track.h:97
char * username
The username.
Definition: track.h:80
int track_id
Definition: track.h:85
struct track_list * track_list_merge(struct track_list **lists)
Merge an array of track_lists.
Definition: track.c:64
struct track * entries
Definition: track.h:98
char * description
Definition: track.h:81
Definition: track.h:95
The basic datastructure representing a single track.
Definition: track.h:67
int duration
duration in seconds
Definition: track.h:83
bool track_list_append(struct track_list *target, struct track_list *source)
Append a list to another list.
Definition: track.c:88
void track_list_sort(struct track_list *list)
Sort a track_list by creation time.
Definition: track.c:84
struct track * track_list_get(struct track_list *list, char *permalink)
Check if list contains a track, identified by its permalink and return it.
Definition: track.c:102
uint8_t flags
Definition: track.h:88
int current_position
current position
Definition: track.h:89
char * stream_url
The URL used for streaming this track.
Definition: track.h:71
char * permalink_url
Definition: track.h:77
char * download_url
The URL pointing to the download. Might be NULL, if the uploader does not provide a download...
Definition: track.h:79
static struct track_list_state lists[MAX_LISTS]
char * name
Definition: track.h:96
void track_list_destroy(struct track_list *list, bool free_trackdata)
Free the memory occupied by a track_list.
Definition: track.c:122
char * name
the tracks name
Definition: track.h:68
struct track * href
Pointer to a normal track (only valid if name == NULL)
Definition: track.h:91
int user_id
Definition: track.h:84
bool track_list_del(struct track_list *list, size_t track_id)
Definition: track.c:47
void track_destroy(struct track *track)
Definition: track.c:111
bool track_list_add(struct track_list *list, struct track *track)
Add a single track to an existing track_list.
Definition: track.c:35
struct tm created_at
Definition: track.h:82