mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
follow max playback speed setting in main player
This commit is contained in:
parent
97ddb74427
commit
b28175c0f1
3 changed files with 29 additions and 21 deletions
|
@ -156,7 +156,7 @@ class MainPlayerGestureListener(
|
||||||
|
|
||||||
private fun onScrollPlaybackSpeed(distanceY: Float) {
|
private fun onScrollPlaybackSpeed(distanceY: Float) {
|
||||||
val bar: ProgressBar = binding.playbackSpeedProgressBar
|
val bar: ProgressBar = binding.playbackSpeedProgressBar
|
||||||
val maxPlaybackSpeed: Float = PlaybackParameterDialog.getMaxPitchOrSpeed()
|
val maxPlaybackSpeed: Float = PlaybackParameterDialog.getMaxPitchOrSpeed(player.context)
|
||||||
val minPlaybackSpeed: Float = PlaybackParameterDialog.getMinPitchOrSpeed()
|
val minPlaybackSpeed: Float = PlaybackParameterDialog.getMinPitchOrSpeed()
|
||||||
val playbackSpeedStep: Float = PlaybackParameterDialog.getCurrentStepSize(player.context) / maxPlaybackSpeed
|
val playbackSpeedStep: Float = PlaybackParameterDialog.getCurrentStepSize(player.context) / maxPlaybackSpeed
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
// Minimum allowable range in ExoPlayer
|
// Minimum allowable range in ExoPlayer
|
||||||
private static final double MIN_PITCH_OR_SPEED = 0.1f;
|
private static final double MIN_PITCH_OR_SPEED = 0.1f;
|
||||||
private static final double MAX_PITCH_OR_SPEED = 5.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,12 +61,6 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
private static final boolean DEFAULT_SKIP_SILENCE = false;
|
private static final boolean DEFAULT_SKIP_SILENCE = false;
|
||||||
private static final boolean DEFAULT_PLAYBACK_UNHOOK = true;
|
private static final boolean DEFAULT_PLAYBACK_UNHOOK = true;
|
||||||
|
|
||||||
private static final SliderStrategy QUADRATIC_STRATEGY = new SliderStrategy.Quadratic(
|
|
||||||
MIN_PITCH_OR_SPEED,
|
|
||||||
MAX_PITCH_OR_SPEED,
|
|
||||||
1.00f,
|
|
||||||
10_000);
|
|
||||||
|
|
||||||
private static final SliderStrategy SEMITONE_STRATEGY = new SliderStrategy() {
|
private static final SliderStrategy SEMITONE_STRATEGY = new SliderStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public int progressOf(final double value) {
|
public int progressOf(final double value) {
|
||||||
|
@ -178,14 +171,17 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
// Tempo
|
// Tempo
|
||||||
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED);
|
final float maxPitchOrSpeed = getMaxPitchOrSpeed(requireContext());
|
||||||
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PITCH_OR_SPEED);
|
final SliderStrategy quadraticStrategy = getQuadraticStrategy(requireContext());
|
||||||
|
|
||||||
binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
|
setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED);
|
||||||
|
setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, maxPitchOrSpeed);
|
||||||
|
|
||||||
|
binding.tempoSeekbar.setMax(quadraticStrategy.progressOf(maxPitchOrSpeed));
|
||||||
setAndUpdateTempo(tempo);
|
setAndUpdateTempo(tempo);
|
||||||
binding.tempoSeekbar.setOnSeekBarChangeListener(
|
binding.tempoSeekbar.setOnSeekBarChangeListener(
|
||||||
getTempoOrPitchSeekbarChangeListener(
|
getTempoOrPitchSeekbarChangeListener(
|
||||||
QUADRATIC_STRATEGY,
|
quadraticStrategy,
|
||||||
this::onTempoSliderUpdated));
|
this::onTempoSliderUpdated));
|
||||||
|
|
||||||
registerOnStepClickListener(
|
registerOnStepClickListener(
|
||||||
|
@ -217,13 +213,13 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
// Pitch - Percent
|
// Pitch - Percent
|
||||||
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PITCH_OR_SPEED);
|
setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PITCH_OR_SPEED);
|
||||||
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PITCH_OR_SPEED);
|
setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, maxPitchOrSpeed);
|
||||||
|
|
||||||
binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED));
|
binding.pitchPercentSeekbar.setMax(quadraticStrategy.progressOf(maxPitchOrSpeed));
|
||||||
setAndUpdatePitch(pitchPercent);
|
setAndUpdatePitch(pitchPercent);
|
||||||
binding.pitchPercentSeekbar.setOnSeekBarChangeListener(
|
binding.pitchPercentSeekbar.setOnSeekBarChangeListener(
|
||||||
getTempoOrPitchSeekbarChangeListener(
|
getTempoOrPitchSeekbarChangeListener(
|
||||||
QUADRATIC_STRATEGY,
|
quadraticStrategy,
|
||||||
this::onPitchPercentSliderUpdated));
|
this::onPitchPercentSliderUpdated));
|
||||||
|
|
||||||
registerOnStepClickListener(
|
registerOnStepClickListener(
|
||||||
|
@ -489,6 +485,12 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
// Sliders
|
// Sliders
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private SliderStrategy getQuadraticStrategy(final Context context) {
|
||||||
|
return new SliderStrategy.Quadratic(
|
||||||
|
MIN_PITCH_OR_SPEED, getMaxPitchOrSpeed(context),
|
||||||
|
1.00f,
|
||||||
|
10_000);
|
||||||
|
}
|
||||||
private SeekBar.OnSeekBarChangeListener getTempoOrPitchSeekbarChangeListener(
|
private SeekBar.OnSeekBarChangeListener getTempoOrPitchSeekbarChangeListener(
|
||||||
final SliderStrategy sliderStrategy,
|
final SliderStrategy sliderStrategy,
|
||||||
final DoubleConsumer newValueConsumer
|
final DoubleConsumer newValueConsumer
|
||||||
|
@ -528,16 +530,18 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAndUpdateTempo(final double newTempo) {
|
private void setAndUpdateTempo(final double newTempo) {
|
||||||
this.tempo = MathUtils.clamp(newTempo, MIN_PITCH_OR_SPEED, MAX_PITCH_OR_SPEED);
|
this.tempo = MathUtils.clamp(newTempo, MIN_PITCH_OR_SPEED,
|
||||||
|
getMaxPitchOrSpeed(requireContext()));
|
||||||
|
|
||||||
binding.tempoSeekbar.setProgress(QUADRATIC_STRATEGY.progressOf(tempo));
|
binding.tempoSeekbar.setProgress(getQuadraticStrategy(requireContext()).progressOf(tempo));
|
||||||
setText(binding.tempoCurrentText, PlayerHelper::formatSpeed, tempo);
|
setText(binding.tempoCurrentText, PlayerHelper::formatSpeed, tempo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAndUpdatePitch(final double newPitch) {
|
private void setAndUpdatePitch(final double newPitch) {
|
||||||
this.pitchPercent = calcValidPitch(newPitch);
|
this.pitchPercent = calcValidPitch(newPitch);
|
||||||
|
|
||||||
binding.pitchPercentSeekbar.setProgress(QUADRATIC_STRATEGY.progressOf(pitchPercent));
|
binding.pitchPercentSeekbar.setProgress(getQuadraticStrategy(requireContext())
|
||||||
|
.progressOf(pitchPercent));
|
||||||
binding.pitchSemitoneSeekbar.setProgress(SEMITONE_STRATEGY.progressOf(pitchPercent));
|
binding.pitchSemitoneSeekbar.setProgress(SEMITONE_STRATEGY.progressOf(pitchPercent));
|
||||||
setText(binding.pitchPercentCurrentText,
|
setText(binding.pitchPercentCurrentText,
|
||||||
PlayerHelper::formatPitch,
|
PlayerHelper::formatPitch,
|
||||||
|
@ -548,7 +552,8 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calcValidPitch(final double newPitch) {
|
private double calcValidPitch(final double newPitch) {
|
||||||
final double calcPitch = MathUtils.clamp(newPitch, MIN_PITCH_OR_SPEED, MAX_PITCH_OR_SPEED);
|
final double calcPitch = MathUtils.clamp(newPitch, MIN_PITCH_OR_SPEED,
|
||||||
|
getMaxPitchOrSpeed(requireContext()));
|
||||||
|
|
||||||
if (!isCurrentPitchControlModeSemitone()) {
|
if (!isCurrentPitchControlModeSemitone()) {
|
||||||
return calcPitch;
|
return calcPitch;
|
||||||
|
@ -613,8 +618,10 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
return (float) MIN_PITCH_OR_SPEED;
|
return (float) MIN_PITCH_OR_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getMaxPitchOrSpeed() {
|
public static float getMaxPitchOrSpeed(final Context context) {
|
||||||
return (float) MAX_PITCH_OR_SPEED;
|
return Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getString(context.getString(R.string.max_playback_speed_key),
|
||||||
|
context.getString(R.string.default_max_playback_speed_value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
|
|
|
@ -246,6 +246,7 @@ public final class PlayerHelper {
|
||||||
context.getString(R.string.default_left_gesture_control_value));
|
context.getString(R.string.default_left_gesture_control_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) {
|
public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) {
|
||||||
return getPreferences(context)
|
return getPreferences(context)
|
||||||
.getBoolean(context.getString(R.string.start_main_player_fullscreen_key), false);
|
.getBoolean(context.getString(R.string.start_main_player_fullscreen_key), false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue