Using units in EditComponentValue

Post Reply
Benard
Posts: 61
Joined: Mon Oct 01, 2018 11:40 am

Using units in EditComponentValue

Post by Benard » Tue Feb 04, 2020 5:55 pm

I would like to input units when editing a component value, so that I can for example type 1 m for a minute or 60 s for 60 seconds when inputing a value for a knob that controls duration.

Does anybody have any tips about how to do this? I mean how to parse the input to get the double and the string values from what is typed in so that I can then do something depending on what the string part is, which I'm guessing is what I would need to do, but it's not clear to me how to do this.

Any help would be appreciated.

Benard
Posts: 61
Joined: Mon Oct 01, 2018 11:40 am

Re: Using units in EditComponentValue

Post by Benard » Wed Feb 05, 2020 1:48 pm

Well, sadly no one responded to this post, even though I know this is something pretty trivial for those of you who know how to do it.

Maybe people are not very active here anymore, or the ones who know weren't looking, or maybe they just don't feel like sharing this type of information, for whatever reason. But I think the more accessible this info is, the easier it will be for people to make better modules, and thus the platform will grow and we will all benefit.

So in the spirit of sharing, here's the answer I came up with to make this work, in case somebody else will find it useful.

You can access the string part of the input when you type something like "10 m" as the input using newText. Then you can check if it contains the character you specified as a condition to scale the values. Something like this works:

if (newText.contains("m")) {
newValue = newValue * 60;
} else if (newText.contains("h")) {
newValue = newValue * 3600;
}

Cheers! :mrgreen:

User avatar
marltetz
Posts: 48
Joined: Tue Feb 26, 2019 9:53 pm
Location: Tokyo, Japan
Contact:

Re: Using units in EditComponentValue

Post by marltetz » Thu Feb 06, 2020 10:26 am

Thanks for the tips. :D
VM specific tips are good for everyone.

<code>
newText = newText.toLowerCase();
</code>
Putting it before "if" statement can make the process case-insensitive.

Benard
Posts: 61
Joined: Mon Oct 01, 2018 11:40 am

Re: Using units in EditComponentValue

Post by Benard » Fri Feb 07, 2020 10:31 am

Yeah, there's no place to really look some of these things up (specific to MD), and questions of this type tend to just go unanswered, so I think it's good to share whatever little tips we can. :geek:

Great job with the vary-step sequencer by the way!

User avatar
marltetz
Posts: 48
Joined: Tue Feb 26, 2019 9:53 pm
Location: Tokyo, Japan
Contact:

Re: Using units in EditComponentValue

Post by marltetz » Sat Feb 08, 2020 12:22 am

Yeah, thanks!

Sometimes, explaining those technical things is slightly difficult and takes much time.
I will try to put little tips when I have something useful. :)

Post Reply