mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
Add HTML5 ReplayGain Track support
This commit is contained in:
parent
e911ae8815
commit
33bb01afbf
10 changed files with 160 additions and 42 deletions
BIN
images/icon_replaygain.png
Normal file
BIN
images/icon_replaygain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -166,6 +166,22 @@ class Song extends database_object implements media, library_item
|
||||||
* @var string $lyrics
|
* @var string $lyrics
|
||||||
*/
|
*/
|
||||||
public $lyrics;
|
public $lyrics;
|
||||||
|
/**
|
||||||
|
* @var float $replaygain_track_gain
|
||||||
|
*/
|
||||||
|
public $replaygain_track_gain;
|
||||||
|
/**
|
||||||
|
* @var float $replaygain_track_peak
|
||||||
|
*/
|
||||||
|
public $replaygain_track_peak;
|
||||||
|
/**
|
||||||
|
* @var float $replaygain_album_gain
|
||||||
|
*/
|
||||||
|
public $replaygain_album_gain;
|
||||||
|
/**
|
||||||
|
* @var float $replaygain_album_peak
|
||||||
|
*/
|
||||||
|
public $replaygain_album_peak;
|
||||||
/**
|
/**
|
||||||
* @var string $f_title
|
* @var string $f_title
|
||||||
*/
|
*/
|
||||||
|
@ -338,6 +354,10 @@ class Song extends database_object implements media, library_item
|
||||||
$language = isset($results['language']) ? $results['language'] : null;
|
$language = isset($results['language']) ? $results['language'] : null;
|
||||||
$channels = $results['channels'] ?: 0;
|
$channels = $results['channels'] ?: 0;
|
||||||
$release_type = isset($results['release_type']) ? $results['release_type'] : null;
|
$release_type = isset($results['release_type']) ? $results['release_type'] : null;
|
||||||
|
$replaygain_track_gain = isset($results['replaygain_track_gain']) ? $results['replaygain_track_gain'] : null;
|
||||||
|
$replaygain_track_peak = isset($results['replaygain_track_peak']) ? $results['replaygain_track_peak'] : null;
|
||||||
|
$replaygain_album_gain = isset($results['replaygain_album_gain']) ? $results['replaygain_album_gain'] : null;
|
||||||
|
$replaygain_album_peak = isset($results['replaygain_album_peak']) ? $results['replaygain_album_peak'] : null;
|
||||||
|
|
||||||
$artist_id = Artist::check($artist, $artist_mbid);
|
$artist_id = Artist::check($artist, $artist_mbid);
|
||||||
$album_artist_id = null;
|
$album_artist_id = null;
|
||||||
|
@ -376,9 +396,9 @@ class Song extends database_object implements media, library_item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'INSERT INTO `song_data` (`song_id`, `comment`, `lyrics`, `label`, `language`, `catalog_number`) ' .
|
$sql = 'INSERT INTO `song_data` (`song_id`, `comment`, `lyrics`, `label`, `language`, `catalog_number`, `replaygain_track_gain`, `replaygain_track_peak`, `replaygain_album_gain`, `replaygain_album_peak`) ' .
|
||||||
'VALUES(?, ?, ?, ?, ?, ?)';
|
'VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
Dba::write($sql, array($song_id, $comment, $lyrics, $label, $language, $catalog_number));
|
Dba::write($sql, array($song_id, $comment, $lyrics, $label, $language, $catalog_number, $replaygain_track_gain, $replaygain_track_peak, $replaygain_album_gain, $replaygain_album_peak));
|
||||||
|
|
||||||
return $song_id;
|
return $song_id;
|
||||||
}
|
}
|
||||||
|
@ -888,37 +908,22 @@ class Song extends database_object implements media, library_item
|
||||||
*/
|
*/
|
||||||
public static function update_song($song_id, Song $new_song)
|
public static function update_song($song_id, Song $new_song)
|
||||||
{
|
{
|
||||||
$title = Dba::escape($new_song->title);
|
|
||||||
$bitrate = Dba::escape($new_song->bitrate);
|
|
||||||
$rate = Dba::escape($new_song->rate);
|
|
||||||
$mode = Dba::escape($new_song->mode);
|
|
||||||
$size = Dba::escape($new_song->size);
|
|
||||||
$time = Dba::escape($new_song->time);
|
|
||||||
$track = Dba::escape($new_song->track);
|
|
||||||
$mbid = Dba::escape($new_song->mbid);
|
|
||||||
$artist = Dba::escape($new_song->artist);
|
|
||||||
$album = Dba::escape($new_song->album);
|
|
||||||
$album_artist = Dba::escape($new_song->album_artist);
|
|
||||||
$year = Dba::escape($new_song->year);
|
|
||||||
$song_id = Dba::escape($song_id);
|
|
||||||
$update_time = time();
|
$update_time = time();
|
||||||
|
|
||||||
$sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " .
|
$sql = "UPDATE `song` SET `album` = ?, `year` = ?, `artist` = ?, " .
|
||||||
"`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " .
|
"`title` = ?, `bitrate` = ?, `rate` = ?, `mode` = ?, " .
|
||||||
"`size`='$size', `time`='$time', `track`='$track', " .
|
"`size` = ?, `time` = ?, `track` = ?, `mbid` = ?, " .
|
||||||
"`mbid`='$mbid', " .
|
"`album_artist` = ?, " .
|
||||||
"`album_artist`='$album_artist', " .
|
"`update_time` = ? WHERE `id` = ?";
|
||||||
"`update_time`='$update_time' WHERE `id`='$song_id'";
|
|
||||||
|
|
||||||
Dba::write($sql);
|
Dba::write($sql, array($new_song->album, $new_song->year, $new_song->artist, $new_song->title, $new_song->bitrate, $new_song->rate,
|
||||||
|
$new_song->mode, $new_song->size, $new_song->time, $new_song->track, $new_song->mbid, $new_song->album_artist, $update_time, $song_id));
|
||||||
|
|
||||||
$comment = Dba::escape($new_song->comment);
|
$sql = "UPDATE `song_data` SET `lyrics` = ?, `language` = ?, `comment` = ?, `replaygain_track_gain` = ?, `replaygain_track_peak` = ?, " .
|
||||||
$language = Dba::escape($new_song->language);
|
"`replaygain_album_gain` = ?, `replaygain_album_peak` = ?" .
|
||||||
$lyrics = Dba::escape($new_song->lyrics);
|
"WHERE `song_id` = ?";
|
||||||
|
Dba::write($sql, array($new_song->lyrics, $new_song->language, $new_song->comment, $new_song->replaygain_track_gain,
|
||||||
$sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " .
|
$new_song->replaygain_track_peak, $new_song->replaygain_album_gain, $new_song->replaygain_album_peak, $song_id));
|
||||||
"WHERE `song_id`='$song_id'";
|
|
||||||
Dba::write($sql);
|
|
||||||
|
|
||||||
} // update_song
|
} // update_song
|
||||||
|
|
||||||
|
@ -1816,6 +1821,10 @@ class Song extends database_object implements media, library_item
|
||||||
$meta['mb_artistid'] = $this->artist_mbid;
|
$meta['mb_artistid'] = $this->artist_mbid;
|
||||||
$meta['mb_albumartistid'] = $this->albumartist_mbid;
|
$meta['mb_albumartistid'] = $this->albumartist_mbid;
|
||||||
$meta['tracknumber'] = $meta['track'] = $this->track;
|
$meta['tracknumber'] = $meta['track'] = $this->track;
|
||||||
|
$meta['replaygain_track_gain'] = $this->replaygain_track_gain;
|
||||||
|
$meta['replaygain_track_peak'] = $this->replaygain_track_peak;
|
||||||
|
$meta['replaygain_album_gain'] = $this->replaygain_album_gain;
|
||||||
|
$meta['replaygain_album_peak'] = $this->replaygain_album_peak;
|
||||||
$meta['genre'] = array();
|
$meta['genre'] = array();
|
||||||
if ($this->tags) {
|
if ($this->tags) {
|
||||||
foreach ($this->tags as $tag) {
|
foreach ($this->tags as $tag) {
|
||||||
|
|
|
@ -476,6 +476,9 @@ class Update
|
||||||
$update_string = " - Add state and city fields to user table.<br />";
|
$update_string = " - Add state and city fields to user table.<br />";
|
||||||
$version[] = array('version' => '370025','description' => $update_string);
|
$version[] = array('version' => '370025','description' => $update_string);
|
||||||
|
|
||||||
|
$update_string = " - Add replay gain fields to song_data table.<br />";
|
||||||
|
$version[] = array('version' => '370026','description' => $update_string);
|
||||||
|
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3215,4 +3218,20 @@ class Update
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update 370026
|
||||||
|
*
|
||||||
|
* Add replay gain fields to song_data table
|
||||||
|
*/
|
||||||
|
public static function update_370026()
|
||||||
|
{
|
||||||
|
$retval = true;
|
||||||
|
|
||||||
|
$sql = "ALTER TABLE `song_data` ADD COLUMN `replaygain_track_gain` DECIMAL(10,6) NULL, ADD COLUMN `replaygain_track_peak` DECIMAL(10,6) NULL, " .
|
||||||
|
"ADD COLUMN `replaygain_album_gain` DECIMAL(10,6) NULL, ADD COLUMN `replaygain_album_peak` DECIMAL(10,6) NULL";
|
||||||
|
$retval = Dba::write($sql) ? $retval : false;
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -378,6 +378,11 @@ class vainfo
|
||||||
'<br />',
|
'<br />',
|
||||||
strip_tags($tags['lyrics']));
|
strip_tags($tags['lyrics']));
|
||||||
|
|
||||||
|
$info['replaygain_track_gain'] = $info['replaygain_track_gain'] ?: floatval($tags['replaygain_track_gain']);
|
||||||
|
$info['replaygain_track_peak'] = $info['replaygain_track_peak'] ?: floatval($tags['replaygain_track_peak']);
|
||||||
|
$info['replaygain_album_gain'] = $info['replaygain_album_gain'] ?: floatval($tags['replaygain_album_gain']);
|
||||||
|
$info['replaygain_album_peak'] = $info['replaygain_album_peak'] ?: floatval($tags['replaygain_album_peak']);
|
||||||
|
|
||||||
$info['track'] = $info['track'] ?: intval($tags['track']);
|
$info['track'] = $info['track'] ?: intval($tags['track']);
|
||||||
$info['resolution_x'] = $info['resolution_x'] ?: intval($tags['resolution_x']);
|
$info['resolution_x'] = $info['resolution_x'] ?: intval($tags['resolution_x']);
|
||||||
$info['resolution_y'] = $info['resolution_y'] ?: intval($tags['resolution_y']);
|
$info['resolution_y'] = $info['resolution_y'] ?: intval($tags['resolution_y']);
|
||||||
|
@ -841,6 +846,18 @@ class vainfo
|
||||||
case 'CATALOGNUMBER':
|
case 'CATALOGNUMBER':
|
||||||
$parsed['catalog_number'] = $this->trimAscii($txxx['data']);
|
$parsed['catalog_number'] = $this->trimAscii($txxx['data']);
|
||||||
break;
|
break;
|
||||||
|
case 'REPLAYGAIN_TRACK_GAIN':
|
||||||
|
$parsed['replaygain_track_gain'] = floatval($txxx['data']);
|
||||||
|
break;
|
||||||
|
case 'REPLAYGAIN_TRACK_PEAK':
|
||||||
|
$parsed['replaygain_track_peak'] = floatval($txxx['data']);
|
||||||
|
break;
|
||||||
|
case 'REPLAYGAIN_ALBUM_GAIN':
|
||||||
|
$parsed['replaygain_album_gain'] = floatval($txxx['data']);
|
||||||
|
break;
|
||||||
|
case 'REPLAYGAIN_ALBUM_PEAK':
|
||||||
|
$parsed['replaygain_album_peak'] = floatval($txxx['data']);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,9 +251,14 @@ class WebPlayer
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($media != null) {
|
if ($media != null) {
|
||||||
|
$media->format();
|
||||||
if ($urlinfo['type'] == 'song') {
|
if ($urlinfo['type'] == 'song') {
|
||||||
$js['artist_id'] = $media->artist;
|
$js['artist_id'] = $media->artist;
|
||||||
$js['album_id'] = $media->album;
|
$js['album_id'] = $media->album;
|
||||||
|
$js['replaygain_track_gain'] = $media->replaygain_track_gain;
|
||||||
|
$js['replaygain_track_peak'] = $media->replaygain_track_peak;
|
||||||
|
$js['replaygain_album_gain'] = $media->replaygain_album_gain;
|
||||||
|
$js['replaygain_album_peak'] = $media->replaygain_album_peak;
|
||||||
}
|
}
|
||||||
$js['media_id'] = $media->id;
|
$js['media_id'] = $media->id;
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,23 @@
|
||||||
function loadContentData(data, status, jqXHR)
|
function loadContentData(data, status, jqXHR)
|
||||||
{
|
{
|
||||||
var $mainContent = $("#content");
|
|
||||||
var $pageWrap = $("#guts");
|
|
||||||
var $response = $(data);
|
var $response = $(data);
|
||||||
|
|
||||||
$mainContent.empty().append($response.find("#guts"));
|
if ($response.find("#guts").length === 0) {
|
||||||
$mainContent.fadeIn(200, function() {
|
$("body").undelegate("a");
|
||||||
$pageWrap.animate({
|
$("body").undelegate("form");
|
||||||
height: $mainContent.height() + "px"
|
$("body").empty().append($response);
|
||||||
});
|
} else {
|
||||||
});
|
var $mainContent = $("#content");
|
||||||
$("a[rel^='prettyPhoto']").prettyPhoto({social_tools:false});
|
var $pageWrap = $("#guts");
|
||||||
initTabs();
|
$mainContent.empty().append($response.find("#guts"));
|
||||||
|
$mainContent.fadeIn(200, function() {
|
||||||
|
$pageWrap.animate({
|
||||||
|
height: $mainContent.height() + "px"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$("a[rel^='prettyPhoto']").prettyPhoto({social_tools:false});
|
||||||
|
initTabs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadContentPage(url)
|
function loadContentPage(url)
|
||||||
|
|
|
@ -10,7 +10,10 @@ jPlayerPlaylist.prototype._createListItem = function(media) {
|
||||||
}
|
}
|
||||||
attrClass += '" ';
|
attrClass += '" ';
|
||||||
|
|
||||||
var listItem = "<li" + attrClass + " name=\"" + $(jplaylist.cssSelector.playlist + " ul li").length + "\" data-poster=\"" + media['poster'] + "\" data-media_id=\"" + media['media_id'] + "\" data-album_id=\"" + media['album_id'] + "\" data-artist_id=\"" + media['artist_id'] + "\"><div>";
|
var listItem = "<li" + attrClass + " name=\"" + $(jplaylist.cssSelector.playlist + " ul li").length + "\" " +
|
||||||
|
"data-poster=\"" + media['poster'] + "\" data-media_id=\"" + media['media_id'] + "\" data-album_id=\"" + media['album_id'] + "\" data-artist_id=\"" + media['artist_id'] + "\" " +
|
||||||
|
"data-replaygain_track_gain=\"" + media['replaygain_track_gain'] + "\" data-replaygain_track_peak=\"" + media['replaygain_track_peak'] + "\" data-replaygain_album_gain=\"" + media['replaygain_album_gain'] + "\" data-replaygain_album_peak=\"" + media['replaygain_album_peak'] + "\"" +
|
||||||
|
"><div>";
|
||||||
|
|
||||||
// Create image
|
// Create image
|
||||||
// listItem += "<img class=\"cover\" src=\"" + media.cover + "\" alt=\"" + media.title + "\"/>";
|
// listItem += "<img class=\"cover\" src=\"" + media.cover + "\" alt=\"" + media.title + "\"/>";
|
||||||
|
|
|
@ -121,6 +121,7 @@ if ($isVideo) {
|
||||||
<?php if (AmpConfig::get('browser_notify')) { ?>
|
<?php if (AmpConfig::get('browser_notify')) { ?>
|
||||||
NotifyOfNewSong(obj.title, obj.artist, currentjpitem.attr("data-poster"));
|
NotifyOfNewSong(obj.title, obj.artist, currentjpitem.attr("data-poster"));
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
ApplyReplayGain();
|
||||||
}
|
}
|
||||||
if (brkey != '') {
|
if (brkey != '') {
|
||||||
sendBroadcastMessage('SONG', currenti.attr("data-media_id"));
|
sendBroadcastMessage('SONG', currenti.attr("data-media_id"));
|
||||||
|
@ -440,6 +441,9 @@ if ($isVideo) {
|
||||||
<div class="action_button">
|
<div class="action_button">
|
||||||
<a onClick="ShowVisualizerFullScreen();" href="#"><?php echo UI::get_icon('fullscreen', T_('Visualizer Full-Screen')); ?></a>
|
<a onClick="ShowVisualizerFullScreen();" href="#"><?php echo UI::get_icon('fullscreen', T_('Visualizer Full-Screen')); ?></a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="action_button">
|
||||||
|
<a href="javascript:ToggleReplayGain();"><?php echo UI::get_icon('replaygain', T_('ReplayGain')); ?></a>
|
||||||
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -52,6 +52,10 @@ function addMedia(media)
|
||||||
jpmedia['artist_id'] = media['artist_id'];
|
jpmedia['artist_id'] = media['artist_id'];
|
||||||
jpmedia['album_id'] = media['album_id'];
|
jpmedia['album_id'] = media['album_id'];
|
||||||
jpmedia['media_id'] = media['media_id'];
|
jpmedia['media_id'] = media['media_id'];
|
||||||
|
jpmedia['replaygain_track_gain'] = media['replaygain_track_gain'];
|
||||||
|
jpmedia['replaygain_track_peak'] = media['replaygain_track_peak'];
|
||||||
|
jpmedia['replaygain_album_gain'] = media['replaygain_album_gain'];
|
||||||
|
jpmedia['replaygain_album_peak'] = media['replaygain_album_peak'];
|
||||||
|
|
||||||
jplaylist.add(jpmedia);
|
jplaylist.add(jpmedia);
|
||||||
}
|
}
|
||||||
|
@ -200,6 +204,51 @@ function SavePlaylist()
|
||||||
}
|
}
|
||||||
handlePlaylistAction(url, 'rb_append_dplaylist_new');
|
handlePlaylistAction(url, 'rb_append_dplaylist_new');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var replaygainEnabled = false;
|
||||||
|
var replaygainNode = null;
|
||||||
|
function ToggleReplayGain()
|
||||||
|
{
|
||||||
|
if (replaygainNode == null) {
|
||||||
|
var mediaElement = document.getElementById("jp_audio_0");
|
||||||
|
if (mediaElement) {
|
||||||
|
var audioContext = null;
|
||||||
|
if (typeof AudioContext !== 'undefined') {
|
||||||
|
audioContext = new AudioContext();
|
||||||
|
} else if (typeof webkitAudioContext !== 'undefined') {
|
||||||
|
audioContext = new webkitAudioContext();
|
||||||
|
} else {
|
||||||
|
audioContext = null;
|
||||||
|
}
|
||||||
|
if (audioContext != null) {
|
||||||
|
var mediaSource = audioContext.createMediaElementSource(mediaElement);
|
||||||
|
replaygainNode = audioContext.createGain();
|
||||||
|
replaygainNode.gain.value = 1;
|
||||||
|
mediaSource.connect(replaygainNode);
|
||||||
|
replaygainNode.connect(audioContext.destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replaygainNode != null) {
|
||||||
|
replaygainEnabled = !replaygainEnabled;
|
||||||
|
ApplyReplayGain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ApplyReplayGain()
|
||||||
|
{
|
||||||
|
if (replaygainNode != null) {
|
||||||
|
var replaygain = 0;
|
||||||
|
if (replaygainEnabled && currentjpitem != null) {
|
||||||
|
var track_gain = currentjpitem.attr("data-replaygain_track_gain");
|
||||||
|
if (track_gain !== 'null') {
|
||||||
|
replaygain = parseFloat(track_gain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replaygainNode.gain.value = (1 + (replaygain / 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
|
@ -112,6 +112,12 @@ $button_flip_state_id = 'button_flip_state_' . $song->id;
|
||||||
$songprops[gettext_noop('Catalog Number')] = scrub_out($song->catalog_number);
|
$songprops[gettext_noop('Catalog Number')] = scrub_out($song->catalog_number);
|
||||||
$songprops[gettext_noop('Bitrate')] = scrub_out($song->f_bitrate);
|
$songprops[gettext_noop('Bitrate')] = scrub_out($song->f_bitrate);
|
||||||
$songprops[gettext_noop('Channels')] = scrub_out($song->channels);
|
$songprops[gettext_noop('Channels')] = scrub_out($song->channels);
|
||||||
|
if ($song->replaygain_track_gain != 0) {
|
||||||
|
$songprops[gettext_noop('ReplayGain Track Gain')] = scrub_out($song->replaygain_track_gain);
|
||||||
|
}
|
||||||
|
if ($song->replaygain_album_gain != 0) {
|
||||||
|
$songprops[gettext_noop('ReplayGain Album Gain')] = scrub_out($song->replaygain_album_gain);
|
||||||
|
}
|
||||||
if (Access::check('interface','75')) {
|
if (Access::check('interface','75')) {
|
||||||
$songprops[gettext_noop('Filename')] = scrub_out($song->file) . " " . $song->f_size;
|
$songprops[gettext_noop('Filename')] = scrub_out($song->file) . " " . $song->f_size;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue