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
110589c0
Commit
110589c0
authored
Dec 04, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/sidplay: merge get_container_name() and get_song_num()
parent
34003982
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
48 deletions
+36
-48
SidplayDecoderPlugin.cxx
src/decoder/plugins/SidplayDecoderPlugin.cxx
+36
-48
No files found.
src/decoder/plugins/SidplayDecoderPlugin.cxx
View file @
110589c0
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include "../DecoderAPI.hxx"
#include "../DecoderAPI.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagHandler.hxx"
#include "fs/Path.hxx"
#include "fs/Path.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/FormatString.hxx"
#include "util/FormatString.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "system/ByteOrder.hxx"
#include "system/ByteOrder.hxx"
...
@@ -40,7 +41,6 @@
...
@@ -40,7 +41,6 @@
static
constexpr
Domain
sidplay_domain
(
"sidplay"
);
static
constexpr
Domain
sidplay_domain
(
"sidplay"
);
static
GPatternSpec
*
path_with_subtune
;
static
const
char
*
songlength_file
;
static
const
char
*
songlength_file
;
static
GKeyFile
*
songlength_database
;
static
GKeyFile
*
songlength_database
;
...
@@ -99,9 +99,6 @@ sidplay_init(const config_param ¶m)
...
@@ -99,9 +99,6 @@ sidplay_init(const config_param ¶m)
all_files_are_containers
=
all_files_are_containers
=
param
.
GetBlockValue
(
"all_files_are_containers"
,
true
);
param
.
GetBlockValue
(
"all_files_are_containers"
,
true
);
path_with_subtune
=
g_pattern_spec_new
(
"*/"
SUBTUNE_PREFIX
"???.sid"
);
filter_setting
=
param
.
GetBlockValue
(
"filter"
,
true
);
filter_setting
=
param
.
GetBlockValue
(
"filter"
,
true
);
return
true
;
return
true
;
...
@@ -110,52 +107,46 @@ sidplay_init(const config_param ¶m)
...
@@ -110,52 +107,46 @@ sidplay_init(const config_param ¶m)
static
void
static
void
sidplay_finish
()
sidplay_finish
()
{
{
g_pattern_spec_free
(
path_with_subtune
);
if
(
songlength_database
)
if
(
songlength_database
)
g_key_file_free
(
songlength_database
);
g_key_file_free
(
songlength_database
);
}
}
/**
struct
SidplayContainerPath
{
* returns the file path stripped of any /tune_xxx.sid subtune
AllocatedPath
path
;
* suffix
unsigned
track
;
*/
};
static
char
*
get_container_name
(
Path
path_fs
)
gcc_pure
static
unsigned
ParseSubtuneName
(
const
char
*
base
)
{
{
char
*
path_container
=
strdup
(
path_fs
.
c_str
());
if
(
memcmp
(
base
,
SUBTUNE_PREFIX
,
sizeof
(
SUBTUNE_PREFIX
)
-
1
)
!=
0
)
return
0
;
if
(
!
g_pattern_match
(
path_with_subtune
,
base
+=
sizeof
(
SUBTUNE_PREFIX
)
-
1
;
strlen
(
path_container
),
path_container
,
nullptr
))
return
path_container
;
char
*
ptr
=
g_strrstr
(
path_container
,
"/"
SUBTUNE_PREFIX
);
char
*
endptr
;
if
(
ptr
)
*
ptr
=
'\0'
;
auto
track
=
strtoul
(
base
,
&
endptr
,
10
);
if
(
endptr
==
base
||
*
endptr
!=
'.'
)
return
0
;
return
path_container
;
return
track
;
}
}
/**
/**
* returns t
une number from file.sid/tune_xxx.sid style path or 1 if
* returns t
he file path stripped of any /tune_xxx.* subtune suffix
*
no subtune is appended
*
and the track number (or 1 if no "tune_xxx" suffix is present).
*/
*/
static
unsigned
static
SidplayContainerPath
get_song_num
(
const
char
*
path_fs
)
ParseContainerPath
(
Path
path_fs
)
{
{
if
(
g_pattern_match
(
path_with_subtune
,
const
Path
base
=
path_fs
.
GetBase
();
strlen
(
path_fs
),
path_fs
,
nullptr
))
{
unsigned
track
;
char
*
sub
=
g_strrstr
(
path_fs
,
"/"
SUBTUNE_PREFIX
);
if
(
base
.
IsNull
()
||
if
(
!
sub
)
return
1
;
(
track
=
ParseSubtuneName
(
base
.
c_str
()))
<
1
)
return
{
AllocatedPath
(
path_fs
),
1
};
sub
+=
strlen
(
"/"
SUBTUNE_PREFIX
);
return
{
path_fs
.
GetDirectoryName
(),
track
};
int
song_num
=
strtol
(
sub
,
nullptr
,
10
);
if
(
errno
==
EINVAL
)
return
1
;
else
return
song_num
;
}
else
return
1
;
}
}
/* get the song length in seconds */
/* get the song length in seconds */
...
@@ -165,9 +156,8 @@ get_song_length(Path path_fs)
...
@@ -165,9 +156,8 @@ get_song_length(Path path_fs)
if
(
songlength_database
==
nullptr
)
if
(
songlength_database
==
nullptr
)
return
SignedSongTime
::
Negative
();
return
SignedSongTime
::
Negative
();
char
*
sid_file
=
get_container_name
(
path_fs
);
const
auto
container
=
ParseContainerPath
(
path_fs
);
SidTuneMod
tune
(
sid_file
);
SidTuneMod
tune
(
container
.
path
.
c_str
());
free
(
sid_file
);
if
(
!
tune
)
{
if
(
!
tune
)
{
LogWarning
(
sidplay_domain
,
LogWarning
(
sidplay_domain
,
"failed to load file for calculating md5 sum"
);
"failed to load file for calculating md5 sum"
);
...
@@ -176,7 +166,7 @@ get_song_length(Path path_fs)
...
@@ -176,7 +166,7 @@ get_song_length(Path path_fs)
char
md5sum
[
SIDTUNE_MD5_LENGTH
+
1
];
char
md5sum
[
SIDTUNE_MD5_LENGTH
+
1
];
tune
.
createMD5
(
md5sum
);
tune
.
createMD5
(
md5sum
);
const
unsigned
song_num
=
get_song_num
(
path_fs
.
c_str
())
;
const
unsigned
song_num
=
container
.
track
;
gsize
num_items
;
gsize
num_items
;
gchar
**
values
=
g_key_file_get_string_list
(
songlength_database
,
gchar
**
values
=
g_key_file_get_string_list
(
songlength_database
,
...
@@ -209,15 +199,14 @@ sidplay_file_decode(Decoder &decoder, Path path_fs)
...
@@ -209,15 +199,14 @@ sidplay_file_decode(Decoder &decoder, Path path_fs)
/* load the tune */
/* load the tune */
char
*
path_container
=
get_container_name
(
path_fs
);
const
auto
container
=
ParseContainerPath
(
path_fs
);
SidTune
tune
(
path_container
,
nullptr
,
true
);
SidTune
tune
(
container
.
path
.
c_str
(),
nullptr
,
true
);
free
(
path_container
);
if
(
!
tune
)
{
if
(
!
tune
)
{
LogWarning
(
sidplay_domain
,
"failed to load file"
);
LogWarning
(
sidplay_domain
,
"failed to load file"
);
return
;
return
;
}
}
const
int
song_num
=
get_song_num
(
path_fs
.
c_str
())
;
const
int
song_num
=
container
.
track
;
tune
.
selectSong
(
song_num
);
tune
.
selectSong
(
song_num
);
auto
duration
=
get_song_length
(
path_fs
);
auto
duration
=
get_song_length
(
path_fs
);
...
@@ -347,11 +336,10 @@ static bool
...
@@ -347,11 +336,10 @@ static bool
sidplay_scan_file
(
Path
path_fs
,
sidplay_scan_file
(
Path
path_fs
,
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
{
{
const
int
song_num
=
get_song_num
(
path_fs
.
c_str
()
);
const
auto
container
=
ParseContainerPath
(
path_fs
);
c
har
*
path_container
=
get_container_name
(
path_fs
)
;
c
onst
unsigned
song_num
=
container
.
track
;
SidTune
tune
(
path_container
,
nullptr
,
true
);
SidTune
tune
(
container
.
path
.
c_str
(),
nullptr
,
true
);
free
(
path_container
);
if
(
!
tune
)
if
(
!
tune
)
return
false
;
return
false
;
...
...
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