# Help with delay group script [UNSOLVED]



## Claud9 (Jul 30, 2018)

Hello everyone,
I have problems with this script hope somebody can help me!
I have a simple instrument with two layers.
I have assigned to each layer 4 groups (of a total of 8 groups)
I have created two knobs that should delay (of some ms) the sample start of the selected group.

The two knob should act independently one from each other so that $delay1 should delay ONLY the first 4 groups and $delay2 should delay only the other 4 groups.

The script below is not working properly because both knobs always delay all groups.
What is wrong? Thanks in advance for any help!


```
on init
 
 
  set_ui_height_px(100)

  make_perfview
  message("")
  declare $i 
   
  
  declare ui_knob $delay1(0, 10000, 10)
  declare ui_knob $delay2(0, 10000, 10)
  set_knob_unit($delay1, $KNOB_UNIT_MS)
  set_knob_unit($delay2, $KNOB_UNIT_MS)

  declare ui_menu $layer1_menu
  
  declare ui_menu $layer2_menu
  

  {LAYERS MENU}

   declare const $LAYER1_FIRST := 0
   declare const $LAYER1_LAST := 3
   declare const $LAYER2_FIRST := 4
   declare const $LAYER2_LAST := 7
 
   $i := $LAYER1_FIRST
   while ($i<=$LAYER1_LAST)
     add_menu_item($layer1_menu,group_name($i),$i)
     inc($i)
   end while

   $i:= $LAYER2_FIRST
   while ($i<=$LAYER2_LAST)
     add_menu_item($layer2_menu,group_name($i),$i)
     inc($i)
   end while
end on

{LAYER 1}

   on ui_control ($layer1_menu)
   $i := $LAYER1_FIRST
   while ($i<=$LAYER1_LAST)
   purge_group($i,0)
   inc($i)
    
   end while
   purge_group($layer1_menu,1)
    
   end on

   {LAYER 2}

   on ui_control ($layer2_menu)
   $i := $LAYER2_FIRST
   while ($i<=$LAYER2_LAST)
   purge_group($i,0)
   inc($i)
    
   end while
   purge_group($layer2_menu,1)
end on

 on note
  ignore_event($EVENT_ID)
  if ($delay1>0 and search(%GROUPS_AFFECTED, $layer1_menu) <=$LAYER1_LAST)   
    wait(400 * $delay1)   
  end if
  if ($delay2>0 and search(%GROUPS_AFFECTED, $layer2_menu) <=$LAYER2_LAST)   
    wait(400 * $delay2)   
  end if
  play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1) 
end on
```


----------



## EvgenyEmelyanov (Jul 30, 2018)

At first, simple solution. Add a little bit of silence in your sound files - and then shift the beginning of samples in the files. This way there is no need in using wait() commands.

Ok, let's take a look at your code:

```
on note
  ignore_event($EVENT_ID)
  if ($delay1>0 and search(%GROUPS_AFFECTED, $layer1_menu) <=$LAYER1_LAST)  
   wait(400 * $delay1)  
  end if
  if ($delay2>0 and search(%GROUPS_AFFECTED, $layer2_menu) <=$LAYER2_LAST)  
   wait(400 * $delay2)  
  end if
  play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
end on
```

Using wait() before play_note() you add a pause before ALL notes, not only four groups. You should do something like that (if you have only one delay at the same time). If you have two delays then you have to calculate the difference between two delays. But I hope you get the idea.

```
on note
  ignore_event($EVENT_ID)

  {first delay condition}
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow second groups only using dissallow, allow commands}
      {then we wait for first groups}
      wait(400 * $delay1) 
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow first groups only using dissallow, allow commands}
  {end first delay condition}

 
 
   {second delay condition}
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow first groups only using dissallow, allow commands}
      {then we wait for second groups}
      wait(400 * $delay1) 
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow second groups only using dissallow, allow commands}
  {end second delay condition}
end on
```

Again, it should work with one delay only. For two delays I would recommend to use an idea in the beginning of this post.


----------



## Claud9 (Jul 30, 2018)

EvgenyEmelyanov said:


> At first, simple solution. Add a little bit of silence in your sound files - and then shift the beginning of samples in the files. This way there is no need in using wait() commands.
> 
> Ok, let's take a look at your code:
> 
> ...





