Extend octave range to 0-9 and adjust MIDI note calculations
This commit is contained in:
@@ -48,7 +48,7 @@ class KeyboardComponent(
|
|||||||
set(value) {
|
set(value) {
|
||||||
_octave = when {
|
_octave = when {
|
||||||
value < 0 -> 0
|
value < 0 -> 0
|
||||||
value > 8 -> 8
|
value > 9 -> 9
|
||||||
else -> value
|
else -> value
|
||||||
}
|
}
|
||||||
requestUpdate()
|
requestUpdate()
|
||||||
@@ -163,7 +163,7 @@ class KeyboardComponent(
|
|||||||
var blackKeyPressed = false
|
var blackKeyPressed = false
|
||||||
for (j in 0 until 5) {
|
for (j in 0 until 5) {
|
||||||
if (x >= blackKeyPositions[j] && x <= blackKeyPositions[j] + blackKeyWidth) {
|
if (x >= blackKeyPositions[j] && x <= blackKeyPositions[j] + blackKeyWidth) {
|
||||||
noteDown(blackKeys[j] + (octave - 4) * 12)
|
noteDown(blackKeys[j] + (octave - 5) * 12)
|
||||||
blackKeyPressed = true
|
blackKeyPressed = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -174,14 +174,14 @@ class KeyboardComponent(
|
|||||||
// Check if click is on a white key
|
// Check if click is on a white key
|
||||||
val keyIndex = (x / whiteKeyWidth).toInt()
|
val keyIndex = (x / whiteKeyWidth).toInt()
|
||||||
if (keyIndex in 0..6) {
|
if (keyIndex in 0..6) {
|
||||||
noteDown(whiteKeys[keyIndex] + (octave - 4) * 12)
|
noteDown(whiteKeys[keyIndex] + (octave - 5) * 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If y > blackKeyHeight, it's definitely a white key
|
// If y > blackKeyHeight, it's definitely a white key
|
||||||
val keyIndex = (x / whiteKeyWidth).toInt()
|
val keyIndex = (x / whiteKeyWidth).toInt()
|
||||||
if (keyIndex in 0..6) {
|
if (keyIndex in 0..6) {
|
||||||
noteDown(whiteKeys[keyIndex] + (octave - 4) * 12)
|
noteDown(whiteKeys[keyIndex] + (octave - 5) * 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ class KeyboardComponent(
|
|||||||
var blackKeyReleased = false
|
var blackKeyReleased = false
|
||||||
for (j in 0 until 5) {
|
for (j in 0 until 5) {
|
||||||
if (x >= blackKeyPositions[j] && x <= blackKeyPositions[j] + blackKeyWidth) {
|
if (x >= blackKeyPositions[j] && x <= blackKeyPositions[j] + blackKeyWidth) {
|
||||||
noteUp(blackKeys[j] + (octave - 4) * 12)
|
noteUp(blackKeys[j] + (octave - 5) * 12)
|
||||||
blackKeyReleased = true
|
blackKeyReleased = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -210,14 +210,14 @@ class KeyboardComponent(
|
|||||||
// Check if release is on a white key
|
// Check if release is on a white key
|
||||||
val keyIndex = (x / whiteKeyWidth).toInt()
|
val keyIndex = (x / whiteKeyWidth).toInt()
|
||||||
if (keyIndex in 0..6) {
|
if (keyIndex in 0..6) {
|
||||||
noteUp(whiteKeys[keyIndex] + (octave - 4) * 12)
|
noteUp(whiteKeys[keyIndex] + (octave - 5) * 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If y > blackKeyHeight, it's definitely a white key
|
// If y > blackKeyHeight, it's definitely a white key
|
||||||
val keyIndex = (x / whiteKeyWidth).toInt()
|
val keyIndex = (x / whiteKeyWidth).toInt()
|
||||||
if (keyIndex in 0..6) {
|
if (keyIndex in 0..6) {
|
||||||
noteUp(whiteKeys[keyIndex] + (octave - 4) * 12)
|
noteUp(whiteKeys[keyIndex] + (octave - 5) * 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user