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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user