11package nestdrop.deck
22
3+ import QUEUES
34import androidx.compose.runtime.Immutable
45import androidx.compose.ui.graphics.Color
56import androidx.compose.ui.graphics.compositeOver
@@ -20,6 +21,7 @@ import kotlinx.coroutines.flow.asStateFlow
2021import kotlinx.coroutines.flow.combine
2122import kotlinx.coroutines.flow.distinctUntilChanged
2223import kotlinx.coroutines.flow.drop
24+ import kotlinx.coroutines.flow.filter
2325import kotlinx.coroutines.flow.filterNotNull
2426import kotlinx.coroutines.flow.flowOn
2527import kotlinx.coroutines.flow.launchIn
@@ -37,6 +39,7 @@ import nestdrop.NestdropSpriteQueue
3739import nestdrop.PresetIdState
3840import nestdrop.PresetLocation
3941import nestdrop.Queue
42+ import nestdrop.QueueType
4043import nestdrop.imgFxMap
4144import nestdrop.nestdropSetPreset
4245import nestdrop.nestdropSetSprite
@@ -516,18 +519,18 @@ class Deck(
516519
517520 val preset = Preset ()
518521
519- @Immutable
520- inner class SpriteQueues :
521- MutableStateFlow <List <Queue <nestdrop.Preset .ImageSprite >>> by MutableStateFlow (emptyList()) {
522- suspend fun startFlows () {
523- // logger.info { "initializing $deckName sprite queues" }
524- }
525- }
522+ // @Immutable
523+ // inner class SpriteQueues :
524+ // MutableStateFlow<List<Queue<nestdrop.Preset.ImageSprite>>> by MutableStateFlow(emptyList()) {
525+ // suspend fun startFlows() {
526+ // // logger.info { "initializing $deckName sprite queues" }
527+ // }
528+ // }
526529
527530 // @Deprecated("lookup queues from QUEUES.allQueues")
528531// val imgSpriteQueues: MutableStateFlow<List<Queue<nestdrop.Preset.ImageSprite>>> = MutableStateFlow(emptyList())
529- @Deprecated(" lookup queues from QUEUES.allQueues" )
530- val spoutSpriteQueues: MutableStateFlow <List <Queue <nestdrop.Preset .SpoutSprite >>> = MutableStateFlow (emptyList())
532+ // @Deprecated("lookup queues from QUEUES.allQueues")
533+ // val spoutSpriteQueues: MutableStateFlow<List<Queue<nestdrop.Preset.SpoutSprite>>> = MutableStateFlow(emptyList())
531534
532535 @Serializable
533536 data class SpriteData (
@@ -662,7 +665,6 @@ class Deck(
662665 if (state != mutableState) {
663666 spoutStates.value = mutableState.toMap()
664667 }
665-
666668 }
667669 }
668670 .launchIn(flowScope)
@@ -801,6 +803,8 @@ class Deck(
801803 } else if (next != null ) {
802804 nestdropSetSprite(next.id, id, single = true )
803805 }
806+ logger.info { " triggering spriteFX sync" }
807+ imgSpriteFx.sync()
804808 }
805809 .launchIn(flowScope)
806810
@@ -828,6 +832,10 @@ class Deck(
828832 private val sync = MutableStateFlow (0 )
829833 private val trigger = MutableStateFlow (0 )
830834
835+ suspend fun sync () {
836+ sync.value++
837+ }
838+
831839 suspend fun next () {
832840 if (id > enabled.value) {
833841 return
@@ -844,13 +852,13 @@ class Deck(
844852
845853 suspend fun setSpriteFx (index : Int , blendMode : Boolean ) {
846854 val fx = if (blendMode) index + 50 else index
847- logger.info { " setting $deckName FX to $fx " }
855+ logger.info { " setting $deckName Sprite FX to $fx " }
848856 val arg = fx / 99.0f
849857 nestdropSendChannel.send(OSCMessage (nestdropDeckAddress(" sSpriteFx" ), arg))
850858 }
851859
852860 suspend fun setSpriteFxRaw (rawFx : Int ) {
853- logger.info { " setting $deckName FX to $rawFx " }
861+ logger.info { " setting $deckName Sprite FX to $rawFx " }
854862 val arg = rawFx / 99.0f
855863 nestdropSendChannel.send(OSCMessage (nestdropDeckAddress(" sSpriteFx" ), arg))
856864 }
@@ -881,11 +889,11 @@ class Deck(
881889
882890 // TODO: remove
883891 // handled via passing raw FX into SpriteKey
884- index
885- .combine(sync) { a, _ -> a }
886- .combine(blendMode ) { index, blendMode ->
887- setSpriteFx(index, blendMode)
888- }
892+ combine(
893+ index, blendMode, sync,
894+ ) { index, blendMode, _ ->
895+ setSpriteFx(index, blendMode)
896+ }
889897// .filter { fx -> fx in (0..99) }
890898// .onEach { fx ->
891899// logger.infoF { "setting $deckName FX to $fx" }
@@ -904,9 +912,11 @@ class Deck(
904912
905913 suspend fun startFlows () {
906914 logger.info { " starting coroutines on $deckName spout-queue" }
915+
916+ val spoutQueues = QUEUES .spoutQueues().map { it.filter { it.deck == id } }
907917 index
908918// .combine(resyncToTouchOSC) { a, _ -> a }
909- .combine(spoutSpriteQueues ) { index, queues ->
919+ .combine(spoutQueues ) { index, queues ->
910920 queues.getOrNull(index)
911921 }
912922 .onEach {
0 commit comments