Skip to content

Commit

Permalink
Add DebugAction
Browse files Browse the repository at this point in the history
  • Loading branch information
simonnorberg committed Dec 27, 2024
1 parent a59ac5d commit 01b91fa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/net/simno/dmach/machine/state/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import net.simno.dmach.settings.Settings

sealed class Action

data class DebugAction(
val debug: Boolean
) : Action()

data object LoadAction : Action()

data object ResumeAction : Action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MachineProcessor(
) : (Flow<Action>) -> Flow<Result> {

override fun invoke(actions: Flow<Action>): Flow<Result> = merge(
actions.filterIsInstance<DebugAction>().let(debug),
actions.filterIsInstance<LoadAction>().let(load),
actions.filterIsInstance<ResumeAction>().let(resume),
actions.filterIsInstance<PlaybackAction>().let(playback),
Expand All @@ -56,6 +57,13 @@ class MachineProcessor(
actions.filterIsInstance<ChangePatchAction>().let(changePatch)
)

private val debug: (Flow<DebugAction>) -> Flow<DebugResult> = { actions ->
actions
.computeResult { action ->
DebugResult(debug = !action.debug)
}
}

private val load: (Flow<LoadAction>) -> Flow<LoadResult> = { actions ->
actions
.onEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ object MachineStateReducer : (ViewState, Result) -> ViewState {
logError("MachineStateReducer", "ErrorResult", result.error)
previousState
}
is DebugResult -> previousState.copy(
debug = result.debug
)
is LoadResult -> previousState.copy(
title = result.title,
sequenceId = result.sequenceId,
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/net/simno/dmach/machine/state/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ data class ErrorResult(
val error: Throwable
) : Result()

data class DebugResult(
val debug: Boolean
) : Result()

data class LoadResult(
val title: String,
val sequenceId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import net.simno.dmach.data.Tempo
import net.simno.dmach.settings.Settings

data class ViewState(
val debug: Boolean = false,
val title: String = "",
val isPlaying: Boolean = false,
val showConfig: Boolean = false,
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/net/simno/dmach/machine/ui/Machine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import net.simno.dmach.machine.state.ChangeStepsAction
import net.simno.dmach.machine.state.ChangeSwingAction
import net.simno.dmach.machine.state.ChangeTempoAction
import net.simno.dmach.machine.state.ConfigAction
import net.simno.dmach.machine.state.DebugAction
import net.simno.dmach.machine.state.DismissAction
import net.simno.dmach.machine.state.ExportAction
import net.simno.dmach.machine.state.ExportFileAction
Expand Down Expand Up @@ -80,7 +81,6 @@ fun Machine(
val paddingMedium = AppTheme.dimens.paddingMedium
val paddingSmall = AppTheme.dimens.paddingSmall
val currentOnAction by rememberUpdatedState(onAction)
var debug by remember { mutableStateOf(false) }

LifecycleResumeEffect(Unit) {
currentOnAction(ResumeAction)
Expand Down Expand Up @@ -145,7 +145,7 @@ fun Machine(
modifier = Modifier
.width(buttonLarge)
.wrapContentWidth(),
onLongClick = { debug = !debug },
onLongClick = { currentOnAction(DebugAction(state.debug)) },
onClick = {
if (state.settings.isAnyEnabled) {
currentOnAction(ChangePatchAction.Reset(state.settings))
Expand Down Expand Up @@ -277,7 +277,7 @@ fun Machine(
position = state.position,
horizontalText = state.hText,
verticalText = state.vText,
debug = debug,
debug = state.debug,
modifier = Modifier
.weight(1f)
.padding(paddingSmall),
Expand All @@ -286,7 +286,7 @@ fun Machine(
PanFader(
panId = state.panId,
pan = state.pan,
debug = debug,
debug = state.debug,
modifier = Modifier
.padding(top = paddingSmall, end = paddingSmall, bottom = paddingSmall),
onPanChange = { currentOnAction(ChangePanAction(it)) }
Expand Down

0 comments on commit 01b91fa

Please sign in to comment.