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