[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | package org.openstreetmap.josm.actions.audio;
|
---|
| 3 |
|
---|
[582] | 4 | import java.awt.event.ActionEvent;
|
---|
| 5 |
|
---|
| 6 | import org.openstreetmap.josm.Main;
|
---|
[563] | 7 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
[582] | 8 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
[1084] | 9 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[563] | 10 |
|
---|
[5871] | 11 | /**
|
---|
| 12 | * Abstract superclass of {@link AudioFasterAction} and {@link AudioSlowerAction}.
|
---|
| 13 | * @since 563
|
---|
| 14 | */
|
---|
[6883] | 15 | public abstract class AudioFastSlowAction extends JosmAction {
|
---|
[626] | 16 |
|
---|
[1169] | 17 | private double multiplier;
|
---|
[1023] | 18 |
|
---|
[5871] | 19 | /**
|
---|
| 20 | * Constructs a new {@code AudioFastSlowAction}.
|
---|
[6069] | 21 | *
|
---|
[5871] | 22 | * @param name the action's text as displayed on the menu (if it is added to a menu)
|
---|
| 23 | * @param iconName the filename of the icon to use
|
---|
| 24 | * @param tooltip a longer description of the action that will be displayed in the tooltip.
|
---|
| 25 | * @param shortcut a ready-created shortcut object.
|
---|
| 26 | * @param fast {@code true} to increase speed (faster audio), {@code false} to decrease it (slower audio).
|
---|
| 27 | */
|
---|
[1169] | 28 | public AudioFastSlowAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean fast) {
|
---|
| 29 | super(name, iconName, tooltip, shortcut, true);
|
---|
[5871] | 30 | multiplier = Main.pref.getDouble("audio.fastfwdmultiplier", 1.3);
|
---|
[8444] | 31 | if (!fast)
|
---|
[1169] | 32 | multiplier = 1.0 / multiplier;
|
---|
| 33 | }
|
---|
[1023] | 34 |
|
---|
[6084] | 35 | @Override
|
---|
[1169] | 36 | public void actionPerformed(ActionEvent e) {
|
---|
| 37 | double speed = AudioPlayer.speed();
|
---|
| 38 | if (speed * multiplier <= 0.1)
|
---|
| 39 | return;
|
---|
| 40 | try {
|
---|
| 41 | if (AudioPlayer.playing() || AudioPlayer.paused())
|
---|
| 42 | AudioPlayer.play(AudioPlayer.url(), AudioPlayer.position(), speed * multiplier);
|
---|
| 43 | } catch (Exception ex) {
|
---|
| 44 | AudioPlayer.audioMalfunction(ex);
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
[626] | 47 | }
|
---|