EvgenyEmelyanov said:


> At first, simple solution. Add a little bit of silence in your sound files - and then shift the beginning of samples in the files. This way there is no need in using wait() commands.
> 
> Ok, let's take a look at your code:
> 
> ...


 Hello, thanks for the help.
I tried to modify the code as you have suggested but the delay knobs are not working at all now. No sort of delay is applied to any of the groups. What I'm doing wrong? 
Also, I don't understand what you mean that It should work with one delay only? Thanks for any suggestion!

```
on note
  ignore_event($EVENT_ID)

  {first delay condition}
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow second groups only using dissallow, allow commands}
      {then we wait for first groups}
disallow_group($ALL_GROUPS)
$i := $LAYER2_FIRST
while ($i<=$LAYER2_LAST) 
allow_group($i)
inc($i)
end while
      wait(400 * $delay1)
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow first groups only using dissallow, allow commands}
  {end first delay condition}
disallow_group($ALL_GROUPS)
$i := $LAYER1_FIRST
while ($i<=$LAYER1_LAST) 
allow_group($i)
inc($i)
end while
 
 
   {second delay condition}
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow first groups only using dissallow, allow commands}
      {then we wait for second groups}
disallow_group($ALL_GROUPS)
$i := $LAYER1_FIRST
while ($i<=$LAYER1_LAST) 
allow_group($i)
inc($i)
end while
      wait(400 * $delay1)
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      {disallow all groups and then allow second groups only using dissallow, allow commands}
  {end second delay condition}
disallow_group($ALL_GROUPS)
$i := $LAYER2_FIRST
while ($i<=$LAYER2_LAST) 
allow_group($i)
inc($i)
end while
end on
```


----------



## EvgenyEmelyanov (Jul 30, 2018)

Claud9 said:


> Also, I don't understand what you mean that It should work with one delay only?



I meant we cannot use two wait() commands for both delays in parallel.



Claud9 said:


> I tried to modify the code as you have suggested but the delay knobs are not working at all now. What I'm doing wrong?



It was just an example. It was not an actual code. Look, let's say we need to play four groups, wait a delay value and then play another four groups, right? This way we need to do the following steps:


disallow all groups

allow four groups that we need
play_note()
wait a delay value
disallow all groups

allow another four groups
play_note()
Also:

By the way, using $EVENT_PAR_ALLOW_GROUP is better than just allow_groups/disallow_groups. In my opinion. Just in case.

I do not understand why do we need to use %GROUPS_AFFECTED. Especially before play_note command. Just bear in mind (keep it in a variable) which group is unpurged.

There is no need to declare four constants. And what if you have sixteen layers? Will you declare 32 constants? All you need is two constants: $NUMBER_OF_LAYERS, $NUMBER_OF_GROUPS_IN_ONE_LAYER


----------



## szcz (Jul 31, 2018)

disallow_group doesn't work on notes generated by play_note, you need to set $EVENT_PAR_ALLOW_GROUP for each group. For example instead of
disallow_group($ALL_GROUPS), you do:


```
$note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
$count := 0
while($count < $NUMBER_OF_GROUPS)
      set_event_par_arr($note_id,$EVENT_PAR_ALLOW_GROUP,0,$count)
      inc($count)
end while
```


----------



## EvilDragon (Jul 31, 2018)

No, that is way too complicated. You just do this:


```
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
```


