wavesurfer.js 6.5.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +24 -0
- package/.prettierrc +8 -0
- package/README.md +26 -117
- package/dist/base-plugin.d.ts +10 -0
- package/dist/base-plugin.js +13 -0
- package/dist/decoder.d.ts +10 -0
- package/dist/decoder.js +43 -0
- package/dist/event-emitter.d.ts +11 -0
- package/dist/event-emitter.js +21 -0
- package/dist/fetcher.d.ts +4 -0
- package/dist/fetcher.js +17 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +166 -0
- package/dist/player-webaudio.d.ts +8 -0
- package/dist/player-webaudio.js +31 -0
- package/dist/player.d.ts +16 -0
- package/dist/player.js +40 -0
- package/dist/plugins/regions.d.ts +48 -0
- package/dist/plugins/regions.js +183 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.js +193 -0
- package/dist/timer.d.ts +10 -0
- package/dist/timer.js +17 -0
- package/examples/audio.ogg +0 -0
- package/examples/bars.js +19 -0
- package/examples/basic.js +8 -0
- package/examples/gradient.js +28 -0
- package/examples/regions.js +63 -0
- package/examples/video.js +19 -0
- package/examples/webaudio.js +14 -0
- package/package.json +19 -99
- package/src/base-plugin.ts +20 -0
- package/src/decoder.ts +41 -0
- package/src/event-emitter.ts +35 -0
- package/src/fetcher.ts +7 -0
- package/src/index.ts +252 -0
- package/src/player-webaudio.ts +34 -0
- package/src/player.ts +50 -0
- package/src/plugins/regions.ts +240 -0
- package/src/renderer.ts +250 -0
- package/src/timer.ts +27 -0
- package/tsconfig.json +105 -0
- package/tutorial/index.html +47 -0
- package/tutorial/src/editor.js +70 -0
- package/tutorial/src/init.js +66 -0
- package/tutorial/src/url.js +25 -0
- package/tutorial/style.css +211 -0
- package/yarn-error.log +1049 -0
- package/LICENSE +0 -29
- package/dist/plugin/wavesurfer.cursor.js +0 -418
- package/dist/plugin/wavesurfer.cursor.js.map +0 -1
- package/dist/plugin/wavesurfer.cursor.min.js +0 -7
- package/dist/plugin/wavesurfer.cursor.min.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.js +0 -381
- package/dist/plugin/wavesurfer.elan.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.min.js +0 -7
- package/dist/plugin/wavesurfer.elan.min.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.js +0 -520
- package/dist/plugin/wavesurfer.markers.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.min.js +0 -7
- package/dist/plugin/wavesurfer.markers.min.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.js +0 -181
- package/dist/plugin/wavesurfer.mediasession.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +0 -7
- package/dist/plugin/wavesurfer.mediasession.min.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.js +0 -466
- package/dist/plugin/wavesurfer.microphone.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.min.js +0 -7
- package/dist/plugin/wavesurfer.microphone.min.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.js +0 -440
- package/dist/plugin/wavesurfer.minimap.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.min.js +0 -7
- package/dist/plugin/wavesurfer.minimap.min.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.js +0 -300
- package/dist/plugin/wavesurfer.playhead.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.min.js +0 -7
- package/dist/plugin/wavesurfer.playhead.min.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.js +0 -1342
- package/dist/plugin/wavesurfer.regions.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.min.js +0 -7
- package/dist/plugin/wavesurfer.regions.min.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.js +0 -736
- package/dist/plugin/wavesurfer.spectrogram.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +0 -7
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.js +0 -649
- package/dist/plugin/wavesurfer.timeline.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.min.js +0 -7
- package/dist/plugin/wavesurfer.timeline.min.js.map +0 -1
- package/dist/wavesurfer-html-init.js +0 -381
- package/dist/wavesurfer-html-init.js.map +0 -1
- package/dist/wavesurfer-html-init.min.js +0 -7
- package/dist/wavesurfer-html-init.min.js.map +0 -1
- package/dist/wavesurfer.js +0 -6145
- package/dist/wavesurfer.js.map +0 -1
- package/dist/wavesurfer.min.js +0 -7
- package/dist/wavesurfer.min.js.map +0 -1
- package/src/drawer.canvasentry.js +0 -427
- package/src/drawer.js +0 -413
- package/src/drawer.multicanvas.js +0 -617
- package/src/html-init.js +0 -241
- package/src/mediaelement-webaudio.js +0 -77
- package/src/mediaelement.js +0 -443
- package/src/peakcache.js +0 -127
- package/src/plugin/cursor/index.js +0 -350
- package/src/plugin/elan/index.js +0 -307
- package/src/plugin/markers/index.js +0 -436
- package/src/plugin/mediasession/index.js +0 -94
- package/src/plugin/microphone/index.js +0 -415
- package/src/plugin/minimap/index.js +0 -403
- package/src/plugin/playhead/index.js +0 -226
- package/src/plugin/regions/index.js +0 -478
- package/src/plugin/regions/region.js +0 -883
- package/src/plugin/spectrogram/fft.js +0 -222
- package/src/plugin/spectrogram/index.js +0 -522
- package/src/plugin/timeline/index.js +0 -600
- package/src/util/absMax.js +0 -16
- package/src/util/clamp.js +0 -11
- package/src/util/fetch.js +0 -222
- package/src/util/frame.js +0 -13
- package/src/util/get-id.js +0 -22
- package/src/util/index.js +0 -14
- package/src/util/max.js +0 -16
- package/src/util/min.js +0 -16
- package/src/util/observer.js +0 -144
- package/src/util/orientation.js +0 -98
- package/src/util/prevent-click.js +0 -19
- package/src/util/request-animation-frame.js +0 -15
- package/src/util/silence-mode.js +0 -42
- package/src/util/style.js +0 -16
- package/src/wavesurfer.js +0 -1797
- package/src/webaudio.js +0 -779
package/src/html-init.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import loadScript from 'load-script';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Object} InitParams
|
|
5
|
-
* @property {WavesurferParams} [defaults={backend: 'MediaElement,
|
|
6
|
-
* mediaControls: true}] The default wavesurfer initialisation parameters
|
|
7
|
-
* @property {string|NodeList} containers='wavesurfer' Selector or NodeList of
|
|
8
|
-
* elements to attach instances to
|
|
9
|
-
* @property {string}
|
|
10
|
-
* pluginCdnTemplate='//localhost:8080/dist/plugin/wavesurfer.[name].js' URL
|
|
11
|
-
* template for the dynamic loading of plugins
|
|
12
|
-
* @property {function} loadPlugin If set overwrites the default request function,
|
|
13
|
-
* can be used to inject plugins differently.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* The HTML initialisation API is not part of the main library bundle file and
|
|
17
|
-
* must be additionally included.
|
|
18
|
-
*
|
|
19
|
-
* The API attaches wavesurfer instances to all `<wavesurfer>` (can be
|
|
20
|
-
* customised), parsing their `data-` attributes to construct an options object
|
|
21
|
-
* for initialisation. Among other things it can dynamically load plugin code.
|
|
22
|
-
*
|
|
23
|
-
* The automatic initialisation can be prevented by setting the
|
|
24
|
-
* `window.WS_StopAutoInit` flag to true. The `html-init[.min].js` file exports
|
|
25
|
-
* the `Init` class, which can be called manually.
|
|
26
|
-
*
|
|
27
|
-
* Site-wide defaults can be added by setting `window.WS_InitOptions`.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* <!-- with minimap and timeline plugin -->
|
|
31
|
-
* <wavesurfer
|
|
32
|
-
* data-url="../media/demo.wav"
|
|
33
|
-
* data-plugins="minimap,timeline"
|
|
34
|
-
* data-minimap-height="30"
|
|
35
|
-
* data-minimap-wave-color="#ddd"
|
|
36
|
-
* data-minimap-progress-color="#999"
|
|
37
|
-
* data-timeline-font-size="13px"
|
|
38
|
-
* data-timeline-container="#timeline"
|
|
39
|
-
* >
|
|
40
|
-
* </wavesurfer>
|
|
41
|
-
* <div id="timeline"></div>
|
|
42
|
-
*
|
|
43
|
-
* <!-- with regions plugin -->
|
|
44
|
-
* <wavesurfer
|
|
45
|
-
* data-url="../media/demo.wav"
|
|
46
|
-
* data-plugins="regions"
|
|
47
|
-
* data-regions-regions='[{"start": 1,"end": 3,"color": "hsla(400, 100%, 30%, 0.5)"}]'
|
|
48
|
-
* >
|
|
49
|
-
* </wavesurfer>
|
|
50
|
-
*/
|
|
51
|
-
class Init {
|
|
52
|
-
/**
|
|
53
|
-
* Instantiate Init class and initialize elements
|
|
54
|
-
*
|
|
55
|
-
* This is done automatically if `window` is defined and
|
|
56
|
-
* `window.WS_StopAutoInit` is not set to true
|
|
57
|
-
*
|
|
58
|
-
* @param {WaveSurfer} WaveSurfer The WaveSurfer library object
|
|
59
|
-
* @param {InitParams} params initialisation options
|
|
60
|
-
*/
|
|
61
|
-
constructor(WaveSurfer, params = {}) {
|
|
62
|
-
if (!WaveSurfer) {
|
|
63
|
-
throw new Error('WaveSurfer is not available!');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* cache WaveSurfer
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
this.WaveSurfer = WaveSurfer;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* build parameters, cache them in _params so minified builds are smaller
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
const _params = (this.params = Object.assign(
|
|
77
|
-
{},
|
|
78
|
-
{
|
|
79
|
-
// wavesurfer parameter defaults so by default the audio player is
|
|
80
|
-
// usable with native media element controls
|
|
81
|
-
defaults: {
|
|
82
|
-
backend: 'MediaElement',
|
|
83
|
-
mediaControls: true
|
|
84
|
-
},
|
|
85
|
-
// containers to instantiate on, can be selector string or NodeList
|
|
86
|
-
containers: 'wavesurfer',
|
|
87
|
-
// @TODO insert plugin CDN URIs
|
|
88
|
-
pluginCdnTemplate:
|
|
89
|
-
'//localhost:8080/dist/plugin/wavesurfer.[name].js',
|
|
90
|
-
// loadPlugin function can be overridden to inject plugin definition
|
|
91
|
-
// objects, this default function uses load-script to load a plugin
|
|
92
|
-
// and pass it to a callback
|
|
93
|
-
loadPlugin(name, cb) {
|
|
94
|
-
const src = _params.pluginCdnTemplate.replace(
|
|
95
|
-
'[name]',
|
|
96
|
-
name
|
|
97
|
-
);
|
|
98
|
-
loadScript(src, { async: false }, (err, plugin) => {
|
|
99
|
-
if (err) {
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
|
-
return console.error(
|
|
102
|
-
`WaveSurfer plugin ${name} not found at ${src}`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
cb(window.WaveSurfer[name]);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
params
|
|
110
|
-
));
|
|
111
|
-
/**
|
|
112
|
-
* The nodes that should have instances attached to them
|
|
113
|
-
* @type {NodeList}
|
|
114
|
-
*/
|
|
115
|
-
this.containers =
|
|
116
|
-
typeof _params.containers == 'string'
|
|
117
|
-
? document.querySelectorAll(_params.containers)
|
|
118
|
-
: _params.containers;
|
|
119
|
-
/** @private */
|
|
120
|
-
this.pluginCache = {};
|
|
121
|
-
/**
|
|
122
|
-
* An array of wavesurfer instances
|
|
123
|
-
* @type {Object[]}
|
|
124
|
-
*/
|
|
125
|
-
this.instances = [];
|
|
126
|
-
|
|
127
|
-
this.initAllEls();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Initialize all container elements
|
|
132
|
-
*/
|
|
133
|
-
initAllEls() {
|
|
134
|
-
// iterate over all the container elements
|
|
135
|
-
Array.prototype.forEach.call(this.containers, el => {
|
|
136
|
-
// load the plugins as an array of plugin names
|
|
137
|
-
const plugins = el.dataset.plugins
|
|
138
|
-
? el.dataset.plugins.split(',')
|
|
139
|
-
: [];
|
|
140
|
-
|
|
141
|
-
// no plugins to be loaded, just render
|
|
142
|
-
if (!plugins.length) {
|
|
143
|
-
return this.initEl(el);
|
|
144
|
-
}
|
|
145
|
-
// … or: iterate over all the plugins
|
|
146
|
-
plugins.forEach((name, i) => {
|
|
147
|
-
// plugin is not cached already, load it
|
|
148
|
-
if (!this.pluginCache[name]) {
|
|
149
|
-
this.params.loadPlugin(name, lib => {
|
|
150
|
-
this.pluginCache[name] = lib;
|
|
151
|
-
// plugins were all loaded, render the element
|
|
152
|
-
if (i + 1 === plugins.length) {
|
|
153
|
-
this.initEl(el, plugins);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
} else if (i === plugins.length) {
|
|
157
|
-
// plugin was cached and this plugin was the last
|
|
158
|
-
this.initEl(el, plugins);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Initialize a single container element and add to `this.instances`
|
|
166
|
-
*
|
|
167
|
-
* @param {HTMLElement} el The container to instantiate wavesurfer to
|
|
168
|
-
* @param {PluginDefinition[]} plugins An Array of plugin names to initialize with
|
|
169
|
-
* @return {Object} Wavesurfer instance
|
|
170
|
-
*/
|
|
171
|
-
initEl(el, plugins = []) {
|
|
172
|
-
const jsonRegex = /^[[|{]/;
|
|
173
|
-
// initialize plugins with the correct options
|
|
174
|
-
const initialisedPlugins = plugins.map(plugin => {
|
|
175
|
-
const options = {};
|
|
176
|
-
// the regex to find this plugin attributes
|
|
177
|
-
const attrNameRegex = new RegExp('^' + plugin);
|
|
178
|
-
let attrName;
|
|
179
|
-
// iterate over all the data attributes and find ones for this
|
|
180
|
-
// plugin
|
|
181
|
-
for (attrName in el.dataset) {
|
|
182
|
-
const regexResult = attrNameRegex.exec(attrName);
|
|
183
|
-
if (regexResult) {
|
|
184
|
-
const attr = el.dataset[attrName];
|
|
185
|
-
// if the string begins with a [ or a { parse it as JSON
|
|
186
|
-
const prop = jsonRegex.test(attr) ? JSON.parse(attr) : attr;
|
|
187
|
-
// this removes the plugin prefix and changes the first letter
|
|
188
|
-
// of the resulting string to lower case to follow the naming
|
|
189
|
-
// convention of ws params
|
|
190
|
-
const unprefixedOptionName =
|
|
191
|
-
attrName
|
|
192
|
-
.slice(plugin.length, plugin.length + 1)
|
|
193
|
-
.toLowerCase() + attrName.slice(plugin.length + 1);
|
|
194
|
-
options[unprefixedOptionName] = prop;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return this.pluginCache[plugin].create(options);
|
|
198
|
-
});
|
|
199
|
-
// build parameter object for this container
|
|
200
|
-
const params = Object.assign(
|
|
201
|
-
{ container: el },
|
|
202
|
-
this.params.defaults,
|
|
203
|
-
el.dataset,
|
|
204
|
-
{ plugins: initialisedPlugins }
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
// @TODO make nicer
|
|
208
|
-
el.style.display = 'block';
|
|
209
|
-
|
|
210
|
-
// initialize wavesurfer, load audio (with peaks if provided)
|
|
211
|
-
const instance = this.WaveSurfer.create(params);
|
|
212
|
-
const peaks = params.peaks ? JSON.parse(params.peaks) : undefined;
|
|
213
|
-
instance.load(params.url, peaks);
|
|
214
|
-
|
|
215
|
-
// push this instance into the instances cache
|
|
216
|
-
this.instances.push(instance);
|
|
217
|
-
return instance;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// if window object exists and window.WS_StopAutoInit is not true
|
|
222
|
-
if (typeof window === 'object' && !window.WS_StopAutoInit) {
|
|
223
|
-
// call init when document is ready, apply any custom default settings
|
|
224
|
-
// in window.WS_InitOptions
|
|
225
|
-
if (document.readyState === 'complete') {
|
|
226
|
-
window.WaveSurferInit = new Init(
|
|
227
|
-
window.WaveSurfer,
|
|
228
|
-
window.WS_InitOptions
|
|
229
|
-
);
|
|
230
|
-
} else {
|
|
231
|
-
window.addEventListener('load', () => {
|
|
232
|
-
window.WaveSurferInit = new Init(
|
|
233
|
-
window.WaveSurfer,
|
|
234
|
-
window.WS_InitOptions
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// export init for manual usage
|
|
241
|
-
export default Init;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import MediaElement from './mediaelement';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* MediaElementWebAudio backend: load audio via an HTML5 audio tag, but playback with the WebAudio API.
|
|
5
|
-
* The advantage here is that the html5 <audio> tag can perform range requests on the server and not
|
|
6
|
-
* buffer the entire file in one request, and you still get the filtering and scripting functionality
|
|
7
|
-
* of the webaudio API.
|
|
8
|
-
* Note that in order to use range requests and prevent buffering, you must provide peak data.
|
|
9
|
-
*
|
|
10
|
-
* @since 3.2.0
|
|
11
|
-
*/
|
|
12
|
-
export default class MediaElementWebAudio extends MediaElement {
|
|
13
|
-
/**
|
|
14
|
-
* Construct the backend
|
|
15
|
-
*
|
|
16
|
-
* @param {WavesurferParams} params Wavesurfer parameters
|
|
17
|
-
*/
|
|
18
|
-
constructor(params) {
|
|
19
|
-
super(params);
|
|
20
|
-
/** @private */
|
|
21
|
-
this.params = params;
|
|
22
|
-
/** @private */
|
|
23
|
-
this.sourceMediaElement = null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Initialise the backend, called in `wavesurfer.createBackend()`
|
|
28
|
-
*/
|
|
29
|
-
init() {
|
|
30
|
-
this.setPlaybackRate(this.params.audioRate);
|
|
31
|
-
this.createTimer();
|
|
32
|
-
this.createVolumeNode();
|
|
33
|
-
this.createScriptNode();
|
|
34
|
-
this.createAnalyserNode();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Private method called by both `load` (from url)
|
|
38
|
-
* and `loadElt` (existing media element) methods.
|
|
39
|
-
*
|
|
40
|
-
* @param {HTMLMediaElement} media HTML5 Audio or Video element
|
|
41
|
-
* @param {number[]|Number.<Array[]>} peaks Array of peak data
|
|
42
|
-
* @param {string} preload HTML 5 preload attribute value
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
_load(media, peaks, preload) {
|
|
46
|
-
super._load(media, peaks, preload);
|
|
47
|
-
this.createMediaElementSource(media);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Create MediaElementSource node
|
|
52
|
-
*
|
|
53
|
-
* @since 3.2.0
|
|
54
|
-
* @param {HTMLMediaElement} mediaElement HTML5 Audio to load
|
|
55
|
-
*/
|
|
56
|
-
createMediaElementSource(mediaElement) {
|
|
57
|
-
this.sourceMediaElement = this.ac.createMediaElementSource(
|
|
58
|
-
mediaElement
|
|
59
|
-
);
|
|
60
|
-
this.sourceMediaElement.connect(this.analyser);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
play(start, end) {
|
|
64
|
-
this.resumeAudioContext();
|
|
65
|
-
return super.play(start, end);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* This is called when wavesurfer is destroyed
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
destroy() {
|
|
73
|
-
super.destroy();
|
|
74
|
-
|
|
75
|
-
this.destroyWebAudio();
|
|
76
|
-
}
|
|
77
|
-
}
|