# Monoponic Script



## dfhagai (Jun 19, 2018)

Hi,

What do you think is the best practice to limit the number of voices in a script?
I trying to block intervals & chords from triggering the script multiple times in parallel.

Unfortunately, Lowering the instrument "Max" number doesn't produce the desired results...

Thanks!
HD


----------



## EvilDragon (Jun 19, 2018)

What exactly are you trying to limit from occuring multiple times in parallel?


----------



## dfhagai (Jun 19, 2018)

I'm trying to figure out how to allow only one note off on the end of a legato line.


----------



## ScoringFilm (Jun 19, 2018)

@dfhagai this script can turn release on/off (and purge) altogether, allow you just to have the last release of a phrase, or adjust the volume of inside releases.

*on init*
``*declare* $i````````
``make_perfview
``SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
``
``*declare* $pressed 
``$pressed := 0
``*declare* $count
``$count := 0
``*declare* $normal_group
``*declare* $release_group
``*declare* $rel_voice
``
``*declare* ui_knob $Inside_Rel (0,200,1)
``$Inside_Rel := 50 _{50%}_
``set_knob_unit ($Inside_Rel, $KNOB_UNIT_PERCENT)
``set_knob_defval( $Inside_Rel,50)
``
``*declare* ui_knob $Rel_Vol (0,200,1)
``$Rel_Vol := 100 _{100%}_
``set_knob_unit ($Rel_Vol, $KNOB_UNIT_PERCENT)
``set_knob_defval( $Rel_Vol,100)
``
``*declare* ui_button $Rel_on_off``
``$Rel_on_off := 0
``*declare* !Rel__text [2]
``!Rel__text[0] := "Release Off"
``!Rel__text[1] := "Release ON" 
``
``*declare* ui_button $Last_on_off``
``$Last_on_off := 0
``*declare* !Last__text [2]
``!Last__text[0] := "Release Last"``
``!Last__text[1] := "Release All"``
``
``move_control($Rel_on_off,1,1)
``move_control($Rel_Vol,2,1)
``move_control($Last_on_off,3,1)
``move_control($Inside_Rel,4,1)
``
``make_persistent($Rel_on_off)
``make_persistent($Last_on_off)
``make_persistent($Inside_Rel)``
``make_persistent($Rel_Vol) 
``
``read_persistent_var($Rel_on_off)
``read_persistent_var($Last_on_off)
``
``set_text ($Inside_Rel, "Inside Vol")
``set_text ($Rel_Vol, "Last Vol")
``set_text ($Rel_on_off, !Rel__text[$Rel_on_off])
``set_text ($Last_on_off, !Last__text[$Last_on_off])
*end* on

*on note*```````
``disallow_group($ALL_GROUPS)
``$normal_group := 0
``*while* ($normal_group < $NUM_GROUPS)
````_{allow normal groups}_
````*if* (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $normal_group, -1, -1) = 0)
``````allow_group($normal_group)
````*end* *if*
````inc($normal_group)
``*end while*``
``_reset_rls_trig_counter($EVENT_NOTE)``
*end* on

*on release*``
``note_off ($EVENT_ID)
``
``*if* ($Rel_On_Off = 0)
````fade_out($EVENT_ID,300000,1) _{for short notes with release sample baked in}_
``*end* *if*
``
``wait (100) 
``*while* ($count<128) 
````*if* (%KEY_DOWN[$count]=1) 
``````$pressed := 1 
````*end* *if* 
````inc($count) 
``*end while* 
``
``disallow_group($ALL_GROUPS)
``$release_group := 0
``*while* ($release_group < $NUM_GROUPS)
````_{allow release groups}_
````*if* (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
``````allow_group($release_group)``````
````*end* *if*
````inc($release_group)
``*end while*
``
``*if* ($Rel_on_off = 1)
````*if* ($Last_on_off = 0)
``````*if* ($pressed = 0) _{only release last note of phrase}_
````````$rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
````````change_vol ($rel_voice, $Rel_Vol * 100, 0)
``````*end* *if*
````*else*`````````
``````*if* ($pressed = 1) _{reduce vol of inside phrase releases}_
````````$rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
````````change_vol ($rel_voice, $Inside_Rel * 100, 0)
``````*else*
````````$rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0) _{all other releases}_
````````change_vol ($rel_voice, $Rel_Vol * 100, 0)
``````*end* *if*
````*end* *if*
``*end* *if*
``
``$count := 0 
``$pressed := 0```````
``allow_group($ALL_GROUPS)
*end* on

*on ui_control* ($Rel_on_off)``````
``$release_group := 0
``*while* ($release_group < $NUM_GROUPS)
````*if* (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
``````purge_group ($release_group,abs($Rel_on_off))``
````*end* *if*
````inc($release_group)
``*end while*``````
``set_text ($Rel_on_off, !Rel__text[$Rel_on_off])
*end* on

*on ui_control* ($Last_on_off)
``set_text ($Last_on_off, !Last__text[$Last_on_off])
*end* on


----------



## dfhagai (Jun 20, 2018)

That's brilliant, thank you so much!


----------



## KrisY (Feb 7, 2019)

ScoringFilm said:


> @dfhagai this script can turn release on/off (and purge) altogether, allow you just to have the last release of a phrase, or adjust the volume of inside releases.
> 
> 
> *... release ... end on... *
> ...



Thanks a lot for this! One little change is needed, a little error in the code above:

[ *purge_group ($release_group,abs($Rel_on_off))* ] - we got a *$*-sign missing in front of the variable being "while´d up" . 

Here I added the whole code again without the formatting, which is beautiful, but adds the "````" signs instead of spaces or tabs. 

*Great script! Here it is again:*


```
on init
  declare $i       
  make_perfview
  SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
 
  declare $pressed
  $pressed := 0
  declare $count
  $count := 0
  declare $normal_group
  declare $release_group
  declare $rel_voice
 
  declare ui_knob $Inside_Rel (0,200,1)
  $Inside_Rel := 50 {50%}
  set_knob_unit ($Inside_Rel, $KNOB_UNIT_PERCENT)
  set_knob_defval( $Inside_Rel,50)
 
  declare ui_knob $Rel_Vol (0,200,1)
  $Rel_Vol := 100 {100%}
  set_knob_unit ($Rel_Vol, $KNOB_UNIT_PERCENT)
  set_knob_defval( $Rel_Vol,100)
 
  declare ui_button $Rel_on_off 
  $Rel_on_off := 0
  declare !Rel__text [2]
  !Rel__text[0] := "Release Off"
  !Rel__text[1] := "Release ON"
 
  declare ui_button $Last_on_off 
  $Last_on_off := 0
  declare !Last__text [2]
  !Last__text[0] := "Release Last" 
  !Last__text[1] := "Release All" 
 
  move_control($Rel_on_off,1,1)
  move_control($Rel_Vol,2,1)
  move_control($Last_on_off,3,1)
  move_control($Inside_Rel,4,1)
 
  make_persistent($Rel_on_off)
  make_persistent($Last_on_off)
  make_persistent($Inside_Rel) 
  make_persistent($Rel_Vol)
 
  read_persistent_var($Rel_on_off)
  read_persistent_var($Last_on_off)
 
  set_text ($Inside_Rel, "Inside Vol")
  set_text ($Rel_Vol, "Last Vol")
  set_text ($Rel_on_off, !Rel__text[$Rel_on_off])
  set_text ($Last_on_off, !Last__text[$Last_on_off])
