1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions.audio;
|
---|
3 |
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
8 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
9 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Abstract superclass of {@link AudioFasterAction} and {@link AudioSlowerAction}.
|
---|
13 | * @since 563
|
---|
14 | */
|
---|
15 | abstract public class AudioFastSlowAction extends JosmAction {
|
---|
16 |
|
---|
17 | private double multiplier;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Constructs a new {@code AudioFastSlowAction}.
|
---|
21 | *
|
---|
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 | */
|
---|
28 | public AudioFastSlowAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean fast) {
|
---|
29 | super(name, iconName, tooltip, shortcut, true);
|
---|
30 | multiplier = Main.pref.getDouble("audio.fastfwdmultiplier", 1.3);
|
---|
31 | if (! fast)
|
---|
32 | multiplier = 1.0 / multiplier;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void actionPerformed(ActionEvent e) {
|
---|
36 | double speed = AudioPlayer.speed();
|
---|
37 | if (speed * multiplier <= 0.1)
|
---|
38 | return;
|
---|
39 | try {
|
---|
40 | if (AudioPlayer.playing() || AudioPlayer.paused())
|
---|
41 | AudioPlayer.play(AudioPlayer.url(), AudioPlayer.position(), speed * multiplier);
|
---|
42 | } catch (Exception ex) {
|
---|
43 | AudioPlayer.audioMalfunction(ex);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|