-
Notifications
You must be signed in to change notification settings - Fork 0
/
soundtools.js
153 lines (122 loc) · 5.65 KB
/
soundtools.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* GDevelop JS Platform
* Copyright 2013-2015 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
/**
* Class used by events to interact with the soundManager.
*
* @namespace gdjs.evtTools
* @class sound
* @static
* @private
*/
gdjs.evtTools.sound = gdjs.evtTools.sound || {};
gdjs.evtTools.sound.getGlobalVolume = function(runtimeScene) {
return runtimeScene.getSoundManager().getGlobalVolume();
};
gdjs.evtTools.sound.setGlobalVolume = function(runtimeScene, globalVolume) {
runtimeScene.getSoundManager().setGlobalVolume(globalVolume);
};
//Sounds:
gdjs.evtTools.sound.playSound = function(runtimeScene, soundFile, loop, volume, pitch) {
runtimeScene.getSoundManager().playSound(soundFile, loop, volume, pitch);
};
gdjs.evtTools.sound.playSoundOnChannel = function(runtimeScene, soundFile, channel, loop, volume, pitch) {
runtimeScene.getSoundManager().playSoundOnChannel(soundFile, channel, loop, volume, pitch);
};
gdjs.evtTools.sound.stopSoundOnChannel = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
sound && sound.stop();
};
gdjs.evtTools.sound.pauseSoundOnChannel = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
sound && sound.pause();
};
gdjs.evtTools.sound.continueSoundOnChannel = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
sound && sound.play();
};
gdjs.evtTools.sound.isSoundOnChannelPlaying = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.playing() : false;
};
gdjs.evtTools.sound.isSoundOnChannelPaused = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.paused() : false;
};
gdjs.evtTools.sound.isSoundOnChannelStopped = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.stopped() : true;
};
gdjs.evtTools.sound.getSoundOnChannelVolume = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.volume() * 100 : 100;
};
gdjs.evtTools.sound.setSoundOnChannelVolume = function(runtimeScene, channel, volume) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
sound && sound.volume(volume / 100);
};
gdjs.evtTools.sound.getSoundOnChannelPlayingOffset = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.seek() : 0;
};
gdjs.evtTools.sound.setSoundOnChannelPlayingOffset = function(runtimeScene, channel, playingOffset) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
sound && sound.seek(playingOffset);
};
gdjs.evtTools.sound.getSoundOnChannelPitch = function(runtimeScene, channel) {
var sound = runtimeScene.getSoundManager().getSoundOnChannel(channel);
return sound ? sound.rate() : 1;
};
//Musics:
gdjs.evtTools.sound.playMusic = function(runtimeScene, soundFile, loop, volume, pitch) {
runtimeScene.getSoundManager().playMusic(soundFile, loop, volume, pitch);
};
gdjs.evtTools.sound.playMusicOnChannel = function(runtimeScene, soundFile, channel, loop, volume, pitch) {
runtimeScene.getSoundManager().playMusicOnChannel(soundFile, channel, loop, volume, pitch);
};
gdjs.evtTools.sound.stopMusicOnChannel = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
music && music.stop();
};
gdjs.evtTools.sound.pauseMusicOnChannel = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
music && music.pause();
};
gdjs.evtTools.sound.continueMusicOnChannel = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
music && music.play();
};
gdjs.evtTools.sound.isMusicOnChannelPlaying = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.playing() : false;
};
gdjs.evtTools.sound.isMusicOnChannelPaused = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.paused() : false;
};
gdjs.evtTools.sound.isMusicOnChannelStopped = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.stopped() : true;
};
gdjs.evtTools.sound.getMusicOnChannelVolume = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.volume() * 100 : 100;
};
gdjs.evtTools.sound.setMusicOnChannelVolume = function(runtimeScene, channel, volume) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
music && music.volume(volume / 100);
};
gdjs.evtTools.sound.getMusicOnChannelPlayingOffset = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.seek() : 0;
};
gdjs.evtTools.sound.setMusicOnChannelPlayingOffset = function(runtimeScene, channel, playingOffset) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
music && music.seek(playingOffset);
};
gdjs.evtTools.sound.getMusicOnChannelPitch = function(runtimeScene, channel) {
var music = runtimeScene.getSoundManager().getMusicOnChannel(channel);
return music ? music.rate() : 1;
};