Skip to content

Commit

Permalink
Feat: set track start position (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: Konrad Daniek <[email protected]>
  • Loading branch information
kdaniek-tuney and Konrad Daniek authored Jul 16, 2024
1 parent 8bb4cb3 commit 02a5d97
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/multitrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,23 @@ class MultiTrack extends EventEmitter<MultitrackEvents> {
;(this.envelopes[index] || this.wavesurfers[index])?.setVolume(volume)
}

public setTrackStartPosition(index: number, value: number) {
const track = this.tracks[index]
if (!track.draggable) return

const newStartPosition = value
const minStart = this.options.dragBounds ? 0 : -this.durations[index] - 1
const maxStart = this.maxDuration - this.durations[index]

if (newStartPosition >= minStart && newStartPosition <= maxStart) {
track.startPosition = newStartPosition
this.initDurations(this.durations)
this.rendering.setContainerOffsets()
this.updatePosition(this.currentTime)
this.emit('start-position-change', { id: track.id, startPosition: newStartPosition })
}
}

public getEnvelopePoints(trackIndex: number): EnvelopePoint[] | undefined {
return this.envelopes[trackIndex]?.getPoints()
}
Expand Down

0 comments on commit 02a5d97

Please sign in to comment.