EditComponentValue()

Centripidity
Posts: 146
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

EditComponentValue()

Post by Centripidity »

I have a knob which is used to set a MIDI note. It's range is 0-127 but I have used GetTooltipText() to display the value as a MIDI note name - C5, F#-1 etc..

When the user chooses to manually edit that value I call EditComponentValue() and the new text is passed in the String newText. I use that to generate the note number to change the knob value.

This all works fine but it also throws a NumberFormatException, presumably because the underlying VM code is trying to turn the text into a double to also pass into the function.

Am I doing something wrong or is this a bug/oversight in VM?

I think I can just ignore the exception but my OCD mind is not comfortable with that.

Any suggestions?

Peter
User avatar
honki-bobo
Posts: 310
Joined: Sat Nov 09, 2019 1:18 pm

Re: EditComponentValue()

Post by honki-bobo »

Hi Peter,
Centripidity wrote: Sun Feb 05, 2023 6:13 am This all works fine but it also throws a NumberFormatException, presumably because the underlying VM code is trying to turn the text into a double to also pass into the function.
I would also assume this, but it's hard to tell what's happening without any code. If you could post the code of your EditComponentValue() it would be easier to analyze.

Best regards,
Martin
Image
Monkey Business Audio
Modules - Music - Twitter - YouTube
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: EditComponentValue()

Post by ColinP »

My guess would be that the exception is being thrown by your code handling the note name to value conversion rather than VM.

I pass the original text on to super.EditComponentValue() so VM must just use the newValue parameter for the new value rather than attempting to parse newText itself.

Here's an example...

Code: Select all

@Override
public void EditComponentValue( VoltageComponent component, double newValue, String newText )
{
   // add your own code here

   i( component == yourKnob )
      newValue = yourStringToValueParser( newText );
      		
   super.EditComponentValue( component, newValue, newText );
}
Centripidity
Posts: 146
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

Re: EditComponentValue()

Post by Centripidity »

honki-bobo wrote: Sun Feb 05, 2023 10:05 am I would also assume this, but it's hard to tell what's happening without any code. If you could post the code of your EditComponentValue() it would be easier to analyze.
The exception gets thrown even if there is no user code in the EditComponentValue() function.

Try right clicking on any knob and enter a text (non-numeric) string. When you hit enter, EditComponetValue() is called, the text you typed is passed in as the newText argument, and it immediately throws the exception NumberFormatException on the string you entered. Of course, you only notice the exception if you’re running in the debugger, it doesn't seem to interfere with the module's operation.

If I add code to convert the text to a MIDI note number and pass it as the newValue to Super the knob value changes as expected.
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: EditComponentValue()

Post by ColinP »

You are correct Peter. It looks like the VM code that calls EditComponentValue() simply uses a Double.parseDouble() on the Edit Value string and doesn't catch the exception.

Well spotted.
Centripidity
Posts: 146
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

Re: EditComponentValue()

Post by Centripidity »

Is there a place to log this as a possible bug?
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: EditComponentValue()

Post by ColinP »

You could just email support and they'll pass it along.
ColinP
Posts: 998
Joined: Mon Aug 03, 2020 7:46 pm

Re: EditComponentValue()

Post by ColinP »

BTW I've just looked at my own code and I've made exactly the same mistake with Double.parseDouble(). I tested it but obviously not in debug mode so never noticed the problem. I probably just assumed that it returned zero rather than checking the Java docs. But clearly it doesn't return zero but throws an exception.

A lesson learned. Thank you.
User avatar
seal58
Posts: 377
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

Re: EditComponentValue()

Post by seal58 »

I've just got a similiar problem with integer conversion. I could fix that exception error this way:

Code: Select all

int sToInt( String txt )
{
   int xValue;
   try { xValue = Integer.valueOf( txt ); }
   catch ( NumberFormatException exc ) { xValue = 0; }
   return xValue;
}
Centripidity
Posts: 146
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

Re: EditComponentValue()

Post by Centripidity »

The problem here is that the exception is not being thrown by my code but within voltage itself so I don't think there is anyway for me to intervene before it happens.

I tried an experiment. I opened Voltage itself, edited a knob value with a text string, "ret" in this case, and when I looked in the Voltage log, it throws the same exception.

19:47:36.550 java.lang.NumberFormatException: For input string: "ret"
java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
java.base/java.lang.Double.parseDouble(Double.java:651)
voltage.core.Values.ParseStringToDouble(Unknown Source)
Post Reply

Return to “Module Designer”