Skip to content

Commit df66534

Browse files
committed
more cleanup
1 parent 7bb1e2b commit df66534

File tree

3 files changed

+10
-80
lines changed

3 files changed

+10
-80
lines changed

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

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ import tags.pickItemToGenerate
4343
import tags.presetTagsMapping
4444
import ui.screens.imgSpritesMap
4545
import ui.screens.presetsMap
46-
import utils.HistoryNotNull
4746
import utils.prettyPrint
4847
import utils.runningHistory
4948
import utils.runningHistoryNotNull
50-
import kotlin.math.roundToInt
5149
import kotlin.time.Duration.Companion.milliseconds
5250
import kotlin.time.Duration.Companion.seconds
5351

@@ -183,23 +181,6 @@ class Deck(
183181
pulseWidth.startFlows()
184182
waveForm.startFlows()
185183
enabled.startFlows()
186-
187-
// Link.bpm
188-
// .combine(bpmSyncMultiplier) { bpm, multiplier ->
189-
// val beatsPerSecond = bpm / 60.0f
190-
// beatsPerSecond / multiplier
191-
// }
192-
// .map {
193-
// (it * 100).roundToInt() / 100f
194-
// }
195-
// .combine(bpmSyncEnabled) { a, b -> a to b }
196-
// .distinctUntilChanged()
197-
// .onEach { (value, toggle) ->
198-
// if (toggle) {
199-
// effectSpeed.value = value
200-
// }
201-
// }
202-
// .launchIn(flowScope)
203184
}
204185
}
205186

