From 6b52e88cb75b1fe14252a7e3301a4e18b7fb27c0 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Thu, 5 Jun 2025 21:38:33 +0200 Subject: [PATCH] Refactor KeyboardComponent dimensions and remove redundant code Updated key size calculations to be dynamic based on keyboard dimensions for improved scalability. Removed unnecessary `println` calls and redundant MIDI note calculations in drawing logic for better performance and code clarity. --- .../astraeus/vst/ui/components/KeyboardComponent.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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 a1eea60..d4e7cb8 100644 --- a/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt +++ b/src/jsMain/kotlin/nl/astraeus/vst/ui/components/KeyboardComponent.kt @@ -43,10 +43,9 @@ class KeyboardComponent( // Key dimensions private val keyboardWidth = 210 private val keyboardHeight = 100 - private val whiteKeyWidth = 30 - private val whiteKeyHeight = 100 - private val blackKeyWidth = 20 - private val blackKeyHeight = 60 + private val whiteKeyWidth = keyboardWidth / 7 + private val blackKeyWidth = whiteKeyWidth * 3 / 2 + private val blackKeyHeight = keyboardHeight * 60 / 100 // Calculate positions for black keys private val blackKeyPositions = listOf( @@ -58,13 +57,11 @@ class KeyboardComponent( ) fun noteDown(midiNote: Int) { - println("noteDown $midiNote") pressedNotes.add(midiNote) onNoteDown(midiNote) } fun noteUp(midiNote: Int) { - println("noteUp $midiNote") pressedNotes.remove(midiNote) onNoteUp(midiNote) } @@ -182,12 +179,11 @@ class KeyboardComponent( // Draw white keys for (i in 0 until 7) { - val midiNote = whiteKeys[i] + (octave - 4) * 12 rect( i * whiteKeyWidth, 0, whiteKeyWidth, - whiteKeyHeight, + keyboardHeight, 0, WhiteKeyCls.name ) @@ -195,7 +191,6 @@ class KeyboardComponent( // Draw black keys for (i in 0 until 5) { - val midiNote = blackKeys[i] + (octave - 4) * 12 rect( blackKeyPositions[i], 0,