Skip to content

Commit babd3cd

Browse files
committed
update versions
improve tag display improve display of minimum transition length
1 parent df66534 commit babd3cd

File tree

15 files changed

+317
-216
lines changed

15 files changed

+317
-216
lines changed

src/desktopMain/kotlin/Main.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ import dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime
2828
import io.github.oshai.kotlinlogging.KotlinLogging
2929
import kotlinx.coroutines.Dispatchers
3030
import kotlinx.coroutines.FlowPreview
31-
import kotlinx.coroutines.channels.consumeEach
3231
import kotlinx.coroutines.delay
3332
import kotlinx.coroutines.flow.consumeAsFlow
3433
import kotlinx.coroutines.flow.debounce
3534
import kotlinx.coroutines.flow.distinctUntilChanged
36-
import kotlinx.coroutines.flow.filterNotNull
37-
import kotlinx.coroutines.flow.flow
3835
import kotlinx.coroutines.flow.flowOn
3936
import kotlinx.coroutines.flow.launchIn
40-
import kotlinx.coroutines.flow.map
4137
import kotlinx.coroutines.flow.mapNotNull
4238
import kotlinx.coroutines.flow.merge
4339
import kotlinx.coroutines.flow.onEach

src/desktopMain/kotlin/beatCounter.kt

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,13 @@ import kotlinx.coroutines.flow.sample
1010
import kotlinx.coroutines.launch
1111
import kotlinx.datetime.Clock
1212
import osc.OscSynced
13-
import utils.runningHistoryNotNull
1413
import kotlin.math.roundToInt
1514
import kotlin.time.Duration.Companion.milliseconds
15+
import kotlin.time.Duration.Companion.seconds
1616

1717
val beatFrame = MutableStateFlow(64) // OscSynced.Value("/beats", 64, target = OscSynced.Target.TouchOSC)
1818
val beatProgress = MutableStateFlow(0f)
1919

20-
// OscSynced.Value("/beatProgress", 0.0f, receive = false, target = OscSynced.Target.TouchOSC).apply {
21-
// logSending = false
22-
//}
23-
val bpmRounded = MutableStateFlow(120f)
24-
25-
// OscSynced.Value("/bpmRounded", 120.0f).apply {
26-
// logSending = false
27-
//}
28-
val bpmRoundedInt = MutableStateFlow(120)
2920

3021
private val logger = KotlinLogging.logger { }
3122

@@ -36,36 +27,12 @@ val bpmSynced = OscSynced.ValueSingle<Float>(
3627
).also {
3728
it.logReceived = false
3829
}
39-
//val beatCountSynced = OscSynced.ValueSingle<Int>(
40-
// "/Controls/sBpmCnt",
41-
// 0, send = false,
42-
// target = OscSynced.Target.Nestdrop,
43-
//).also {
44-
// it.logReceived = false
45-
//}
30+
val bpmRounded = MutableStateFlow(120f)
31+
val bpmInt = MutableStateFlow(120)
4632

4733
val beatCounter = MutableStateFlow(0.0)
4834

