Skip to content

Commit 7649776

Browse files
committed
fixes
1 parent 7ac53ee commit 7649776

File tree

7 files changed

+65
-29
lines changed

7 files changed

+65
-29
lines changed

src/desktopMain/kotlin/Main.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ object Main {
189189
} ?: error("failed to load queues (timeout)")
190190
logger.info { "queues are initialized" }
191191

192+
queues.startFlows()
193+
192194
loadConfig()
193195
delay(500)
194196

195-
queues.startFlows()
196197
flowScope.launch {
197198
decks.forEach { deck ->
198199
launch {

src/desktopMain/kotlin/nestdrop/deck/Deck.kt

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package nestdrop.deck
22

3+
import QUEUES
34
import androidx.compose.runtime.Immutable
45
import androidx.compose.ui.graphics.Color
56
import androidx.compose.ui.graphics.compositeOver
@@ -20,6 +21,7 @@ import kotlinx.coroutines.flow.asStateFlow
2021
import kotlinx.coroutines.flow.combine
2122
import kotlinx.coroutines.flow.distinctUntilChanged
2223
import kotlinx.coroutines.flow.drop
24+
import kotlinx.coroutines.flow.filter
2325
import kotlinx.coroutines.flow.filterNotNull
2426
import kotlinx.coroutines.flow.flowOn
2527
import kotlinx.coroutines.flow.launchIn
@@ -37,6 +39,7 @@ import nestdrop.NestdropSpriteQueue
3739
import nestdrop.PresetIdState
3840
import nestdrop.PresetLocation
3941
import nestdrop.Queue
42+
import nestdrop.QueueType
4043
import nestdrop.imgFxMap
4144
import nestdrop.nestdropSetPreset
4245
import 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 {

src/desktopMain/kotlin/nestdrop/deck/DeckConfig.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package nestdrop.deck
22

33
import DeckConfig
4+
import QUEUES
45
import imgSpritesMap
56
import io.github.oshai.kotlinlogging.KotlinLogging
67
import kotlinx.coroutines.delay
78
import kotlinx.coroutines.flow.Flow
89
import kotlinx.coroutines.flow.combine
910
import kotlinx.coroutines.flow.first
1011
import kotlinx.coroutines.flow.flowOf
12+
import kotlinx.coroutines.flow.map
1113
import kotlinx.coroutines.withTimeoutOrNull
14+
import nestdrop.Preset
15+
import nestdrop.Queue
16+
import nestdrop.QueueType
1217
import tags.nestdropQueueSearches
1318
import tags.queueTagsInitialized
1419
import ui.screens.customSearches
@@ -51,11 +56,17 @@ suspend fun Deck.applyConfig(deckConfig: DeckConfig) = measureTimedValue {
5156
logger.debug { "loading spoutQueue on $deckName" }
5257
val spoutSpriteQueuesValue = measureTimedValue {
5358
withTimeoutOrNull(10.seconds) {
54-
spoutSpriteQueues.first {
59+
QUEUES.spoutQueues().map { it.filter { it.deck == id } }
60+
.first {
5561
it
5662
.also { logger.debug { "spoutSpritesQueue: $it" } }
5763
.isNotEmpty()
5864
}
65+
// spoutSpriteQueues.first {
66+
// it
67+
// .also { logger.debug { "spoutSpritesQueue: $it" } }
68+
// .isNotEmpty()
69+
// }
5970
} ?: run {
6071
logger.error { "failed to load spoutSpriteQueues on $deckName" }
6172
emptyList()

src/desktopMain/kotlin/nestdrop/deck/Queues.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.asStateFlow
99
import kotlinx.coroutines.flow.combine
1010
import kotlinx.coroutines.flow.consumeAsFlow
1111
import kotlinx.coroutines.flow.launchIn
12+
import kotlinx.coroutines.flow.map
1213
import kotlinx.coroutines.flow.onEach
1314
import kotlinx.coroutines.flow.runningFold
1415
import kotlinx.coroutines.flow.sample
@@ -98,6 +99,18 @@ class Queues {
9899
private val allQueuesInternal = MutableStateFlow<Map<String, Queue<out Preset>>>(emptyMap())
99100
val allQueues = allQueuesInternal.asStateFlow()
100101

102+
fun spoutQueues() = allQueues.map { queueMap ->
103+
queueMap.values.filter { queue ->
104+
queue.open &&
105+
// queue.deck == deckId &&
106+
queue.type == QueueType.SPRITE &&
107+
!queue.isFileExplorer &&
108+
queue.presets.all { it is nestdrop.Preset.SpoutSprite }
109+
}.map {
110+
it as Queue<Preset.SpoutSprite>
111+
}
112+
}
113+
101114
val isInitialized = MutableStateFlow(false)
102115
private val logger = KotlinLogging.logger { }
103116

@@ -192,8 +205,6 @@ class Queues {
192205
}
193206
}
194207

195-
val combinedUpdates = MutableStateFlow<Map<String, OSCQueueUpdate.UpdateQueue>>(emptyMap())
196-
197208
@OptIn(FlowPreview::class)
198209
suspend fun startFlows() {
199210
logger.info { "starting coroutines for preset-queues" }
@@ -253,6 +264,7 @@ class Queues {
253264
queue.updateQueue(update)
254265
} ?: queue
255266
}
267+
logger.info { "written to $allQueuesInternal" }
256268

257269
// val queueUpdate = queues[updatesMap.name]?.updateQueue(updatesMap)
258270
// val presetQueueUpdate = presets[update.name]?.updateQueue(update)

src/desktopMain/kotlin/nestdrop/loadNestdropConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ suspend fun loadNestdropConfig(
226226
// deck.imgSpriteQueues.value = imgSpriteQueues.filter { queue ->
227227
// queue.open && queue.deck == deck.id && queue.type == QueueType.SPRITE
228228
// }
229-
deck.spoutSpriteQueues.value = spoutSpriteQueues.filter { queue ->
230-
queue.open && queue.deck == deck.id && queue.type == QueueType.SPRITE
231-
}
229+
// deck.spoutSpriteQueues.value = spoutSpriteQueues.filter { queue ->
230+
// queue.open && queue.deck == deck.id && queue.type == QueueType.SPRITE
231+
// }
232232
}
233233
// queues.presetQueues.value = presetQueues.associateBy { it.name }
234234
// queues.allQueues.update { oldList ->

src/desktopMain/kotlin/ui/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ enum class Tabs(
266266
}
267267
),
268268
SpoutSprites(
269-
"Spout Sprites",
269+
"SPT Sprites",
270270
{
271271
it.spriteState.spoutStates.map { it.values.firstOrNull()?.label ?: "-" }
272272
}

src/desktopMain/kotlin/ui/screens/QueueControlScreen.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,11 @@ fun QueueControlScreen() {
278278
if (!queue.open) return@items
279279

280280
val deck = decks[queue.deck - 1]
281+
val deckEnabled = deck.id <= decksEnabled
281282
// val color = colors[queue.deck - 1]
282283
// val disabledColor = disabledColors[queue.deck - 1]
283284

285+
284286
Column(
285287
modifier = Modifier
286288
.padding(4.dp)
@@ -298,12 +300,12 @@ fun QueueControlScreen() {
298300
// .background(deck.color),
299301
.padding(start = 4.dp, end = 4.dp, bottom = 2.dp),
300302
// strokeCap = StrokeCap.Square,
301-
color = if (autoPlayEnabled) {
303+
color = if (autoPlayEnabled && deckEnabled) {
302304
deck.color
303305
} else {
304306
deck.disabledColor
305307
},
306-
trackColor = if (autoPlayEnabled) {
308+
trackColor = if (autoPlayEnabled && deckEnabled) {
307309
deck.disabledColor
308310
} else {
309311
Color.DarkGray
@@ -317,7 +319,7 @@ fun QueueControlScreen() {
317319
.padding(4.dp)
318320
.border(
319321
width = 2.dp,
320-
color = if (queue.active) deck.color else deck.disabledColor,
322+
color = if (queue.active && deckEnabled) deck.color else deck.disabledColor,
321323
shape = CutCornerShape(5.dp),
322324
)
323325
.padding(4.dp)

0 commit comments

Comments
 (0)