Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d562ba5f
Commit
d562ba5f
authored
Oct 08, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
song: converted typedef Song to struct song
Again, a data type which can be forward-declared.
parent
25f67da5
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
196 additions
and
118 deletions
+196
-118
dbUtils.c
src/dbUtils.c
+23
-12
decoder_api.c
src/decoder_api.c
+1
-0
decoder_control.c
src/decoder_control.c
+4
-2
decoder_control.h
src/decoder_control.h
+8
-6
decoder_thread.c
src/decoder_thread.c
+1
-0
directory.c
src/directory.c
+7
-6
directory.h
src/directory.h
+5
-3
locate.c
src/locate.c
+10
-4
locate.h
src/locate.h
+8
-3
player_control.c
src/player_control.c
+11
-5
player_control.h
src/player_control.h
+10
-7
player_thread.c
src/player_thread.c
+1
-0
playlist.c
src/playlist.c
+13
-10
playlist.h
src/playlist.h
+9
-3
song.c
src/song.c
+11
-7
song.h
src/song.h
+13
-8
song_print.c
src/song_print.c
+6
-3
song_print.h
src/song_print.h
+6
-4
song_save.c
src/song_save.c
+8
-5
song_save.h
src/song_save.h
+2
-1
songvec.c
src/songvec.c
+14
-11
songvec.h
src/songvec.h
+7
-6
stats.c
src/stats.c
+3
-1
storedPlaylist.c
src/storedPlaylist.c
+3
-2
storedPlaylist.h
src/storedPlaylist.h
+3
-2
update.c
src/update.c
+9
-7
No files found.
src/dbUtils.c
View file @
d562ba5f
...
...
@@ -66,7 +66,8 @@ printDirectoryInDirectory(struct directory *directory, void *data)
return
0
;
}
static
int
printSongInDirectory
(
Song
*
song
,
mpd_unused
void
*
data
)
static
int
printSongInDirectory
(
struct
song
*
song
,
mpd_unused
void
*
data
)
{
struct
client
*
client
=
data
;
song_print_url
(
client
,
song
);
...
...
@@ -78,7 +79,8 @@ struct search_data {
LocateTagItemArray
array
;
};
static
int
searchInDirectory
(
Song
*
song
,
void
*
_data
)
static
int
searchInDirectory
(
struct
song
*
song
,
void
*
_data
)
{
struct
search_data
*
data
=
_data
;
LocateTagItemArray
*
array
=
&
data
->
array
;
...
...
@@ -119,7 +121,8 @@ int searchForSongsIn(struct client *client, const char *name,
return
ret
;
}
static
int
findInDirectory
(
Song
*
song
,
void
*
_data
)
static
int
findInDirectory
(
struct
song
*
song
,
void
*
_data
)
{
struct
search_data
*
data
=
_data
;
LocateTagItemArray
*
array
=
&
data
->
array
;
...
...
@@ -148,7 +151,8 @@ static void printSearchStats(struct client *client, SearchStats *stats)
client_printf
(
client
,
"playtime: %li
\n
"
,
stats
->
playTime
);
}
static
int
searchStatsInDirectory
(
Song
*
song
,
void
*
data
)
static
int
searchStatsInDirectory
(
struct
song
*
song
,
void
*
data
)
{
SearchStats
*
stats
=
data
;
...
...
@@ -186,7 +190,8 @@ int printAllIn(struct client *client, const char *name)
printDirectoryInDirectory
,
client
);
}
static
int
directoryAddSongToPlaylist
(
Song
*
song
,
mpd_unused
void
*
data
)
static
int
directoryAddSongToPlaylist
(
struct
song
*
song
,
mpd_unused
void
*
data
)
{
return
addSongToPlaylist
(
song
,
NULL
);
}
...
...
@@ -195,7 +200,8 @@ struct add_data {
const
char
*
path
;
};
static
int
directoryAddSongToStoredPlaylist
(
Song
*
song
,
void
*
_data
)
static
int
directoryAddSongToStoredPlaylist
(
struct
song
*
song
,
void
*
_data
)
{
struct
add_data
*
data
=
_data
;
...
...
@@ -219,14 +225,16 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file)
&
data
);
}
static
int
directoryPrintSongInfo
(
Song
*
song
,
void
*
data
)
static
int
directoryPrintSongInfo
(
struct
song
*
song
,
void
*
data
)
{
struct
client
*
client
=
data
;
song_print_info
(
client
,
song
);
return
0
;
}
static
int
sumSongTime
(
Song
*
song
,
void
*
data
)
static
int
sumSongTime
(
struct
song
*
song
,
void
*
data
)
{
unsigned
long
*
sum_time
=
(
unsigned
long
*
)
data
;
...
...
@@ -279,8 +287,9 @@ static void freeListCommandItem(ListCommandItem * item)
free
(
item
);
}
static
void
visitTag
(
struct
client
*
client
,
struct
strset
*
set
,
Song
*
song
,
enum
tag_type
tagType
)
static
void
visitTag
(
struct
client
*
client
,
struct
strset
*
set
,
struct
song
*
song
,
enum
tag_type
tagType
)
{
int
i
;
struct
tag
*
tag
=
song
->
tag
;
...
...
@@ -308,7 +317,8 @@ struct list_tags_data {
struct
strset
*
set
;
};
static
int
listUniqueTagsInDirectory
(
Song
*
song
,
void
*
_data
)
static
int
listUniqueTagsInDirectory
(
struct
song
*
song
,
void
*
_data
)
{
struct
list_tags_data
*
data
=
_data
;
ListCommandItem
*
item
=
data
->
item
;
...
...
@@ -371,7 +381,8 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
return
0
;
}
static
int
sumSavedFilenameMemoryInSong
(
Song
*
song
,
void
*
data
)
static
int
sumSavedFilenameMemoryInSong
(
struct
song
*
song
,
void
*
data
)
{
int
*
sum
=
data
;
...
...
src/decoder_api.c
View file @
d562ba5f
...
...
@@ -22,6 +22,7 @@
#include "decoder_control.h"
#include "player_control.h"
#include "audio.h"
#include "song.h"
#include "utils.h"
#include "normalize.h"
...
...
src/decoder_control.c
View file @
d562ba5f
...
...
@@ -53,7 +53,8 @@ static void dc_command_async(enum decoder_command cmd)
notify_signal
(
&
dc
.
notify
);
}
void
dc_start
(
Notify
*
notify
,
Song
*
song
)
void
dc_start
(
Notify
*
notify
,
struct
song
*
song
)
{
assert
(
song
!=
NULL
);
...
...
@@ -62,7 +63,8 @@ void dc_start(Notify *notify, Song *song)
dc_command
(
notify
,
DECODE_COMMAND_START
);
}
void
dc_start_async
(
Song
*
song
)
void
dc_start_async
(
struct
song
*
song
)
{
assert
(
song
!=
NULL
);
...
...
src/decoder_control.h
View file @
d562ba5f
...
...
@@ -21,7 +21,6 @@
#define DECODE_H
#include "decoder_api.h"
#include "song.h"
#include "audio_format.h"
#include "notify.h"
...
...
@@ -49,8 +48,8 @@ struct decoder_control {
volatile
int8_t
seekable
;
volatile
double
seekWhere
;
struct
audio_format
audioFormat
;
S
ong
*
current_song
;
S
ong
*
volatile
next_song
;
struct
s
ong
*
current_song
;
struct
s
ong
*
volatile
next_song
;
volatile
float
totalTime
;
};
...
...
@@ -72,7 +71,8 @@ static inline int decoder_is_starting(void)
dc
.
state
==
DECODE_STATE_START
;
}
static
inline
Song
*
decoder_current_song
(
void
)
static
inline
struct
song
*
decoder_current_song
(
void
)
{
if
(
dc
.
state
==
DECODE_STATE_STOP
||
dc
.
error
!=
DECODE_ERROR_NOERROR
)
...
...
@@ -83,9 +83,11 @@ static inline Song *decoder_current_song(void)
void
dc_command_wait
(
Notify
*
notify
);
void
dc_start
(
Notify
*
notify
,
Song
*
song
);
void
dc_start
(
Notify
*
notify
,
struct
song
*
song
);
void
dc_start_async
(
Song
*
song
);
void
dc_start_async
(
struct
song
*
song
);
void
dc_stop
(
Notify
*
notify
);
...
...
src/decoder_thread.c
View file @
d562ba5f
...
...
@@ -21,6 +21,7 @@
#include "decoder_control.h"
#include "decoder_internal.h"
#include "player_control.h"
#include "song.h"
#include "path.h"
#include "log.h"
...
...
src/directory.c
View file @
d562ba5f
...
...
@@ -17,7 +17,7 @@
*/
#include "directory.h"
#include "song.h"
#include "conf.h"
#include "log.h"
#include "ls.h"
...
...
@@ -448,7 +448,7 @@ int readDirectoryDB(void)
static
int
traverseAllInSubDirectory
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
S
ong
*
,
void
*
),
int
(
*
forEachSong
)
(
struct
s
ong
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
)
{
...
...
@@ -474,13 +474,13 @@ traverseAllInSubDirectory(struct directory * directory,
int
traverseAllIn
(
const
char
*
name
,
int
(
*
forEachSong
)
(
S
ong
*
,
void
*
),
int
(
*
forEachSong
)
(
struct
s
ong
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
)
{
struct
directory
*
directory
;
if
((
directory
=
getDirectory
(
name
))
==
NULL
)
{
S
ong
*
song
;
struct
s
ong
*
song
;
if
((
song
=
getSongFromDB
(
name
))
&&
forEachSong
)
{
return
forEachSong
(
song
,
data
);
}
...
...
@@ -499,9 +499,10 @@ void directory_init(void)
stats
.
dbPlayTime
=
sumSongTimesIn
(
NULL
);
}
Song
*
getSongFromDB
(
const
char
*
file
)
struct
song
*
getSongFromDB
(
const
char
*
file
)
{
S
ong
*
song
=
NULL
;
struct
s
ong
*
song
=
NULL
;
struct
directory
*
directory
;
char
*
dir
=
NULL
;
char
*
duplicated
=
xstrdup
(
file
);
...
...
src/directory.h
View file @
d562ba5f
...
...
@@ -19,12 +19,13 @@
#ifndef DIRECTORY_H
#define DIRECTORY_H
#include "song.h"
#include "songvec.h"
#include "list.h"
#include <stdbool.h>
struct
client
;
struct
dirvec
{
struct
directory
**
base
;
size_t
nr
;
...
...
@@ -75,12 +76,13 @@ int writeDirectoryDB(void);
int
readDirectoryDB
(
void
);
Song
*
getSongFromDB
(
const
char
*
file
);
struct
song
*
getSongFromDB
(
const
char
*
file
);
time_t
getDbModTime
(
void
);
int
traverseAllIn
(
const
char
*
name
,
int
(
*
forEachSong
)
(
S
ong
*
,
void
*
),
int
(
*
forEachSong
)
(
struct
s
ong
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
);
#define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "")
...
...
src/locate.c
View file @
d562ba5f
...
...
@@ -20,6 +20,7 @@
#include "path.h"
#include "utils.h"
#include "tag.h"
#include "song.h"
#define LOCATE_TAG_FILE_KEY "file"
#define LOCATE_TAG_FILE_KEY_OLD "filename"
...
...
@@ -122,7 +123,8 @@ void freeLocateTagItem(LocateTagItem * item)
free
(
item
);
}
static
int
strstrSearchTag
(
Song
*
song
,
enum
tag_type
type
,
char
*
str
)
static
int
strstrSearchTag
(
struct
song
*
song
,
enum
tag_type
type
,
char
*
str
)
{
int
i
;
char
*
duplicate
;
...
...
@@ -167,7 +169,8 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str)
return
ret
;
}
int
strstrSearchTags
(
Song
*
song
,
int
numItems
,
LocateTagItem
*
items
)
int
strstrSearchTags
(
struct
song
*
song
,
int
numItems
,
LocateTagItem
*
items
)
{
int
i
;
...
...
@@ -181,7 +184,8 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items)
return
1
;
}
static
int
tagItemFoundAndMatches
(
Song
*
song
,
enum
tag_type
type
,
char
*
str
)
static
int
tagItemFoundAndMatches
(
struct
song
*
song
,
enum
tag_type
type
,
char
*
str
)
{
int
i
;
int8_t
visitedTypes
[
TAG_NUM_OF_ITEM_TYPES
]
=
{
0
};
...
...
@@ -221,7 +225,9 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
}
int
tagItemsFoundAndMatches
(
Song
*
song
,
int
numItems
,
LocateTagItem
*
items
)
int
tagItemsFoundAndMatches
(
struct
song
*
song
,
int
numItems
,
LocateTagItem
*
items
)
{
int
i
;
...
...
src/locate.h
View file @
d562ba5f
...
...
@@ -19,11 +19,13 @@
#ifndef LOCATE_H
#define LOCATE_H
#include
"song.h"
#include
<stdint.h>
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
struct
song
;
/* struct used for search, find, list queries */
typedef
struct
_LocateTagItem
{
int8_t
tagType
;
...
...
@@ -44,8 +46,11 @@ void freeLocateTagItemArray(int count, LocateTagItem * array);
void
freeLocateTagItem
(
LocateTagItem
*
item
);
int
strstrSearchTags
(
Song
*
song
,
int
numItems
,
LocateTagItem
*
items
);
int
strstrSearchTags
(
struct
song
*
song
,
int
numItems
,
LocateTagItem
*
items
);
int
tagItemsFoundAndMatches
(
Song
*
song
,
int
numItems
,
LocateTagItem
*
items
);
int
tagItemsFoundAndMatches
(
struct
song
*
song
,
int
numItems
,
LocateTagItem
*
items
);
#endif
src/player_control.c
View file @
d562ba5f
...
...
@@ -20,6 +20,7 @@
#include "path.h"
#include "log.h"
#include "tag.h"
#include "song.h"
#include "os_compat.h"
#include "main_notify.h"
...
...
@@ -43,7 +44,8 @@ void pc_deinit(void)
notify_deinit
(
&
pc
.
notify
);
}
static
void
set_current_song
(
Song
*
song
)
static
void
set_current_song
(
struct
song
*
song
)
{
assert
(
song
!=
NULL
);
assert
(
song
->
url
!=
NULL
);
...
...
@@ -61,7 +63,8 @@ static void player_command(enum player_command cmd)
}
}
void
playerPlay
(
Song
*
song
)
void
playerPlay
(
struct
song
*
song
)
{
assert
(
pc
.
queueLockState
==
PLAYER_QUEUE_UNLOCKED
);
...
...
@@ -174,7 +177,8 @@ char *getPlayerErrorStr(void)
return
*
error
?
error
:
NULL
;
}
void
queueSong
(
Song
*
song
)
void
queueSong
(
struct
song
*
song
)
{
assert
(
pc
.
queueState
==
PLAYER_QUEUE_BLANK
);
...
...
@@ -208,7 +212,8 @@ void playerQueueUnlock(void)
assert
(
pc
.
queueLockState
==
PLAYER_QUEUE_UNLOCKED
);
}
int
playerSeek
(
Song
*
song
,
float
seek_time
)
int
playerSeek
(
struct
song
*
song
,
float
seek_time
)
{
assert
(
song
!=
NULL
);
...
...
@@ -265,7 +270,8 @@ int getPlayerChannels(void)
}
/* this actually creates a dupe of the current metadata */
Song
*
playerCurrentDecodeSong
(
void
)
struct
song
*
playerCurrentDecodeSong
(
void
)
{
return
NULL
;
}
src/player_control.h
View file @
d562ba5f
...
...
@@ -20,7 +20,6 @@
#define PLAYER_H
#include "notify.h"
#include "song.h"
#include "os_compat.h"
enum
player_state
{
...
...
@@ -92,8 +91,8 @@ struct player_control {
volatile
float
totalTime
;
volatile
float
elapsedTime
;
volatile
float
fileTime
;
S
ong
*
volatile
next_song
;
S
ong
*
errored_song
;
struct
s
ong
*
volatile
next_song
;
struct
s
ong
*
errored_song
;
volatile
enum
player_queue_state
queueState
;
volatile
int8_t
queueLockState
;
volatile
double
seekWhere
;
...
...
@@ -108,7 +107,8 @@ void pc_init(unsigned int buffered_before_play);
void
pc_deinit
(
void
);
void
playerPlay
(
Song
*
song
);
void
playerPlay
(
struct
song
*
song
);
void
playerSetPause
(
int
pause_flag
);
...
...
@@ -132,7 +132,8 @@ int getPlayerError(void);
void
playerWait
(
void
);
void
queueSong
(
Song
*
song
);
void
queueSong
(
struct
song
*
song
);
enum
player_queue_state
getPlayerQueueState
(
void
);
...
...
@@ -142,7 +143,8 @@ void playerQueueLock(void);
void
playerQueueUnlock
(
void
);
int
playerSeek
(
Song
*
song
,
float
seek_time
);
int
playerSeek
(
struct
song
*
song
,
float
seek_time
);
void
setPlayerCrossFade
(
float
crossFadeInSeconds
);
...
...
@@ -158,7 +160,8 @@ int getPlayerBits(void);
int
getPlayerChannels
(
void
);
Song
*
playerCurrentDecodeSong
(
void
);
struct
song
*
playerCurrentDecodeSong
(
void
);
void
playerInit
(
void
);
...
...
src/player_thread.c
View file @
d562ba5f
...
...
@@ -25,6 +25,7 @@
#include "log.h"
#include "main_notify.h"
#include "crossfade.h"
#include "song.h"
enum
xfade_state
{
XFADE_DISABLED
=
-
1
,
...
...
src/playlist.c
View file @
d562ba5f
...
...
@@ -21,6 +21,7 @@
#include "command.h"
#include "ls.h"
#include "tag.h"
#include "song.h"
#include "song_print.h"
#include "client.h"
#include "conf.h"
...
...
@@ -140,7 +141,7 @@ void initPlaylist(void)
playlist_saveAbsolutePaths
=
DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS
;
playlist
.
songs
=
xmalloc
(
sizeof
(
S
ong
*
)
*
playlist_max_length
);
playlist
.
songs
=
xmalloc
(
sizeof
(
struct
s
ong
*
)
*
playlist_max_length
);
playlist
.
songMod
=
xmalloc
(
sizeof
(
uint32_t
)
*
playlist_max_length
);
playlist
.
order
=
xmalloc
(
sizeof
(
int
)
*
playlist_max_length
);
playlist
.
idToPosition
=
xmalloc
(
sizeof
(
int
)
*
playlist_max_length
*
...
...
@@ -452,7 +453,7 @@ enum playlist_result playlistId(struct client *client, int id)
static
void
swapSongs
(
int
song1
,
int
song2
)
{
S
ong
*
sTemp
;
struct
s
ong
*
sTemp
;
int
iTemp
;
sTemp
=
playlist
.
songs
[
song1
];
...
...
@@ -554,7 +555,7 @@ static void clearPlayerQueue(void)
enum
playlist_result
addToPlaylist
(
const
char
*
url
,
int
*
added_id
)
{
S
ong
*
song
;
struct
s
ong
*
song
;
DEBUG
(
"add to playlist: %s
\n
"
,
url
);
...
...
@@ -569,7 +570,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id)
int
addToStoredPlaylist
(
const
char
*
url
,
const
char
*
utf8file
)
{
S
ong
*
song
;
struct
s
ong
*
song
;
DEBUG
(
"add to stored playlist: %s
\n
"
,
url
);
...
...
@@ -590,7 +591,8 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
return
ACK_ERROR_NO_EXIST
;
}
enum
playlist_result
addSongToPlaylist
(
Song
*
song
,
int
*
added_id
)
enum
playlist_result
addSongToPlaylist
(
struct
song
*
song
,
int
*
added_id
)
{
int
id
;
...
...
@@ -775,7 +777,8 @@ enum playlist_result deleteFromPlaylistById(int id)
return
deleteFromPlaylist
(
song
);
}
void
deleteASongFromPlaylist
(
const
Song
*
song
)
void
deleteASongFromPlaylist
(
const
struct
song
*
song
)
{
int
i
;
...
...
@@ -877,8 +880,8 @@ enum playlist_result playPlaylistById(int id, int stopOnError)
static
void
syncCurrentPlayerDecodeMetadata
(
void
)
{
S
ong
*
songPlayer
=
playerCurrentDecodeSong
();
S
ong
*
song
;
struct
s
ong
*
songPlayer
=
playerCurrentDecodeSong
();
struct
s
ong
*
song
;
int
songNum
;
char
path_max_tmp
[
MPD_PATH_MAX
];
...
...
@@ -1000,7 +1003,7 @@ void setPlaylistRepeatStatus(int status)
enum
playlist_result
moveSongInPlaylist
(
int
from
,
int
to
)
{
int
i
;
S
ong
*
tmpSong
;
struct
s
ong
*
tmpSong
;
int
tmpId
;
int
currentSong
;
...
...
@@ -1358,7 +1361,7 @@ int PlaylistInfo(struct client *client, const char *utf8file, int detail)
int
wrote
=
0
;
if
(
detail
)
{
S
ong
*
song
=
getSongFromDB
(
temp
);
struct
s
ong
*
song
=
getSongFromDB
(
temp
);
if
(
song
)
{
song_print_info
(
client
,
song
);
wrote
=
1
;
...
...
src/playlist.h
View file @
d562ba5f
...
...
@@ -21,9 +21,13 @@
#include "locate.h"
#include <stdio.h>
#define PLAYLIST_FILE_SUFFIX "m3u"
#define PLAYLIST_COMMENT '#'
struct
client
;
enum
playlist_result
{
PLAYLIST_RESULT_SUCCESS
,
PLAYLIST_RESULT_ERRNO
,
...
...
@@ -37,7 +41,7 @@ enum playlist_result {
};
typedef
struct
_Playlist
{
S
ong
**
songs
;
struct
s
ong
**
songs
;
/* holds version a song was modified on */
uint32_t
*
songMod
;
int
*
order
;
...
...
@@ -71,7 +75,8 @@ enum playlist_result addToPlaylist(const char *file, int *added_id);
int
addToStoredPlaylist
(
const
char
*
file
,
const
char
*
utf8file
);
enum
playlist_result
addSongToPlaylist
(
Song
*
song
,
int
*
added_id
);
enum
playlist_result
addSongToPlaylist
(
struct
song
*
song
,
int
*
added_id
);
void
showPlaylist
(
struct
client
*
client
);
...
...
@@ -101,7 +106,8 @@ enum playlist_result savePlaylist(const char *utf8file);
enum
playlist_result
deletePlaylist
(
const
char
*
utf8file
);
void
deleteASongFromPlaylist
(
const
Song
*
song
);
void
deleteASongFromPlaylist
(
const
struct
song
*
song
);
enum
playlist_result
moveSongInPlaylist
(
int
from
,
int
to
);
...
...
src/song.c
View file @
d562ba5f
...
...
@@ -28,11 +28,11 @@
#include "os_compat.h"
S
ong
*
struct
s
ong
*
song_alloc
(
const
char
*
url
,
struct
directory
*
parent
)
{
size_t
urllen
;
S
ong
*
song
;
struct
s
ong
*
song
;
assert
(
url
);
urllen
=
strlen
(
url
);
...
...
@@ -46,9 +46,10 @@ song_alloc(const char *url, struct directory *parent)
return
song
;
}
Song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
)
struct
song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
)
{
S
ong
*
song
;
struct
s
ong
*
song
;
assert
(
*
url
);
if
(
strchr
(
url
,
'\n'
))
{
...
...
@@ -79,14 +80,16 @@ Song *newSong(const char *url, struct directory *parentDir)
return
song
;
}
void
freeJustSong
(
Song
*
song
)
void
freeJustSong
(
struct
song
*
song
)
{
if
(
song
->
tag
)
tag_free
(
song
->
tag
);
free
(
song
);
}
int
updateSongInfo
(
Song
*
song
)
int
updateSongInfo
(
struct
song
*
song
)
{
if
(
song_is_file
(
song
))
{
struct
decoder_plugin
*
plugin
;
...
...
@@ -114,7 +117,8 @@ int updateSongInfo(Song * song)
return
0
;
}
char
*
get_song_url
(
char
*
path_max_tmp
,
Song
*
song
)
char
*
get_song_url
(
char
*
path_max_tmp
,
struct
song
*
song
)
{
if
(
!
song
)
return
NULL
;
...
...
src/song.h
View file @
d562ba5f
...
...
@@ -30,21 +30,24 @@
struct
client
;
typedef
struct
_S
ong
{
struct
s
ong
{
struct
tag
*
tag
;
struct
directory
*
parentDir
;
time_t
mtime
;
char
url
[
sizeof
(
size_t
)];
}
Song
;
};
S
ong
*
struct
s
ong
*
song_alloc
(
const
char
*
url
,
struct
directory
*
parent
);
Song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
);
struct
song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
);
void
freeJustSong
(
Song
*
);
void
freeJustSong
(
struct
song
*
);
int
updateSongInfo
(
Song
*
song
);
int
updateSongInfo
(
struct
song
*
song
);
/*
* get_song_url - Returns a path of a song in UTF8-encoded form
...
...
@@ -52,9 +55,11 @@ int updateSongInfo(Song * song);
* buffer is assumed to be MPD_PATH_MAX or greater (including
* terminating '\0').
*/
char
*
get_song_url
(
char
*
path_max_tmp
,
Song
*
song
);
char
*
get_song_url
(
char
*
path_max_tmp
,
struct
song
*
song
);
static
inline
int
song_is_file
(
const
Song
*
song
)
static
inline
int
song_is_file
(
const
struct
song
*
song
)
{
return
!!
song
->
parentDir
;
}
...
...
src/song_print.c
View file @
d562ba5f
...
...
@@ -17,12 +17,14 @@
*/
#include "song_print.h"
#include "song.h"
#include "songvec.h"
#include "directory.h"
#include "tag_print.h"
#include "client.h"
void
song_print_url
(
struct
client
*
client
,
Song
*
song
)
void
song_print_url
(
struct
client
*
client
,
struct
song
*
song
)
{
if
(
song
->
parentDir
&&
song
->
parentDir
->
path
)
{
client_printf
(
client
,
"%s%s/%s
\n
"
,
SONG_FILE
,
...
...
@@ -32,7 +34,8 @@ void song_print_url(struct client *client, Song * song)
}
}
int
song_print_info
(
struct
client
*
client
,
Song
*
song
)
int
song_print_info
(
struct
client
*
client
,
struct
song
*
song
)
{
song_print_url
(
client
,
song
);
...
...
@@ -43,7 +46,7 @@ int song_print_info(struct client *client, Song * song)
}
static
int
song_print_info_x
(
S
ong
*
song
,
void
*
data
)
song_print_info_x
(
struct
s
ong
*
song
,
void
*
data
)
{
struct
client
*
client
=
data
;
return
song_print_info
(
client
,
song
);
...
...
src/song_print.h
View file @
d562ba5f
...
...
@@ -19,14 +19,16 @@
#ifndef SONG_PRINT_H
#define SONG_PRINT_H
#include "song.h"
struct
client
;
struct
song
;
struct
songvec
;
int
song_print_info
(
struct
client
*
client
,
Song
*
song
);
int
song_print_info
(
struct
client
*
client
,
struct
song
*
song
);
int
songvec_print
(
struct
client
*
client
,
const
struct
songvec
*
sv
);
void
song_print_url
(
struct
client
*
client
,
Song
*
song
);
void
song_print_url
(
struct
client
*
client
,
struct
song
*
song
);
#endif
src/song_save.c
View file @
d562ba5f
...
...
@@ -17,6 +17,7 @@
*/
#include "song_save.h"
#include "song.h"
#include "tag_save.h"
#include "directory.h"
#include "path.h"
...
...
@@ -27,7 +28,8 @@
#define SONG_KEY "key: "
#define SONG_MTIME "mtime: "
static
void
song_save_url
(
FILE
*
fp
,
Song
*
song
)
static
void
song_save_url
(
FILE
*
fp
,
struct
song
*
song
)
{
if
(
song
->
parentDir
!=
NULL
&&
song
->
parentDir
->
path
!=
NULL
)
fprintf
(
fp
,
SONG_FILE
"%s/%s
\n
"
,
...
...
@@ -38,7 +40,7 @@ static void song_save_url(FILE *fp, Song * song)
}
static
int
song_save
(
S
ong
*
song
,
void
*
data
)
song_save
(
struct
s
ong
*
song
,
void
*
data
)
{
FILE
*
fp
=
data
;
...
...
@@ -61,9 +63,10 @@ void songvec_save(FILE *fp, struct songvec *sv)
fprintf
(
fp
,
"%s
\n
"
,
SONG_END
);
}
static
void
insertSongIntoList
(
struct
songvec
*
sv
,
Song
*
newsong
)
static
void
insertSongIntoList
(
struct
songvec
*
sv
,
struct
song
*
newsong
)
{
S
ong
*
existing
=
songvec_find
(
sv
,
newsong
->
url
);
struct
s
ong
*
existing
=
songvec_find
(
sv
,
newsong
->
url
);
if
(
!
existing
)
{
songvec_add
(
sv
,
newsong
);
...
...
@@ -102,7 +105,7 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
{
char
buffer
[
MPD_PATH_MAX
+
1024
];
int
bufferSize
=
MPD_PATH_MAX
+
1024
;
S
ong
*
song
=
NULL
;
struct
s
ong
*
song
=
NULL
;
int
itemType
;
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
&&
0
!=
strcmp
(
SONG_END
,
buffer
))
{
...
...
src/song_save.h
View file @
d562ba5f
...
...
@@ -19,9 +19,10 @@
#ifndef SONG_SAVE_H
#define SONG_SAVE_H
#include
"song.h"
#include
<stdio.h>
struct
songvec
;
struct
directory
;
void
songvec_save
(
FILE
*
fp
,
struct
songvec
*
sv
);
...
...
src/songvec.c
View file @
d562ba5f
#include "songvec.h"
#include "song.h"
#include "utils.h"
static
pthread_mutex_t
nr_lock
=
PTHREAD_MUTEX_INITIALIZER
;
...
...
@@ -6,28 +7,28 @@ static pthread_mutex_t nr_lock = PTHREAD_MUTEX_INITIALIZER;
/* Only used for sorting/searchin a songvec, not general purpose compares */
static
int
songvec_cmp
(
const
void
*
s1
,
const
void
*
s2
)
{
const
Song
*
a
=
((
const
S
ong
*
const
*
)
s1
)[
0
];
const
Song
*
b
=
((
const
S
ong
*
const
*
)
s2
)[
0
];
const
struct
song
*
a
=
((
const
struct
s
ong
*
const
*
)
s1
)[
0
];
const
struct
song
*
b
=
((
const
struct
s
ong
*
const
*
)
s2
)[
0
];
return
strcmp
(
a
->
url
,
b
->
url
);
}
static
size_t
sv_size
(
struct
songvec
*
sv
)
{
return
sv
->
nr
*
sizeof
(
S
ong
*
);
return
sv
->
nr
*
sizeof
(
struct
s
ong
*
);
}
void
songvec_sort
(
struct
songvec
*
sv
)
{
pthread_mutex_lock
(
&
nr_lock
);
qsort
(
sv
->
base
,
sv
->
nr
,
sizeof
(
S
ong
*
),
songvec_cmp
);
qsort
(
sv
->
base
,
sv
->
nr
,
sizeof
(
struct
s
ong
*
),
songvec_cmp
);
pthread_mutex_unlock
(
&
nr_lock
);
}
S
ong
*
struct
s
ong
*
songvec_find
(
const
struct
songvec
*
sv
,
const
char
*
url
)
{
int
i
;
S
ong
*
ret
=
NULL
;
struct
s
ong
*
ret
=
NULL
;
pthread_mutex_lock
(
&
nr_lock
);
for
(
i
=
sv
->
nr
;
--
i
>=
0
;
)
{
...
...
@@ -40,7 +41,8 @@ songvec_find(const struct songvec *sv, const char *url)
return
ret
;
}
int
songvec_delete
(
struct
songvec
*
sv
,
const
Song
*
del
)
int
songvec_delete
(
struct
songvec
*
sv
,
const
struct
song
*
del
)
{
int
i
;
...
...
@@ -54,7 +56,7 @@ int songvec_delete(struct songvec *sv, const Song *del)
sv
->
base
=
NULL
;
}
else
{
memmove
(
&
sv
->
base
[
i
],
&
sv
->
base
[
i
+
1
],
(
sv
->
nr
-
i
+
1
)
*
sizeof
(
S
ong
*
));
(
sv
->
nr
-
i
+
1
)
*
sizeof
(
struct
s
ong
*
));
sv
->
base
=
xrealloc
(
sv
->
base
,
sv_size
(
sv
));
}
break
;
...
...
@@ -64,7 +66,8 @@ int songvec_delete(struct songvec *sv, const Song *del)
return
i
;
}
void
songvec_add
(
struct
songvec
*
sv
,
Song
*
add
)
void
songvec_add
(
struct
songvec
*
sv
,
struct
song
*
add
)
{
pthread_mutex_lock
(
&
nr_lock
);
++
sv
->
nr
;
...
...
@@ -86,13 +89,13 @@ void songvec_destroy(struct songvec *sv)
int
songvec_for_each
(
const
struct
songvec
*
sv
,
int
(
*
fn
)(
S
ong
*
,
void
*
),
void
*
arg
)
int
(
*
fn
)(
struct
s
ong
*
,
void
*
),
void
*
arg
)
{
size_t
i
;
pthread_mutex_lock
(
&
nr_lock
);
for
(
i
=
0
;
i
<
sv
->
nr
;
++
i
)
{
S
ong
*
song
=
sv
->
base
[
i
];
struct
s
ong
*
song
=
sv
->
base
[
i
];
assert
(
song
);
assert
(
*
song
->
url
);
...
...
src/songvec.h
View file @
d562ba5f
#ifndef SONGVEC_H
#define SONGVEC_H
#include "song.h"
#include "os_compat.h"
struct
songvec
{
S
ong
**
base
;
struct
s
ong
**
base
;
size_t
nr
;
};
void
songvec_sort
(
struct
songvec
*
sv
);
S
ong
*
struct
s
ong
*
songvec_find
(
const
struct
songvec
*
sv
,
const
char
*
url
);
int
songvec_delete
(
struct
songvec
*
sv
,
const
Song
*
del
);
int
songvec_delete
(
struct
songvec
*
sv
,
const
struct
song
*
del
);
void
songvec_add
(
struct
songvec
*
sv
,
Song
*
add
);
void
songvec_add
(
struct
songvec
*
sv
,
struct
song
*
add
);
void
songvec_destroy
(
struct
songvec
*
sv
);
int
songvec_for_each
(
const
struct
songvec
*
sv
,
int
(
*
fn
)(
S
ong
*
,
void
*
),
void
*
arg
);
int
(
*
fn
)(
struct
s
ong
*
,
void
*
),
void
*
arg
);
#endif
/* SONGVEC_H */
src/stats.c
View file @
d562ba5f
...
...
@@ -21,6 +21,7 @@
#include "directory.h"
#include "tag.h"
#include "song.h"
#include "client.h"
#include "player_control.h"
#include "strset.h"
...
...
@@ -39,7 +40,8 @@ struct visit_data {
struct
strset
*
set
;
};
static
int
visit_tag_items
(
Song
*
song
,
void
*
_data
)
static
int
visit_tag_items
(
struct
song
*
song
,
void
*
_data
)
{
const
struct
visit_data
*
data
=
_data
;
unsigned
i
;
...
...
src/storedPlaylist.c
View file @
d562ba5f
...
...
@@ -17,6 +17,7 @@
*/
#include "storedPlaylist.h"
#include "song.h"
#include "path.h"
#include "utils.h"
#include "ls.h"
...
...
@@ -107,7 +108,7 @@ List *loadStoredPlaylist(const char *utf8path)
while
(
myFgets
(
buffer
,
sizeof
(
buffer
),
file
))
{
char
*
s
=
buffer
;
S
ong
*
song
;
struct
s
ong
*
song
;
if
(
*
s
==
PLAYLIST_COMMENT
)
continue
;
...
...
@@ -260,7 +261,7 @@ removeOneSongFromStoredPlaylistByPath(const char *utf8path, int pos)
}
enum
playlist_result
appendSongToStoredPlaylistByPath
(
const
char
*
utf8path
,
S
ong
*
song
)
appendSongToStoredPlaylistByPath
(
const
char
*
utf8path
,
struct
s
ong
*
song
)
{
FILE
*
file
;
char
*
s
;
...
...
src/storedPlaylist.h
View file @
d562ba5f
...
...
@@ -19,10 +19,11 @@
#ifndef STORED_PLAYLIST_H
#define STORED_PLAYLIST_H
#include "song.h"
#include "list.h"
#include "playlist.h"
struct
song
;
List
*
loadStoredPlaylist
(
const
char
*
utf8path
);
enum
playlist_result
...
...
@@ -35,7 +36,7 @@ enum playlist_result
removeOneSongFromStoredPlaylistByPath
(
const
char
*
utf8path
,
int
pos
);
enum
playlist_result
appendSongToStoredPlaylistByPath
(
const
char
*
utf8path
,
S
ong
*
song
);
appendSongToStoredPlaylistByPath
(
const
char
*
utf8path
,
struct
s
ong
*
song
);
enum
playlist_result
renameStoredPlaylist
(
const
char
*
utf8from
,
const
char
*
utf8to
);
...
...
src/update.c
View file @
d562ba5f
...
...
@@ -19,6 +19,7 @@
#include "update.h"
#include "directory.h"
#include "song.h"
#include "log.h"
#include "ls.h"
#include "path.h"
...
...
@@ -45,7 +46,7 @@ static const int update_task_id_max = 1 << 15;
static
int
update_task_id
;
static
S
ong
*
delete
;
static
struct
s
ong
*
delete
;
static
struct
condition
delete_cond
;
...
...
@@ -63,7 +64,7 @@ directory_set_stat(struct directory *dir, const struct stat *st)
}
static
void
delete_song
(
struct
directory
*
dir
,
S
ong
*
del
)
delete_song
(
struct
directory
*
dir
,
struct
s
ong
*
del
)
{
/* first, prevent traversers in main task from getting this */
songvec_delete
(
&
dir
->
songs
,
del
);
...
...
@@ -87,7 +88,8 @@ struct delete_data {
};
/* passed to songvec_for_each */
static
int
delete_song_if_removed
(
Song
*
song
,
void
*
_data
)
static
int
delete_song_if_removed
(
struct
song
*
song
,
void
*
_data
)
{
struct
delete_data
*
data
=
_data
;
...
...
@@ -196,7 +198,7 @@ addToDirectory(struct directory *directory, const char *name)
if
(
S_ISREG
(
st
.
st_mode
)
&&
hasMusicSuffix
(
name
,
0
)
&&
isMusic
(
name
,
NULL
,
0
))
{
S
ong
*
song
;
struct
s
ong
*
song
;
const
char
*
shortname
=
mpd_basename
(
name
);
if
(
!
(
song
=
newSong
(
shortname
,
directory
)))
...
...
@@ -216,7 +218,7 @@ addToDirectory(struct directory *directory, const char *name)
static
enum
update_return
updateInDirectory
(
struct
directory
*
directory
,
const
char
*
name
)
{
S
ong
*
song
;
struct
s
ong
*
song
;
struct
stat
st
;
if
(
myStat
(
name
,
&
st
))
...
...
@@ -313,7 +315,7 @@ addDirectoryPathToDB(const char *utf8path)
char
*
parent
;
struct
directory
*
parentDirectory
;
struct
directory
*
directory
;
S
ong
*
conflicting
;
struct
s
ong
*
conflicting
;
parent
=
parent_path
(
path_max_tmp
,
utf8path
);
...
...
@@ -372,7 +374,7 @@ static enum update_return updatePath(const char *utf8path)
{
struct
directory
*
directory
;
struct
directory
*
parentDirectory
;
S
ong
*
song
;
struct
s
ong
*
song
;
char
*
path
=
sanitizePathDup
(
utf8path
);
time_t
mtime
;
enum
update_return
ret
=
UPDATE_RETURN_NOUPDATE
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment