# Enable or disable groups outside of on note



## tonewill (Aug 29, 2010)

Hello,
Is there any way to enable or disable groups outside of the *on note* callback?

I'm working on a script that generates notes outside of the *on note* callback but cannot use allow_group or disallow_group because of this. Every group plays which is no good for what I want.

I've tried using SET_CONDITION(NO_SYS_SCRIPT_GROUP_START) in *on init* but this did not do the trick so I assume that disabling the system script passes everything to all groups.

Any ideas on a way round this welcome.
Thanks a lot.


----------



## snapshot (Aug 29, 2010)

Hi !

im not sure if you can . But maybe you can do some statements in ON_NOTE that will deal with your group states ? 

cheers
k


----------



## tonewill (Aug 29, 2010)

Hello k,
This is what I have in on note:

```
on note
  disallow_group(ALL_GROUPS)
end on
```
but it has no effect, whether SET_CONDITION(NO_SYS_SCRIPT_GROUP_START) is set or not. By that I mean it has no effect on any artificially produced notes that are not produced within *on note*.
Thanks though.


----------



## snapshot (Aug 29, 2010)

perhaps you can assign your artificial notes within play_note in ON_NOTE callback

like


```
on note
  ignore_event($EVENT_ID)
  disallow_group(ALL_GROUPS)
if ($button = 0)
allow_group(0)
disallow_group(1)
play_note({here your artificial note function},$EVENT_VELOCITY,0,-1)
else
disallow_group(0)
allow_group(1)
play_note({here your artificial note function},$EVENT_VELOCITY,0,-1)
disallow_group(1)
end if
end on
```


----------



## tonewill (Aug 29, 2010)

Thanks k,
I will have to try and rearrange my code to see if I can move the sequence playback to on note, but it will be complicated so I wanted to avoid that if possible. Meanwhile if you or anyone else can see a way round this please let me know.
Thanks for your help.


----------



## snapshot (Aug 29, 2010)

I learned to use "call" functions ,that you can call everywhere you want

so you do your artificial engine code within "call" function and whenever you wish recall it .

you do callback like

*Function {you name it here}

{here your note engine code ,with play_note or not}

end function*


and then on ON_NOTE you just call for it for dedicated group with allow and disallow.

on note

*ignore_event($EVENT_ID)

disallow_group(ALL_GROUPS)
allow_group(0)
call {your function name here} -

if you used play note within your function then just calling is ok ,if not you can replace $EVENT_NOTE in play_note with you function name i guess


disallow_group(0)

end on*


----------



## snapshot (Aug 29, 2010)

its also good to assign $variables that influence on your $EVENT_NOTE inside play_note on ON NOTE callback .

so you equal ($variable := )to your maths that will do its job for $EVENT_NOTE

it should not be so hard . otherwise you can post your code here . so me or some geeks can tells you more about it .


cheers
k


----------



## tonewill (Aug 29, 2010)

Thanks k,
I should have mentioned that I'm using version 3.5, I assume *call* is something new in version 4.

At the moment I'm starting a virtual new thread using the PGS commands as suggested here. The code loops until the PGS variable changes. not sure if this was absolutely necessary but I thought I'd try it. Apart from the group problem it works well.

My script is pretty long and involved mixed with code not connected with the problem so I'd have to make a small, basic script that just shows the part I'm trying to do. Just trying to re-arrange things at the moment to see if I can do this in on note but I don't think I can because a loop is needed and I want to be able to play 'live' notes along with the loop.

It can sound complicated when explaining, I know.

Thanks again.


----------



## tonewill (Aug 29, 2010)

I've just been experimenting,
If I use two scripts, any notes created artificially in the first will appear in *on note* of the second which would allow me to select groups there. I can add an event parameter to the notes so that I can distinguish them from 'real' played notes. If only I can find a way to disable groups in the first script to stop the notes sounding there that would do the job I think.


----------



## snapshot (Aug 29, 2010)

im SURE you can do it all within one script ! this what you did now you could do in one script already . then experiment for disabling .

for play_note

