From 538aa6b9ae2fce320bcd7f9e5f6f7081451af521 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Fri, 6 Jun 2025 20:21:51 +0200 Subject: [PATCH] Update to version 2.1.1-SNAPSHOT and improve KeyboardComponent note handling Bumped project version to 2.1.1-SNAPSHOT in `build.gradle.kts`. Enhanced `KeyboardComponent` logic to visually indicate pressed keys with new CSS classes for both white and black keys. Added `requestUpdate` calls to ensure UI updates on note changes. Simplified JVM target configuration in build script. --- build.gradle.kts | 6 ++--- .../vst/ui/components/KeyboardComponent.kt | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index dfb6a14..07fcb7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { } group = "nl.astraeus" -version = "2.1.0" +version = "2.1.1-SNAPSHOT" repositories { mavenCentral() @@ -37,9 +37,7 @@ kotlin { } } } - jvm { - withJava() - } + jvm {} sourceSets { val commonMain by getting { diff --git a/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt b/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt index 3fe8ba3..0c53885 100644 --- a/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt +++ b/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt @@ -78,11 +78,13 @@ class KeyboardComponent( fun noteDown(midiNote: Int) { pressedNotes.add(midiNote) onNoteDown(midiNote) + requestUpdate() } fun noteUp(midiNote: Int) { pressedNotes.remove(midiNote) onNoteUp(midiNote) + requestUpdate() } private fun releaseAllNotes() { @@ -227,25 +229,29 @@ class KeyboardComponent( // Draw white keys for (i in 0 until 7) { + val midiNote = whiteKeys[i] + (octave - 5) * 12 + val isPressed = pressedNotes.contains(midiNote) rect( i * whiteKeyWidth, 0, whiteKeyWidth, keyboardHeight, 0, - WhiteKeyCls.name + if (isPressed) WhiteKeyPressedCls.name else WhiteKeyCls.name ) } // Draw black keys for (i in 0 until 5) { + val midiNote = blackKeys[i] + (octave - 5) * 12 + val isPressed = pressedNotes.contains(midiNote) rect( blackKeyPositions[i], 0, blackKeyWidth, blackKeyHeight, 0, - BlackKeyCls.name + if (isPressed) BlackKeyPressedCls.name else BlackKeyCls.name ) } } @@ -263,6 +269,8 @@ class KeyboardComponent( object OctaveButtonCls : CssName() object WhiteKeyCls : CssName() object BlackKeyCls : CssName() + object WhiteKeyPressedCls : CssName() + object BlackKeyPressedCls : CssName() init { defineCss { @@ -330,11 +338,23 @@ class KeyboardComponent( plain("stroke-width", "1") } + select(cls(WhiteKeyPressedCls)) { + plain("fill", "#E6E6E6") // 10% darker than white + plain("stroke", "#000000") + plain("stroke-width", "1") + } + select(cls(BlackKeyCls)) { plain("fill", "#000000") plain("stroke", "#000000") plain("stroke-width", "1") } + + select(cls(BlackKeyPressedCls)) { + plain("fill", "#333333") // 10% lighter than black + plain("stroke", "#000000") + plain("stroke-width", "1") + } } } }