1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Trigger looped sample by switch script?

Discussion in 'Scripting Workshop' started by etothedizzy, Feb 12, 2014.

  1. Big Bob

    Big Bob Forum Member

    Messages:
    606
    To trigger a note from the ICB, you can also use the pgs post-init process.

    Essentially what you do is change a pgs variable at the end of the ICB. In the pgs callback you test for that variable being set and if it is you reset it (never to be set again). But inside the if clause you also issue your play_note. This trigger will only occur once after you load or 'apply' the script. Thus this sets up a post-initialization phase that runs immediately after the ICB exits. The advantages of post initialization over that of ICB initialization is that many operations that are not allowed in the ICB (such as play_note or user function calls) are allowed in the pgs callback.

    Rejoice,

    Bob
     
  2. etothedizzy

    etothedizzy New Member

    Messages:
    23
    I'll get on it. Thanks.

    I'll spend a day or two trying to make sense of everything you just said. I'm JUST getting into KSP and haven't fully grasped the fundamentals yet.
     
  3. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Sorry I didn't know you weren't familiar with pgs stuff. Here's an example for you.

    on init
    ``declare $one_time
    ``pgs_create_key(PINIT,1)
    ``pgs_set_key_val(PINIT,0,1)``{ change value to trigger pgs callback }
    end on

    on pgs_changed
    ``if ($one_time=0)
    ````$one_time := 1```````````````{ don't do this again }
    ````play_note(60,127,0,1000000)``{ play middle C for one second }
    ``end if
    end
    on



    Put the above script into an instrument and everytime you load the instrument (or hit apply for the script), it will play middle C for one second.

    Rejoice,

    Bob
     
  4. stefangs

    stefangs NI Product Owner

    Messages:
    97
    I'm digging out this thread, because it deals with the same problem I'm having right now. I haven't gotten as far as using Kontakt as a plugin, for now it's the standalone app. To makes things more complicated, I have a release sample for the continuous noise.

    The code which I copied from earlier on in this thread:

    on ui_control ($motor_switch)
    if ($motor_switch = 1)
    $motorid := play_note (24, 127, 0, -1)
    else
    note_off ($motorid)
    end if
    end on​

    didn't help. Every time I click the button in the UI, both the attack and release samples play. While the release sample fades out, the looped samples start building up with an extra voice every time I click, no matter if the button changes from on to off or vice versa. It also makes no difference if I set the release sample group to 'release trigger' status in group start options. It also tried to just kill these voices, but disallow group is not allowed inside on ui_control.

    Any help appreciated, thanks!