you need to ignore_event($EVENT_ID) at the beginning of ON NOTE i guess .
then 
disallow all groups ,
allow group you need , right after your functions disallow if you use more then one group and you dont want to affect others while enabling them after first group execution .

or

slim your code and drop necessary part here . 

i hope i can help
K


----------



## tonewill (Aug 29, 2010)

You're right, an example is needed and much easier for you or others to see what I'm trying to do. Here's a bare-bones script that works (needs KScript editor):

```
on init
  message("")
  make_perfview
  
  {VARIABLES}
  declare i
  declare patternBuffer[512]
  declare arraySize
  declare sequence[16] := (36,-1,-1,-1,38,-1,36,-1,36,-1,-1,-1,38,-1,36,-1)
  
  {UI}
  declare ui_button patternStart_button
  set_text(patternStart_button,"Start/Stop")
  move_control(patternStart_button,1,1)
end on

on ui_control(patternStart_button)
  if(patternStart_button = 1)
    {copy selected pattern to buffer and play pattern}
    i := 0
    while(i < num_elements(sequence))
      patternBuffer[i] := sequence[i]
      inc(i)
    end while
    arraySize := num_elements(sequence)
 
    {loop through each pulse}
    i := 0 {initialise to first pulse}
    while(patternStart_button = 1) {while start/stop button is active}
      if(patternBuffer[i] # -1) {if a note is assigned to this pulse}
        play_note(patternBuffer[i],100,0,0) {drum sounds, so play until end}
      end if
      inc(i) {move to next pulse}
      if(i = 16) {reached the end of the bar}
        i := 0 {reset to beginning of bar}
      end if
      wait(DURATION_SIXTEENTH)
    end while
  end if
end on
```
If I could either disable the groups for these generated notes or move it to on note as you suggest, that would be the answer I think. I'm using version 3.5 though remember.

Thanks for any suggestions.


----------



## snapshot (Aug 29, 2010)

ive got not really much time to make it nicer , 

for now ,pressing any note will trigger a sequence instead of button, while you change the group you need to hit key one more time .


```
on init
  message("")
  make_perfview
  declare $i
  declare %patternBuffer[512] 
  declare $arraySize
  declare %sequence[16]  := (36, -1, -1, -1, 38, -1, 36, -1, 36, -1, -1, -1, 38, -1, 36, -1)
  declare ui_button $patternStart_button
  set_text($patternStart_button,"Start/Stop")
  move_control($patternStart_button,1,1)
  declare ui_value_edit $group (0,5,1) {6 groups ?}
end on

on note 
    ignore_event($EVENT_ID)
    disallow_group($ALL_GROUPS)
    
    allow_group($group)
  if ($NOTE_HELD = 1)
     
    $i := 0
    while ($i<num_elements(%sequence))
      %patternBuffer[$i] := %sequence[$i]
      inc($i)
    end while
    $arraySize := num_elements(%sequence)
    $i := 0
    $patternStart_button := 1
    while ($NOTE_HELD = 1)
      if (%patternBuffer[$i] # -1)
        play_note(%patternBuffer[$i],100,0,0)
      end if
      inc($i)
      if ($i=16)
        $i := 0
      end if
      wait($DURATION_SIXTEENTH)
    end while
    end if

    if ($NOTE_HELD = 0)
        
        $patternStart_button := 0   
    end if

  disallow_group($group)
 
end on
```


----------



## kotori (Aug 29, 2010)

You could try to use the old release callback trick: in your UI callback you play a very short note marked with event parameter that contains information about what the note signifies (this note is merely used to tell another part of the script of the control click event). Then in the release callback you intercept this note and use allow_group/disallow_group along with the play_note function there.


----------



## tonewill (Aug 29, 2010)

Snapshot,
Thank you, your idea works of course, but not in the way I want it to unfortunately. I appreciate you taking the time to help me with this.

kotori,
I tried this quickly and so far, it would seem to be the answer. Thanks a lot for the trick, I wouldn't have been able to come up with that one.


----------



## snapshot (Aug 30, 2010)

no problem, its all good ! have Fun 

cheers 
K


----------

