Mouse press event. This UI will de/activate keys when you click them and reports it as MIDI note events to the plugin. */
| 85 | This UI will de/activate keys when you click them and reports it as MIDI note events to the plugin. |
| 86 | */ |
| 87 | bool onMouse(const MouseEvent& ev) override |
| 88 | { |
| 89 | // Test for last key release first |
| 90 | if (fLastKey != -1 && ! ev.press) |
| 91 | { |
| 92 | // Send a note event. Velocity=0 means off |
| 93 | sendNote(0, kNoteOctaveStart+fLastKey, 0); |
| 94 | // Unset key state |
| 95 | fKeyState[fLastKey] = false; |
| 96 | fLastKey = -1; |
| 97 | repaint(); |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | // Test for left-clicked first. |
| 102 | if (ev.button != 1) |
| 103 | return false; |
| 104 | |
| 105 | // Find the key which is pressed, if any |
| 106 | int whichKey = -1; |
| 107 | for (int key = 0; key < 12 && whichKey == -1; ++key) |
| 108 | { |
| 109 | Rectangle<int> bounds = getKeyBounds(key); |
| 110 | |
| 111 | if (bounds.contains(ev.pos)) |
| 112 | whichKey = key; |
| 113 | } |
| 114 | |
| 115 | if (whichKey == -1) |
| 116 | return false; |
| 117 | if (fKeyState[whichKey] == ev.press) |
| 118 | return false; |
| 119 | |
| 120 | // Send a note event. Velocity=0 means off |
| 121 | sendNote(0, kNoteOctaveStart+whichKey, ev.press ? kNoteVelocity : 0); |
| 122 | |
| 123 | // Set pressed state of this key, and update display |
| 124 | fLastKey = whichKey; |
| 125 | fKeyState[whichKey] = ev.press; |
| 126 | repaint(); |
| 127 | |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | Set our UI class as non-copyable and add a leak detector just in case. |