forked from cassiodezotti/Rabisco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundService.java
104 lines (85 loc) · 1.92 KB
/
SoundService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.HashMap;
import processing.core.*;
import processing.sound.*;
public class SoundService
{
private HashMap<String, SoundFile> soundFileMap;
private HashMap<SoundID, SoundFile> soundIDMap;
private PApplet pApplet;
private static SoundService soundService;
private SoundService(PApplet pApplet)
{
soundFileMap = new HashMap<String, SoundFile>();
soundIDMap = new HashMap<SoundID, SoundFile>();
this.pApplet = pApplet;
}
public void load(String file)
{
SoundFile soundFile = new SoundFile(pApplet, file);
soundFileMap.put(file, soundFile);
}
public void defineID(SoundID id, String file)
{
SoundFile soundFile = soundFileMap.get(file);
soundIDMap.put(id, soundFile);
}
private void play(SoundFile soundFile)
{
if(!soundFile.isPlaying())
{
soundFile.play();
}
}
private void loop(SoundFile soundFile)
{
if(!soundFile.isPlaying())
{
soundFile.loop();
}
}
public void play(SoundID id)
{
SoundFile soundFile = soundIDMap.get(id);
play(soundFile);
}
public void play(String file)
{
SoundFile soundFile = soundFileMap.get(file);
play(soundFile);
}
public void stop(SoundID id)
{
SoundFile soundFile = soundIDMap.get(id);
soundFile.stop();
}
public void stop(String file)
{
SoundFile soundFile = soundFileMap.get(file);
soundFile.stop();
}
public void loop(SoundID id)
{
SoundFile soundFile = soundIDMap.get(id);
loop(soundFile);
}
public void loop(String file)
{
SoundFile soundFile = soundFileMap.get(file);
loop(soundFile);
}
public void stopAll()
{
for (SoundFile soundFile : soundFileMap.values())
{
soundFile.stop();
}
}
static public void initialize(PApplet papplet)
{
SoundService.soundService = new SoundService(papplet);
}
static public SoundService getInstance()
{
return soundService;
}
}