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
0720702c
Commit
0720702c
authored
Nov 24, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplayGainMode: add ToString(), FromString()
Move code from ReplayGainConfig.cxx.
parent
5f396e82
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
69 deletions
+91
-69
Makefile.am
Makefile.am
+1
-1
ReplayGainConfig.cxx
src/ReplayGainConfig.cxx
+7
-45
ReplayGainConfig.hxx
src/ReplayGainConfig.hxx
+0
-16
ReplayGainMode.cxx
src/ReplayGainMode.cxx
+63
-0
ReplayGainMode.hxx
src/ReplayGainMode.hxx
+17
-0
PlayerCommands.cxx
src/command/PlayerCommands.cxx
+3
-7
No files found.
Makefile.am
View file @
0720702c
...
...
@@ -853,7 +853,7 @@ libbasic_a_SOURCES = \
src/CheckAudioFormat.cxx src/CheckAudioFormat.hxx
\
src/AudioFormat.cxx src/AudioFormat.hxx
\
src/AudioParser.cxx src/AudioParser.hxx
\
src/ReplayGainMode.hxx
\
src/ReplayGainMode.
cxx src/ReplayGainMode.
hxx
\
src/ReplayGainInfo.cxx src/ReplayGainInfo.hxx
# configuration library
...
...
src/ReplayGainConfig.cxx
View file @
0720702c
...
...
@@ -22,10 +22,10 @@
#include "config/Param.hxx"
#include "config/ConfigGlobal.hxx"
#include "system/FatalError.hxx"
#include "util/RuntimeError.hxx"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
ReplayGainMode
replay_gain_mode
=
ReplayGainMode
::
OFF
;
...
...
@@ -36,54 +36,16 @@ float replay_gain_preamp = 1.0;
float
replay_gain_missing_preamp
=
1.0
;
bool
replay_gain_limit
=
DEFAULT_REPLAYGAIN_LIMIT
;
const
char
*
replay_gain_get_mode_string
(
void
)
{
switch
(
replay_gain_mode
)
{
case
ReplayGainMode
:
:
AUTO
:
return
"auto"
;
case
ReplayGainMode
:
:
OFF
:
return
"off"
;
case
ReplayGainMode
:
:
TRACK
:
return
"track"
;
case
ReplayGainMode
:
:
ALBUM
:
return
"album"
;
}
assert
(
false
);
gcc_unreachable
();
}
bool
replay_gain_set_mode_string
(
const
char
*
p
)
{
assert
(
p
!=
nullptr
);
if
(
strcmp
(
p
,
"off"
)
==
0
)
replay_gain_mode
=
ReplayGainMode
::
OFF
;
else
if
(
strcmp
(
p
,
"track"
)
==
0
)
replay_gain_mode
=
ReplayGainMode
::
TRACK
;
else
if
(
strcmp
(
p
,
"album"
)
==
0
)
replay_gain_mode
=
ReplayGainMode
::
ALBUM
;
else
if
(
strcmp
(
p
,
"auto"
)
==
0
)
replay_gain_mode
=
ReplayGainMode
::
AUTO
;
else
return
false
;
return
true
;
}
void
replay_gain_global_init
(
void
)
{
const
auto
*
param
=
config_get_param
(
ConfigOption
::
REPLAYGAIN
);
if
(
param
!=
nullptr
&&
!
replay_gain_set_mode_string
(
param
->
value
.
c_str
()))
{
FormatFatalError
(
"replaygain value
\"
%s
\"
at line %i is invalid
\n
"
,
param
->
value
.
c_str
(),
param
->
line
);
try
{
if
(
param
!=
nullptr
)
replay_gain_mode
=
FromString
(
param
->
value
.
c_str
());
}
catch
(...)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to parse line %i"
,
param
->
line
));
}
param
=
config_get_param
(
ConfigOption
::
REPLAYGAIN_PREAMP
);
...
...
src/ReplayGainConfig.hxx
View file @
0720702c
...
...
@@ -22,7 +22,6 @@
#include "check.h"
#include "ReplayGainMode.hxx"
#include "Compiler.h"
extern
ReplayGainMode
replay_gain_mode
;
extern
float
replay_gain_preamp
;
...
...
@@ -32,19 +31,4 @@ extern bool replay_gain_limit;
void
replay_gain_global_init
();
/**
* Returns the current replay gain mode as a machine-readable string.
*/
gcc_pure
const
char
*
replay_gain_get_mode_string
();
/**
* Sets the replay gain mode, parsed from a string.
*
* @return true on success, false if the string could not be parsed
*/
bool
replay_gain_set_mode_string
(
const
char
*
p
);
#endif
src/ReplayGainMode.cxx
0 → 100644
View file @
0720702c
/*
* Copyright 2003-2016 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "ReplayGainMode.hxx"
#include <stdexcept>
#include <assert.h>
#include <string.h>
const
char
*
ToString
(
ReplayGainMode
mode
)
{
switch
(
mode
)
{
case
ReplayGainMode
:
:
AUTO
:
return
"auto"
;
case
ReplayGainMode
:
:
OFF
:
return
"off"
;
case
ReplayGainMode
:
:
TRACK
:
return
"track"
;
case
ReplayGainMode
:
:
ALBUM
:
return
"album"
;
}
assert
(
false
);
gcc_unreachable
();
}
ReplayGainMode
FromString
(
const
char
*
s
)
{
assert
(
s
!=
nullptr
);
if
(
strcmp
(
s
,
"off"
)
==
0
)
return
ReplayGainMode
::
OFF
;
else
if
(
strcmp
(
s
,
"track"
)
==
0
)
return
ReplayGainMode
::
TRACK
;
else
if
(
strcmp
(
s
,
"album"
)
==
0
)
return
ReplayGainMode
::
ALBUM
;
else
if
(
strcmp
(
s
,
"auto"
)
==
0
)
return
ReplayGainMode
::
AUTO
;
else
throw
std
::
invalid_argument
(
"Unrecognized replay gain mode"
);
}
src/ReplayGainMode.hxx
View file @
0720702c
...
...
@@ -20,6 +20,8 @@
#ifndef MPD_REPLAY_GAIN_MODE_HXX
#define MPD_REPLAY_GAIN_MODE_HXX
#include "Compiler.h"
#include <stdint.h>
enum
class
ReplayGainMode
:
uint8_t
{
...
...
@@ -29,4 +31,19 @@ enum class ReplayGainMode : uint8_t {
AUTO
,
};
/**
* Return the string representation of a #ReplayGainMode.
*/
gcc_pure
const
char
*
ToString
(
ReplayGainMode
mode
);
/**
* Parse a string to a #ReplayGainMode. Throws std::runtime_error on
* error.
*/
gcc_pure
ReplayGainMode
FromString
(
const
char
*
s
);
#endif
src/command/PlayerCommands.cxx
View file @
0720702c
...
...
@@ -331,13 +331,9 @@ handle_mixrampdelay(Client &client, Request args, gcc_unused Response &r)
}
CommandResult
handle_replay_gain_mode
(
Client
&
client
,
Request
args
,
Response
&
r
)
handle_replay_gain_mode
(
Client
&
client
,
Request
args
,
Response
&
)
{
if
(
!
replay_gain_set_mode_string
(
args
.
front
()))
{
r
.
Error
(
ACK_ERROR_ARG
,
"Unrecognized replay gain mode"
);
return
CommandResult
::
ERROR
;
}
replay_gain_mode
=
FromString
(
args
.
front
());
client
.
partition
.
UpdateEffectiveReplayGainMode
(
replay_gain_mode
);
client
.
partition
.
EmitIdle
(
IDLE_OPTIONS
);
return
CommandResult
::
OK
;
...
...
@@ -347,6 +343,6 @@ CommandResult
handle_replay_gain_status
(
gcc_unused
Client
&
client
,
gcc_unused
Request
args
,
Response
&
r
)
{
r
.
Format
(
"replay_gain_mode: %s
\n
"
,
replay_gain_get_mode_string
(
));
r
.
Format
(
"replay_gain_mode: %s
\n
"
,
ToString
(
replay_gain_mode
));
return
CommandResult
::
OK
;
}
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