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. etothedizzy

    etothedizzy New Member

    Messages:
    23
    Hi all, I'm new to the forum. I've been experimenting with KSP for a few weeks now, but have come to a dead end. I'm attempting to get a looped sample of constant "noise floor" to be triggered on and off by a switch on the GUI. I do not want this noise loop sample associated with any keys. I suppose the switch could act as a basic Mute, as the sample could loop endlessly in the background if necessary for this to work. But the "loop" would still need to be triggered somehow. Is this possible? Thanks all in advance!
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes, it's possible. Let's say you map this sample to MIDI note 0, so you can avoid accidentally playing it from your keyboard. Then you can use this script to play that note:

    Code:
    on init
        declare $ID
        declare ui_switch $Noise
    end on
    
    on ui_control($Noise)
        if ($Noise = 1)
            $ID := play_note(0,127,0,-1)
        else
            note_off($ID)
        end if
    end on
     
  3. etothedizzy

    etothedizzy New Member

    Messages:
    23
    Thank you for the quick reply, sorry I'm late! So I'm running into the same problem I ran into the last time I tried this myself. Allot of DAWs send the "all notes off" message when you press STOP on the transport (and apparently when you press PLAY as well). Is there a way to keep the noise loop playing even when an "all notes off" message is sent to Kontakt? Is it possible for only MIDI note 0 to ignore all messages besides the ones defined by the switch? I've been tinkering with it for hours...I cant get Kontakt to keep playing the loop once that "notes off" message is sent. I hope there is a decent work-around that doesn't "feel" like a work-around.
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You can try by going to Instrument Options>Controller and disabling "Accept all notes off / all sounds off".
     
  5. etothedizzy

    etothedizzy New Member

    Messages:
    23
    Tried that last night. It didn't work. Odd, huh?
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah, odd. Well then, not much you could do, I guess.
     
  7. etothedizzy

    etothedizzy New Member

    Messages:
    23
    I cant figure out why this isn't working, but there must be a solution...right? MIDI Monitor still reads "Controller: 123 Value: 0" when I hit the stop button even though ""Accept all notes off / all sounds off" is disabled. When I use this script...
    Code:
    on controller
      if ($CC_NUM = 123)
        ignore_controller
      end if
    end on
    ...Midi Monitor reads that it is not receiving that message, but somehow the note off command is still killing my note. Am I missing something? Is it possible to have the noise sample triggered (again) whenever it receives a note off message and the state of the switch is On? I don't think that a work-around should be necessary, but I'm really at a loss.
     
  8. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Seems like it's a bug in Kontakt... in this case I'm not sure what you could do, except filtering all notes/sounds off externally before Kontakt, in your DAW.
     
  9. etothedizzy

    etothedizzy New Member

    Messages:
    23
    So is automatically sending a note on message to note 0 right after the note off message is received not possible? Thanks again for your help and quick reply by the way.
     
  10. Big Bob

    Big Bob Forum Member

    Messages:
    606
    The instrument options checkbox for 'all notes off' seems to work OK for me. I tried it with both K4 and K5.

    Perhaps there is a misunderstanding of what it should do? Turning off the checkbox does not suppress the CC123 from daisy-chaining its way through the script slots, it merely causes NI's system script to not react to it.

    Try this, create a simple MIDI track in your DAW consisting of one long held note and a cc123 somewhere in the middle of that note. Load some simple instrument into your Kontakt plugin and then play the MIDI track. With the inst options cc123 box checked, when you play the MIDI track the note should sound only until the cc123 is reached. Now, uncheck the box and repeat. The long MIDI note should now play through without being silenced at the CC123 point.

    So, when you say
    in what way doesn't it work?

    Rejoice,

    Bob
     
  11. etothedizzy

    etothedizzy New Member

    Messages:
    23
    Thanks for the reply. I have a looped sample playing via a switch that is triggering MIDI note 0. Even though the "Accept all notes off / all sounds off" check box is UNchecked, the note is still turned off once I press STOP or PLAY on the transport. I cant make sense of it, and I do fancy myself a pretty clever troubleshooter. I've tried a combination of this with and without the "ignore_controller" script above, I've tried saving and restarting Kontakt, I've tried desperately tinkering with the volume envelope just in case, I've tried everything I can think of so far. BTW, I'm using Kontakt as a plugin, don't know if that variable matters here. Can you try to recreate the problem using a looped sample assigned to MIDI note 0 triggered by a switch and see if you get the same results as me?
     
  12. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    OK I've just tried this in Reaper:

    1. Load Kontakt, put a sample in the mapping editor and load the above script.
    2. Disable receiving all notes/sounds off in Instrument Properties
    3. Press Play in Reaper's transport
    4. Hit the scripted button - the note plays
    5. Press Stop in Reaper's transport - the note continues playing.
     
  13. etothedizzy

    etothedizzy New Member

    Messages:
    23
    I'm using FL Studio to test the script, and there must be something unique about the way FL's transport controls function because the "Notes Off" message is still getting through. I've started over multiple times. Thanks allot for your efforts, I'm still hopeful.
     
  14. etothedizzy

    etothedizzy New Member

    Messages:
    23
    Doing some research, I found this:
    I don't know how helpful that is...
     
  15. Big Bob

    Big Bob Forum Member

    Messages:
    606
    I get the same results as Mario reported above. I used a looped organ sound and it continues after stopping Reaper.

    It also continues even if I check the box but put a CC123 blocking filter in the first script slot. ie
    Code:
    on controller
    
    if CC_NUM = 123
    ignore_controller
    end if
    end on
    Did you mean on start or on stop? It seems like your problem occurs when you stop the DAW so why post the MIDI stream for the start up?

    Could there be something special about how you are looping the noise sample? Have you tried an ordinary loop sustain sample to see if it behaves any differently?

    Rejoice,

    Bob

    BTW
    How elaborate OF a script are you testing with? Do you have more than one script slot being used? Could it be that somewhere there is a scripted 'all notes off'? That would be something like a note_off(id) command with a negative id (like -1 for ALL_EVENTS)?
     
    Last edited: Feb 19, 2014
  16. etothedizzy

    etothedizzy New Member

    Messages:
    23
    The same problem occurs weather I press START or STOP on the transport. My looped sample stops every time. I found that MIDI stream on another forum concerning something unrelated.

    My sample is an ordinary .WAV sample with a loop point set in the meta data. Nothing special. Kontakt loops it just fine by default.

    I'm starting my script completely empty, trying to problem solve this before I introduce more scripting to avoid complicating things.

    I feel like FL must be sending redundant note off messages in a way that is not completely taken care of by the above methods.
     
  17. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Here's an idea: why not use standalone Kontakt (outside FLS) to trigger the sample you'd need to loop continuously?
     
  18. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Here's a few other random thoughts.

    1. If you move the looped sound to something other than note 0 does it still get killed when you stop your DAW?
    2. Why not use something like MIDI OX to actually catch the MIDI stream from your DAW when you hit stop. Maybe there will be some obvious series of events that would explain your observations. For example, see item 3 next.
    3. Could your DAW actually send MIDI note off for all 128 notes? If it did, that of course would explain it, no?
    4. Are you sure the looped sound actually terminates? Could it still be playing but just essentially muted? Maybe with a CC7 = 0?

    I wish you the best with running this into the ground. When you finally solve it, please post your findings. I'll keep an eye on this thread and If I think of anything else along the way, I'll drop a post (ie if you haven't yet nailed it :) )

    Rejoice,

    Bob
     
  19. etothedizzy

    etothedizzy New Member

    Messages:
    23
    I could think of a few work-arounds, but I'd really like to actually solve this problem once and for all.

    Thanks Bob, you ideas are great! I will put them all to work this evening and post my results.
     
  20. etothedizzy

    etothedizzy New Member

    Messages:
    23
    I took a week off from this to get a fresh start. I've been at it all day and I think I'm getting closer...

    So this is exactly what FL Studio sends when you press the stop button once:
    Code:
    TIMESTAMP IN PORT STATUS DATA1 DATA2 CHAN NOTE EVENT            
    000065D6  1  --    B0    7B    00      1  ---  CC: All Notes Off  
    000065D6  1  --    B1    7B    00      2  ---  CC: All Notes Off  
    000065D6  1  --    B2    7B    00      3  ---  CC: All Notes Off  
    000065D6  1  --    B3    7B    00      4  ---  CC: All Notes Off  
    000065D6  1  --    B4    7B    00      5  ---  CC: All Notes Off  
    000065D6  1  --    B5    7B    00      6  ---  CC: All Notes Off  
    000065D6  1  --    B6    7B    00      7  ---  CC: All Notes Off  
    000065D6  1  --    B7    7B    00      8  ---  CC: All Notes Off  
    000065D6  1  --    B8    7B    00      9  ---  CC: All Notes Off  
    000065D6  1  --    B9    7B    00     10  ---  CC: All Notes Off  
    000065D7  1  --    BA    7B    00     11  ---  CC: All Notes Off  
    000065D7  1  --    BB    7B    00     12  ---  CC: All Notes Off  
    000065D7  1  --    BC    7B    00     13  ---  CC: All Notes Off  
    000065D7  1  --    BD    7B    00     14  ---  CC: All Notes Off  
    000065D7  1  --    BE    7B    00     15  ---  CC: All Notes Off  
    000065D7  1  --    BF    7B    00     16  ---  CC: All Notes Off  
    What would I script to have my instrument ignore "CC: All Notes Off" from specifically channels 1-16? Does "7B" under DATA1 have any significance? What about the STATUS' of B0, B1, B2, BA, BB, etc? I've tried and failed and tried and failed again. I must be doing something wrong.