| 16 | track = sequence.createTrack() // Begin with a new track |
| 17 | } |
| 18 | |
| 19 | @Documentation("`note(time, pitch, velocity, duration)` adds a note to this file. Times are in seconds, pitch is 1-127, velocity is 0 to 1.") |
| 20 | fun note(time: Double, pitch: Int, velocity: Double, duration: Double) { |
| 21 | val on = ShortMessage() |
| 22 | on.setMessage(ShortMessage.NOTE_ON, 0, Math.max(0, Math.min(127, pitch)), Math.max(0, Math.min(127, (127 * velocity).toInt()))) |
| 23 | val off = ShortMessage() |
| 24 | off.setMessage(ShortMessage.NOTE_OFF, 0, Math.max(0, Math.min(127, pitch)), 0) |
| 25 | track.add(MidiEvent(on, secondsToTicks(time))) |
| 26 | track.add(MidiEvent(off, secondsToTicks(time + duration))) |
| 27 | } |
| 28 | |
| 29 | @Documentation("`note(time, pitch, velocity, duration, channel)` adds a note to this file. Times are in seconds, pitch is 1-127, velocity is 0 to 1. channel from 0-15") |