Make pitch bend wheel drag start at center (0)

This commit is contained in:
Armin 2026-07-15 23:53:34 +02:00
commit c45d12db1d

View file

@ -1332,9 +1332,14 @@ void PianoRollComponent::paint(juce::Graphics& g) {
void PianoRollComponent::mouseDown(const juce::MouseEvent& e) { void PianoRollComponent::mouseDown(const juce::MouseEvent& e) {
auto pos = e.getPosition(); auto pos = e.getPosition();
// Pitch bend strip: ignore plain clicks — require a vertical drag (see mouseDrag) // Pitch bend strip: begin a drag that starts from center (0 bend)
if (pos.x < pitchBendWidth) { if (pos.x < pitchBendWidth) {
pitchBendDragging = false; pitchBendDragging = true;
pitchBendGliding = false;
pitchBendStartY = pos.y;
currentPitchBend = 64;
processor.pitchBendValue.store(0.0f);
repaint();
return; return;
} }
@ -1387,11 +1392,11 @@ void PianoRollComponent::timerCallback() {
void PianoRollComponent::mouseDrag(const juce::MouseEvent& e) { void PianoRollComponent::mouseDrag(const juce::MouseEvent& e) {
auto pos = e.getPosition(); auto pos = e.getPosition();
// Pitch bend drag — only while touching the strip // Pitch bend drag — relative to where the drag started (starts at 0)
if (pos.x < pitchBendWidth) { if (pos.x < pitchBendWidth) {
pitchBendDragging = true; pitchBendDragging = true;
pitchBendGliding = false; pitchBendGliding = false;
float pbNorm = 1.0f - 2.0f * static_cast<float>(pos.y) / static_cast<float>(whiteKeyHeight); float pbNorm = 2.0f * static_cast<float>(pitchBendStartY - pos.y) / static_cast<float>(whiteKeyHeight);
pbNorm = std::clamp(pbNorm, -1.0f, 1.0f); pbNorm = std::clamp(pbNorm, -1.0f, 1.0f);
currentPitchBend = 64 + static_cast<int>(pbNorm * 64.0f); currentPitchBend = 64 + static_cast<int>(pbNorm * 64.0f);
processor.pitchBendValue.store(pbNorm); processor.pitchBendValue.store(pbNorm);