# Multiscript increment midi_byte2 on note command



## mikerodi (Aug 1, 2021)

Hi, I would like to send a series of controller messages incrementing the 2nd byte from one value to another. The value should not jump, but increment or decrement by values of one. For example, 47 to 97, at a defined speed in increments of one.

I was able to achieve this with a script, but I’m having difficulty in achieving the same thing with a multiscript.
It should be triggered by a note on.
Any help would be greatly appreciated…


----------



## A.G (Aug 2, 2021)

mikerodi said:


> Hi, I would like to send a series of controller messages incrementing the 2nd byte from one value to another.
> It should be triggered by a note on.


If I understand correctly you try to build a script which is a sort of "Note Velocity via CC value" right?
I just created a multi script for that so you can try it and let me know if it is what you are looking for.

1. Assign a CC# in the UI Controller number box.
2. Switch ON the ON/OFF button (it is a sort of Bypass button).
3. Move the external Controller and play. The Note velocity will get the CC# values.


```
{***********************************************
Note Velocity via CC value v1.0
Author: www.audiogrocery.com
Written by: Ivan Kovachev 
Modified: August 02, 2021
*************************************************}
on init
    set_script_title("Note Velocity via CC value")
  message("")
  
declare $B2:=90 {CC BYTE 2 variable}
make_persistent($B2)

declare ui_switch $ON_OFF
set_control_par(get_ui_id($ON_OFF),$CONTROL_PAR_TEXT_ALIGNMENT,1)
make_persistent($ON_OFF)
_read_persistent_var($ON_OFF)

declare ui_value_edit $CC_num(0, 127, 1) 
set_text($CC_num,"CC#")
make_persistent($CC_num)

declare !on_off_names[2]
!on_off_names[0] := "OFF"
!on_off_names[1] := "ON"
set_text($On_Off,!on_off_names[$On_Off])
end on

on ui_control($On_Off)
set_text($On_Off,!on_off_names[$On_Off])
end on

on midi_in

{ ::::::::::::::::::::::::::: NOTE ON ::::::::::::::::::::::::::::::::: }
if($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and $MIDI_BYTE_2 # 0)
if($ON_OFF=1)
set_event_par($EVENT_ID,$EVENT_PAR_MIDI_BYTE_2,$B2)
end if
end if

{ ::::::::::::::::::::::::::: CONTROLER :::::::::::::::::::::::::::::::::  }

if ($MIDI_COMMAND=$MIDI_COMMAND_CC)
if($MIDI_BYTE_1=$CC_num)
ignore_midi
$B2:=$MIDI_BYTE_2
end if
end if
end on
```


----------



## mikerodi (Aug 2, 2021)

A.G… thank you for your reply!
I’ll try it tomorrow and let you know.


----------



## A.G (Aug 2, 2021)

mikerodi said:


> A.G… thank you for your reply!
> I’ll try it tomorrow and let you know.


Hi. I just updated the code a little bit so get the new one from above tomorrow. I set the B2 to default value 90, so you do not have to tweak the Controller when you play for a very 1st time. After you tweak the Controller say to value 50 and store the multi script as a preset, then it will come with value 50 whenever you load that script.


----------



## mikerodi (Aug 3, 2021)

