Skip to content

Commit 766d165

Browse files
Added volumeStep to config (#214)
* Added volumeStep to config - with 16 notches by default (much cleaner to change volume using iphone up/down buttons). * Use 64 volume steps for continuity Co-authored-by: devgianlu <[email protected]>
1 parent c2155da commit 766d165

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/FileConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ public int initialVolume() {
284284
return vol;
285285
}
286286

287+
@Override
288+
public int volumeSteps() {
289+
int volumeSteps = config.get("player.volumeSteps");
290+
if (volumeSteps < 0 || volumeSteps > PlayerRunner.VOLUME_MAX)
291+
throw new IllegalArgumentException("Invalid volume steps: " + volumeSteps);
292+
293+
return volumeSteps;
294+
}
295+
287296
@Override
288297
public boolean autoplayEnabled() {
289298
return config.get("player.autoplayEnabled");

core/src/main/java/xyz/gianlu/librespot/connectstate/DeviceStateHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static Connect.DeviceInfo.Builder initializeDeviceInfo(@NotNull Session
7575
.setCanBePlayer(true).setGaiaEqConnectId(true).setSupportsLogout(true)
7676
.setIsObservable(true).setCommandAcks(true).setSupportsRename(false)
7777
.setSupportsPlaylistV2(true).setIsControllable(true).setSupportsTransferCommand(true)
78-
.setSupportsCommandRequest(true).setVolumeSteps(PlayerRunner.VOLUME_STEPS)
78+
.setSupportsCommandRequest(true).setVolumeSteps(session.conf().volumeSteps())
7979
.setSupportsGzipPushes(true).setNeedsFullPlayerState(false)
8080
.addSupportedTypes("audio/episode")
8181
.addSupportedTypes("audio/track")

core/src/main/java/xyz/gianlu/librespot/player/Player.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ public void initState() {
7777

7878
public void volumeUp() {
7979
if (state == null) return;
80-
setVolume(Math.min(PlayerRunner.VOLUME_MAX, state.getVolume() + PlayerRunner.VOLUME_ONE_STEP));
80+
setVolume(Math.min(PlayerRunner.VOLUME_MAX, state.getVolume() + oneVolumeStep()));
8181
}
8282

8383
public void volumeDown() {
8484
if (state == null) return;
85-
setVolume(Math.max(0, state.getVolume() - PlayerRunner.VOLUME_ONE_STEP));
85+
setVolume(Math.max(0, state.getVolume() - oneVolumeStep()));
86+
}
87+
88+
private int oneVolumeStep() {
89+
return PlayerRunner.VOLUME_MAX / conf.volumeSteps();
8690
}
8791

8892
public void setVolume(int val) {
@@ -755,6 +759,8 @@ public interface Configuration {
755759

756760
int initialVolume();
757761

762+
int volumeSteps();
763+
758764
boolean autoplayEnabled();
759765

760766
int crossfadeDuration();

core/src/main/java/xyz/gianlu/librespot/player/PlayerRunner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
* @author Gianlu
4141
*/
4242
public class PlayerRunner implements Runnable, Closeable {
43-
public static final int VOLUME_STEPS = 64;
4443
public static final int VOLUME_MAX = 65536;
45-
public static final int VOLUME_ONE_STEP = VOLUME_MAX / VOLUME_STEPS;
4644
public static final AudioFormat OUTPUT_FORMAT = new AudioFormat(44100, 16, 2, true, false);
4745
private static final Logger LOGGER = Logger.getLogger(PlayerRunner.class);
4846
private static final AtomicInteger IDS = new AtomicInteger(0);

core/src/main/resources/default.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ preferredAudioQuality = "VORBIS_160" # Preferred audio quality (VORBIS_96, VORBI
3535
enableNormalisation = true # Whether to apply the Spotify loudness normalisation
3636
normalisationPregain = +3.0 # Normalisation pregain in decibels (loud at +6, normal at +3, quiet at -5)
3737
initialVolume = 65536 # Initial volume (0-65536)
38+
volumeSteps = 64 # Number of volume notches
3839
logAvailableMixers = true # Log available mixers
3940
mixerSearchKeywords = "" # Mixer/backend search keywords (semicolon separated)
4041
crossfadeDuration = 0 # Crossfade overlap time (in milliseconds)
@@ -55,4 +56,4 @@ address = "" # The proxy hostname
5556
port = 0 # The proxy port
5657
auth = false # Whether authentication is enabled on the server
5758
username = "" # Basic auth username
58-
password = "" # Basic auth password
59+
password = "" # Basic auth password

0 commit comments

Comments
 (0)