Also, (dis)allow_group() command(s) do work with play_note(), but not in all cases (like if there's a wait() it might not work, I think).


----------



## Claud9 (Jul 31, 2018)

EvilDragon said:


> No, that is way too complicated. You just do this:
> 
> 
> ```
> ...


Thank you all for the help but I'm still confused and It is still not working properly. I'm doing step by step trying with only one delay knob at the time but the delay is still applied to all layers. For example, in my instrument, I'm playing Group 2 (assigned to Layer 1) and Group 7 (assigned to Layer 2). $delay1 in my intentions should delay only Group 2 so that when I play a note Group 7 should start immediately and instead Group 2 should start delayed of X ms. But the delay is applied to both layers... What I'm doing wrong? Thanks a lot in advance for any help!

```
on init
 
 
  set_ui_height_px(100)

  make_perfview
  message("")
  declare $i 
  
  
  declare ui_knob $delay1(0, 10000, 10)
  declare ui_knob $delay2(0, 10000, 10)
  set_knob_unit($delay1, $KNOB_UNIT_MS)
  set_knob_unit($delay2, $KNOB_UNIT_MS)
  declare $note_id

  declare ui_menu $layer1_menu
  
  declare ui_menu $layer2_menu
  

  {LAYERS MENU GROUPS ASSIGNEMENTS}

   declare const $LAYER1_FIRST := 0
   declare const $LAYER1_LAST := 3
   declare const $LAYER2_FIRST := 4
   declare const $LAYER2_LAST := 7
 
   $i := $LAYER1_FIRST
   while ($i<=$LAYER1_LAST)
     add_menu_item($layer1_menu,group_name($i),$i)
     inc($i)
   end while

   $i:= $LAYER2_FIRST
   while ($i<=$LAYER2_LAST)
     add_menu_item($layer2_menu,group_name($i),$i)
     inc($i)
   end while
end on

{LAYER 1}

   on ui_control ($layer1_menu)
   $i := $LAYER1_FIRST
   while ($i<=$LAYER1_LAST)
   purge_group($i,0)
   inc($i)
    
   end while
   purge_group($layer1_menu,1)
    
   end on

   {LAYER 2}

   on ui_control ($layer2_menu)
   $i := $LAYER2_FIRST
   while ($i<=$LAYER2_LAST)
   purge_group($i,0)
   inc($i)
    
   end while
   purge_group($layer2_menu,1)
end on

 on note

ignore_event($EVENT_ID)
        
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
$i := $LAYER1_FIRST
while ($i<=$LAYER1_LAST)
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 1, $i)
inc($i)
end while
 
      wait(400 * $delay1)

$note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
    
          
end on
```


----------



## EvgenyEmelyanov (Jul 31, 2018)

Claud9 said:


> What I'm doing wrong?



Look, you work with $note_id using set_event_par_arr command but $note_id is zero here:


```
on note
ignore_event($EVENT_ID) 
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
...
```

You are trying to disallow groups for $note_id event but this variable ($note_id) has no value (zero).

It should work (I did not check). By the way, you can use a function here:


```
on note

ignore_event($EVENT_ID)

$note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)  
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
$i := $LAYER2_FIRST
while ($i<=$LAYER2_LAST)
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 1, $i)
inc($i)
end while

wait(400 * $delay1)

$note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)  
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
$i := $LAYER1_FIRST
while ($i<=$LAYER1_LAST)
set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 1, $i)
inc($i)
end while
 
    
end on
```



szcz said:


> disallow_group doesn't work on notes generated by play_note



As I think disallow_group works perfectly with play_note command. It is identical to:


```
set_event_par_arr($ALL_EVENTS, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
```


----------



## Claud9 (Jul 31, 2018)

> If you have two delays then you have to calculate the difference between two delays.


Thanks for the help, now $delay1 is working fine! But I tried to do the same also for $delay2 but is not working.
How can I have both delays working at the same time (delay1 to apply the delay to Layer1 groups only and delay2 to apply the delay to Layer2 groups only)? What do you mean with "_If you have two delays then you have to calculate the difference between two delays_."? Thanks in advance for any help


----------



## EvilDragon (Jul 31, 2018)

You need to use some math. Basic subtraction really. If delay 1 is 500 ms and delay 2 is 300 ms, that means the difference between them is 200 ms. But it also means you MUST play second delay first (because it's shorter!), then the first one.


----------



## Claud9 (Jul 31, 2018)

EvilDragon said:


> You need to use some math. Basic subtraction really. If delay 1 is 500 ms and delay 2 is 300 ms, that means the difference between them is 200 ms. But it also means you MUST play second delay first (because it's shorter!), then the first one.


So basically the scheme of what I have to code is this (taking your numbers as an example):

get $delay1 and $delay2 knobs ms values at the moment of the "on note" callback (500 ms and 300 ms)
calculate the difference between them (200 ms)
tell Kontakt to play first the layer with the shortest delay (Layer 2 with a delay of 300 ms)
tell Kontakt to play (after the 300 ms) the layer with the higher delay (Layer 1 with a delay of 200 ms)
Is this something close to what I have to do? Also is there something similar on KSP manual that I can check? Just to have an idea because I have no idea how to translate in code this!


----------



## EvgenyEmelyanov (Aug 1, 2018)

Claud9 said:


> Also is there something similar on KSP manual that I can check?



KSP manual is a "bible" that contains all the basic commands and ideas. Now you should use simple math to combine simple commands into something bigger.

Declare two new variables - $shortest_delay and $start_position_of_fastest_layer. Also, a new constant - $NUMBER_OF_GROUPS_IN_ONE_LAYER := 4.

I did not check it but it looks clean for me and should work. Also, I have added a couple of functions to make note callback clear.


```
on note
  ignore_event($EVENT_ID)

  call calculate_shortest_values
 
  wait(400 * $shortest_delay)

  call play_fast_layer

  wait(400 * abs($delay1 - $delay2))
 
  call play_slow_layer
 
end on

function calculate_shortest_values
   if($delay1 < $delay2)
     $shortest_delay := $delay1
     $start_position_of_fastest_layer := $LAYER1_FIRST
  else
      $shortest_delay := $delay2
      $start_position_of_fastest_layer := $LAYER2_FIRST
  end if
end function

function play_fast_layer
  $note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
  set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
  $i := $start_position_of_fastest_layer
  while ($i<=$start_position_of_fastest_layer + $NUMBER_OF_GROUPS_IN_ONE_LAYER)
      set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 1, $i)
     inc($i)
  end while
