-
Notifications
You must be signed in to change notification settings - Fork 19
/
IgnisSoundSynchronizer.js
168 lines (156 loc) · 6.33 KB
/
IgnisSoundSynchronizer.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//=============================================================================
// RPG Maker MZ - Ignis Sound Synchronizer
//=============================================================================
/*:
* @target MZ
* @plugindesc Ignis Sound Synchronizer
* @url https://www.patreon.com/raizen884
* @author Reisen (Mauricio Pastana)
* @help Ignis Sound Synchronizer - this plugins is under zlib license
* For support and new plugins join our discord server! https://discord.gg/Kh9XXZ2
* Want to support new creations? be a patreon! https://www.patreon.com/raizen884
*
* You can configure the parameters to set if it should be on or off by default,
* You can also use plugin commands to change the syncronization whenever you need.
* I do recommend for synchronization to be on, only when its needed, since it will
* wait for the audio to synchronize before continuing the images.
*
* You can also create conditions with the following if you do wish to improve
* your evented scenes:
* Just create conditions and use the fourth tab, script for this:
*
* | Ignis.SoundSynchronizer.SoundLoaded
* | returns true if all audio has been loaded and false if not
* | Do remember to turn off the synchronizer, or else the events/graphics will
* | not update until the audio has been loaded.
*
* | Ignis.SoundSynchronizer.NeedToSynchronizeBGM
* | true if BGM synchronization is true
*
* | Ignis.SoundSynchronizer.NeedToSynchronizeBGS
* | true if BGS synchronization is true
*
* @param syncronizeBGM
* @type boolean
* @text Default BGM Syncronization
* @desc Choose if the bgm needs to be syncronized
* @param syncronizeBGS
* @type boolean
* @text Default BGS Syncronization
* @desc Choose if the bgs needs to be syncronized
* @command Syncronize Audio
* @text Syncronize Audio
* @desc Choose whether or not to syncronize the Audio with the image.
* @arg bgm
* @type boolean
* @default false
* @arg bgs
* @type boolean
* @default false
*
*/
// DON'T MODIFY THIS PART!!!
var Ignis = Ignis || {};
Ignis.SoundSynchronizer = Ignis.SoundSynchronizer || {};
Ignis.SoundSynchronizer.VERSION = [1, 0, 0];
Ignis.SoundSynchronizer.CanUpdate = true;
Ignis.SoundSynchronizer.SoundLoaded = true;
Ignis.SoundSynchronizer.NeedToSynchronizeBGM = false;
Ignis.SoundSynchronizer.NeedToSynchronizeBGS = false;
(() => {
const pluginName = "IgnisSoundSynchronizer";
const ignisParameters = PluginManager.parameters(pluginName);
Ignis.SoundSynchronizer.NeedToSynchronizeBGM = ignisParameters['syncronizeBGM'] == "true" ? true : false;
Ignis.SoundSynchronizer.NeedToSynchronizeBGS = ignisParameters['syncronizeBGS'] == "true" ? true : false;
PluginManager.registerCommand(pluginName, "Syncronize Audio", args => {
const bgm = args['bgm'] == "true" ? true : false;
const bgs = args['bgs'] == "true" ? true : false;
Ignis.SoundSynchronizer.NeedToSynchronizeBGM = bgm;
Ignis.SoundSynchronizer.NeedToSynchronizeBGS = bgm;
});
Ignis.SoundSynchronizer.LoadedNewSong = [];
const _Scene_Base_update = Scene_Base.prototype.update;
Scene_Base.prototype.update = function () {
if (Ignis.SoundSynchronizer.CanUpdate)
_Scene_Base_update.call(this, ...arguments);
};
const _AudioManager_playBgm = AudioManager.playBgm;
AudioManager.playBgm = function (bgm, pos) {
Ignis.SoundSynchronizer.LoadedNewSong.push(true);
Ignis.SoundSynchronizer.SoundLoaded = false;
if (!this.isCurrentBgm(bgm) && Ignis.SoundSynchronizer.NeedToSynchronizeBGM) {
Ignis.SoundSynchronizer.CanUpdate = false;
};
_AudioManager_playBgm.call(this, ...arguments);
if (this._bgmBuffer)
this._bgmBuffer.setAudioType("bgm");
else {
Ignis.SoundSynchronizer.SoundLoaded = true;
Ignis.SoundSynchronizer.CanUpdate = true;
Ignis.SoundSynchronizer.LoadedNewSong.pop();
}
};
const _AudioManager_playBgs = AudioManager.playBgs;
AudioManager.playBgs = function (bgs, pos) {
Ignis.SoundSynchronizer.LoadedNewSong.push(true);
Ignis.SoundSynchronizer.SoundLoaded = false;
if (!this.isCurrentBgs(bgs) && Ignis.SoundSynchronizer.NeedToSynchronizeBGS) {
Ignis.SoundSynchronizer.CanUpdate = false;
}
_AudioManager_playBgs.call(this, ...arguments);
if (this._bgsBuffer)
this._bgsBuffer.setAudioType("bgs");
else {
Ignis.SoundSynchronizer.SoundLoaded = true;
Ignis.SoundSynchronizer.CanUpdate = true;
Ignis.SoundSynchronizer.LoadedNewSong.pop();
}
};
WebAudio.prototype.setAudioType = function (type) {
this._audioTypeBuffer = type;
}
WebAudio.prototype._startPlaying = function (offset) {
if (this._loopLengthTime > 0) {
while (offset >= this._loopStartTime + this._loopLengthTime) {
offset -= this._loopLengthTime;
}
}
this._startTime = WebAudio._currentTime() - offset / this._pitch;
this._removeEndTimer();
this._removeNodes();
this._createPannerNode();
this._createGainNode();
this._createAllSourceNodes();
if (Ignis.SoundSynchronizer.LoadedNewSong.length == 0) {
this._startAllSourceNodes();
this._createEndTimer();
} else {
this._checkNeedToWait();
}
};
WebAudio.prototype._checkNeedToWait = function () {
Ignis.SoundSynchronizer.LoadedNewSong.pop();
if (Ignis.SoundSynchronizer.CanUpdate) {
this._startAllSourceNodes();
this._createEndTimer();
if (Ignis.SoundSynchronizer.LoadedNewSong.length == 0)
Ignis.SoundSynchronizer.SoundLoaded = true;
} else {
if (Ignis.SoundSynchronizer.LoadedNewSong.length == 0) {
Ignis.SoundSynchronizer.SoundLoaded = true;
AudioManager.continueAllSound();
Ignis.SoundSynchronizer.CanUpdate = true;
}
}
}
WebAudio.prototype.syncronizedPlay = function () {
this._startAllSourceNodes();
this._createEndTimer();
};
AudioManager.continueAllSound = function () {
if (this._bgmBuffer)
this._bgmBuffer.syncronizedPlay();
if (this._bgsBuffer)
this._bgsBuffer.syncronizedPlay();
};
})();