Change the slider name and value placement
-
@Mickolos you can write
g.drawAlignedText(Math.round(obj.value * 100) / 100 + "", [0, 0, a[2], a[3] - 15], "centred");
although this can result sometimes in a value like 25.100203344 and I'm not entirely sure how to solve that
For the laf to work with multiple knobs, you can write
const var knobs = Content.getAllComponents("Knob");
; and it will get any component starting with Knob and followed by the numbers, so Knob1, Knob2, Knob3 etc. You can do this for any naming convention as long as it is followed by a number. You would need to do this in addition to addKnob, if you use also want to use that. Then after the laf you can just write
for (i = 0; i < knobs.length; i++) { knobs[i].setLocalLookAndFeel(knb_LAF); }
-
-
@rglides said in Change the slider name and value placement:
you can write
Engine.doubleToString()
is probably a better choice, or even betterobj.valueAsText
(I think that's the one).@rglides said in Change the slider name and value placement:
and it will get any component starting with Knob and followed by the numbers,
Almost, this pattern will get any component that has the word "Knob" in its id. To get Knob followed by a number you need
Knob\\d
but I'd try and come up with more meaningful names. -
@d-healey haha I just came back here to update my post as I found somewhere in my project I was using Engine.doubleToString. totally forgot. And thanks for the tip on \d, although my solution seems to work for me, maybe if I open/close it'll stop working, I don't know
-
@rglides said in Change the slider name and value placement:
although my solution seems to work for me
It will work if all your knobs are called Knob followed by a number. But if you add a knob called MyKnob it will also pick that up, or KnobForDelay, or any other control with the word Knob in its ID.
-
@d-healey Ah I did not know that, ok cool
-
@d-healey has already said it all. :-)
In addition to “getAllComponents”, the following should be said: This function uses regex to select the corresponding components. It therefore makes sense to familiarize yourself with it.
With
const comps = Content.getAllComponents("^.*(Knob|Button).*$");
you can, for example, select all components whose name contains "Knob" or “Button”.With
const comps = Content.getAllComponents("^(?!.*Slider).*(Knob|Button).*$");
you can select all components whose name contains “Knob” or "Button", but not “Slider”.And with
const comps = Content.getAllComponents("^(?!.*Slider).*$");
for example, you can select all components except those that have “Slider” in their name. -
and @Mickolos - Using David's tip for your specific laf would look like this
g.drawAlignedText(Engine.doubleToString(obj.value, 0), [0, 0, area[2], area[3] - VALUE_Y_POS], "centred");
-
@Oli-Ullmann Useful! Thanks Oli!
-
@rglides said in Change the slider name and value placement:
Using David's tip for your specific laf would look like this
I think obj.valueAsText is better because it will include the same formatting as the original knob.
-
@d-healey You're right, although Engine.doubleToString sounds cooler :D
-
@d-healey said in Change the slider name and value placement:
or even better obj.valueAsText
wahh? Nugget!
-
@Oli-Ullmann This is great!
-
Thanks everyone for your input but none of those new suggestions are working for me. Obviously because I'm doing it wrong.
There was a lot of different recommendations and any combination of them seems to break the code from affecting the knobs. As a noob, I'm not sure where and what to place everything...
Heres what I got which compiles okay but does nothing to the knob
.------- PS: I don't know how to make all the code appear in the black box so it overflows at the top and bottom on this page------
Content.makeFrontInterface(1000, 1000);
const comps = Content.getAllComponents("^.(Knob|Button).$");
const ValueLAF = Content.createLocalLookAndFeel();
ValueLAF.registerFunction("drawRotarySlider", function(g, obj)
{
g.setColour(Colours.white);
g.setFont("Arial", 20);var area = obj.area; g.drawAlignedText(obj.valueAsText(obj.value, 0), [0, 0, area[2], area[3] - VALUE_Y_POS], "centred"); var a = obj.area; // Knob Background Colour g.setColour (obj.bgColour); g.fillEllipse(a); // Knob Inner Colour (Item 1) g.setColour(obj.itemColour1); g.fillEllipse ([5, 5, a[2] - 10, a[3] -10]); //Knob Marker Position var start = 2.5; var end = start * 2 * obj.valueNormalized - start; g.rotate (end, [a[2] / 2, a[3] / 2]); // Knob Marker Colour g.setColour(obj.itemColour2); g.fillRoundedRectangle([a[2] / 2 - 5 / 2, 3, 5, 11], 2.5);
});
for (i = 0; i < knobs.length; i++)
{
knobs[i].setLocalLookAndFeel(knb_LAF);
} -
I don't know what exactly you are trying to achieve but this code is now working:
HiseSnippet 1247.3ocsV0saaaCElJIpa1aqXcnWrKIL1EJsdNV1wKdHqnw4G2YzjTi3zfBDDTPKQIyYJRCI5j3VTfcwdd1qvdV1avdC1NjR1VtIHo0.yvFl77624vCOG1MV5QSRjwHqhmNYDEY8018lHTC1a.gIPc1GY8P6iHIJZLNkztSFQRRn9HKqUeglfUg0PlO+yy2kvIBO5bRHzYRlG8PV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EghHWmePax3f.10lQhPcbThBvVmHXRIx56reMb80mFPFyU3jgfc3LwPn4kzH+ULe0f415zcFPYgCT4oft4bEXhlzeLmnVbLm9A.YLzwT9YK54GBHVmjG2eFy9pdmy99Tg3ir6xTdCtcLtxsfQnT4+CLl8hguw9ff.nayb.tlc62rrOO3dbOzcSwDgGQfpCnVw93wQ8f9edTv6vDBNXbaqUzW1R2WUuWmA5AsbMa9W3SFSW8dqLltSYB0kdwx25kdEU+ljuzPAvjv7lsBviGg83a4tIbef8VOuEM0MTr1xpX8kUwMWVEarrJ9SKqhasrJ179UT+B1ViUxnzqMHzQcOvzK0x5.AAp.MUqn+CnJNxYI
-
@Mickolos You could export a snippet, it would be a lot easier - In HISE go to Export, Export as HISE Snippet and then in here click the </> in the menu above where you write a message, then replace the ... with the copied hise snippet. You can paste any code with the same method, but a snippet would make it easy to take a look
-
@Mickolos You're missing the * in your regex.
Instead of
const comps = Content.getAllComponents("^.(Knob|Button).$");
use
const comps = Content.getAllComponents("^.*(Knob|Button).*$");
The dot is looking for exactly one character. The * modifies that to look for any number of characters, including zero.
The way you had it will only match components that have exactly one character before the word and one character after the word, like 1Knob1 or ZButtonZ.
If in doubt, use a regex tester like regex101.com. Put the regex in the top text field then add some example component names including wrong ones, to see which ones the regex matches.
The next image shows that the only ones matched by your original regex are the last two.
The next image shows that with the extra * in the regex, ALL the names are matched.
-
@Mickolos Other than the incorrect regex, your code seems have a couple of other problems:
- You put all knobs into 'comps' but then later loop through 'knobs', which is not defined in your code.
- You create a look and feel called 'ValueLAF', then later assign one called 'knb_LAF', which is not defined in your code.
I realise these might be copy/paste inconsistencies and your code is actually correct. But just wanted to point it out.
-
The problem is you are trying to use code without understanding it, what you end up with is Frankencode which is little bits and pieces copy and pasted together.
Start by not touching copy/paste. Instead write out your code from scratch, and only write things that you understand, if you don't understand something, look it up, or ask here for an explanation.
-
@dannytaurus Thank you.