@@ -252,45 +233,10 @@ class Deck(
252233

253234
@Immutable
254235
inner class PresetSwitching() {
255-
val transitionTime =
256-
MutableStateFlow(1f) // OscSynced.Value("/deck$N/transitionTime", 1.0f, target = Target.TouchOSC)
257-
val triggerTime =
258-
MutableStateFlow(0.75f) // OscSynced.Value("/deck$N/triggerTime", 0.75f, target = Target.TouchOSC)
259-
// val hasSwitched = MutableStateFlow(false)
260-
private val hasSwitchedNew = MutableStateFlow(false)
261-
val hasSwitched = hasSwitchedNew.asStateFlow()
262-
263-
suspend fun beatFlow(
264-
flow: Flow<HistoryNotNull<Double>>
265-
) = combine(
266-
flow,
267-
beatFrame,
268-
triggerTime,
269-
isEnabled,
270-
) { (currentBeat, lastBeat), beatFrame, triggerTime, isEnabled ->
271-
val triggerAt = triggerTime * beatFrame
272-
// logger.info { "currentBeat: $currentBeat" }
273-
// logger.info { "triggerAt: $triggerAt" }
274-
// logger.info { "lastBeat: $lastBeat" }
275-
//TODO: reset hasSwitched after transition time has passed
276-
if (isEnabled && !hasSwitchedNew.value) {
277-
val shouldTrigger = (lastBeat < triggerAt && currentBeat >= triggerAt) || (lastBeat > beatFrame && currentBeat >= triggerAt)
278-
279-
if(shouldTrigger) {
280-
flowScope.launch {
281-
logger.info { "$deckName triggered at $currentBeat ($triggerAt)" }
282-
}
283-
hasSwitchedNew.value = true
284-
flowScope.launch {
285-
val transitionTime = ndTime.transitionTime.value.toDouble().seconds
286-
delay(transitionTime)
287-
hasSwitchedNew.value = false
288-
}
289-
doSwitch()
290-
}
291-
}
292-
currentBeat
293-
}
236+
val transitionTime = MutableStateFlow(1f)
237+
val triggerTime = MutableStateFlow(0.75f)
238+
private val switchingLocked = MutableStateFlow(false)
239+
val isLocked = switchingLocked.asStateFlow()
294240

295241
private suspend fun doSwitch() {
296242
// change preset queue
@@ -330,17 +276,17 @@ class Deck(
330276
isEnabled,
331277
) { (currentBeat, lastBeat), beatFrame, triggerTime, isEnabled ->
332278
val triggerAt = triggerTime * beatFrame
333-
if (isEnabled && !hasSwitchedNew.value) {
279+
if (isEnabled && !switchingLocked.value) {
334280
val shouldTrigger =
335281
(lastBeat < triggerAt && currentBeat >= triggerAt) || (lastBeat > beatFrame && currentBeat >= triggerAt)
336282

337283
if (shouldTrigger) {
338-
logger.info { "$deckName triggered at $currentBeat $triggerAt" }
339-
hasSwitchedNew.emit(true)
284+
logger.debug { "$deckName triggered at $currentBeat $triggerAt" }
285+
switchingLocked.emit(true)
340286
flowScope.launch {
341287
val transitionTime = ndTime.transitionTime.value.toDouble().seconds
342288
delay(transitionTime)
343-
hasSwitchedNew.emit(false)
289+
switchingLocked.emit(false)
344290
}
345291
flowScope.launch {
346292
doSwitch()

src/desktopMain/kotlin/osc/OSCUtil.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package osc
22

3-
import com.illposed.osc.OSCBadDataEvent
4-
import com.illposed.osc.OSCBundle
53
import com.illposed.osc.OSCMessage
64
import com.illposed.osc.OSCPacket
7-
import com.illposed.osc.OSCPacketEvent
8-
import com.illposed.osc.OSCPacketListener
95
import com.illposed.osc.OSCSerializerAndParserBuilder
106
import com.illposed.osc.argument.handler.BlobArgumentHandler
117
import com.illposed.osc.argument.handler.BooleanFalseArgumentHandler
@@ -23,43 +19,31 @@ import com.illposed.osc.argument.handler.StringArgumentHandler
2319
import com.illposed.osc.argument.handler.SymbolArgumentHandler
2420
import com.illposed.osc.argument.handler.TimeTag64ArgumentHandler
2521
import com.illposed.osc.argument.handler.UnsignedIntegerArgumentHandler
26-
import com.illposed.osc.messageselector.OSCPatternAddressMessageSelector
2722
import com.illposed.osc.transport.OSCPortIn
2823
import com.illposed.osc.transport.OSCPortInBuilder
2924
import com.illposed.osc.transport.OSCPortOut
30-
import com.illposed.osc.transport.OSCPortOutBuilder
3125
import flowScope
3226
import io.github.oshai.kotlinlogging.KotlinLogging
33-
import io.github.xn32.json5k.Json5
3427
import kotlinx.coroutines.Dispatchers
3528
import kotlinx.coroutines.FlowPreview
3629
import kotlinx.coroutines.channels.Channel
3730
import kotlinx.coroutines.coroutineScope
3831
import kotlinx.coroutines.delay
3932
import kotlinx.coroutines.flow.MutableStateFlow
4033
import kotlinx.coroutines.flow.collectLatest
41-
import kotlinx.coroutines.flow.consumeAsFlow
42-
import kotlinx.coroutines.flow.debounce
4334
import kotlinx.coroutines.flow.distinctUntilChanged
4435
import kotlinx.coroutines.flow.drop
4536
import kotlinx.coroutines.flow.launchIn
46-
import kotlinx.coroutines.flow.map
4737
import kotlinx.coroutines.flow.onEach
48-
import kotlinx.coroutines.flow.runningFold
4938
import kotlinx.coroutines.flow.sample
5039
import kotlinx.coroutines.launch
5140
import kotlinx.coroutines.runBlocking
5241
import kotlinx.datetime.Clock
5342
import kotlinx.datetime.Instant
54-
import kotlinx.serialization.builtins.MapSerializer
55-
import kotlinx.serialization.builtins.serializer
56-
import utils.receiveAvailable
57-
import java.io.File
5843
import java.net.InetAddress
5944
import java.net.InetSocketAddress
6045
import kotlin.time.Duration.Companion.milliseconds
6146
import kotlin.time.Duration.Companion.minutes
62-
import kotlin.time.Duration.Companion.seconds
6347

6448

6549
private val logger = KotlinLogging.logger { }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ fun beatProgressScreen(
9898
val enabled by deck.isEnabled.collectAsState()
9999
if(!enabled) return@mapNotNull null
100100

101-
val hasSwitched by deck.presetSwitching.hasSwitched.collectAsState()
101+
val isLocked by deck.presetSwitching.isLocked.collectAsState()
102102
val triggerTime by deck.presetSwitching.triggerTime.collectAsState()
103103

104104
val transitionTime by deck.ndTime.transitionTime.collectAsState()
105105
val beatsPerSecond = 60.0f / bpmRounded.toFloat()
106106
val beatsInTransitionTime = transitionTime / beatsPerSecond
107107
val sweepAngle = 1.0f / frame * beatsInTransitionTime
108108

109-
val brush = if (!hasSwitched)
109+
val brush = if (!isLocked)
110110
Brush.sweepGradient(
111111
0f to deck.color,
112112
sweepAngle*0.2f to deck.dimmedColor,

0 commit comments

Comments
 (0)