Reducing LAF scripting redundancy
-
Not sure why this is causing me such a headache, but I have a LAF for my knobs with display labels. In most cases I want the display labels to just show the values, but in some cases I want it to make exceptions to display a specific list (LPF, HPF, BPF, or for TempoSync 1/1, 1/2, etc.)
I have figured out how to display the labels I want fairly easily, for example:
// Labels for Filter Mode const filterModeLabels = ["Lowpass", "Highpass", "Bandpass"]; //... var displayLabel = filterModeLabels[parseInt(Widget.value)]; Style.drawAlignedText(displayLabel, [Area[STARTX] + LabelOffset, Area[HEIGHT]-Area [HEIGHT] +6, Area [HEIGHT]+LabelOffset, Area[HEIGHT]], "left");
I cannot figure out how to make an exception in my LAF code for each specific use case. So far I have just been copying my entire LAF and creating a new one for each use case (creating a lot of redundancy). Wondering if someone can help me out. Here is a snippet:
HiseSnippet 1954.3oc6Ys0aiaiEVJSzzZ2KnEn8cB+Pg7DGGKmjoYf2sMwI1SLhSbZr6zY2.iALRT1DQlzPhdl31NE8mx9KXedeb+G09On8PcW9RRp6UTLxHFlmqe7vCO7Dpyc4lDOOtqhZtdSGSTTeWstSYhgGNDSYJsNBnqcBieUarsR8oiwddDKEU0G7TIa0bqq3+7iedcrClYRRHon7LN0jzlNhJRnd99mPcbZhsH8niRI8N62xjyNj6vm.P4AZUTFiMuFOfbFVJ1ZZJpOrgEUvc6JvBhGHSct0ztC4uhEH+yndzqbHxAFJcACEPV4vgTGqyilldJJpqedxj9AAS5OR6TpEMldxj+C7YfRzHcLPcsaCRF+BfjZJHsd.j9PstltzwhDNR77NZsXBhqMFB0ogRfrJq8u+XsC4fDLQ4Q3qIMcgAwZn+3JUJgfuJVKedHb6IPc6cvE8dN5ehpTKMk+EPwHhxW05ndGCDpFQ33Fsd5w8.JaGamC6bV2dun6De+7TWrEEfPO9XokuoYyJ9O0tMgqyEB9nP42Yucpua0rxWm6ZQbCRQBE6IaCedRVwNh5ggftUKlE0DCqNozv1dW7tWsq4h0HDPY7fwSLvFVKV95S.Dy5QtQjET6.evyFYFgcbBTnIrjzk90DYHFlh42Z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j5AY37HzlPBjwRQ1RUqR4pOY2EqlO2JaWZoZVYWHwdaYAL3yqC6BKntpGxl6hB5IBIaJJrSI63tjBEC5inPa9qjM6CGuT3XnGkneWGZNx+28CaWJoEqeMMKg98rYoeS5U5u1sJg9itWon5gVTuwN3o99D71roRWNF65Qf+eP8zmEUres+V2r0xlboCV+o06yaZ84Ms972pVe9qeyNuoWlek8xDzGi+MQIm0yc2MyduMf392B0RENoqkh0h5HAwYmwEjNLc+6tIOr.NKKa6ExSVF0k63PbWHa4EO6daJpylL5JhaofNgiETQc8rW26CueW2qYPU8TBxYsXTQmwjvwMgixkWiq72ye4vJgGKnnntVHBAQE9WR76GdIwA8yoPAi7V9WWughO3Cuf8u+i9u+vmqbuUtZFkCd9xVGgEX4UUGBG.hiItBpLRndD4kTSRvEWmS6Hh20B9Xe7FdOjJpu8ch3aRbn09SiG78ew9Q0n.ZO7mfGI4jV2jTU9te5+Io9JY0VEUM02WUQYneGpxQ+GE+3XLXxemQfDv7+uJEX1e79wtX84bwhwzhPObTUpv69Pe5ik2ILXHM3jWEk4ee.efFr+.55Qj80SHeOLgLfj3LuS.489y7nhooeOM+BdmEUt02Yw8Ehen14Tg4vEiw0V.Fk44+Nfwv2zy6o0v1FJ6l.v00Z97U805bGtGJyKnrAmhEtTX8V6rIi5BIBlDv6LFzPtLwYMYpYv3JxwxHPW3XI+Ax7kPlFxwpgLMhXBYRlt7WXFr2V9tjdaeJ.lX9u5rbZmJGiLleS8HpE8EllYM0bJVcUUb6UUwcVUE2cUU7wqphe5pp3d2shx273ASD7QAaaTTN87F9EgUUav7eCTxrUkeF7bR6sA
-
@HISEnberg said in Reducing LAF scripting redundancy:
You are looking for a way to differentiate between different types of Knob, so :
one way is to use the text attribute...
ZeroToOne:Knob1
FilterType:Knob2so in your single LAF callback, check to see if the Widget.text contains "ZeroToOne", and if it does extract the string after the colon for your widget display text - if that's what you want - and calc the value in the way you have,
if it not "ZeroToOne" then look for "FilterType" if its there then again - everything after the colon is the text and you can process the display value as you have in your second call back...
like this:
HiseSnippet 1967.3ocsX0sbhbiEtwyzYCjMoRRkG.UbQplwXLM1dhmg7CFaXLkwFGCYxrqKWSI2s.T4FIptEyX1DuUdAx6StbeTx86M6aPxQp+SMF7LE0FnLk042OczQGcjN2m6PBB39F4xOX9ThQt+tY+4Lw3CGioLiNGAzMOgwutKdnQy4SwAADWib4dzKjryk+wFpO+uuqI1CybHojLLdIm5P5RmPEoTOuwITOu1XWx.5DMo2sQGGN6PtGeF.kGYV0XJ14F7HxYXoXaXZj6CZ4REb+9BrfDXj6wM4ty6Ol+VVn7ujFPu1iHGXazGLTH41bOWIhkTMNbL0y873obfAXkySC.OJL.7ElmRcoIzSCDephAJUC83QtMxBuGkAd15vqpF7VBjxoAoGGBoOyruiOcpHkiDOejYGlf3ODCgccnDJqwF+5GadHGjfIpLAeCosOLHQCqmVsZYD7So5EJ.g9.Ap+fCtXvqPeCpZccJ+CfhcLkeryQCNFHTKlvws57hiG.T1IwNG16r9Cdc+YJ+7BerKEfv.9Tokusc6ppO0eHgaxEB9jH42c+catWsrx2j66R7CSWhD6Y6.eeVVwNhFfgftaGlK0ACqNZZLb3d38tdOmkqQDfx3A6mYiscWt7MmAHlMfbqHKn1E9hWLxLA64EpPaXIoO8eQjgXXJVX6s+gNnHgeC1GI24YCLiWGGQ.6OYJmACrJp3VrT8ETn1CpPMoBROs3GzIm0qIpaudmfN3riPsa0pK59REOUFR8fLoS4tjt3qIdAfOurXW9akogEKiJdLcz33+uIl4p9+qhgZ2CZ+ZXmByE66JAkFhc7IvNntbGrWWN+lCXtsIDOKEnWTsJ9jQz..GsmwbDTNypnqO9sWvEX+488nPNB3+gwL6Kl6QJ+iTWHpTpvOUHuLhc.3Ov8gTqfgQ0CYHcvwDXZH.1RotLLW+JM9fVhw2mM.KjKMXpGdtJ5.XOQknLqH2docsxH4epwwlXqZ6VNiMABWIC.4USgJADQ7Vk1P4TqKiPOUPlDl+YufE2FbAre+dxUaIxo63qf3djSgUb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8h.F+PmivBr7FsQvAf3ThufJm84Nh7FpCI79s4MOhDbifOUg2nqq.jemH91TG51Xdxfe46aDWLCn8A+A7QRNssWIUi+8e7aRpuUVVNQ0eeZiwpl90srbCo7V3IcL87P2anA1O5cFgRA6+4ZMv1XZirPnwxfvxw9xlkvYeZuBSC35QSkWwTeoIb974locY87PHZb+2d3SMgdrfVNEYeJD46+Dw.x9y79Cx2XfEPEy0c4+2dej2WH9YlmSENiWNF2XIXTtY4u.LF8pRerYqgCgp1o.7wlse0eMOgjAbJg.ZD+TLzONjLXd1rI8grDGB3cFCZVFnkaCYchvwUkikQf9voZpAxjoHl1xw4hXZGyDRyb74u1Ir.g7cq9PEE.SL0S1k27T4XTRYESS3j.iITW5qcbjS+srMLVtN0VCc1YMzY20Pm8VCcd5ZnyWsF5r+Cpi70KOXlfOIb6.P37VpJz4x0hodEKYVnweJQB0kO
-
@HISEnberg said in Reducing LAF scripting redundancy:
So far I have just been copying my entire LAF and creating a new one for each use case (creating a lot of redundancy).
These two videos might be of help here:
https://youtu.be/k2SnYLkdlWE?si=0BvA8T8rUNiSREhK
https://youtu.be/jO-KOEcJRKo?si=A0FXp4MDqyQWbJCG -
@d-healey & @Lindon Thank you very much, both of your responses have really helped me explore the possibilities here. I am pleased to know I can use the text property in this way, and will definitley explore this more in future projects. A lot of this particularly UI is already laid out so I am settling for bypassing any text that is not the exception cases, and employing it for any cases that call for customized value displays.
Example based on Lindon's edits:
const tempos = ["1/1", "1/2D", "1/2", "1/2T", "1/4D", "1/4", "1/4T", "1/8D", "1/8", "1/8T", "1/16D", "1/16", "1/16T", "1/32D", "1/32", "1/32T", "1/64D", "1/64", "1/64T"]; const filterModeLabels = ["Lowpass", "Highpass", "Bandpass"]; const LAF_StandardKnob = Content.createLocalLookAndFeel(); LAF_StandardKnob.registerFunction("drawRotarySlider", function(Style,Widget) //... if (Widget.text.contains("FilterType")) { // For FilterType knob, display the corresponding label displayLabel = filterModeLabels[parseInt(Widget.value)]; //For TempoSync, display tempo sync values }else if (Widget.text.contains("TempoSync")){ displayLabel = tempos[parseInt(Widget.value)]; } else { // For all other knobs, display the value displayLabel = Engine.doubleToString(KnobValue, 2) + Widget.suffix; } Style.drawAlignedText(displayLabel, [Area[STARTX] + LabelOffset, Area[HEIGHT]-Area [HEIGHT] +6, Area [HEIGHT]+LabelOffset, Area[HEIGHT]], "left"); //...
-