@@ -9,7 +9,11 @@ import type {
99} from "./types" ;
1010import { KomorebiEvents } from "./events" ;
1111import { StateMachine } from "./state" ;
12- import { QueueManager , type WeightedRandomizer , type ShuffleMode } from "./queue" ;
12+ import {
13+ QueueManager ,
14+ type WeightedRandomizer ,
15+ type ShuffleMode ,
16+ } from "./queue" ;
1317import { Scheduler } from "./scheduler" ;
1418import type { IAudioBackend } from "../../platform/audio" ;
1519
@@ -125,7 +129,7 @@ export class KomorebiEngine {
125129 }
126130
127131 this . queue . setCurrentIndex (
128- this . queue . getTracks ( ) . findIndex ( ( t ) => t . id === track . id )
132+ this . queue . getTracks ( ) . findIndex ( ( t ) => t . id === track . id ) ,
129133 ) ;
130134
131135 this . stateMachine . transition ( "loading" ) ;
@@ -209,7 +213,9 @@ export class KomorebiEngine {
209213 const nextTrack = this . queue . getNextTrack ( this . settings . smartShuffle ) ;
210214 if ( nextTrack ) {
211215 const currentTrack = this . queue . getCurrentTrack ( ) ;
212- this . queue . setCurrentIndex ( this . queue . getNextIndex ( this . settings . smartShuffle ) ) ;
216+ this . queue . setCurrentIndex (
217+ this . queue . getNextIndex ( this . settings . smartShuffle ) ,
218+ ) ;
213219
214220 if ( this . stateMachine . isPlaying ( ) ) {
215221 this . loadAndPlay ( nextTrack ) ;
@@ -239,7 +245,9 @@ export class KomorebiEngine {
239245 const prevTrack = this . queue . getPreviousTrack ( this . settings . smartShuffle ) ;
240246 if ( prevTrack ) {
241247 const currentTrack = this . queue . getCurrentTrack ( ) ;
242- this . queue . setCurrentIndex ( this . queue . getPreviousIndex ( this . settings . smartShuffle ) ) ;
248+ this . queue . setCurrentIndex (
249+ this . queue . getPreviousIndex ( this . settings . smartShuffle ) ,
250+ ) ;
243251
244252 if ( this . stateMachine . isPlaying ( ) ) {
245253 this . loadAndPlay ( prevTrack ) ;
@@ -300,8 +308,11 @@ export class KomorebiEngine {
300308
301309 toggleRepeat ( ) : void {
302310 const current = this . settings . repeat ;
303- this . settings . repeat = current === "off" ? "all" : current === "all" ? "one" : "off" ;
304- this . events . emit ( "settingschange" , { settings : { repeat : this . settings . repeat } } ) ;
311+ this . settings . repeat =
312+ current === "off" ? "all" : current === "all" ? "one" : "off" ;
313+ this . events . emit ( "settingschange" , {
314+ settings : { repeat : this . settings . repeat } ,
315+ } ) ;
305316 }
306317
307318 setCrossfade ( duration : number ) : void {
@@ -313,7 +324,9 @@ export class KomorebiEngine {
313324 setGapless ( enabled : boolean ) : void {
314325 this . settings . gaplessPlayback = enabled ;
315326 this . scheduler . setGaplessConfig ( { enabled } ) ;
316- this . events . emit ( "settingschange" , { settings : { gaplessPlayback : enabled } } ) ;
327+ this . events . emit ( "settingschange" , {
328+ settings : { gaplessPlayback : enabled } ,
329+ } ) ;
317330 }
318331
319332 updateSettings ( newSettings : Partial < EngineSettings > ) : void {
@@ -372,14 +385,14 @@ export class KomorebiEngine {
372385
373386 on < E extends keyof EngineEventMap > (
374387 event : E ,
375- callback : ( data : EngineEventMap [ E ] ) => void
388+ callback : ( data : EngineEventMap [ E ] ) => void ,
376389 ) : void {
377390 this . events . on ( event , callback ) ;
378391 }
379392
380393 off < E extends keyof EngineEventMap > (
381394 event : E ,
382- callback : ( data : EngineEventMap [ E ] ) => void
395+ callback : ( data : EngineEventMap [ E ] ) => void ,
383396 ) : void {
384397 this . events . off ( event , callback ) ;
385398 }
@@ -396,17 +409,18 @@ export class KomorebiEngine {
396409 return new Promise ( ( resolve , reject ) => {
397410 const onEndedHandler = ( ) => {
398411 this . backend ?. offEnded ( onEndedHandler ) ;
399- this . play ( )
400- . then ( resolve )
401- . catch ( reject ) ;
412+ this . play ( ) . then ( resolve ) . catch ( reject ) ;
402413 } ;
403414
404415 this . backend ?. onEnded ( onEndedHandler ) ;
405416 this . load ( track ) ;
406417 } ) ;
407418 }
408419
409- private async waitForState ( targetState : PlayerState , timeout = 5000 ) : Promise < void > {
420+ private async waitForState (
421+ targetState : PlayerState ,
422+ timeout = 5000 ,
423+ ) : Promise < void > {
410424 return new Promise ( ( resolve , reject ) => {
411425 const checkState = ( ) => {
412426 if ( this . stateMachine . getState ( ) === targetState ) {
@@ -465,7 +479,8 @@ export class KomorebiEngine {
465479 const nextTrack = this . queue . getNextTrack ( this . settings . smartShuffle ) ;
466480 if ( ! nextTrack ) return ;
467481
468- const delay = this . scheduler . getMode ( ) === "gapless" ? 100 : this . settings . crossfade ;
482+ const delay =
483+ this . scheduler . getMode ( ) === "gapless" ? 100 : this . settings . crossfade ;
469484
470485 this . scheduledTransitionId = window . setTimeout ( ( ) => {
471486 this . scheduledTransitionId = null ;
@@ -475,7 +490,9 @@ export class KomorebiEngine {
475490
476491 private executeTransition ( nextTrack : Track ) : void {
477492 const currentTrack = this . queue . getCurrentTrack ( ) ;
478- this . queue . setCurrentIndex ( this . queue . getNextIndex ( this . settings . smartShuffle ) ) ;
493+ this . queue . setCurrentIndex (
494+ this . queue . getNextIndex ( this . settings . smartShuffle ) ,
495+ ) ;
479496
480497 this . load ( nextTrack ) ;
481498 this . play ( ) ;
@@ -544,15 +561,21 @@ export class KomorebiEngine {
544561 private emitStateChange ( ) : void {
545562 const prevState = this . stateMachine . getPreviousState ( ) ;
546563 const newState = this . stateMachine . getState ( ) ;
547- this . events . emit ( "statechange" , { oldState : prevState ?? "idle" , newState } ) ;
564+ this . events . emit ( "statechange" , {
565+ oldState : prevState ?? "idle" ,
566+ newState,
567+ } ) ;
548568 }
549569
550570 private emitTrackChange ( from : Track | null , to : Track | null ) : void {
551571 this . events . emit ( "trackchange" , { from, to } ) ;
552572 }
553573
554574 private emitTimeUpdate ( ) : void {
555- this . events . emit ( "timeupdate" , { currentTime : this . currentTime , duration : this . duration } ) ;
575+ this . events . emit ( "timeupdate" , {
576+ currentTime : this . currentTime ,
577+ duration : this . duration ,
578+ } ) ;
556579 }
557580
558581 private emitError ( code : string , message : string , track ?: Track ) : void {
@@ -561,4 +584,4 @@ export class KomorebiEngine {
561584 this . events . emit ( "error" , { error : this . currentError } ) ;
562585 this . emitStateChange ( ) ;
563586 }
564- }
587+ }
0 commit comments