Slow Mute Button - Fade Out Effect Volume

MTC84
MTC84 Member Posts: 49 Member
edited February 2 in Scripting Workshop

Hi,

I am trying to make a "Slow Mute" essentially. What I mean is, when I press the Mute Button it slowly sets the volume of the Inverter in slot 0 of Group 0 go to zero dB. The inverse should happen to fade the volume back up too.

The script below works correctly in setting the volume levels of the effect but the fade part seems to be doing nothing at all.

Can someone help please? Thanks a lot!

on ui_control ($Grp_1_Mute)
	if ($Grp_1_Mute = 0)
	
		$Grp_1_Inverter_Volume := get_engine_par($ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN, 0, 0, -1)
		set_engine_par($ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN, 0, 0, 0, -1)
		fade_out($Grp_1_Inverter_Volume, 4000000, 0)
	else
		set_engine_par($ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN, 397500, 0, 0, -1)
		fade_in($Grp_1_Inverter_Volume, 4000000)
	end if
end on

Comments

  • MTC84
    MTC84 Member Posts: 49 Member
    edited February 11

    I understand the fade_out command doesn't work on volume knobs as the code above attempted so I am looking into the on note method of fading out groups but I'm struggling to figure it out.

    Let's say I have 2 Mute buttons that turn on and off the first 2 groups. Using the basic on note - allow/disallow groups only partially gets me there.

    If I hold a chord, then press Mute Button 1, I'd like Group 0 to fade out (Ideally using a Fade Time knob to set the fade out length) whilst Group 1 continues to play as the chord is held.

    As a starting point, here is what I have so far. Obviously missing the key components to make the fade out work.

    Surely there is a simple solution to make this work? Any help is greatly appreciated.

    on init
    	make_perfview
    	set_script_title("MIXER")
    	declare const $UI_HEIGHT := 100
    	set_ui_height_px(100)
    
    
    	set_skin_offset(0)
    	message ("")
    
    	declare $Note_ID
    	declare $Fade_Out
    
    	declare ui_slider $Fade_Out_Knob(1000, 4000000)
    	move_control($Fade_Out_Knob, 1, 2)
    	make_persistent($Fade_Out_Knob)	
    
    
    {MUTE BUTTONS}
    
    	declare ui_switch $Grp_1_Mute
    	move_control($Grp_1_Mute, 3, 1)
    	make_persistent($Grp_1_Mute)
    
    	declare ui_switch $Grp_2_Mute
    	move_control($Grp_2_Mute, 4, 1)
    	make_persistent($Grp_2_Mute)
    end on
    
    
    {ON NOTE - MUTE BUTTONS}
    on note
    	
    	disallow_group($ALL_GROUPS)
    
    {GRP 1}
    	if ($Grp_1_Mute = 1)
    		allow_group(0)
    	else
    		disallow_group(0)     {NEED THIS GROUP TP FADE OUT}
    	end if
    
    {GRP 2}
    	if ($Grp_2_Mute = 1)
    		allow_group(1)
    	else
    		disallow_group(1)     {NEED THIS GROUP TP FADE OUT}
    	end if
    end on
    


  • MTC84
    MTC84 Member Posts: 49 Member
    edited February 18

    Not sure if this forum is alive or dead but I will share what I have found so far. I have everything I need except the ability to fade a particular group attached to that mute button.

    I am building an instrument with an on / off matrix - hence the desire to mute particulat groups with a fade out time. I have the fade out time knob code figured out from using this method:

    https://community.native-instruments.com/discussion/comment/9608#Comment_9608?utm_source=community-search&utm_medium=organic-search&utm_term=fade_out

    The manual says I need to attach an ID but I don't know how to attach the specific group ID or if that is possible here.

    fade_out(<ID NUMBER>), <FADE TIME>, <STOP VOICE>)

    Worth noting is that my Mute buttons are actually acting as ON buttons which is why my code is set to = 0 and not 1.

    If anyone can help with the last part of the puzzle I would be a very happy chap. Thanks.

    on note
    
    	disallow_group($ALL_GROUPS)
    
    {GRP 1}
    	if ($Grp_1_Mute = 1)
    		allow_group(0)
    	else
        	        fade_out(0, $Fade_Out_Knob, 0) {NEED THIS TO FADE OUT GROUP ZERO}
    	end if
    
    {GRP 2}
    	if ($Grp_2_Mute = 1)
    		allow_group(1)
    	else
        		fade_out(1, $Fade_Out_Knob, 0) {NEED THIS TO FADE OUT GROUP 1}
    	end if
    end on
    
  • stephen24
    stephen24 Member Posts: 258 Advisor

    Sorry - hoping that you might get more expert advice than I can provide. I'm sure there's no simple answer.

    Fading out is an active process so you would need to do it before disallowing your group. It has to be done on a note event. You would have to track down the ID of every note event that is still active in that group.

    You could do this with arrays of 128 elements, one for each note, one array for each group. Initialise each one e.g. with -1. Each note-on, find which group(s) are affected with %GROUPS_AFFECTED, and write the event ID in that note's position in the array(s) of the affected group(s). Each note-off, replace with the initialisation value.

    When you press your button, run through the array of that particular group, extracting the event IDs and fading them out individually. You can then disallow the group.

    Have fun!

  • MTC84
    MTC84 Member Posts: 49 Member
    edited February 21

    You Sir are very helpful. Thank you for the input. I will spend some time on this again at some point soon. In its current state, my instrument is functional and playable but it would be nice to have 2 mode options where Mode B behaves as Mutes with Fade outs.

    I have 36 Mutes that control 3 groups per mute. Building 36 arrays is a fairly complex task for a novice like myself who has largely avoided using arrays to date due to a lack of skills!

    I will report back if I do build the solution. If anyone can show me how to code a single Mute button using the info you gave above, I could build the rest from there. Depending on cost, I could be interested in paying for this solution so feel free to get in touch with a quote.

    I'm developing with K6 - I assume K7 doesn't offer a simplified way of fading a single group out? You'd have thought it would be an in demand feature given the simplicity of working with Group ID's.

    Thanks.

  • stephen24
    stephen24 Member Posts: 258 Advisor
    edited February 21

    You can't fade a group which is just a sort of folder.

    Not as complicated as perhaps I made it sound. This is syntactically OK but untested. Should get you going.

    Set up the array and a general purpose variable

    on init
     declare %events [128*3] :=(-1) {array of events 128 notes X 3 groups}
     declare $a
    end on
    

    Update all affected groups in the array with the event IDs as you play

    on note
     $a:=num_elements(%GROUPS_AFFECTED) {how many there are in the list of groups affected}
     while ($a>0)
      %events [$EVENT_NOTE*%GROUPS_AFFECTED[$a]+1] := $EVENT_ID
     dec ($a)
     end while
    end on
    
    {the +1 near the end 4 lines back - also below - may be wrong - it's there
    because I think group IDs start at 0, array element numbers start at 1
    You might need to check this}
    
    on release
     $a:=num_elements(%GROUPS_AFFECTED)
     while ($a>0)
     %events [$EVENT_NOTE*%GROUPS_AFFECTED[$a]+1] := -1
     dec ($a)
     end while
    end on
    

    When you press your button, your callback will need to give you the group ID and with this you can extract the event IDs and do the fading. e.g. for group ID = 0:

    $group_ID := 0 {for instance}
     $a := 127  {this will check every note from 0 to 127 which you may not need to do}
     disallow_group($ALL_GROUPS)
     allow_group($group_ID)
     while ($a >= 0)
     if (%events [$a*$group_ID+1] # -1)
      fade_out(%events [$a*$group_ID+1],5000,1) {see note above about the +1}
     end if
     dec ($a)
     end while
    allow_group($ALL_GROUPS)
    disallow_group($group_ID)
    

    This assumes the group numbers will be 0 - 2, so don't add or delete groups in your instrument or you'll mess up the numbers. You can use find_group if necessary but that could complicate things quite a lot.

    It occurs to me that notes also are 0-127, while the note array numbers are (I think) 1-128, so to be completely accurate maybe each note's position in the array should be EVENT_NOTE + 1. You might have to experiment. I shouldn't bother.

    Good luck let us know how you get on.

  • MTC84
    MTC84 Member Posts: 49 Member

    You really are incredibly helpful! Thank you so much for your time and effort. I will definitely spend some time trying to get this working now you have put the work in. The insrument I am building is going to benefit immensely from this.

    I'll let you know how I get on.

  • MTC84
    MTC84 Member Posts: 49 Member

    Quick question - What is this line of code?

     dec ($a)
    

    Should it be declare and not dec? Thanks.

  • stephen24
    stephen24 Member Posts: 258 Advisor

    No. It's a loop. Familiarise yourself with while... loops.

    I've just put in a couple of extra allow/disallow_groups lines so (if it works) the fade-out in the last section will affect only the notes of the required group.

  • MTC84
    MTC84 Member Posts: 49 Member

    Ah ok. I haven't seen that line of code anywhere else befote but i am familiar with While loops. More study time required for me! I think i have only ever seen loop counters written like while ($a >= 0) or $a := 127 etc. The "dec" is new to me. What does it stand for?

    Thanks for adding the fade out lines. The code seems pretty straight forward to understand after a few read throughs. I need to put some real time into this soon. It could be weeks before i get to it but i will definitely have a crack at it soon enough.

    Thanks for everything.

  • MTC84
    MTC84 Member Posts: 49 Member
    edited February 22

    dec(x)

    Decrement an expression by 1 (x – 1) 

    Found an example in the manual so that clears that up.

    I can't thank you enough. I will be in touch in future when I am in a position to share a copy of the library I am building. It's only decent of me to reward your efforts!

    I posted another message before this one but it is awaiting approval so when it gets approved this will make more sense!

Back To Top