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"
|
group = "nl.astraeus"
|
||||||
version = "2.1.0"
|
version = "2.1.1-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -37,9 +37,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jvm {
|
jvm {}
|
||||||
withJava()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
|
|||||||
@@ -78,11 +78,13 @@ class KeyboardComponent(
|
|||||||
fun noteDown(midiNote: Int) {
|
fun noteDown(midiNote: Int) {
|
||||||
pressedNotes.add(midiNote)
|
pressedNotes.add(midiNote)
|
||||||
onNoteDown(midiNote)
|
onNoteDown(midiNote)
|
||||||
|
requestUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun noteUp(midiNote: Int) {
|
fun noteUp(midiNote: Int) {
|
||||||
pressedNotes.remove(midiNote)
|
pressedNotes.remove(midiNote)
|
||||||
onNoteUp(midiNote)
|
onNoteUp(midiNote)
|
||||||
|
requestUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun releaseAllNotes() {
|
private fun releaseAllNotes() {
|
||||||
@@ -227,25 +229,29 @@ class KeyboardComponent(
|
|||||||
|
|
||||||
// Draw white keys
|
// Draw white keys
|
||||||
for (i in 0 until 7) {
|
for (i in 0 until 7) {
|
||||||
|
val midiNote = whiteKeys[i] + (octave - 5) * 12
|
||||||
|
val isPressed = pressedNotes.contains(midiNote)
|
||||||
rect(
|
rect(
|
||||||
i * whiteKeyWidth,
|
i * whiteKeyWidth,
|
||||||
0,
|
0,
|
||||||
whiteKeyWidth,
|
whiteKeyWidth,
|
||||||
keyboardHeight,
|
keyboardHeight,
|
||||||
0,
|
0,
|
||||||
WhiteKeyCls.name
|
if (isPressed) WhiteKeyPressedCls.name else WhiteKeyCls.name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw black keys
|
// Draw black keys
|
||||||
for (i in 0 until 5) {
|
for (i in 0 until 5) {
|
||||||
|
val midiNote = blackKeys[i] + (octave - 5) * 12
|
||||||
|
val isPressed = pressedNotes.contains(midiNote)
|
||||||
rect(
|
rect(
|
||||||
blackKeyPositions[i],
|
blackKeyPositions[i],
|
||||||
0,
|
0,
|
||||||
blackKeyWidth,
|
blackKeyWidth,
|
||||||
blackKeyHeight,
|
blackKeyHeight,
|
||||||
0,
|
0,
|
||||||
BlackKeyCls.name
|
if (isPressed) BlackKeyPressedCls.name else BlackKeyCls.name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +269,8 @@ class KeyboardComponent(
|
|||||||
object OctaveButtonCls : CssName()
|
object OctaveButtonCls : CssName()
|
||||||
object WhiteKeyCls : CssName()
|
object WhiteKeyCls : CssName()
|
||||||
object BlackKeyCls : CssName()
|
object BlackKeyCls : CssName()
|
||||||
|
object WhiteKeyPressedCls : CssName()
|
||||||
|
object BlackKeyPressedCls : CssName()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
defineCss {
|
defineCss {
|
||||||
@@ -330,11 +338,23 @@ class KeyboardComponent(
|
|||||||
plain("stroke-width", "1")
|
plain("stroke-width", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select(cls(WhiteKeyPressedCls)) {
|
||||||
|
plain("fill", "#E6E6E6") // 10% darker than white
|
||||||
|
plain("stroke", "#000000")
|
||||||
|
plain("stroke-width", "1")
|
||||||
|
}
|
||||||
|
|
||||||
select(cls(BlackKeyCls)) {
|
select(cls(BlackKeyCls)) {
|
||||||
plain("fill", "#000000")
|
plain("fill", "#000000")
|
||||||
plain("stroke", "#000000")
|
plain("stroke", "#000000")
|
||||||
plain("stroke-width", "1")
|
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