# Polyphony and SIPS



## joris1974 (Aug 16, 2008)

Hi,
I was trying to automate the switching on and off of SIPS Legato depending on polyphony. By which I mean actual note polyphony, not group polyphony. I came up with this so far (this in slot 1, SLS in slot 2)


> on init
> declare $lasttime:=0
> declare $offset:=0
> declare $oldnote
> ...



When I play two notes close enough together, it leaves the legato mode as intended, however, the note of the "chord" that was played first, which was triggered before SLS is turned off, hangs. The note_off doesn't seem to have any effect nor does a note_off($ALL_EVENTS) (which I tried in despair). Is SLS ignoring those for some reason? Thanks in advance for any tip!

Joris


----------



## gmet (Aug 17, 2008)

Joris,

There is no need to have the script using the note on/off at all and indeed it probably will cause problems with SLS anyway.

I use the following method with SIPS which literally turns it on or off depening on polyphony (chords or single notes) which I presume is what you are trying to achieve:

*on init*
``*declare* $lasttime
``*declare* $Offset
``*declare* ui_value_edit $Chord_ms(0,1000,1)
``$Chord_ms := 20
``make_persistent ($Chord_ms)
``*declare* ui_button $solo
``$solo:=0 
``*declare* $SLS_On_Off
``$SLS_On_Off := _{What ever #CC to turn On/Off SLS}_
*end on*

*on note*
``$Offset := $ENGINE_UPTIME - $lasttime
``ignore_event($EVENT_ID)
``*if* ($Offset <= $Chord_ms)
````set_controller($SLS_On_Off,0)
````$solo:=0
``*else*
````set_controller($SLS_On_Off,127)
````$solo:=1
``*end if*``````
``$lasttime := $ENGINE_UPTIME
*end on*

Justin


----------



## joris1974 (Aug 17, 2008)

Justin,

Thank you for your input. I assume you didn't really mean the ignore_event call :wink: Anyway, I did try it with both SIPS 1.5.1 and 2.05 and I get the "slightly older" note of the chord either hung or cut off by the "slightly newer" one. After that chords play fine as SLS is effectively off. I can't wrap my mind around the fact that one note is triggered before SLS is turned off and one right after - this is what I clumsily tried to avoid in my initial script. Is SLS supposed to react a certain way when turned off, while a key is still depressed? I guess I can live with it, or I'll just stick to hiding CCs in Sibelius to force a "divisi" for winds and brass sections.

Thanks again for your help in cleaning up my mess!

Joris


----------



## Big Bob (Aug 18, 2008)

Justin & Joris,

To do what you are trying to do, I think you will have to do something like the following (I just edited Justin's code a little):

*on init* 
``*declare* $lasttime 
``*declare* $Offset 
``*declare* ui_value_edit $Chord_ms(0,1000,1) 
``$Chord_ms := 20 
``make_persistent ($Chord_ms) 
``*declare* ui_button $solo 
``$solo:=0 
``*declare* $SLS_On_Off 
``$SLS_On_Off := 1 _{What ever #CC to turn On/Off SLS}_ 
``*declare* *const* $LegatoMode := 96
*end on* 

*on note* 
``$Offset := $ENGINE_UPTIME - $lasttime 
``ignore_event($EVENT_ID)
``*if* ($Offset <= $Chord_ms) 
````set_controller($SLS_On_Off,0) 
````$solo:=0 
``*else* 
````set_controller($SLS_On_Off,LegatoMode) 
````$solo:=1 
``*end if* 
``wait(1)
``play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)``````
``$lasttime := $ENGINE_UPTIME 
*end on* 

The problem boils down to the fact that K2/K3 doesn't act on the set_controller calls until the callback is dismissed. But by then it is too late because the note-on event will then go through first. The above code may work out for you because it essentially holds the note for at least 1 microsecond to allow the CC event to go through first.

Note that I also changed the Legato mode value from 127 to 96 (as Joris had it) because 127 will not work for SIPS 2.

I hope this helps a bit but keep in mind that K2/K3 doesn't always handle the -1 in the play_note function correctly.

God Bless,

Bob


----------



## joris1974 (Aug 18, 2008)

Big Bob,

You did it again, my friend. Amazing what 1 microsecond of waiting and years of experience can do! I'll probably make the return to solo mode optional as "a2" or "1."/"2."/"solo" are customary notations that I can easily translate into CCs from Sibelius. As you may have guessed, this is going to be included in my front-end to SIPS2 (still have to make the port. mode play nicely with Sibelius's interpretation of glissandi, but I'm getting there  )

Just a slightly off-topic question (although...). Is there any trick, script or insert fx, that can make a section instrument (say a 2 trumpets .nki) sound reasonably solo-ish in little-exposed passages? I tried stereo modeler set to mono + HP filter, and it helps somewhat, but not decidedly.

Thanks again to you and Justin for your generous help.

Joris


----------



## Big Bob (Aug 18, 2008)

Hi Joris,



> Is there any trick, script or insert fx, that can make a section instrument (say a 2 trumpets .nki) sound reasonably solo-ish in little-exposed passages?



Sorry but I don't know of anyway to do this and considering the physics of the situation it seems doubful to me that there is any. You don't have a solo instrument in your tool box or you just don't want to use it for some reason? Most often people seem to want to use a solo instrument to sythesize sections, this is the first time I heard anyone ask to do the reverse :lol: .

God Bless,

Bob


----------



## joris1974 (Aug 18, 2008)

Hi Bob,



> Sorry but I don't know of anyway to do this and considering the physics of the situation it seems doubful to me that there is any. You don't have a solo instrument in your tool box or you just don't want to use it for some reason?



Well, it was just for completenessò{   ‚‘]{   ‚‘^{   ‚‘_{   ‚‘`{   ‚‘a{   ‚‘b{   ‚‘c{   ‚‘d{   ‚‘e{   ‚‘f{   ‚‘g{   ‚‘h{   ‚‘i{   ‚‘j{    ‚‘w{    ‚‘x{    ‚‘y{    ‚‘z{    ‚‘{{    ‚‘|{    ‚‘}{    ‚‘~{    ‚‘{    ‚‘€{    ‚‘{    ‚‘‚{    ‚‘ƒ{    ‚‘„{    ‚‘…{    ‚‘†{    ‚‘‡{    ‚‘ˆ{    ‚‘‰{    ‚‘Š{    ‚‘‹{    ‚‘Œ{    ‚‘{    ‚‘Ž{    ‚‘{    ‚‘{    ‚‘‘{    ‚‘’{    ‚‘“{    ‚‘”{    ‚‘•{    ‚‘–{    ‚‘—{    ‚‘˜{    ‚‘™{    ‚‘š{    ‚‘›{    ‚‘œ{    ‚‘{    ‚‘ž{    ‚‘Ÿ{    ‚‘ {    ‚‘¡{    ‚‘¢{    ‚‘£{    ‚‘¤{    ‚‘¥{    ‚‘¦{    ‚‘§{    ‚‘¨{    ‚‘©{    ‚‘ª{    ‚‘«{    ‚‘¬{    ‚‘­{    ‚‘®{    ‚‘¯{    ‚‘°{    ‚‘±{    ‚‘²{    ‚‘³{    ‚‘´{    ‚‘µ{    ‚‘¶{    ‚‘·{    ‚‘¸{    ‚‘¹{    ‚‘º{    ‚‘»{    ‚‘¼{    ‚‘½{    ‚‘¾{    ‚‘¿{    ‚‘À{    ‚‘Á{    ‚‘Â{    ‚‘Ã{    ‚‘Ä{    ‚‘Å{    ‚‘Æ{    ‚‘


----------



## gmet (Nov 6, 2008)

Joris,

I have only just seen the replies in this thread - been very busy! Your description sounds wonderful but why don't you just try this script to achieve solo & sections with one patch:

http://www.vi-control.net/forum/viewtop ... ht=#133621

Bob,

Thanks for the input. I have not used the 1ms wait and had no problems but for acuracy I will add it.

Regards,

Justin


----------



## joris1974 (Nov 6, 2008)

> Joris,
> 
> I have only just seen the replies in this thread - been very busy! Your description sounds wonderful but why don't you just try this script to achieve solo & sections with one patch:
> 
> http://www.vi-control.net/forum/viewtop ... ht=#133621



Justin,

Thank you for the follow-up. I did take a look at this and have used a stripped-down version of the technique. I decided to separate the handling of section/voicing and the automation part. What I found is that the script that yourself and Bob contributed works well when poly and mono are clearly separated (e.g. a melody followed by a chord and conversely). However, in a more contrapuntal setting (hold a C, wait, play an E without releasing the C), nothing happens. I ended up writing this :


```
on init
  declare $notecnt := 0
  declare ui_value_edit $Gate_ms (0,100,1)
  declare ui_value_edit $SectionCC (0,127,1)
  declare ui_value_edit $PolyOn (0,127,1)
  declare ui_value_edit $PolyOff (0,127,1)
  declare ui_button $InPlace
  
  make_persistent ($Gate_ms)
  make_persistent ($SectionCC)
  make_persistent ($PolyOn)
  make_persistent ($Polyoff)
  make_persistent ($InPlace)

  _read_persistent_var($Gate_ms)
  _read_persistent_var($SectionCC)
  _read_persistent_var($PolyOn)
  _read_persistent_var($PolyOff)
  _read_persistent_var($InPlace)
end on

on note
  if ($EVENT_NOTE>0)
    inc($notecnt)
  end if
  if ($notecnt>1)
    wait(1000*$Gate_ms)
    if ($notecnt>1)
      set_controller($SectionCC,$PolyOn)
    else
      if ($InPlace=0)
        set_controller($SectionCC,$PolyOff)
      end if
    end if
  else
    if ($InPlace=0)
      set_controller($SectionCC,$PolyOff)
    end if
  end if
	
end on

on release
  if ($EVENT_NOTE>0 and ($notecnt>0))
    dec($notecnt)
  end if
end on
```

Just set the SectionCC to whatever CC you use (either for Sips, or Ensemble Maker, or anything else). The Gate_ms is used to filter false positives from legato overlap (set to 50ms here). Finally, the InPlace alters the logic. When on PolyOn and PolyOff values are not toggled, but the polyphonic mode (PolyOn value) stays in place unless SectionCC is manually changed. This is the most common situation for woodwinds and brass, where unison and soli are explicitly notated in a score.

This gives me stuck notes from Sips every now and then, so I am not claiming it works fully at this time... Feel free to critique the code!

Cheers,
Joris


----------



## Hannes_F (Jan 10, 2009)

Hi,

I would be interested in the same as nlundberg. Thanks.


----------



## joris1974 (Jan 12, 2009)

Hi,

The code I posted some time ago was meant as a stand-alone script - you could add the starter script part to it, I'm sure. If using with SIPS, make sure it is loaded in a slot that comes before SIPS. To have the desired effect with strings, set the "InPlace" button to off, set the sectionCC to whatever CC you are using to control SLS mode, and for PolyOn, set the value to 0 (SLS off when polyphonic). Finally, set PolyOff to 96 (for SLS 2 ; 127 for SLS 1). It "should" work. BTW, if you're controlling the legato phrasing with CC64 (i.e. no overlap of notes), you can set the gate_ms value to 0, otherwise I would tend to use 50ms. Let me know if that works for you. This was an experimental bit of code so please be aware of potential flaws. Hope this helps, though 


Joris


----------



## nlundberg (Jan 12, 2009)

Hi,

I got it working! Thanks a lot.

But only working by means of seeing the buttons. If I play "by hand" it works pretty allright, but when I sequence from Sibelius I get stuck notes galore. That is really weird. It should not be any difference.

I understand that it is experimental code, but still, it would be wonderful if it worked! Are there any more tweaks that I could do?

Best,

Nicklas.


----------



## joris1974 (Jan 14, 2009)

Hi Nicklas,

If you're using Sibelius, as I do, do you have a soundset with a legato SoundID? If so, you can try to set the "gate_ms" to 0 (you may want to enclose the wait command in a "if gate_ms>0 ... end if" condition so that Kontakt doesn't complain), and have the legato switch in your soundset file trigger a CC64=127 message. As for the script as provided, I'm not sure what the problem is, to be honest, and I've had similar results with either a lot of instruments loaded, or with fast passages. This is something I am working on, but I am also finishing a score right now, so it is somewhat on the back burner, I'm afraid. If you are not using double-stops that start as a single stop or move in a contrapuntal manner (e.g. Bach's partitas/chaconnas, and many other examples from fine composers ), then give Big Bob's suggested script a try - from the same thread. I am sorry I cannot help you much further, trust me, I would love to have the "magic bullet" myself :? 

Cheers,

Joris


----------



## nlundberg (Jan 15, 2009)

Hi Joris,

I actually got it to work in another way, a way I tried before but it did not work then by some reason (but I have two suspects).

In SEE (sibelius Sound Set Edtior) I add a +legato switch and in it a CC65 (or whatever) with a 96 value. And in [reset] I add CC65, 0. 
In SIPS legato I set the Mode CC to 65, of course.

At this point this works flawless. If I put in slurs in Sibelius it plays mono/legato and if there are no slurs I can put in any chord I like. 

Before this did not work since the notes has to overlap in order to make SIPS play legato. What I think have happened is that Kontakt or SIPS is sluggish for some reason and the note offs are delayed, and then SIPS legato kicks in.

At the same time I realise that fast keyswitching does not work well. I suspect Kontakt or SIPS. I have checked Sibelius midi output and it appears to send it out right, although there are a lot if keyswitching for just some straight staccato 8ths (reset after every note)! But I guess this is just how Sibby works. And it did work before. I guess I should be posting this in a separate tread.

But if this lag problem gets resolved I believe that the legato is not going to work again. So what then would be needed is to make a short delay of the midi note offs as soon as CC65 (in this case) is between 96-127 and not 0. I would gladly do it if anyone could give me a hint, but I guess it is so simple that it is no point.

As for your suggestion, I am not sure what the "gate_ms" does, sorry. But setting the soundset to trigger CC64 for legato lines makes editing notes by hand chaotic since you will have sustained notes all over the place.

Good luck with the score!

Nicklas.


----------



## nlundberg (Aug 29, 2009)

Joris:

I tried out and really like your polyphony script. I have looked at the code and can not figure out this problem. When I play a few staccato notes and then hold a note and play another I get a legato. If I repeatedly play polyphonic it from now on works. But as soon as I play staccato notes the first two simultaneously held notes are recognised as legato.
When I look at SLS it looks right in both cases.

Any ideas?

Best regards,

Nicklas.


----------