49-
suspend fun startBeatCounter(
50-
// vararg decks: Deck
51-
) {
52-
// @OptIn(FlowPreview::class)
53-
// Link.bpm
54-
// .sample(100.milliseconds)
55-
// .map { bpm ->
56-
// (bpm * 10).roundToInt() / 10.0f
57-
// }
58-
// .onEach {
59-
// bpmRounded.value = it
60-
// bpmRoundedInt.value = it.roundToInt()
61-
// }
62-
// .launchIn(flowScope)
63-
64-
// beatCountSynced
65-
// .onEach {
66-
// logger.info { "beat: $it" }
67-
// }
68-
// .launchIn(flowScope)
35+
suspend fun startBeatCounter() {
6936

7037
@OptIn(FlowPreview::class)
7138
bpmSynced
@@ -75,7 +42,7 @@ suspend fun startBeatCounter(
7542
}
7643
.onEach {
7744
bpmRounded.value = it
78-
bpmRoundedInt.value = it.roundToInt()
45+
bpmInt.value = it.roundToInt()
7946
}
8047
.launchIn(flowScope)
8148
beatProgress
@@ -91,14 +58,11 @@ suspend fun startBeatCounter(
9158

9259

9360
run {
94-
// val beatCounter = MutableStateFlow(0.0)
9561

9662
beatCounter.combine(beatFrame) { beats, beatFrame ->
9763
beats to beatFrame
9864
}.onEach { (beats, totalBeats) ->
9965
if (beats > totalBeats) {
100-
// beats -= totalBeats
101-
// start += ((bpmFromLink.value / 60_000.0) * totalBeats).milliseconds
10266

10367
logger.trace { "reached $totalBeats beats, resetting to ${beats % totalBeats}" }
10468
// var newBeatCounter = beatCounter.value
@@ -119,41 +83,16 @@ suspend fun startBeatCounter(
11983
}
12084
.launchIn(flowScope)
12185

122-
// beatCountSynced.onEach {
123-
// beatCounter.value = (beatCounter.value+1) % beatFrame.value
124-
// }
125-
// .launchIn(flowScope)
126-
127-
// beatCounter.combine(beatFrame) { beats, beatFrame ->
128-
// beats.toFloat() / beatFrame
129-
// }.onEach {
130-
// beatProgress.value = it
131-
// }
132-
// .launchIn(flowScope)
133-
134-
// decks.forEach { deck ->
135-
// deck.presetSwitching.beatFlow(beatCounter.runningHistoryNotNull())
136-
// .launchIn(flowScope)
137-
// }
138-
139-
// decks.forEach { deck ->
140-
// deck.presetSwitching
141-
// .beatFlow(
142-
// beatCountSynced.runningHistoryNotNull()
143-
// )
144-
// .launchIn(flowScope)
145-
// }
146-
14786
flowScope.launch {
14887
var lastLoop = Clock.System.now()
14988
// var beats = 0.0
15089
// var deck1Switched = false
15190
// var deck2Switched = false
15291
while (true) {
153-
delay(10)
92+
delay(1.seconds/60)
15493
val now = Clock.System.now()
15594
val timeDelta = now - lastLoop
156-
lastLoop = Clock.System.now()
95+
lastLoop = now
15796
val beatsPerMillisecond = bpmSynced.value / 60_000.0
15897
val beatsInDuration = beatsPerMillisecond * timeDelta.inWholeMilliseconds
15998
beatCounter.value += beatsInDuration

src/desktopMain/kotlin/nestdrop/XmlDataClasses.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nestdrop
22

33
import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
5+
import nl.adaptivity.xmlutil.serialization.XmlChildrenName
56
import nl.adaptivity.xmlutil.serialization.XmlElement
67
import nl.adaptivity.xmlutil.serialization.XmlSerialName
78
import xml.FavoriteListSerializer
@@ -349,18 +350,22 @@ data class NestdropSettings(
349350
val active: Boolean,
350351
@SerialName("MidiDevice")
351352
val midiDevice: String? = null,
353+
// @XmlElement
354+
// @SerialName("Presets")
355+
// val presetsContainer: Presets,
352356
@XmlElement
353357
@SerialName("Presets")
354-
val presetsWrappers: Presets,
358+
@XmlChildrenName("Presets")
359+
val presets: List<Preset>,
355360
) {
356-
val presets get() = presetsWrappers.presets
357-
358-
@Serializable
359-
data class Presets(
360-
@XmlElement
361-
@SerialName("Presets")
362-
val presets: List<Preset>,
363-
) {
361+
// val presets get() = presetsContainer.presets
362+
//
363+
// @Serializable
364+
// data class Presets(
365+
// @XmlElement
366+
// @SerialName("Presets")
367+
// val presets: List<Preset>,
368+
// ) {
364369
@Serializable
365370
@XmlSerialName("Preset")
366371
data class Preset(
@@ -403,7 +408,7 @@ data class NestdropSettings(
403408
@SerialName("Comments")
404409
val comments: String? = null,
405410
)
406-
}
411+
// }
407412

408413

409414
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class Deck(
7676
id <= decksEnabled
7777
}.stateIn(flowScope, SharingStarted.Lazily, false)
7878

79-
// val color = Color(hexColor)
8079
val dimmedColor = color.copy(alpha = 0.5f).compositeOver(Color.Black)
80+
val disabledColor = color.copy(alpha = 0.25f).compositeOver(Color.Black)
8181

8282
@Immutable
8383
inner class NdTime {
@@ -451,7 +451,9 @@ class Deck(
451451
val mode: ImgMode = ImgMode.Overlay,
452452
val fx: Int = 0,
453453
val mystery: Int = 0
454-
)
454+
) {
455+
val label: String = "$name\nFX: $fx"
456+
}
455457

456458
@Immutable
457459
inner class SpriteState {
@@ -843,9 +845,10 @@ class Deck(
843845
// spriteTargetKey.value = spoutPreset?.let {
844846
// SpriteKey(id = it.id, name = it.name, mode = if(it.overlay == true) ImgMode.Overlay else ImgMode.Nested, fx = it.effects ?: 0)
845847
// }
846-
logger.info { "$deckName spout name\n${spoutPreset?.prettyPrint()}" }
847-
fx.value = spoutPreset?.effects ?: 0
848-
name.value = spoutPreset?.label ?: "-"
848+
logger.info { "$deckName spout name: ${spoutPreset?.prettyPrint()}" }
849+
spriteTargetKey.value = SpriteKey(id=-1, name=spoutPreset?.label ?: "-", fx = spoutPreset?.effects ?: 0 )
850+
// fx.value = spoutPreset?.effects ?: 0
851+
// name.value = spoutPreset?.label ?: "-"
849852
}
850853
.launchIn(flowScope)
851854

src/desktopMain/kotlin/nestdrop/loadQueues.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ suspend fun parseNestdropXml(
2323
): NestdropSettings {
2424
val nestdropSettings: NestdropSettings = try {
2525
xml.decodeFromString(
26-
NestdropSettings.serializer(), nestdropConfig.readText()
26+
NestdropSettings.serializer(), nestdropConfig.readText().also {
27+
logger.info { "parsing xml: $it" }
28+
}
2729
.substringAfter(
2830
"""<?xml version="1.0" encoding="utf-8"?>"""
2931
)

src/desktopMain/kotlin/tags/tags.kt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package tags
22

3+
import androidx.compose.foundation.layout.height
4+
import androidx.compose.material.Chip
5+
import androidx.compose.material.ChipColors
6+
import androidx.compose.material.ChipDefaults
7+
import androidx.compose.material.ExperimentalMaterialApi
8+
import androidx.compose.material.Text
9+
import androidx.compose.runtime.Composable
310
import androidx.compose.runtime.Immutable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.graphics.Color
13+
import androidx.compose.ui.text.font.FontWeight
14+
import androidx.compose.ui.unit.dp
415
import flowScope
516
import kotlinx.coroutines.Dispatchers
617
import kotlinx.coroutines.channels.consumeEach
@@ -55,13 +66,40 @@ data class Tag(
5566
val name: String,
5667
val namespace: List<String> = emptyList()
5768
) { //}: Comparable<Tag> {
69+
val namespaceLabel by lazy {
70+
namespace.joinToString(":")
71+
}
5872
val label by lazy { "${namespace.joinToString(":")} : $name" }
5973
val file by lazy {
6074
namespace.fold(tagsFolder) { file, namespace ->
6175
file.resolve(namespace)
6276
}.resolve("$name.txt")
6377
}
6478

79+
@Composable
80+
fun Chip(
81+
onClick: () -> Unit = {},
82+
enabled: Boolean = false,
83+
@OptIn(ExperimentalMaterialApi::class)
84+
colors: ChipColors = ChipDefaults.chipColors()
85+
) {
86+
@OptIn(ExperimentalMaterialApi::class)
87+
Chip(
88+
onClick = onClick,
89+
enabled = enabled,
90+
colors = colors,
91+
modifier = Modifier
92+
.height(24.dp)
93+
) {
94+
Text("$namespaceLabel:", color = Color.LightGray, softWrap = false)
95+
Text(
96+
name,
97+
color = Color.White,
98+
softWrap = false,
99+
fontWeight = FontWeight.Bold
100+
)
101+
}
102+
}
65103
// override fun compareTo(other: Tag): Int {
66104
// val ordering = (namespace + name).zip(other.namespace + other.name) { first, second ->
67105
// first.compareTo(second, ignoreCase = true)
@@ -130,7 +168,7 @@ suspend fun startTagsFileWatcher(presetQueues: PresetQueues) {
130168
Tag(name = name, namespace = namespace)
131169
}
132170

133-
setOfNotNull(categoryTag, subCategoryTag) + queueTags + customTags + customCategories
171+
setOfNotNull(categoryTag, subCategoryTag) + queueTags + customTags // + customCategories
134172
}
135173
}.launchIn(flowScope)
136174

0 commit comments

Comments
 (0)