Refactored code
This commit is contained in:
parent
b9190eddfe
commit
0f551baf37
2 changed files with 17 additions and 16 deletions
|
@ -44,8 +44,8 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
private static final String TAG = "PlaybackParameterDialog";
|
private static final String TAG = "PlaybackParameterDialog";
|
||||||
|
|
||||||
// Minimum allowable range in ExoPlayer
|
// Minimum allowable range in ExoPlayer
|
||||||
private static final double MIN_PLAYBACK_VALUE = 0.10f;
|
private static final double MIN_PITCH_OR_SPEED = 0.10f;
|
||||||
private static final double MAX_PLAYBACK_VALUE = 3.00f;
|
private static final double MAX_PITCH_OR_SPEED = 3.00f;
|
||||||
|
|
||||||
private static final boolean PITCH_CTRL_MODE_PERCENT = false;
|
private static final boolean PITCH_CTRL_MODE_PERCENT = false;
|
||||||
private static final boolean PITCH_CTRL_MODE_SEMITONE = true;
|
private static final boolean PITCH_CTRL_MODE_SEMITONE = true;
|
||||||
|
@ -62,8 +62,8 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
private static final boolean DEFAULT_SKIP_SILENCE = false;
|
private static final boolean DEFAULT_SKIP_SILENCE = false;
|
||||||
|
|
||||||
private static final SliderStrategy QUADRATIC_STRATEGY = new SliderStrategy.Quadratic(
|
private static final SliderStrategy QUADRATIC_STRATEGY = new SliderStrategy.Quadratic(
|
||||||
MIN_PLAYBACK_VALUE,
|
MIN_PITCH_OR_SPEED,
|
||||||
MAX_PLAYBACK_VALUE,
|
MAX_PITCH_OR_SPEED,
|
||||||
1.00f,
|
1.00f,
|
||||||
10_000);
|
10_000);
|
||||||
|
|
||||||
|
@ -177,10 +177,10 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
// Tempo
|
// Tempo
|
||||||
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PLAYBACK_VALUE);
|
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED);
|
||||||
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PLAYBACK_VALUE);
|
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PITCH_OR_SPEED);
|
||||||
|
|
||||||
binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PLAYBACK_VALUE));
|
binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
|
||||||
setAndUpdateTempo(tempo);
|
setAndUpdateTempo(tempo);
|
||||||
binding.tempoSeekbar.setOnSeekBarChangeListener(
|
binding.tempoSeekbar.setOnSeekBarChangeListener(
|
||||||
getTempoOrPitchSeekbarChangeListener(
|
getTempoOrPitchSeekbarChangeListener(
|
||||||
|
@ -215,10 +215,10 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
changePitchControlMode(isCurrentPitchControlModeSemitone());
|
changePitchControlMode(isCurrentPitchControlModeSemitone());
|
||||||
|
|
||||||
// Pitch - Percent
|
// Pitch - Percent
|
||||||
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PLAYBACK_VALUE);
|
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PITCH_OR_SPEED);
|
||||||
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PLAYBACK_VALUE);
|
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PITCH_OR_SPEED);
|
||||||
|
|
||||||
binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PLAYBACK_VALUE));
|
binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
|
||||||
setAndUpdatePitch(pitchPercent);
|
setAndUpdatePitch(pitchPercent);
|
||||||
binding.pitchPercentSeekbar.setOnSeekBarChangeListener(
|
binding.pitchPercentSeekbar.setOnSeekBarChangeListener(
|
||||||
getTempoOrPitchSeekbarChangeListener(
|
getTempoOrPitchSeekbarChangeListener(
|
||||||
|
@ -557,12 +557,12 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calcValidTempo(final double newTempo) {
|
private double calcValidTempo(final double newTempo) {
|
||||||
return Math.max(MIN_PLAYBACK_VALUE, Math.min(MAX_PLAYBACK_VALUE, newTempo));
|
return Math.max(MIN_PITCH_OR_SPEED, Math.min(MAX_PITCH_OR_SPEED, newTempo));
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calcValidPitch(final double newPitch) {
|
private double calcValidPitch(final double newPitch) {
|
||||||
final double calcPitch =
|
final double calcPitch =
|
||||||
Math.max(MIN_PLAYBACK_VALUE, Math.min(MAX_PLAYBACK_VALUE, newPitch));
|
Math.max(MIN_PITCH_OR_SPEED, Math.min(MAX_PITCH_OR_SPEED, newPitch));
|
||||||
|
|
||||||
if (!isCurrentPitchControlModeSemitone()) {
|
if (!isCurrentPitchControlModeSemitone()) {
|
||||||
return calcPitch;
|
return calcPitch;
|
||||||
|
|
|
@ -9,7 +9,7 @@ package org.schabi.newpipe.player.helper;
|
||||||
* </a>
|
* </a>
|
||||||
*/
|
*/
|
||||||
public final class PlayerSemitoneHelper {
|
public final class PlayerSemitoneHelper {
|
||||||
public static final int TONES = 12;
|
public static final int SEMITONE_COUNT = 12;
|
||||||
|
|
||||||
private PlayerSemitoneHelper() {
|
private PlayerSemitoneHelper() {
|
||||||
// No impl
|
// No impl
|
||||||
|
@ -24,14 +24,15 @@ public final class PlayerSemitoneHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double semitonesToPercent(final int semitones) {
|
public static double semitonesToPercent(final int semitones) {
|
||||||
return Math.pow(2, ensureSemitonesInRange(semitones) / (double) TONES);
|
return Math.pow(2, ensureSemitonesInRange(semitones) / (double) SEMITONE_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int percentToSemitones(final double percent) {
|
public static int percentToSemitones(final double percent) {
|
||||||
return ensureSemitonesInRange((int) Math.round(TONES * Math.log(percent) / Math.log(2)));
|
return ensureSemitonesInRange(
|
||||||
|
(int) Math.round(SEMITONE_COUNT * Math.log(percent) / Math.log(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ensureSemitonesInRange(final int semitones) {
|
private static int ensureSemitonesInRange(final int semitones) {
|
||||||
return Math.max(-TONES, Math.min(TONES, semitones));
|
return Math.max(-SEMITONE_COUNT, Math.min(SEMITONE_COUNT, semitones));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue