Skip to content

Commit 3ad7fe3

Browse files
committed
nestdrop native preset switching and beat offsets
1 parent ece3298 commit 3ad7fe3

File tree

15 files changed

+696
-411
lines changed

15 files changed

+696
-411
lines changed

src/desktopMain/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ suspend fun loadConfig() {
205205
config.value.also { config ->
206206
logger.info { "loaded config" }
207207
logger.debug { config.prettyPrint() }
208-
beatFrame.value = config.beats
208+
// beatFrame.value = config.beats
209209
customSearches.value = config.presetPlaylists
210210
decks.forEach { deck ->
211211
when (deck.id) {

src/desktopMain/kotlin/Main.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ object Main {
185185
}
186186
}
187187

188-
nestdropSettingsState.value.loadDeckSettings(decks)
188+
// nestdropSettingsState.value.let { settings ->
189+
// controlBeatSlider.setValue(settings.mainWindow.settingsGeneral.beatThreshold.toFloat())
190+
// controlShuffleButton.setValue(settings.mainWindow.settingsGeneral.shuffleEnable.let { if(it) 1 else 0 })
191+
// controlAutoButton.setValue(settings.mainWindow.settingsGeneral.autoChangeEnable.let { if(it) 1 else 0 })
192+
// settings.loadDeckSettings(decks)
193+
// }
189194
delay(250.milliseconds)
190195

191196
// decks.forEach {

src/desktopMain/kotlin/beatCounter.kt

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,62 @@ import kotlinx.coroutines.flow.onEach
1111
import kotlinx.coroutines.flow.sample
1212
import kotlinx.coroutines.launch
1313
import kotlinx.datetime.Clock
14+
import osc.OSCMessage
1415
import osc.OscSynced
16+
import osc.nestdropSendChannel
1517
import kotlin.math.roundToInt
1618
import kotlin.time.Duration.Companion.milliseconds
1719
import kotlin.time.Duration.Companion.seconds
1820

19-
val beatFrame = MutableStateFlow(64) // OscSynced.Value("/beats", 64, target = OscSynced.Target.TouchOSC)
21+
//val beatFrame = MutableStateFlow(64) // OscSynced.Value("/beats", 64, target = OscSynced.Target.TouchOSC)
2022
val beatProgress = MutableStateFlow(0f)
2123

2224

2325
private val logger = KotlinLogging.logger { }
2426

25-
val controlBeat = OscSynced.ValueSingle<Float>(
27+
val controlBeatSlider = OscSynced.ValueSingle<Float>(
2628
"/Controls/sBeat",
27-
64f, send = false,
29+
64f,
30+
// send = false,
31+
dropFirst = 1,
2832
target = OscSynced.Target.Nestdrop
2933
).also {
3034
it.logReceived = false
3135
}
3236

37+
38+
val controlShuffleButton = OscSynced.ValueSingle<Int>(
39+
address = "/Controls/btRandom",
40+
initialValue = 0,
41+
dropFirst = 1,
42+
target = OscSynced.Target.Nestdrop
43+
)
44+
val controlAutoButton = OscSynced.ValueSingle<Int>(
45+
address = "/Controls/btAuto",
46+
initialValue = 0,
47+
dropFirst = 1,
48+
target = OscSynced.Target.Nestdrop
49+
)
50+
val beatFrame = controlBeatSlider.flow
51+
val controlBeatCounter = OscSynced.ValueSingle<Int>(
52+
"/Controls/sBpmCnt",
53+
0,
54+
send = false,
55+
dropFirst = 1,
56+
target = OscSynced.Target.Nestdrop
57+
).also {
58+
it.logReceived = false
59+
}
60+
suspend fun beatResync() {
61+
nestdropSendChannel.send(
62+
OSCMessage("/Controls/btResync", 1)
63+
)
64+
}
65+
3366
val controlBpm = OscSynced.ValueSingle<Float>(
3467
"/Controls/sBpm",
3568
120f, send = false,
69+
dropFirst = 1,
3670
target = OscSynced.Target.Nestdrop
3771
).also {
3872
it.logReceived = false
@@ -44,6 +78,11 @@ val secondsPerBeat = MutableStateFlow(0.5f)
4478
val beatCounter = MutableStateFlow(0.0)
4579

4680
suspend fun startBeatCounter() {
81+
// force initialization
82+
controlShuffleButton.flow.onEach {
83+
84+
}.launchIn(flowScope)
85+
4786
@OptIn(FlowPreview::class)
4887
controlBpm
4988
.flow
@@ -58,6 +97,13 @@ suspend fun startBeatCounter() {
5897
}
5998
.launchIn(flowScope)
6099

100+
controlBeatSlider
101+
.flow
102+
.onEach {
103+
beatResync()
104+
}
105+
.launchIn(flowScope)
106+
61107
decks.forEach { deck ->
62108

63109
combine(
@@ -95,7 +141,11 @@ suspend fun startBeatCounter() {
95141
.launchIn(flowScope)
96142
beatFrame
97143
.onEach {
98-
config.value = config.value.copy(beats = it)
144+
updateConfig {
145+
copy(
146+
beats = it.roundToInt()
147+
)
148+
}
99149
}
100150
.launchIn(flowScope)
101151

src/desktopMain/kotlin/locations.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ val tagsFolder = configFolder.resolve("tags").also {
1212
val configFile = configFolder.resolve("config.json5").also {
1313
logger.info { "config file: $it" }
1414
}
15+
val queueFolder = configFolder.resolve("queues").also {
16+
logger.info { "queue folder: $it" }
17+
}
1518

1619
private fun String.parsePath(): File {
1720
val rawPath = this

src/desktopMain/kotlin/nestdrop/NestdropSpriteQueue.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sealed interface PresetIdState {
2121
val force: Boolean = false,
2222
// val hardCut: Boolean = false,
2323
) : PresetIdState {
24-
val id get() = queue.presets.getOrNull(index)?.id
24+
// val id get() = queue.presets.getOrNull(index)?.id
2525
}
2626

2727
data object Unset : PresetIdState
@@ -44,15 +44,18 @@ class NestdropSpriteQueue(
4444
channel.send(state)
4545
}
4646

47-
private suspend fun presetId(queue: Queue<out Preset>, id: Int?, overlay: Boolean = false) {
48-
if(id == null) {
47+
private suspend fun presetId(queue: Queue<out Preset>, index: Int?, overlay: Boolean = false) {
48+
if(index == null) {
4949
logger.warn { "failed to find sprite id" }
5050
return
5151
}
52-
logger.debug { "setting presetId $id on ${queue.name} (\"/PresetID/${queue.name}/$id\")" }
52+
logger.debug { "setting index $index on ${queue.name} (/Queue/${queue.name}/ActIdx/$index)" }
53+
// logger.debug { "setting presetId $index on ${queue.name} (\"/PresetID/${queue.name}/$id\")" }
5354
nestdropSendChannel.send(
5455
OSCMessage(
55-
"/PresetID/${queue.name}/$id",
56+
// /PresetID/spout_1/15879 or /Queue/spout_1/ActIdx/0
57+
"/Queue/${queue.name}/ActIdx/$index",
58+
// "/PresetID/${queue.name}/$id",
5659
// "/PresetID/$id",
5760
listOf(
5861
if (overlay) 0 else 1
@@ -70,7 +73,7 @@ class NestdropSpriteQueue(
7073
.onEach { current ->
7174
// logger.warnF { "previous: $previous" }
7275
// logger.warnF { "current: $current" }
73-
if (previous != null) {
76+
// if (previous != null) {
7477
when (current) {
7578
is PresetIdState.Unset -> {
7679
when (val previous = previous) {
@@ -80,7 +83,7 @@ class NestdropSpriteQueue(
8083
logger.debug { "unsetting previous sprite" }
8184
presetId(
8285
queue = previous.queue,
83-
id = previous.id,
86+
index = previous.index,
8487
overlay = false
8588
)
8689
} else {
@@ -102,7 +105,7 @@ class NestdropSpriteQueue(
102105
logger.debug { "force setting sprite" }
103106
presetId(
104107
queue = current.queue,
105-
id = current.id,
108+
index = current.index,
106109
// current.queue.presets.first { it.id != current.id }.id,
107110
// (current.index + 1) % current.queue.presets.size,
108111
overlay = false
@@ -120,7 +123,7 @@ class NestdropSpriteQueue(
120123
logger.info { "ND: received same preset id again, resetting ${current.queue.name} to $presetName" }
121124
presetId(
122125
queue = current.queue,
123-
id = current.id,
126+
index = current.index,
124127
// current.queue.presets.first { it.id != current.id }.id,
125128
overlay = false
126129
)
@@ -137,11 +140,11 @@ class NestdropSpriteQueue(
137140
}
138141
}
139142
}
140-
} else {
141-
logger.debug { "not switching after initializing program" }
142-
143-
//TODO switch to another preset and back to ensure it is set correctly
144-
}
143+
// } else {
144+
// logger.debug { "not switching after initializing program" }
145+
//
146+
// //TODO switch to another preset and back to ensure it is set correctly
147+
// }
145148
previous = current
146149

147150
}

0 commit comments

Comments
 (0)