# MIDI control problem

**URL:** <https://in-thread.sonic-pi.net/t/midi-control-problem/2907>\
**Category:** Support, Help & Resources\
**Created:** [November 10, 2019, 5:51pm UTC](https://in-thread.sonic-pi.net/t/midi-control-problem/2907 "2019-11-10T17:51:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [November 11, 2019, 9:21am UTC](https://in-thread.sonic-pi.net/t/midi-control-problem/2907/2 "2019-11-11T09:21:21Z")

</div>

Hi and welcome  
(This has been edited…The first post got muddled up)

Looking at your code and the cue log, it looks like you are using a keyboard that uses separate note\_on and note\_off triggers.  
The way Sonic Pi generates notes is that you have to specify a start time and a duration in order to play a note. With a keyboard sonic pi doesn’t know how long the note is going to be when you press the key down. There are two possible solutions.  
The easiest way is to assume a length for the note. This is supplied by means of the sustain: parameter. If you don’t supply one it is assumed to be 1 beat, which at the default bpm of 60 lasts for 1 second, then dies away. This may explain why your netes seem to be lost if you play too many close together. You could try more staccato notes using  
`synth :piano, note: note, amp: 1, release: 0.2` for example which would play notes which died away over 0.2 beats  
The harder solution is to start each note playing with an arbitrary long time (say 5 seconds) and use the note\_off symbol to kill the note when the key is released. (On many keyeboards note\_off is signified by using note\_on with a velocity parameter of 0).  
I have developed programs to use this second method, and it works well playing aSonic Pi synth with an external keyboard. I wrote an article [here](http://in-thread.sonic-pi.net/t/polyphonic-gated-synth-for-sonic-pi-3-works-on-a-pi3/452) which shows how it works. If you select the link to the revised-simpler-polyphonic-gated-synth-using-sonic-pi-3 and use the second version of the program which is designed for keyboards that have separate note\_on and note\_off signals that should work for you. (the program is called [**simplepolysynth2.rb**](https://gist.github.com/rbnpi/ebedd26d61180230db891ccbd9d74971#file-simplepolysynth2-rb)

---

_[View the full topic](https://in-thread.sonic-pi.net/t/midi-control-problem/2907)._
