# MIDI program changes, cc, Cubase and Vep



## Eldhrimnir (Dec 15, 2017)

Hi! 
Long time lurker, first time poster here. 

I've really hit a brick wall here, and would greatly appreciate any help. 
I've searched and read all about potential similar issues, but have come up shorthanded, despite learning a lot of new things along the way. So..please bear with me.

I'm aware that VST3 does not support Program Changes, which turned out to be a huge bummer now that I'm about to rework and update my entire orchestral template (since I've upgraded to VEP 6 and Cubase Pro 9, was previously on VE and Cubase 6.5).

I (like many others) want to use instrument banks in Kontakt 5 to switch between sounds and articulations. And since I want to load all my Kontakt instruments inside VEP which runs as VST3, Program Changes apparently won't work anymore. 
So, after doing some reading, I learned that I could change my Cubase Expression Maps to transmit MIDI CC#0 (bank select) instead of Program Changes, and then apply a script in my Kontakt instance to convert the CC's to PC's; and all should be fine and dandy. 

Lo and behold, it did seem to work...or so I thought. What happened was, my instrument bank actually DID switch between articulations (thus, the script did work...somewhat); BUT, the program switching somehow doesn't "keep up". I'm not sure how to explain it, but it appears the program change doesn't happen fast enough, so the notes played does not follow the selected articulation/program. It LOOKS right, as in; I can see the switching happening in Kontakt, seemingly on time, but what I hear is a different story. 

Now, I've tried to troubleshoot to the best of my abilities (I'm in no way a Kontakt or script mastermind), but to no avail. 
I've noticed that if I put a very very short midi note just before the intended one, and apply the same articulation in my Cubase expression map, the program change in Kontakt DOES work. As if you're "kickstarting" the PC. That's why I'm suspecting there might be some kind of delay/latency in the "conversion" from CC to PC. So that the note sounds just a few tiny ticks before the PC is properly registered. Or is that even remotely plausible?

I've tried to use both the built-in script called Transformer, as well as this script which I found elsewhere online:

on midi_in
if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_BYTE_1 = 0)
set_event_par($EVENT_ID, $EVENT_PAR_MIDI_COMMAND, $MIDI_COMMAND_PROGRAM_CHANGE)
set_event_par($EVENT_ID, $EVENT_PAR_MIDI_BYTE_1, $MIDI_BYTE_2)
end if
end on

Both scripts APPEAR to do the job just fine, but alas, in reality they do not. 

I would rather not resort to using keyswitched multis..programming them would be tedious, and my Kontakt instances would be chaos with articulations all over the place. Instrument banks is really the way to go, and if push comes to shove, I suppose I have to fall back to using the VST2 version of VEP for just the Kontakt instances (where Expression Maps with Program Changes works just fine), which would feel like a rather silly and counter-intuitive workaround. 

Please, does anyone know how to solve this infuriating conundrum? 
Thank you!
/dB


----------



## pilgrim (Dec 15, 2017)

There's apparently a bug in VEPro that puts all CC messages after all Note messages when they are sent at the exact same timestep, even if they were originally in the right order.

I work around this in my own similar multiscript by explicitly delaying all note events by one tick to make sure that the Cubase CC expression map message is processed before the note it is associated with:

on midi_in
if ($MIDI_COMMAND = $MIDI_COMMAND_NOTE_ON or $MIDI_COMMAND = $MIDI_COMMAND_NOTE_OFF)
ignore_midi
wait(1)
set_midi($MIDI_CHANNEL, $MIDI_COMMAND, $MIDI_BYTE_1, $MIDI_BYTE_2)
end if
end on

You can edit this into your script, or drop it into an extra multiscript slot to the left of your script or the Transformer.

It's a pretty terrible hack, but it appears to do the trick. The delay is not perceptible. I wouldn't be surprised if there were other side effects, though.


----------



## Eldhrimnir (Dec 15, 2017)

By the nine divines! That actually worked! Thank you SO much! After hours of trial and error; what a relief! 
So I guess my initial assessment was in the ballpark...but my serious lack of knowledge in the script department didn't allow me to address what I suspected to be the culprit. But yeah, pretty stupid bug, albeit a clever hack indeed. Good work!
Again, thanks a million!


----------

