Out of range and init error

The problem is you are passing a frequency value to cpsmidinn, that’s why it’s out of range. You can either remove the cpsmidinn or change --midi-key-cps=4 to --midi-key=4.

Also, p3 is not known during a real time MIDI event. So instead of using linen, use one of the r envelope variants, linenr, madsr, exponr, etc. That will give you better control over real time envelopes. If you must have a fixed note duration you will probably need to to trigger another instrument to perform the note.