# 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:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HappyChen](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@HappyChen](https://in-thread.sonic-pi.net/u/HappyChen)\
**Post date:** [November 10, 2019, 5:51pm UTC](https://in-thread.sonic-pi.net/t/midi-control-problem/2907/1 "2019-11-10T17:51:47Z")

</div>

Hi, I am a student who is beginning to learn Sonic Pi.  
I have a question about that I used sample MIDI controlling code in tutorial.

This is my program.

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/b/b88d142f2b870912a251d1dd1c3a3ac762a66402.png)  
When I play Triads many times, Sonic Pi can catch all notes but the live\_loop sometimes only synth one or two notes.  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/2/2666fbb096fac2e5898943d8055d048781707690.png)

Could someone tell me how to solve it?

---

<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)

---

<div class="post-metadata">

**Author:** ![HappyChen](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@HappyChen](https://in-thread.sonic-pi.net/u/HappyChen)\
**Post date:** [November 12, 2019, 8:18pm UTC](https://in-thread.sonic-pi.net/t/midi-control-problem/2907/3 "2019-11-12T20:18:52Z")

</div>

Thank you, Your suggestion is useful.
