| 40 | val off = ShortMessage() |
| 41 | off.setMessage(ShortMessage.NOTE_OFF, channel, Math.max(0, Math.min(127, pitch)), 0) |
| 42 | receiver!!.send(on, 0); |
| 43 | |
| 44 | generationNumbers.computeIfAbsent(pitch, { 0 }) |
| 45 | val generation = generationNumbers.compute(pitch, { k, v -> |
| 46 | v!! + 1 |
| 47 | }) |
| 48 | |
| 49 | RunLoop.main.delay({ |
| 50 | if (generationNumbers.get(pitch) != generation) return@delay |
| 51 | receiver!!.send(off, 0); |
| 52 | }, (duration * 1000).toInt()) |
| 53 | } |
| 54 | |
| 55 | |
| 56 | @Documentation("`noteOff(pitch, channel)` sends a note off. pitch is 1-127, channel from 0-15") |
| 57 | fun noteOff(pitch: Int, channel: Int) { |
| 58 | val off = ShortMessage() |
| 59 | off.setMessage(ShortMessage.NOTE_OFF, channel, Math.max(0, Math.min(127, pitch)), 0) |
| 60 | receiver!!.send(off, 0); |
| 61 | off.setMessage(ShortMessage.NOTE_ON, channel, Math.max(0, Math.min(127, pitch)), 0) |
| 62 | receiver!!.send(off, 0); |