Last active
January 21, 2024 07:05
-
-
Save katspaugh/868654c2209973d0a56975c5341eb6f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Multitrack from 'https://unpkg.com/wavesurfer-multitrack' | |
import WebAudioPlayer from 'https://unpkg.com/wavesurfer-multitrack/dist/webaudio.js' | |
const audioContext = new AudioContext() | |
const GAIN = 2 | |
const multitrack = Multitrack.create( | |
[ | |
{ | |
id: 0, | |
options: { | |
waveColor: 'hsl(161, 87%, 49%)', | |
progressColor: 'hsl(161, 87%, 20%)', | |
media: new WebAudioPlayer(audioContext), | |
}, | |
url: '/examples/audio/audio.wav', | |
}, | |
{ | |
id: 1, | |
options: { | |
waveColor: 'hsl(121, 87%, 49%)', | |
progressColor: 'hsl(161, 87%, 20%)', | |
media: new WebAudioPlayer(audioContext), | |
}, | |
url: '/examples/audio/demo.wav', | |
}, | |
], | |
{ | |
container: document.querySelector('#container'), // required! | |
minPxPerSec: 10, // zoom level | |
rightButtonDrag: false, // set to true to drag with right mouse button | |
cursorWidth: 2, | |
cursorColor: '#D72F21', | |
trackBackground: '#2D2D2D', | |
trackBorderColor: '#7C7C7C', | |
dragBounds: true, | |
envelopeOptions: { | |
lineColor: 'rgba(255, 0, 0, 0.7)', | |
lineWidth: 4, | |
dragPointSize: window.innerWidth < 600 ? 20 : 10, | |
dragPointFill: 'rgba(255, 255, 255, 0.8)', | |
dragPointStroke: 'rgba(255, 255, 255, 0.3)', | |
}, | |
}, | |
) | |
document.querySelector('#play').addEventListener('click', () => { | |
multitrack.setTime(0) | |
multitrack.play() | |
}) | |
document.querySelector('#only-0').addEventListener('click', () => { | |
multitrack.setTrackVolume(1, 0) | |
multitrack.setTrackVolume(0, GAIN) | |
}) | |
document.querySelector('#only-1').addEventListener('click', () => { | |
multitrack.setTrackVolume(0, 0) | |
multitrack.setTrackVolume(1, GAIN) | |
}) | |
/* | |
<html> | |
<label> | |
Zoom: <input type="range" min="10" max="100" value="10" /> | |
</label> | |
<div style="margin: 2em 0"> | |
<button id="play">Play</button> | |
<button id="only-0">Only track #0</button> | |
<button id="only-1">Only track #1</button> | |
</div> | |
<div id="container" style="background: #2d2d2d; color: #fff"></div> | |
</html> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment