Skip to content

Instantly share code, notes, and snippets.

View fluxtah's full-sized avatar

Ian Warwick fluxtah

  • Just Eat
  • London
View GitHub Profile
if (showNoteNames) {
Row {
repeat(7) { noteIndex ->
Container(
LayoutPadding(right = 1.dp) + LayoutSize(16.dp, 62.dp),
alignment = Alignment.BottomCenter
) {
val noteName = formatNoteName(startFromF, noteIndex, octave)
Text(text = noteName, style = TextStyle(fontSize = 8.sp))
}
@Composable
private fun AccidentalPianoKey(leftSpacing: Dp) {
Spacer(modifier = LayoutWidth(leftSpacing))
ColoredRect(
color = Color.Black,
height = 40.dp,
width = 13.dp
)
}
Row {
if (startFromF) {
AccidentalPianoKey(10.dp)
AccidentalPianoKey(5.dp)
AccidentalPianoKey(4.dp)
AccidentalPianoKey(21.dp)
AccidentalPianoKey(4.dp)
} else {
AccidentalPianoKey(10.dp)
AccidentalPianoKey(5.dp)
@Composable
private fun PianoKey() {
ColoredRect(
modifier = LayoutPadding(right = 1.dp),
color = Color.White,
height = 64.dp,
width = 16.dp
)
}
Row {
repeat(7) {
PianoKey()
}
}
@Composable
fun PianoRollOctave(startFromF: Boolean = false, showNoteNames: Boolean = false, octave: Int? = 0) {
Stack {
Row {
repeat(7) {
PianoKey()
}
}
Row {
if (startFromF) {
@Composable
fun PianoRoll(from: PianoKey, to: PianoKey) {
val startsAtF = from.note >= F
Row {
for (octave in from.octave..to.octave) {
PianoRollOctave(startsAtF, true, octave)
}
}
}
@Composable
@Preview
fun PianoRollPreview() {
PianoRoll(PianoKey(F, 0), PianoKey(C, 1))
}
val onCardSaved = {
runBlocking {
repository.saveCard(state.card)
goto(Destination.HomeScreen)
}
}
MemsetMainTemplate {
when (state.loadingState) {
LoadingState.Loaded -> CardEditorContent(state, onCardSaved)
@Composable
fun <T> observe(observable: () -> LiveData<T>, result: (T) -> Unit) {
val thing = stateFor<T?> { null }
onActive {
val observer =
Observer<T> {
thing.value = it
result(it)
}
with(observable()) {