end function

function play_slow_layer
   $note_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
   set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
   $i := abs($LAYER1_FIRST - $LAYER2_FIRST)
   while ($i<=abs($LAYER1_FIRST - $LAYER2_FIRST) + $NUMBER_OF_GROUPS_IN_ONE_LAYER)
      set_event_par_arr($note_id, $EVENT_PAR_ALLOW_GROUP, 1, $i)
      inc($i)
   end while
end function
```


----------



## EvilDragon (Aug 1, 2018)

I'm not sure why you're multiplying the wait time by 400, it should multiply by 1000 (from microseconds to milliseconds).

In any case the way I would do it would be a bit more elegant perhaps (you don't need a function for fast and slow layers, one function with a pointer is enough, with a little bit of help from some arrays), and covers more cases (if wait time is 0 wait() shouldn't happen at all, and also covers the situation when both delay times are the same). Also your script wouldn't work because you cannot use $EVENT_VELOCITY and $EVENT_NOTE in functions.


```
on init
    declare %group_min[2] := (0, 4)
    declare %group_max[2] := (3, 7)
    declare %delay_times[2]

    declare $i
    declare $first_layer_to_play
    declare $layer
    declare $diff
    declare $note_ID
    declare $note
    declare $vel

    declare ui_knob $Delay1 (0, 1000, 1)
    declare ui_knob $Delay2 (0, 1000, 1)

end on

function PlayLayer()
        $note_ID := play_note($note, $vel, 0, -1)
        set_event_par_arr($EVENT_PAR_ALLOW_GROUP, $note_ID, 0, $ALL_GROUPS)
        $i := %group_min[$layer]
        while ($i < %group_max[$layer])
            set_event_par_arr($EVENT_PAR_ALLOW_GROUP, $note_ID, 1, $i)
            inc($i)
        end while
end function

on note
    ignore_event($EVENT_ID)

    %delay_times[0] := $Delay1 * 1000
    %delay_times[1] := $Delay2 * 1000

    $note := $EVENT_NOTE
    $vel := $EVENT_VELOCITY

    if (%delay_times[0] = %delay_times[1])
        if (%delay_times[0] > 0)
            wait(%delay_times[0])
        end if

        $layer := 0
        call PlayLayer()
        $layer := 1
        call PlayLayer()
    else
        $diff := abs(%delay_times[0] - %delay_times[1])

        if (%delay_times[0] < %delay_times[1])
            $first_layer_to_play := 0
        else
            $first_layer_to_play := 1
        end if

        if (%delay_time[$first_layer_to_play] > 0)
            wait(%delay_times[$first_layer_to_play])
        end if

        $layer := $first_layer_to_play
        call PlayLayer()

        if ($diff > 0)
            wait($diff)
        end if

        $layer := 1 - $first_layer_to_play
        call PlayLayer()
    end if
