Switching sample maps with radio buttons.



  • I need to switch sample maps in several samplers with radio buttons.

    So one button would set sampler1 to sample map 1 and sampler2 to sample map 2 etc .

    Havent made any samplers before , anyone have a start snippet for me to look at ?

    😛



  • @lalalandsynth This should point you in the right direction.



  • This post is deleted!


  • @d-healey So I have a combobox where I can select samplemaps.
    So I have the array for the sample maps , unsure how I can select a sample index with a radio button though , anyone that can help me a bit with this ?



  • @lalalandsynth

    Hey there, I played around with it a while and found a solution. It´s not @d-healey style, like looping through everything all efficient n stuff ☺ But it gets it done.

    Note: I just made the basic Samplemap loading using Sampler.loadSamplerMap(), but did not make any actual radio buttons in the design, but I gathered you got that covered from Healey´s video.

    // onInit
    
    Content.makeFrontInterface(633, 400);
    
    // store references to the samplers.
    const var Sampler1 = Synth.getSampler("Sampler1");
    const var Sampler2 = Synth.getSampler("Sampler2");
    const var Sampler3 = Synth.getSampler("Sampler3");
    
    // UI references
    const var ComboBox1 = Content.getComponent("ComboBox1");
    const var boxVals = ComboBox1.getAllProperties(); // just get all properties of the combobox element, for later reference.
    
    // just printing all values of the combobox´s available properties:
    for (var i = 0; i < boxVals.length; i++) {
        Console.print("ComboBox1:s element id " + i + ": " + boxVals[i]);
    }
    
    
    // get state of combobox, on init:
    const var cboxState = ComboBox1.getValue();
    Console.print("Current choice made in combobox: " + cboxState);
    
    
    
    // onControl ui-control:
    
    function onControl(number, value) // this needs to be copied into the onControl callback.
    {
    	
        if (number == ComboBox1)
        {
            Console.print("ComboBox1: " + value);
            if (value == 1)
            {
                // loading Samplemap nr 1 for all three.
                Sampler1.loadSampleMap("Samplemap-1-1"); 
                Sampler2.loadSampleMap("Samplemap-1-2");
                Sampler3.loadSampleMap("Samplemap-1-3");
            }
            if (value == 2)
            {
                Sampler1.loadSampleMap("Samplemap-2-1");
                Sampler2.loadSampleMap("Samplemap-2-2");
                Sampler3.loadSampleMap("Samplemap-2-3");
            }
            if (value == 3)
            {
                Sampler1.loadSampleMap("Samplemap-3-1");
                Sampler2.loadSampleMap("Samplemap-3-2");
                Sampler3.loadSampleMap("Samplemap-3-3");
            }
        }
    }
    

    Here´s an upload of the full project from my hise testing, so you can load it directly, with a single sample in the all the sample maps.

    radio-buttons-control-samplermaps.zip

    Made using Scriptnode branch (2020-08 ish), if that´s important. On macos.



  • @andioak said in Switching sample maps with radio buttons.:

    // loading Samplemap nr 1 for all three.
    Sampler1.loadSampleMap("Samplemap-1-1");
    Sampler2.loadSampleMap("Samplemap-1-2");
    Sampler3.loadSampleMap("Samplemap-1-3");

    That is helpful thanks.

    I am still not sure how to approach this ...how can I assign an index value to the buttons in the radio buttons , I guess that would be the way ?



  • Are you planning to let the user change sample maps by clicking buttons?



  • @d-healey yes , that is the plan .



  • @d-healey These buttons will be switching sample maps.
    Sample maps.png



  • Ok, but if they do it while the instrument is being played they will get some surprises 🙂



  • @d-healey Isnt it just silence while it loads ? I tried it and cannot hear any glitches or nasty stuff ?
    Its the same as changing a sample map via a combobox or a preset.
    Not great for live playing but kind of acceptable in a daw ...I guess.
    To be honest, not sure if that is acceptable?

    To do it without interruptions I would need 26 samplers.
    Only 9 running at a time though ,with the other disabled when not in use.. wonder if that is a better way to do it ? Also wonder if they take any cpu if disabled ?
    Just concerned with the cpu, is it advisable to run have 26 samplers in a project ?

    Any recommendations ?

    EDIT: I could maybe cheat and map 2 sample maps into one sampler and use transpose to go from on to the other ...if that makes sense ?
    That would reduce the amount of samplers needed , although that might give me silence as well....

    EDIT2: Could I somehow cheat by loading each sample group into different velocity layers and then switch the velocity around ? No velocity is needed for the samples themselves. Probably not...:P



  • @d-healey @lalalandsynth

    Okay I got a little upgrade here with 6 linked buttons. It does what radio-buttons do. One turned on turns the others off. Also, no button can ever be turned off, if it is trying to set itself to 0, we simply switch it on again.

    radio-buttons-with-6-buttons.gif

    onInit callback:

    • const var all elements
    • set array with elements var names
    • sync array with states in 0s and 1s in arr_buttons_sw.
    const var Button1 = Content.getComponent("Button1");
    const var Button2 = Content.getComponent("Button2");
    const var Button3 = Content.getComponent("Button3");
    const var Button4 = Content.getComponent("Button4");
    const var Button5 = Content.getComponent("Button5");
    const var Button6 = Content.getComponent("Button6");
    const var arr_buttons = [Button1, Button2, Button3, Button4, Button5, Button6];
    const var arr_buttons_sw = [
    	
    	[1, 0, 0, 0, 0, 0], // for button 1 [0], we set all else to 0.
    	[0, 1, 0, 0, 0, 0], 
    	[0, 0, 1, 0, 0, 0], 
    	[0, 0, 0, 1, 0, 0], 
    	[0, 0, 0, 0, 1, 0], 
    	[0, 0, 0, 0, 0, 1] 
    ];
    

    Then the onControl callback:

    for (var i = 0; i < arr_buttons.length; i++) { // loop through the 6.
    
    	// for any button matching one in array list.
    	if (number == arr_buttons[i]) { 
    
    		if (value == 1) {
    
    			var btn_nr = arr_buttons.indexOf(number);
    
    			for (var j = 0; j < arr_buttons.length; j++) { 
    
    				// now setting the elements all in one go to their pre-set values in the arr_buttons_sw array number presets.
    				arr_buttons[j].setValue(arr_buttons_sw[btn_nr][j]);
    
    			}
    
    		} else {
    
    			// we dont want the value to be able to be set to 0, cause that´s not radio-style.
    			number.setValue(1); // just set it back to one.
    
    		}
    		
    	}
    
    }
    

    Here´s the new project in all its might:

    radio-buttons-control-samplermaps-v2.zip



  • @andioak I think you can tidy up and just use this to get the array.

    const var Buttons = [Content.getComponent("0Btn"),
                       Content.getComponent("accBtn"),
                       Content.getComponent("soloBtn"),
                        Content.getComponent("orchBtn"),
                       Content.getComponent("organBtn")];
    


  • @lalalandsynth said in Switching sample maps with radio buttons.:

    EDIT: I could maybe cheat and map 2 sample maps into one sampler and use transpose to go from on to the other ...if that makes sense ?
    That would reduce the amount of samplers needed , although that might give me silence as well....
    EDIT2: Could I somehow cheat by loading each sample group into different velocity layers and then switch the velocity around ? No velocity is needed for the samples themselves. Probably not...:P

    You have 128 keys, 128 velocities, and a whole lot of groups in each sampler. You can almost certainly map everything in a single sampler. I do this all the time unless I need different modulators/effects for different samples.



  • @lalalandsynth said in Switching sample maps with radio buttons.:

    @andioak I think you can tidy up and just use this to get the array.

    const var Buttons = [Content.getComponent("0Btn"),
                       Content.getComponent("accBtn"),
                       Content.getComponent("soloBtn"),
                        Content.getComponent("orchBtn"),
                       Content.getComponent("organBtn")];
    

    If you rename your buttons you can do it in two lines.

    for (i = 0; i < num_buttons; i++)
        buttons[i] = Content.getComponent("button"+i);
    


  • @d-healey I dont need any different fx or modulators , so this is perfect , will have a look at this , thanks !
    Btw , is it then possible to switch without any interruptions ?



  • @lalalandsynth said in Switching sample maps with radio buttons.:

    Btw , is it then possible to switch without any interruptions ?

    Yep



  • @d-healey Awesome , redesign time !
    Finally understood the Defer script thing as well .

    Thanks mate !



  • ok, So I have set the instrument up with velocity switching but a bit unsure of how to implement the buttons since I am not using the keyswitching , should I set up 4 buttons in the Midi processor On Init and then link to those buttons for the main interface or do I do the whole thing from the main interface script ?

    not sure if this is the right approach ?
    switching.gif



  • @lalalandsynth

    Your interface script is non-realtime, so it can't change the velocity of incoming notes. So your first idea is right, you need to add 4 buttons (or a slider pack) to your velocity changing script, and then link the interface controls to them.


Log in to reply
 

18
Online

807
Users

3.0k
Topics

25.5k
Posts