UNPKG

waveform-playlist

Version:

Multiple track web audio editor and player with waveform preview

61 lines (51 loc) 1.17 kB
import { pixelsToSeconds } from "../../utils/conversions"; export default class { constructor(track) { this.track = track; this.active = false; } setup(samplesPerPixel, sampleRate) { this.samplesPerPixel = samplesPerPixel; this.sampleRate = sampleRate; } emitShift(x) { const deltaX = x - this.prevX; const deltaTime = pixelsToSeconds(deltaX, this.samplesPerPixel, this.sampleRate); this.prevX = x; this.track.ee.emit("shift", deltaTime, this.track); } complete(x) { this.emitShift(x); this.active = false; } mousedown(e) { e.preventDefault(); this.active = true; this.el = e.target; this.prevX = e.offsetX; } mousemove(e) { if (this.active) { e.preventDefault(); this.emitShift(e.offsetX); } } mouseup(e) { if (this.active) { e.preventDefault(); this.complete(e.offsetX); } } mouseleave(e) { if (this.active) { e.preventDefault(); this.complete(e.offsetX); } } static getClass() { return ".state-shift"; } static getEvents() { return ["mousedown", "mousemove", "mouseup", "mouseleave"]; } }