end on
```


This should work, I think. Didn't test it. It could be problem with polyphony because variables $note, $vel, and some others could change their values between the two waits... Ideally a task function from SublimeKSP should be used, and tcm.wait() as well.


----------



## EvgenyEmelyanov (Aug 1, 2018)

EvilDragon said:


> This should work, I think



I've been always wanting to ask the question. Do you like to give a full solution especially when the task is very simple? Or give an idea how to do it?


----------



## EvilDragon (Aug 1, 2018)

Depends on how simple the solution is. This one is not _that_ simple for newbies to wrap their heads around...


But considering how often claud9 posts here with questions, I wonder if he should've just gotten somebody to script the whole thing for him...


----------



## Claud9 (Aug 1, 2018)

Thanks a lot for your help. Yes, I think this is something too complicated for my scripting knowledge. I have found very easy to apply the delay to a "one Layer" instrument that I thought It was not too complicated to modify that script for a "multi Layers" instrument.. but I was wrong! 
If I had known it was such a complex task I probably would not have even created this post ...
I think this forum is very useful for people like me who have no presumption of becoming a professional programmer and I thank you so much for the help you always give to people like me.
Anyway, I tried both your latest scripts and both are not working. For one I get this error message: "variable "$EVENT_VELOCITY" may only be used in a note or release callback". For the other one, both delay knobs are not doing anything and all Layers are not delayed, but I did not understand if the script should work as It is or have to be integrated with some other code...


----------



## EvgenyEmelyanov (Aug 1, 2018)

Claud9 said:


> For one I get this error message: "variable "$EVENT_VELOCITY" may only be used in a note or release callback".



Try this code.

Also, as ED said, "It could be problem with polyphony because variables $note, $vel, and some others could change their values between the two waits...". So, there is a possibility you should declare these two variables in this way:


```
declare polyphonic $note
  declare polyphonic $vel
```

But I'm not sure. Anyway, try this code:


```
on init
  set_ui_height_px(100)
  make_perfview
  message("")
  declare $i
  declare $note
  declare $vel
  declare $shortest_delay
  declare $start_position_of_fastest_layer
  declare const $NUMBER_OF_GROUPS_IN_ONE_LAYER := 4
  declare ui_knob $delay1(0, 10000, 10)
  declare ui_knob $delay2(0, 10000, 10)
  set_knob_unit($delay1,$KNOB_UNIT_MS)
  set_knob_unit($delay2,$KNOB_UNIT_MS)
  declare $note_id
  declare ui_menu $layer1_menu
  declare ui_menu $layer2_menu
  declare const $LAYER1_FIRST := 0
  declare const $LAYER1_LAST := 3
  declare const $LAYER2_FIRST := 4
  declare const $LAYER2_LAST := 7
  $i := $LAYER1_FIRST
  while ($i<=$LAYER1_LAST)
    add_menu_item($layer1_menu,group_name($i),$i)
    inc($i)
  end while
  $i := $LAYER2_FIRST
  while ($i<=$LAYER2_LAST)
    add_menu_item($layer2_menu,group_name($i),$i)
    inc($i)
  end while
end on

function calculate_shortest_values
  if ($delay1<$delay2)
    $shortest_delay := $delay1
    $start_position_of_fastest_layer := $LAYER1_FIRST
  else
    $shortest_delay := $delay2
    $start_position_of_fastest_layer := $LAYER2_FIRST
  end if
end function

function play_fast_layer
  $note_id := play_note($note,$vel,0,-1)
  set_event_par_arr($note_id,$EVENT_PAR_ALLOW_GROUP,0,$ALL_GROUPS)
  $i := $start_position_of_fastest_layer
  while ($i<=($start_position_of_fastest_layer+$NUMBER_OF_GROUPS_IN_ONE_LAYER))
    set_event_par_arr($note_id,$EVENT_PAR_ALLOW_GROUP,1,$i)
    inc($i)
  end while
end function

