Skip to content

Commit 0f551ba

Browse files
committed
Refactored code
1 parent b9190ed commit 0f551ba

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class PlaybackParameterDialog extends DialogFragment {
4444
private static final String TAG = "PlaybackParameterDialog";
4545

4646
// Minimum allowable range in ExoPlayer
47-
private static final double MIN_PLAYBACK_VALUE = 0.10f;
48-
private static final double MAX_PLAYBACK_VALUE = 3.00f;
47+
private static final double MIN_PITCH_OR_SPEED = 0.10f;
48+
private static final double MAX_PITCH_OR_SPEED = 3.00f;
4949

5050
private static final boolean PITCH_CTRL_MODE_PERCENT = false;
5151
private static final boolean PITCH_CTRL_MODE_SEMITONE = true;
@@ -62,8 +62,8 @@ public class PlaybackParameterDialog extends DialogFragment {
6262
private static final boolean DEFAULT_SKIP_SILENCE = false;
6363

6464
private static final SliderStrategy QUADRATIC_STRATEGY = new SliderStrategy.Quadratic(
65-
MIN_PLAYBACK_VALUE,
66-
MAX_PLAYBACK_VALUE,
65+
MIN_PITCH_OR_SPEED,
66+
MAX_PITCH_OR_SPEED,
6767
1.00f,
6868
10_000);
6969

@@ -177,10 +177,10 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
177177

178178
private void initUI() {
179179
// Tempo
180-
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PLAYBACK_VALUE);
181-
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PLAYBACK_VALUE);
180+
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED);
181+
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PITCH_OR_SPEED);
182182

183-
binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PLAYBACK_VALUE));
183+
binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
184184
setAndUpdateTempo(tempo);
185185
binding.tempoSeekbar.setOnSeekBarChangeListener(
186186
getTempoOrPitchSeekbarChangeListener(
@@ -215,10 +215,10 @@ private void initUI() {
215215
changePitchControlMode(isCurrentPitchControlModeSemitone());
216216

217217
// Pitch - Percent
218-
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PLAYBACK_VALUE);
219-
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PLAYBACK_VALUE);
218+
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PITCH_OR_SPEED);
219+
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PITCH_OR_SPEED);
220220

221-
binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PLAYBACK_VALUE));
221+
binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
222222
setAndUpdatePitch(pitchPercent);
223223
binding.pitchPercentSeekbar.setOnSeekBarChangeListener(
224224
getTempoOrPitchSeekbarChangeListener(
@@ -557,12 +557,12 @@ private void setAndUpdatePitch(final double newPitch) {
557557
}
558558

559559
private double calcValidTempo(final double newTempo) {
560-
return Math.max(MIN_PLAYBACK_VALUE, Math.min(MAX_PLAYBACK_VALUE, newTempo));
560+
return Math.max(MIN_PITCH_OR_SPEED, Math.min(MAX_PITCH_OR_SPEED, newTempo));
561561
}
562562

563563
private double calcValidPitch(final double newPitch) {
564564
final double calcPitch =
565-
Math.max(MIN_PLAYBACK_VALUE, Math.min(MAX_PLAYBACK_VALUE, newPitch));
565+
Math.max(MIN_PITCH_OR_SPEED, Math.min(MAX_PITCH_OR_SPEED, newPitch));
566566

567567
if (!isCurrentPitchControlModeSemitone()) {
568568
return calcPitch;

app/src/main/java/org/schabi/newpipe/player/helper/PlayerSemitoneHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* </a>
1010
*/
1111
public final class PlayerSemitoneHelper {
12-
public static final int TONES = 12;
12+
public static final int SEMITONE_COUNT = 12;
1313

1414
private PlayerSemitoneHelper() {
1515
// No impl
@@ -24,14 +24,15 @@ public static String formatPitchSemitones(final int semitones) {
2424
}
2525

2626
public static double semitonesToPercent(final int semitones) {
27-
return Math.pow(2, ensureSemitonesInRange(semitones) / (double) TONES);
27+
return Math.pow(2, ensureSemitonesInRange(semitones) / (double) SEMITONE_COUNT);
2828
}
2929

3030
public static int percentToSemitones(final double percent) {
31-
return ensureSemitonesInRange((int) Math.round(TONES * Math.log(percent) / Math.log(2)));
31+
return ensureSemitonesInRange(
32+
(int) Math.round(SEMITONE_COUNT * Math.log(percent) / Math.log(2)));
3233
}
3334

3435
private static int ensureSemitonesInRange(final int semitones) {
35-
return Math.max(-TONES, Math.min(TONES, semitones));
36+
return Math.max(-SEMITONE_COUNT, Math.min(SEMITONE_COUNT, semitones));
3637
}
3738
}

0 commit comments

Comments
 (0)