[MPlayer-cvslog] r37994 - in trunk: Changelog DOCS/man/de/mplayer.1 DOCS/man/en/mplayer.1 gui/app/cfg.c gui/interface.c gui/util/list.c gui/util/list.h
ib
subversion at mplayerhq.hu
Tue Oct 10 19:56:43 EEST 2017
Author: ib
Date: Tue Oct 10 19:56:43 2017
New Revision: 37994
Log:
Enable ReplayGain for files without ReplayGain data.
The GUI will receive ReplayGain information from the audio stream, if
such data has been stored in the file. Files without such data do not
have to be modified, if the new configuration file gui.gain is used.
If gui.gain exists, the GUI will read it at startup and expects a plain
text file containing a float value (the ReplayGain) followed by a space
character and a full filename. Later, whenever playing the file with
this name, it will apply the given gain.
Please note, that an entry in gui.gain takes precedence over ReplayGain
data stored in the file, and that it is recommended to sort gui.gain by
descending filenames in order to speed up parsing.
Add listMgr command GAINLIST_ITEM_INSERT to create a sorted linked list
of the filenames and listMgr command GAINLIST_ITEM_FIND for a quick,
binary search.
Additionally, update man pages and add a changelog information.
Modified:
trunk/Changelog
trunk/gui/app/cfg.c
trunk/gui/interface.c
trunk/gui/util/list.c
trunk/gui/util/list.h
Changes in other areas also in this revision:
Modified:
trunk/DOCS/man/de/mplayer.1
trunk/DOCS/man/en/mplayer.1
Modified: trunk/Changelog
==============================================================================
--- trunk/Changelog Tue Oct 10 17:31:51 2017 (r37993)
+++ trunk/Changelog Tue Oct 10 19:56:43 2017 (r37994)
@@ -33,6 +33,7 @@ MPlayer
* Implementation of audio playback utilizing ReplayGain data
* New symbol character 'g' and new dynamic label variable $g
* Skins can leave current volume unchanged at startup
+ * New configuration file: gui.gain
1.3.0: "worksforme" February 16, 2016
Modified: trunk/gui/app/cfg.c
==============================================================================
--- trunk/gui/app/cfg.c Tue Oct 10 17:31:51 2017 (r37993)
+++ trunk/gui/app/cfg.c Tue Oct 10 19:56:43 2017 (r37994)
@@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -111,6 +112,7 @@ char *skinName;
char *fsHistory[5];
static const char gui_configuration[] = "gui.conf";
+static const char gui_gainlist[] = "gui.gain";
static const char gui_history[] = "gui.history";
static const char gui_playlist[] = "gui.pl";
static const char gui_urllist[] = "gui.url";
@@ -365,6 +367,39 @@ void cfg_read(void)
fclose(file);
}
+
+ free(fname);
+
+ /* ReplayGain list */
+
+ fname = get_path(gui_gainlist);
+ file = fopen(fname, "rt");
+
+ if (file) {
+ while (fgetstr(line, sizeof(line), file)) {
+ char *space = strchr(line, ' ');
+
+ if (space) {
+ float gain;
+
+ *space = 0;
+ errno = 0;
+ gain = strtof(line, NULL);
+
+ if (errno == 0) {
+ gainItem *item = calloc(1, sizeof(*item));
+
+ if (item) {
+ item->filename = strdup(space + 1);
+ item->replay_gain = gain;
+ listMgr(GAINLIST_ITEM_INSERT, item);
+ }
+ }
+ }
+ }
+
+ fclose(file);
+ }
free(fname);
}
Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c Tue Oct 10 17:31:51 2017 (r37993)
+++ trunk/gui/interface.c Tue Oct 10 19:56:43 2017 (r37994)
@@ -927,7 +927,20 @@ int gui(int what, void *data)
}
if (gtkReplayGainOn) {
- if (demux_control(mpctx_get_demuxer(guiInfo.mpcontext), DEMUXER_CTRL_GET_REPLAY_GAIN, &replay_gain) == DEMUXER_CTRL_OK) {
+ gainItem *item;
+ int ReplayGain = False;
+
+ item = listMgr(GAINLIST_ITEM_FIND, guiInfo.Filename);
+
+ if (item) {
+ replay_gain = (item->replay_gain < 0.0f ? item->replay_gain - 0.05f : item->replay_gain + 0.05f) * 10;
+ ReplayGain = True;
+ }
+
+ if (!ReplayGain)
+ ReplayGain = (demux_control(mpctx_get_demuxer(guiInfo.mpcontext), DEMUXER_CTRL_GET_REPLAY_GAIN, &replay_gain) == DEMUXER_CTRL_OK);
+
+ if (ReplayGain) {
guiInfo.LastVolume = guiInfo.Volume;
guiInfo.Volume = constrain(100.0 + (replay_gain / 10.0 + gtkReplayGainAdjustment) / 0.5);
guiInfo.ReplayGainVolume = -1.0f;
Modified: trunk/gui/util/list.c
==============================================================================
--- trunk/gui/util/list.c Tue Oct 10 17:31:51 2017 (r37993)
+++ trunk/gui/util/list.c Tue Oct 10 19:56:43 2017 (r37994)
@@ -33,6 +33,9 @@
#include "mp_msg.h"
#include "path.h"
+static gainItem *gainList;
+static unsigned int gainCount;
+
static plItem *plList;
static plItem *plCurrent;
@@ -42,7 +45,7 @@ static urlItem *urlList;
* @brief Manage playlists and URL lists.
*
* @param cmd task to be performed
- * @param data list item for the task
+ * @param data list item (or string in case of GAINLIST_ITEM_FIND) for the task
*
* @return pointer to top of list (GET command),
* pointer to current list item (ITEM command),
@@ -56,11 +59,66 @@ static urlItem *urlList;
void *listMgr(int cmd, void *data)
{
uintptr_t pos;
+ gainItem *gdat = (gainItem *)data;
+ char *cdat = (char *)data;
plItem *pdat = (plItem *)data;
urlItem *udat = (urlItem *)data;
plItem *item;
switch (cmd) {
+ /* ReplayGain list (sorted) */
+
+ case GAINLIST_ITEM_INSERT:
+
+ if (!gainList || (strcmp(gainList->filename, gdat->filename) >= 0)) {
+ gdat->next = gainList;
+ gainList = gdat;
+ } else {
+ gainItem *item = gainList;
+
+ while (item->next && (strcmp(item->next->filename, gdat->filename) < 0))
+ item = item->next;
+
+ gdat->next = item->next;
+ item->next = gdat;
+ }
+
+ gainCount++;
+ return gdat;
+
+ case GAINLIST_ITEM_FIND:
+
+ if (!gainList || (strcmp(gainList->filename, cdat) == 0))
+ return gainList;
+ else {
+ gainItem *left = gainList, *right = NULL;
+ unsigned int count = gainCount;
+
+ while (count > 1) {
+ int cmp;
+ unsigned int i, newcount = count / 2;
+
+ right = left;
+
+ for (i = 0; i < newcount && right->next != NULL; i++)
+ right = right->next;
+
+ cmp = strcmp(right->filename, cdat);
+
+ if (cmp == 0)
+ return right;
+ else if (cmp < 0)
+ left = right;
+
+ count -= newcount;
+ }
+
+ if (right && (strcmp(right->filename, cdat) == 0))
+ return right;
+ else
+ return NULL;
+ }
+
/* playlist */
case PLAYLIST_GET:
Modified: trunk/gui/util/list.h
==============================================================================
--- trunk/gui/util/list.h Tue Oct 10 17:31:51 2017 (r37993)
+++ trunk/gui/util/list.h Tue Oct 10 19:56:43 2017 (r37994)
@@ -21,6 +21,8 @@
/// listMgr() commands
enum {
+ GAINLIST_ITEM_INSERT,
+ GAINLIST_ITEM_FIND,
PLAYLIST_GET,
PLAYLIST_ITEM_APPEND,
PLAYLIST_ITEM_INSERT,
@@ -40,6 +42,12 @@ enum {
URLLIST_DELETE
};
+typedef struct gainItem {
+ char *filename;
+ float replay_gain;
+ struct gainItem *next;
+} gainItem;
+
typedef struct plItem {
char *path;
char *name;
More information about the MPlayer-cvslog
mailing list