@@ -13,8 +13,9 @@ class SoundboardInstance extends InstanceBase {
1313 this . cues = [ ] // Store the cues received from the soundboard app
1414 this . reconnectInterval = null
1515 this . currentlyPlayingCueId = null // Track which cue is considered "currently playing"
16- this . cuePlayStates = { } // cueId: 'playing' | 'paused' | 'stopped'
16+ this . cuePlayStates = { } // cueId: 'playing' | 'paused' | 'stopped' | 'fading'
1717 this . cueStartTimestamps = { } // cueId: number (ms since epoch)
18+ this . cueFadeStates = { } // cueId: { isFadingIn: boolean, isFadingOut: boolean }
1819 }
1920
2021 async init ( config ) {
@@ -134,27 +135,72 @@ class SoundboardInstance extends InstanceBase {
134135
135136 // Trigger feedback updates if status changed
136137 if ( oldStatus !== status ) {
137- this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' )
138+ if ( status === 'stopped' ) {
139+ delete this . cueFadeStates [ cueId ]
140+ } else if ( status === 'fading' ) {
141+ this . cueFadeStates [ cueId ] = {
142+ isFadingIn : message . payload . isFadingIn || false ,
143+ isFadingOut : message . payload . isFadingOut || false ,
144+ }
145+ } else {
146+ delete this . cueFadeStates [ cueId ]
147+ }
148+ this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' , 'cue_is_fading' , 'cue_is_fading_in' , 'cue_is_fading_out' )
138149 }
139150 }
140151 } else if ( message . event === 'playbackTimeUpdate' && message . payload ) {
141152 // Determine transitions and update current-cue semantics
142- const { cueId, status } = message . payload
143- let oldStatus
144- if ( cueId && status ) {
145- oldStatus = this . cuePlayStates [ cueId ]
146- const setAsCurrentNow = status === 'playing' && oldStatus !== 'playing'
147- if ( setAsCurrentNow ) {
148- this . cueStartTimestamps [ cueId ] = Date . now ( )
149- }
150- if ( status === 'stopped' ) {
151- delete this . cueStartTimestamps [ cueId ]
152- }
153- updateVariablesForCue ( this , message . payload , { setAsCurrentNow } )
154- this . cuePlayStates [ cueId ] = status
155- if ( oldStatus !== status ) {
156- this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' )
157- }
153+ const { cueId, status } = message . payload
154+ let oldStatus
155+ if ( cueId && status ) {
156+ oldStatus = this . cuePlayStates [ cueId ]
157+ const oldFadeState = this . cueFadeStates [ cueId ]
158+ const setAsCurrentNow = ( status === 'playing' || status === 'fading' ) && oldStatus !== 'playing' && oldStatus !== 'fading'
159+ if ( setAsCurrentNow ) {
160+ this . cueStartTimestamps [ cueId ] = Date . now ( )
161+ }
162+ if ( status === 'stopped' ) {
163+ delete this . cueStartTimestamps [ cueId ]
164+ delete this . cueFadeStates [ cueId ]
165+ // Update state first so feedbacks evaluate correctly
166+ this . cuePlayStates [ cueId ] = status
167+ updateVariablesForCue ( this , message . payload , { setAsCurrentNow } )
168+ // Clear fade feedbacks if it was fading before
169+ if ( oldStatus === 'fading' ) {
170+ this . checkFeedbacks ( 'cue_is_fading_in' , 'cue_is_fading_out' , 'cue_is_fading' )
171+ }
172+ if ( oldStatus !== status ) {
173+ this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' )
174+ }
175+ } else if ( status === 'fading' ) {
176+ // Store fade state for feedbacks
177+ const newFadeState = {
178+ isFadingIn : message . payload . isFadingIn || false ,
179+ isFadingOut : message . payload . isFadingOut || false ,
180+ }
181+ this . cueFadeStates [ cueId ] = newFadeState
182+ this . cuePlayStates [ cueId ] = status
183+ updateVariablesForCue ( this , message . payload , { setAsCurrentNow } )
184+ // Check if fade direction changed
185+ const fadeDirectionChanged = ! oldFadeState ||
186+ oldFadeState . isFadingIn !== newFadeState . isFadingIn ||
187+ oldFadeState . isFadingOut !== newFadeState . isFadingOut
188+ if ( oldStatus !== status ) {
189+ // Status changed to fading
190+ this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' , 'cue_is_fading' , 'cue_is_fading_in' , 'cue_is_fading_out' )
191+ } else if ( fadeDirectionChanged ) {
192+ // Fade direction changed while status remained fading
193+ this . checkFeedbacks ( 'cue_is_fading_in' , 'cue_is_fading_out' )
194+ }
195+ } else {
196+ // Clear fade state when not fading
197+ delete this . cueFadeStates [ cueId ]
198+ this . cuePlayStates [ cueId ] = status
199+ updateVariablesForCue ( this , message . payload , { setAsCurrentNow } )
200+ if ( oldStatus !== status ) {
201+ this . checkFeedbacks ( 'cue_is_playing' , 'cue_is_paused' , 'cue_is_stopped' , 'cue_is_fading' , 'cue_is_fading_in' , 'cue_is_fading_out' )
202+ }
203+ }
158204
159205 // If the current cue stopped, switch to the most recently started remaining playing cue
160206 if ( status === 'stopped' && this . currentlyPlayingCueId === cueId ) {
0 commit comments