Good morning Ivan,
I tested the script and though it will come very handy, it's not the function I was looking for.
I'll try to explain what I need better.
Basically, I intend to use this script with sample modeling violin, which has a bow control function (CC1). Moving this controller from 0 to 127 causes the bow of the violin to move and a note is played according to the note pressed. So, for example, if you increment the CC1 value by 1, you will have a very short sound. The more values are incremented, the longer the sound.
The problem is that I would like to have the values increment automatically (so that I won't have to go and input the values manually) when I press the note. I've been able to achieve it with "If", but this would mean inserting 127 commands with the "wait" feature. I can't seem to make it happen with "While".

Something like this: (Obviously this is just a very raw idea)


on midi_in


if ($MIDI_COMMAND = $MIDI_COMMAND_NOTE_ON)
set_midi(0,$MIDI_COMMAND_NOTE_ON,$MIDI_BYTE_1,$MIDI_BYTE_2)
set_midi(0,$MIDI_COMMAND_CC,$MIDI_BYTE_1,$MIDI_BYTE_2)


while ($MIDI_BYTE_2 < 127) {$MIDI_BYTE_2 of CC1}
inc($MIDI_BYTE_2)
wait(100000)
end while

end if


if ($MIDI_COMMAND = $MIDI_COMMAND_NOTE_OFF)
set_midi(0,$MIDI_COMMAND_NOTE_OFF,$MIDI_BYTE_1,$MIDI_BYTE_2)
end if

end on

All I would need is to get this going, then controlling speed and range of increment shouldn't be that difficult.

P.S. I forgot to mention that I would be sending messages to the outside world to the SWAM module.


----------



## A.G (Aug 3, 2021)

mikerodi said:


> Basically, I intend to use this script with sample modeling violin, which has a bow control function (CC1). Moving this controller from 0 to 127 causes the bow of the violin to move and a note is played according to the note pressed. So, for example, if you increment the CC1 value by 1, you will have a very short sound. The more values are incremented, the longer the sound.


I think I could get your idea. I developed a new multi script called "CC Generator via Note".






The generator will generate continuous Controllers whenever you play a MIDI Note. The "Lo/Hi val" boxes are set to 0-127 by default however you can assign a new CC value range. All default UI settings can be replaces by custom ones and stored in an user Multi Script preset. The custom UI assignments will be loaded whenever you insert the Script.
There are 100 speed assignments: 1= very slow; 100 = fastest.
The "Monitor" knob will give you a visual speed presentation of the motorized CC events.


```
{***********************************************
CC Generator via Note v1.0
Author: www.audiogrocery.com
Written by: Ivan Kovachev
Modified: August 03, 2021
*************************************************}
on init
set_script_title("CC Generator via Note")
message("")
declare $n_count             {Note counter}
declare $Running := 0        {Helper}

declare ui_value_edit $Cha(1, 16, 1)
set_text($Cha,"Cha #")
move_control($Cha,1,1)
$Cha:=1
make_persistent($Cha)

declare ui_value_edit $CC_num(0, 127, 1)
set_text($CC_num,"CC #")
$CC_num:=1
move_control($CC_num,2,1)
make_persistent($CC_num)

declare ui_value_edit $Lo_val(0, 127, 1)
set_text($Lo_val,"Lo CC val")
move_control($Lo_val,3,1)
$Lo_val:=0
make_persistent($Lo_val)

declare ui_value_edit $Hi_val(0, 127, 1)
set_text($Hi_val,"Hi CC val")
move_control($Hi_val,4,1)
$Hi_val:=127
make_persistent($Hi_val)

declare ui_value_edit $Speed(1, 100, 1)
set_text($Speed,"Speed")
move_control($Speed,5,1)
$Speed:=40
make_persistent($Speed)

declare ui_knob $Monitor(0, 127, 1) {Motor monitoring knob}
move_control($Monitor,6,1)
end on {end init}

on ui_control($Lo_val)
if($Lo_val>$Hi_val)
  $Hi_val:=$Lo_val
end if
end on

on ui_control($Hi_val)
if($Hi_val<$Lo_val)
  $Lo_val:=$Hi_val
end if
end on

on midi_in

{ ::::::::::::::::::::::::::: NOTE ON ::::::::::::::::::::::::::::::::: }
if($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and $MIDI_BYTE_2 # 0)
inc($n_count)
if ($n_count>1)
exit
else
$Running := 1
$Monitor := $Lo_val
while ($Running=1)
inc($Monitor)
set_midi($Cha-1,$MIDI_COMMAND_CC,$CC_num,$Monitor)
wait((101-$Speed)*1000)
if ($Monitor=$Hi_val)
$Monitor := $Lo_val
end if
end while
end if
end if

{ ::::::::::::::::::::::::::: NOTE OFF ::::::::::::::::::::::::::::::::: }
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_OFF or $MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and $MIDI_BYTE_2=0)
dec($n_count)
if($n_count<0)
$n_count:=0
$Running := 0
end if

if ($n_count=0)
$Running := 0
end if
end if
end on
```


----------



## mikerodi (Aug 3, 2021)

Evan, I think this is perfect! I’ll try it as soon as possible. With your permission, I may have to make a few modifications because the values will have to go from lo to high for one note, then high to low for the next. I’ll also have to implement a function where the direction of the values is inverted every 2 to X notes in order to simulate legato playing. If you already have something in mind, else I could give it a shot, then send you the code so you can make any corrections?

Meanwhile, I’m going to analyze your code so I can learn new things!
I can’t thank you enough!


----------



## A.G (Aug 3, 2021)

mikerodi said:


> I may have to make a few modifications because the values will have to go from lo to high for one note, then high to low for the next. I’ll also have to implement a function where the direction of the values is inverted every 2 to X notes in order to simulate legato playing.


I do not mind if you want to do any code modifications. Originally you were talking about CC value increment only, that's why I programed the code this way. 

You mentioned that you use Kontakt multi script as a MIDI FX and send the CC to the SWAM engine. Which DAW do you use by the way (Cubase supports such internal routing)? 

The SWAM Violin CC1 is mapped to Vibrato by default as far as I remember. Did you re-mapped the bow to CC1. If yes, please let me know which bow UI parameter MIDI mapping do you use so I can try your scenario?


----------



## mikerodi (Aug 3, 2021)

Yes , you’re right, it’s just that I hadn’t completely worked out everything I needed, so I described it in steps.
I’m using SWAM violin 3 on cubase 10.5. I have two tracks: 1 for Kontakt, input master keyboard, output Kontakt (as I have configured Kontakt to send midi to the outside world in the settings section - I have selected all options).
The other track for SWAM, input Kontakt out and output SWAM.
I remapped the expression controller to CC1 and in the “play mode” section/ right hand, I select bowed. So now expression is achieved with bow movement.

P.S. both tracks must be selected in cubase when testing


----------



## A.G (Aug 4, 2021)

mikerodi said:


> P.S. both tracks must be selected in cubase when testing


There is a better way. Just disable the arm button (in the Kontakt track) and enable the monitoring (speaker track icon) in the Kontakt track. This tip will allow you to select only the SWAM Violin track whenever you need, and have a discrete MIDI "thru" from the Kontakt track. You can even hide the Kontakt track after you finish the MIDI FX building .


----------



## mikerodi (Aug 4, 2021)

You’ve just resolved a lifelong issue I’ve had with my orchestral set up!
Thank you!
Is there anyway I can recommend you on this site?


----------



## A.G (Aug 4, 2021)

It is my pleasure.


----------



## A.G (Aug 8, 2021)

mikerodi said:


> I’m using SWAM violin 3 on cubase 10.5. I have two tracks: 1 for Kontakt, input master keyboard, output Kontakt (as I have configured Kontakt to send midi to the outside world in the settings section - I have selected all options).
> The other track for SWAM, input Kontakt out and output SWAM.
> I remapped the expression controller to CC1 and in the “play mode” section/ right hand, I select bowed. So now expression is achieved with bow movement.








Your topic aroused my curiosity, because one of my instruments I play is the violin (here is my latest violin video, below) .
SWAM V3 is based on various time dependent conditions. I did my best to fit the current code defaults to V3 (bowing via expression).

There is no need to remap Expression to Modulation in SWAM (the default CC# is set to CC11 in this code). Everything happens automatically. I implemented a KS assignment (C1 by default) which can be used to alternate the CC inc/dec direction in real time if you need that (the KS must be triggered before the musical Note triggering).

EXAMPLE: If you play "Legato" notes then the bow direction will not be changed. If you play "Detache" notes, then the bow direction will be restarted according to the current down/up bow direction ("alt" status). The "alt" status (bow direction) can be changed on the fly via the "Alt KS".



Here is the latest code. Tryout and report:


```
{***********************************************
CC Generator via Note v1.0
Author: www.audiogrocery.com
Written by: Ivan Kovachev
Modified: August 08, 2021
*************************************************}
on init
set_script_title("CC Generator via Note")
message("")
declare $n_count         {Note counter}
declare $alt:= 1         {CC Alternator: CC inc <=> CC dec}
declare $Lo_val:=20      {Low CC Generator Range}
declare $Hi_val:=127     {High CC Generator Range}
declare $CB_id           {$NI_CALLBACK_ID}

declare ui_value_edit $Cha(1, 16, 1)
set_text($Cha,"Cha #")
move_control($Cha,1,1)
$Cha:=1
make_persistent($Cha)

declare ui_value_edit $CC_num(0, 127, 1)
set_text($CC_num,"CC #")
$CC_num:=11
move_control($CC_num,2,1)
make_persistent($CC_num)

declare ui_value_edit $Alt_KS(0, 127, 0)
set_text($Alt_KS,"Alt KS")
move_control($Alt_KS,3,1)
$Alt_KS:=36
make_persistent($Alt_KS)

declare ui_value_edit $Speed(1, 100, 1)
set_text($Speed,"Speed")
move_control($Speed,5,1)
$Speed:=50
make_persistent($Speed)

declare ui_knob $CC_Gen ($Lo_val, $Hi_val, 1) {CC Generator monitoring knob}
set_text($CC_Gen,"CC Mon")
move_control($CC_Gen ,6,1)
$CC_Gen:=$Hi_val
end on {end init}

on midi_in
{ ::::::::::::::::::::::::::: NOTE ON ::::::::::::::::::::::::::::::::: }
if($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and $MIDI_BYTE_2 # 0)
if($Alt_KS=$MIDI_BYTE_1)
ignore_midi
$alt:=1-$alt
else
inc($n_count)
$CB_id:= $NI_CALLBACK_ID

while ($NI_CALLBACK_ID = $CB_id and $n_count#0)
if($alt=0)
inc($CC_Gen)
if ($CC_Gen =$Hi_val)
$alt:=1-$alt
end if
else
dec($CC_Gen)
if ($CC_Gen=$Lo_val)
$alt:=1-$alt
end if
end if

set_midi($Cha-1,$MIDI_COMMAND_CC,$CC_num,$CC_Gen )
wait((101-$Speed)*500)
end while
end if
end if

{ ::::::::::::::::::::::::::: NOTE OFF ::::::::::::::::::::::::::::::::: }
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_OFF or $MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and $MIDI_BYTE_2=0)
if($MIDI_BYTE_1 # $Alt_KS)
dec($n_count)
if($n_count<=0)
$n_count:=0
end if
end if
end if
end on
```


----------



## mikerodi (Aug 9, 2021)

Good morning Evan! Since you are violinist, I definitely won’t argue with you!😁
I’ll try it and let you know… also because I was trying to work on your script and was complicating my life!
My idea, ultimately, is to use them together with noteperformer, of course at a much lower volume level in order to simulate first and second chair violin.
The thing which is always missing from most samples is the bow action, which is so important in terms of phrasing and expressivity!
So what you are saying is that by key switch I can invert the bow action whenever I need to? Is that correct?


----------



## mikerodi (Aug 9, 2021)

By the way, listened to your album… very nice, with Balkan inflection which I love! Compliments!
These are some of the things I compose:


----------



## mikerodi (Aug 9, 2021)

Evan, the script works to perfection!
Keys witches need to be inserted just before the note in order to ensure a smooth transition before every note, so I could set up two tracks on cubase: one to record everything except the key switch, and the other to record only the key switch so I can offset the timing on the key switch tracking in order to slightly anticipate every key switch. Does that seem like a good idea? Do you have a better idea?


----------



## A.G (Aug 9, 2021)

mikerodi said:


> Do you have a better idea?


Hi Michael,
I'm working on "Auto-Legato/Detache" bow alternation function, so the Key Switch "Alt" will be optional or I will remove it if the "Auto-Legato/Detache" will work well.

It seems that I have to change the original code title "CC Generator" to : "Bow Control via Auto Generator".
Stay tuned...

BTW: Your YouTube music compositions are transparent and relaxing. I love them: Bravissimo!


----------



## mikerodi (Aug 10, 2021)

Thank you for your compliment!
Yes, an automatic function would be more practical… maybe via key switch or Cc one could decide whether bow should change every X notes, or better still, overlapping the notes legato, else or detachè, or else manually, giving freedom to control bow.


----------



## A.G (Aug 16, 2021)

mikerodi said:


> Yes, an automatic function would be more practical… maybe via key switch or Cc one could decide whether bow should change every X notes, or better still, overlapping the notes legato, else or detachè, or else manually, giving freedom to control bow.


Done! All "Bow Control" features are automatic now. They are powered by Legato, Detache and Rest Time performance techniques.
The new version is 100% FREE and is available in the Audio Grocery Free Stuff web page. Download it from there, read the specifications and watch the Video presentation. Let's play the Violin...


----------



## mikerodi (Aug 16, 2021)

Evan, I checked the video and can’t wait to test!
I was wondering if in the future it could be possible to implement a “ramp” function which can control the speed at the moment of bow change. (Something that is useful when playing long sustained notes)
As you know, the bow is given a slight jolt at the moment of bow change so as to make that change less audible. So the idea was that, according to how you set the “ramp” speed, which is essentially the start off the bow, the CC (for the first +-values) would go slightly faster according to setting.
It’s just an idea, but this script is already amazing and can be made to sound just like the real thing!
Once again, thank you! Like your website…


----------



## A.G (Aug 16, 2021)

Mike, I noted that SWAM V3 cannot react quickly to "Detache" when I use a hardware fader to tweak CC11 inc/dec.
I guarantee that my "CC Generator" works well (if I sample and program a Violin with such bow control), however the SWAM does not respond rapidly to instant CC inc/dec changes (especially in slow tempos).

I tested the SWAM V3 with BPM 120 - 130 and higher tempos (the MIDI FX "Rate" knob is set to "1 Bar") and it seemed that the "Detache" is smoother than if you use slow BPM. The other alternative is to set the AG plugin "Rate" to 1/2, to double the bow speed.

Try the AG "Bow Control" in slow and fast DAW tempos and let me know about the "Detache" results.


----------



## mikerodi (Aug 16, 2021)

Ok….. will do!


----------



## mikerodi (Aug 17, 2021)

Evan, I have tested the script and it works as expected. Is it possible to implement the manual option?
I think it comes in handy when dealing with irregular values or when more notes should be played in a single bow stroke. Maybe having a learnable Auto-Manual button giving one complete freedom of control. What do you think?


----------



## A.G (Aug 17, 2021)

I cannot understand the Auto-Manual idea. In common Auto and Manual are opposite actions. Could you give some example of the feature you want.


----------



## mikerodi (Aug 17, 2021)

I was referring to the version you had sent before this one (with key switch to change bow). For this one, I meant manual and the current script auto.
Ev n though not as practical as this one, the previous version with key switch gave more freedom in using the bow feature, especially where there is a continuous alternation between, for example, long and short notes… I don’t know if I’ve made it clearer this time. Maybe one could choose wether to use the previous (manual) or current (auto).


----------



## A.G (Aug 17, 2021)

I see. I will add the KS alternation feature when I have time. I will inform you here.


----------



## mikerodi (Aug 18, 2021)

Thanks Evan. I’ll be uploading my latest orchestral composition if you’re interested…😊


----------



## A.G (Aug 18, 2021)

mikerodi said:


> Thanks Evan. I’ll be uploading my latest orchestral composition if you’re interested…😊


I am interested, so yes please.


----------



## mikerodi (Aug 18, 2021)

Here it is!😁


----------



## A.G (Aug 18, 2021)

Congratulations, the music is matching the title and reminds of the cool war...


----------



## mikerodi (Aug 18, 2021)

Thanks 😊


----------