function play_slow_layer
  $note_id := play_note($note,$vel,0,-1)
  set_event_par_arr($note_id,$EVENT_PAR_ALLOW_GROUP,0,$ALL_GROUPS)
  $i := abs($LAYER1_FIRST-$LAYER2_FIRST)
  while ($i<=(abs($LAYER1_FIRST-$LAYER2_FIRST)+$NUMBER_OF_GROUPS_IN_ONE_LAYER))
    set_event_par_arr($note_id,$EVENT_PAR_ALLOW_GROUP,1,$i)
    inc($i)
  end while
end function

on ui_control($layer1_menu)
  $i := $LAYER1_FIRST
  while ($i<=$LAYER1_LAST)
    purge_group($i,0)
    inc($i)
  end while
  purge_group($layer1_menu,1)
end on

on ui_control($layer2_menu)
  $i := $LAYER2_FIRST
  while ($i<=$LAYER2_LAST)
    purge_group($i,0)
    inc($i)
  end while
  purge_group($layer2_menu,1)
end on

on note
  ignore_event($EVENT_ID)
  $note := $EVENT_NOTE
  $vel := $EVENT_VELOCITY
  call calculate_shortest_values
  wait(400*$shortest_delay)
  call play_fast_layer
  wait(400*abs($delay1-$delay2))
  call play_slow_layer
end on
```


----------



## Claud9 (Aug 1, 2018)

EvgenyEmelyanov said:


> Try this code.
> 
> Also, as ED said, "It could be problem with polyphony because variables $note, $vel, and some others could change their values between the two waits...". So, there is a possibility you should declare these two variables in this way:
> 
> ...


Thanks again for your help. I tried this new code (with both options "declare polyphonic" and "declare") but it is working properly only in one case.
If can help this is what I found:

with both delays knobs non-active (set to zero ms) only Layer 2 (groups 5 to 8) are played (with no delay), Layer 1 (groups 1 to 4) is not playing at all.
with delay 1 active and delay 2 not active same as the case above (only Layer 2 is played - with no delay)
with both delays active only Layer 2 is played - with the delay
with delay 1 non-active and delay 2 active both Layers are played (Layer 1 with no delay - Layer 2 with the delay)
So according to my test only case 4 is working properly.....


----------



## Claud9 (Aug 2, 2018)

EvilDragon said:


> I'm not sure why you're multiplying the wait time by 400, it should multiply by 1000 (from microseconds to milliseconds).
> 
> In any case the way I would do it would be a bit more elegant perhaps (you don't need a function for fast and slow layers, one function with a pointer is enough, with a little bit of help from some arrays), and covers more cases (if wait time is 0 wait() shouldn't happen at all, and also covers the situation when both delay times are the same). Also your script wouldn't work because you cannot use $EVENT_VELOCITY and $EVENT_NOTE in functions.
> 
> ...


Thanks again for your help, I made further tests with your code. It looks is working only when I activate both delay knobs, but the delay applied it is the same for both Layers even if one, for example Delay1, is set to 200 and Delay2 to 1000: both layers start playing (delayed) at the same time. But if one of the delay knobs are set to zero both layers start to play immediately even if the other delay is activated. But I still don't know if your code was supposed to work as you posted it or I have to add something. 
I never imagined it would be so complicated, for one layer instrument It is so easy!


----------



## EvilDragon (Aug 2, 2018)

I wrote that script without any testing since I was in a hurry. Please use it as an excercise to find what's wrong and fix it.


----------



## Claud9 (Aug 3, 2018)

EvilDragon said:


> I wrote that script without any testing since I was in a hurry. Please use it as an excercise to find what's wrong and fix it.


Yes that is exactly what I'm trying to do and what I have already tried yesterday, but the point is that since according to my test nothing is working properly with this code and both delays aren't affecting in any way both layers, I do not even have a starting point where to focus my attention.


----------



## Claud9 (Aug 13, 2018)

EvgenyEmelyanov said:


> Do you like to give a full solution especially when the task is very simple? Or give an idea how to do it?


I tried several times with all the codes provided in this post, doing some experiment and trying to do some modification but I have not ended up with a solution for making it works for a multiple layers instruments. I'm quitting this post as "not solved". By the way, this task looks "not very simple at all" since all the codes provided here, according to all test I have done, are not working at all.


----------

