Skip to content

Commit

Permalink
Adapt to new overamplification setting
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Oct 4, 2024
1 parent 1e43299 commit 520b4db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
20 changes: 9 additions & 11 deletions files/usr/share/cinnamon/applets/sound@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const VOLUME_ADJUSTMENT_STEP = 0.05; /* Volume adjustment step in % */
const ICON_SIZE = 28;

const CINNAMON_DESKTOP_SOUNDS = "org.cinnamon.desktop.sound";
const MAXIMUM_VOLUME_KEY = "maximum-volume";
const OVERAMPLIFICATION_KEY = "allow-amplified-volume";

class ControlButton {
constructor(icon, tooltip, callback, small = false) {
Expand Down Expand Up @@ -1023,8 +1023,8 @@ class CinnamonSoundApplet extends Applet.TextIconApplet {
this._control.connect('stream-removed', (...args) => this._onStreamRemoved(...args));

this._sound_settings = new Gio.Settings({ schema_id: CINNAMON_DESKTOP_SOUNDS });
this._volumeMax = this._sound_settings.get_int(MAXIMUM_VOLUME_KEY) / 100 * this._control.get_vol_max_norm();
this._volumeNorm = this._control.get_vol_max_norm();
this._volumeMax = this._volumeNorm;

this._streams = [];
this._devices = [];
Expand Down Expand Up @@ -1088,23 +1088,21 @@ class CinnamonSoundApplet extends Applet.TextIconApplet {
let appsys = Cinnamon.AppSystem.get_default();
appsys.connect("installed-changed", () => this._updateLaunchPlayer());

if (this._volumeMax > this._volumeNorm) {
this._outputVolumeSection.set_mark(this._volumeNorm / this._volumeMax);
}

this._sound_settings.connect("changed::" + MAXIMUM_VOLUME_KEY, () => this._on_sound_settings_change());
this._sound_settings.connect("changed::" + OVERAMPLIFICATION_KEY, () => this._on_overamplification_change());
this._on_overamplification_change();
}

_setKeybinding() {
Main.keybindingManager.addHotKey("sound-open-" + this.instance_id, this.keyOpen, Lang.bind(this, this._openMenu));
}

_on_sound_settings_change () {
this._volumeMax = this._sound_settings.get_int(MAXIMUM_VOLUME_KEY) / 100 * this._control.get_vol_max_norm();
if (this._volumeMax > this._volumeNorm) {
this._outputVolumeSection.set_mark(this._volumeNorm / this._volumeMax);
_on_overamplification_change () {
if (this._sound_settings.get_boolean(OVERAMPLIFICATION_KEY)) {
this._volumeMax = 1.5 * this._volumeNorm;
this._outputVolumeSection.set_mark(1/1.5);
}
else {
this._volumeMax = this._volumeNorm;
this._outputVolumeSection.set_mark(0);
}
this._outputVolumeSection._update();
Expand Down
37 changes: 17 additions & 20 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

CINNAMON_SOUNDS = "org.cinnamon.sounds"
CINNAMON_DESKTOP_SOUNDS = "org.cinnamon.desktop.sound"
MAXIMUM_VOLUME_KEY = "maximum-volume"
OVERAMPLIFICATION_KEY = "allow-amplified-volume"

DECAY_STEP = .15

Expand Down Expand Up @@ -538,8 +538,7 @@ def buildLayout(self):
sizeGroup = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

# output volume
max_volume = self.sound_settings.get_int(MAXIMUM_VOLUME_KEY)
self.outVolume = VolumeBar(self.controller.get_vol_max_norm(), max_volume, sizeGroup=sizeGroup)
self.outVolume = VolumeBar(self.controller.get_vol_max_norm(), 100, sizeGroup=sizeGroup)
devSettings.add_row(self.outVolume)

# balance
Expand All @@ -550,6 +549,11 @@ def buildLayout(self):
self.woofer = BalanceBar("lfe", 0, self.controller.get_vol_max_norm(), sizeGroup=sizeGroup)
devSettings.add_row(self.woofer)

# overamplification
switch = GSettingsSwitch(_("Overamplification"), CINNAMON_DESKTOP_SOUNDS, OVERAMPLIFICATION_KEY)
switch.set_tooltip_text(_("Allow the volume to exceed 100%, with reduced sound quality."))
devSettings.add_row(switch)

## Input page
page = SettingsPage()
self.sidePage.stack.add_titled(page, "input", _("Input"))
Expand All @@ -569,7 +573,7 @@ def buildLayout(self):
sizeGroup = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

# input volume
self.inVolume = VolumeBar(self.controller.get_vol_max_norm(), max_volume, sizeGroup=sizeGroup)
self.inVolume = VolumeBar(self.controller.get_vol_max_norm(), 100, sizeGroup=sizeGroup)
devSettings.add_row(self.inVolume)

# input level
Expand Down Expand Up @@ -626,24 +630,17 @@ def buildLayout(self):
noAppsMessage.pack_start(box, True, True, 0)
self.appStack.add_named(noAppsMessage, "noAppsMessage")

## Settings page
page = SettingsPage()
self.sidePage.stack.add_titled(page, "settings", _("Settings"))

amplificationSection = page.add_section(_("Amplification"))
self.maxVolume = Slider(_("Maximum volume: %d") % max_volume + "%", _("Reduced"), _("Amplified"), 1, 150, None, step=1, page=10, value=max_volume, gicon=None, iconName=None)
self.maxVolume.adjustment.connect("value-changed", self.onMaxVolumeChanged)
self.maxVolume.setMark(100)
amplificationSection.add_row(self.maxVolume)

def onMaxVolumeChanged(self, adjustment):
newValue = int(round(adjustment.get_value()))
self.sound_settings.set_int(MAXIMUM_VOLUME_KEY, newValue)
self.maxVolume.label.set_label(_("Maximum volume: %d") % newValue + "%")
self.outVolume.adjustment.set_upper(newValue)
self.sound_settings.connect(f"changed::{OVERAMPLIFICATION_KEY}", self.onOverAmplificationChanged)
self.onOverAmplificationChanged()

def onOverAmplificationChanged(self, settings=None, key=None):
overamplification = self.sound_settings.get_boolean(OVERAMPLIFICATION_KEY)
self.outVolume.slider.clear_marks()
if newValue > 100:
if overamplification:
self.outVolume.adjustment.set_upper(150)
self.outVolume.setMark(100)
else:
self.outVolume.adjustment.set_upper(100)

def inializeController(self):
self.controller = Cvc.MixerControl(name = "cinnamon")
Expand Down

0 comments on commit 520b4db

Please sign in to comment.