API: operate on cubic volume scale

Instead converting volume inside GJS, simplify things by making API operate on cubic volume scale.
This commit is contained in:
Rafał Dzięgiel
2021-02-24 08:42:27 +01:00
parent 6130ffa6c0
commit 86d365872a
5 changed files with 33 additions and 45 deletions

5
src/controls.js vendored
View File

@@ -489,7 +489,7 @@ class ClapperControls extends Gtk.Box
const initialVolume = (settings.get_string('volume-initial') === 'custom')
? settings.get_int('volume-value') / 100
: Misc.getCubicValue(settings.get_double('volume-last'));
: settings.get_double('volume-last');
this.volumeScale.set_value(initialVolume);
}
@@ -567,10 +567,9 @@ class ClapperControls extends Gtk.Box
_onVolumeScaleValueChanged(scale)
{
const volume = scale.get_value();
const linearVolume = Misc.getLinearValue(volume);
const { player } = this.get_ancestor(Gtk.Grid);
player.set_volume(linearVolume);
player.set_volume(volume);
/* FIXME: All of below should be placed in 'volume-changed'
* event once we move to message bus API */

View File

@@ -95,21 +95,3 @@ function getFormattedTime(time, showHours)
const parsed = (hours) ? `${hours}:` : '';
return parsed + `${minutes}:${seconds}`;
}
function getCubicValue(linearVal)
{
return GstAudio.StreamVolume.convert_volume(
GstAudio.StreamVolumeFormat.LINEAR,
GstAudio.StreamVolumeFormat.CUBIC,
linearVal
);
}
function getLinearValue(cubicVal)
{
return GstAudio.StreamVolume.convert_volume(
GstAudio.StreamVolumeFormat.CUBIC,
GstAudio.StreamVolumeFormat.LINEAR,
cubicVal
);
}

View File

@@ -24,8 +24,6 @@ class ClapperPlayer extends PlayerBase
this.keyPressCount = 0;
this._maxVolume = Misc.getLinearValue(Misc.maxVolume);
const keyController = new Gtk.EventControllerKey();
keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this));
keyController.connect('key-released', this._onWidgetKeyReleased.bind(this));
@@ -180,17 +178,6 @@ class ClapperPlayer extends PlayerBase
this.seek_seconds(seconds);
}
set_volume(volume)
{
if(volume < 0)
volume = 0;
else if(volume > this._maxVolume)
volume = this._maxVolume;
super.set_volume(volume);
debug(`set player volume: ${volume}`);
}
adjust_position(isIncrease)
{
this.seek_done = false;
@@ -316,7 +303,9 @@ class ClapperPlayer extends PlayerBase
}
settings.set_string('resume-database', JSON.stringify([resumeInfo]));
}
settings.set_double('volume-last', this.volume);
const volume = this.volume;
debug(`saving last volume: ${volume}`);
settings.set_double('volume-last', volume);
clapperWidget.controls._onCloseRequest();
}

View File

@@ -530,7 +530,7 @@ class ClapperWidget extends Gtk.Grid
_onPlayerVolumeChanged(player)
{
const volume = player.get_volume();
const volume = player.volume;
/* FIXME: This check should not be needed, GstPlayer should not
* emit 'volume-changed' with the same values, but it does. */
@@ -540,8 +540,7 @@ class ClapperWidget extends Gtk.Grid
/* Once above is fixed in GstPlayer, remove this var too */
this.controls.currentVolume = volume;
const cubicVolume = Misc.getCubicValue(volume);
this.controls._updateVolumeButtonIcon(cubicVolume);
this.controls._updateVolumeButtonIcon(volume);
}
_onStateNotify(toplevel)