end on

on note       
  disallow_group($ALL_GROUPS)
  $normal_group := 0
  while ($normal_group < $NUM_GROUPS)
    {allow normal groups}
    if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $normal_group, -1, -1) = 0)
      allow_group($normal_group)
    end if
    inc($normal_group)
  end while 
  _reset_rls_trig_counter($EVENT_NOTE) 
end on

on release 
  note_off ($EVENT_ID)
 
  if ($Rel_On_Off = 0)
    fade_out($EVENT_ID,300000,1) {for short notes with release sample baked in}
  end if
 
  wait (100)
  while ($count<128)
    if (%KEY_DOWN[$count]=1)
      $pressed := 1
    end if
    inc($count)
  end while
 
  disallow_group($ALL_GROUPS)
  $release_group := 0
  while ($release_group < $NUM_GROUPS)
    {allow release groups}
    if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
      allow_group($release_group)     
    end if
    inc($release_group)
  end while
 
  if ($Rel_on_off = 1)
    if ($Last_on_off = 0)
      if ($pressed = 0) {only release last note of phrase}
        $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
        change_vol ($rel_voice, $Rel_Vol * 100, 0)
      end if
    else
      if ($pressed = 1) {reduce vol of inside phrase releases}
        $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
        change_vol ($rel_voice, $Inside_Rel * 100, 0)
      else
        $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0) {all other releases}
        change_vol ($rel_voice, $Rel_Vol * 100, 0)
      end if
    end if
  end if
 
  $count := 0
  $pressed := 0
  allow_group($ALL_GROUPS)
end on

on ui_control ($Rel_on_off)     
  $release_group := 0
  while ($release_group < $NUM_GROUPS)
    if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
      purge_group ($release_group,abs($Rel_on_off)) 
    end if
    inc($release_group)
  end while     
  set_text ($Rel_on_off, !Rel__text[$Rel_on_off])
end on

on ui_control ($Last_on_off)
  set_text ($Last_on_off, !Last__text[$Last_on_off])
end on
```


----------



## ScoringFilm (Feb 7, 2019)

@KrisY - no error, all my scripts are compiled before pasting into Kontakt which adds/removes necessary items!


----------



## KrisY (Feb 7, 2019)

ScoringFilm said:


> @KrisY - no error, all my scripts are compiled before pasting into Kontakt which adds/removes necessary items!



Okay, but Kontakt reported an error with the above code. Copy-paste was unsuccessful, due to the missing *$*.


----------



## ScoringFilm (Feb 7, 2019)

KrisY said:


> Okay, but Kontakt reported an error with the above code. Copy-paste was unsuccessful, due to the missing *$*.



Which is what compiling does!

There are two editors for KSP which compile the script; Sublime 3 or Nils' older editor:

https://nilsliberg.se/ksp/


----------



## KrisY (Feb 7, 2019)

ScoringFilm said:


> Which is what compiling does!
> 
> There are two editors for KSP which compile the script; Sublime 3 or Nils' older editor:
> 
> https://nilsliberg.se/ksp/




Okay, haha. I see. I thought it was a single mistake. All else in the script was without error. Usually with preprocessors its completely off. Good to know. Will check it out. Just on native code in atom :/.


----------



## EvilDragon (Feb 7, 2019)

I would honestly stop recommending Nils' standalone editor. It is horribly out of date. Sublime Text 3 with SublimeKSP is what everybody should use, really. It's the most up to date, plus it has some really cool features Nils' standalone editor doesn't have at all.


----------



## KrisY (Feb 7, 2019)

EvilDragon said:


> I would honestly stop recommending Nils' standalone editor. It is horribly out of date. Sublime Text 3 with SublimeKSP is what everybody should use, really. It's the most up to date, plus it has some really cool features Nils' standalone editor doesn't have at all.



New SublimeKSP is in use, as of 1h ago. Thanks.


----------

