About labels -> get value



  • Hey :) I did a long break :D
    Well I have an interrogation.
    I have a knob (Midi channel selecter), and next to, a label displaying the value selected by that knob.
    But... the problem is that I don't know how about linking the value as the text.
    I did this but of course it doesn't work:

    // [JSON MIDIDisplay]
    Content.setPropertiesFromJSON("MIDIDisplay", {
      "text": ScriptLabel.getValue(MidiChan)   override
      "width": 99,
      "height": 34,
      "fontName": "Digital-7 Mono",
      "fontSize": 21,
      "multiline": false
    });
    // [/JSON MIDIDisplay]
    

    Well I don't understand that 'override' and even without it it doesnt' work :)

    Perhaps should I do an OnControl function?
    Thanks,
    D.B.


  • administrators

    That override is a glitch from the automatic API creation (I have to remove this). However, getValue() has no arguments.

    But most importantly, the value for ScriptLabel - if that's your knob then kudos to your variable naming :) - can't be accessed during the onInit callback. For all UI controls that don't have the saveInPreset property set to false, the values will be handled in this order at compiling / recompiling:

    1. Save the value (if recompiling)
    2. Compile the script (run the onInit callback and parse all other callback). Because the old controls are deleted and replaced with new ones, the new controls don't have access to the previous values during this stage.
    3. Restore the values from step 1 or the ones saved in the preset (if not recompiling). Also the onControl callback will be executed for each control, which is the place to handle the value (you need to implement this here anyway for value changes caused by automation or human interaction).

    TLDR: Use the onControl callback as you've guessed and call MidiDisplay.set("text", ScriptLabel.getValue());. Also set saveInPreset for the Label to false (since it does not contain a real value but just displays the value from another control).



  • Content.makeFrontInterface(300, 200);
    
    const var MIDIDisplay = Content.addKnob("MIDIDisplay", 0, 0);
    // [JSON Knob]
    Content.setPropertiesFromJSON("MIDIDisplay", {
      "text": "MidiChannel",
      "min": 1,
      "max": 16,
      "mode": "Discrete",
      "stepSize": 1,
      "middlePosition": 8
    });
    // [/JSON Knob]
    
    inline function onMIDIDisplayControl(component, value)
    {
    	Label.set("text", MIDIDisplay.getValue());
    };
    MIDIDisplay.setControlCallback(onMIDIDisplayControl);
    
    
    const var Label = Content.addLabel("Label", 30, 50);
    // [JSON Label]
    Content.setPropertiesFromJSON("Label", {
      "editable": false,
      "saveInPreset": false
    });
    // [/JSON Label]
    


  • Nice!
    And one more question:
    If I use a personnal font stored in my computer, will it saves the font while exporting?
    Should I put the font file somewhere in the Project Folder?



  • The font goes in the images folder. You need to use the loadFont command in your front interface script to include it with the instrument. Make sure you own the license to use the font or that it is royalty free or similar :)



Looks like your connection to About labels -> get value was lost, please wait while we try to reconnect.