Page 2 of 3

Re: Scripting error

Posted: Sun May 26, 2019 5:13 pm
by Captain
Got your source code, thanks! To tell the truth, I'm a bit confused what you want the code to do :D Anyway, here are some pointers to help you get forward:

- Everything is case sensitive! From Java's point of view, "volumevalue" is a completely different thing than "volumeValue". It doesn't really matter which one you use, as long as you use it consistently everywhere. I also suggest reading about Java's naming conventions (how to name objects and methods etc). Those are only conventions, but help make your code more readable to other people, and probably yourself too.

- Read about objects and primitives, and what is their difference. In your code, "volumevalue" is declared a primitive (double), but elsewhere, you try to call a method called volumevalue.SetValue(), which does not work, since primitives don't have methods.

- Be careful what goes where in the module's source code. As you can see, when you start a new project in MD, there's already a bunch of code there, and you can only edit some specific spots in the code. Familiarize yourself with the structure of a new blank project, and the stuff that is already there: which methods get called at what times, etc. For example, the code you have placed inside the "GetTooltipText" method, I'm pretty sure it's not supposed to be there... Make sure you read the help text above the GetTooltipText method, it should give you an idea when that method is called. Also make sure you don't have any extra leftover code anywhere where there is not supposed to be any.

- Most of audio processing code will probably be inside the ProcessSample() method

- As I said earlier, using curly brackets with IF is always a good idea :) Like this:

Code: Select all

if ( test something here ) {
	do something here
	do something more
	still part of the IF block
}
after the IF block
Hope this helps at least a little bit! I warmly recommend reading some general Java tutorials and learning the basics of Java, before diving too deep into Module Designer. I guarantee things will be much easier that way. :) But on the other hand, you can get pretty far with just the basics!

Re: Scripting error

Posted: Mon May 27, 2019 9:15 am
by JackOats
Hi - Thanks very much for the message.
I'm a bit confused what you want the code to do
Well, as I said in my original post I'm trying to create a Volume Knob.

I'm just copying the code supplied in the example given by MD - it's not my scripting.

You can see the tutorial at: Help page/Voltage User Guide/Voltage Module Designer/Module Programming Example.
I warmly recommend reading some general Java tutorials and learning the basics of Java
Thanks. Yes, I am studying Java scripting at the moment. I'm following a set of very helpful videos at cosmo learning.org by

'thenewboston'.

Very interesting.

I'm going to go through the MD tutorial again, with a fine tooth comb! I must have gone wrong somewhere. :?

Thanks very much for all your tips. Really appreciate it.

Re: Scripting error

Posted: Mon May 27, 2019 11:57 am
by Captain
Yeah, the thing about programming is that you need to be very careful with syntax and other details. :D One wrong character somewhere might mean the whole thing won’t compile. You seem to have all the necessary stuff there already, just make sure the syntax is correct (lowercase vs uppercase, etc), every line of code is where it is supposed to be, and if-statements have the curly brackets... and I’m sure it will work. Good luck!

BTW, you could create the simplest possible volume knob module with just a single line of code :) Make sure you have one input jack, one ouput jack, and one knob in the GUI, and set their variable names to inputJack, outputJack, and volumeKnob (and check that the knob has a range 0-1). Then insert this inside the ProcessSample() function:

Code: Select all

outputJack.SetValue( inputJack.GetValue() * volumeKnob.GetValue() );
Very crude and could use a lot of improvements, but already does the job! (Disclaimer: I’m typing this on my phone, so there might be some typos etc.)

Re: Scripting error

Posted: Mon May 27, 2019 5:09 pm
by JackOats
Thank you.
insert this inside the ProcessSample() function:
CODE: SELECT ALL
outputJack.SetValue( inputJack.GetValue() * volumeKnob.GetValue() );

Tried this code but still get the same response I'm afraid:
java: 323: error: variable declaration not allowed here
Think I need to put in a request with the VM guys - I'm going crazy with this. :?

Thank you so much for taking the time & trouble - I'm really grateful for all your help. :)

Re: Scripting error

Posted: Mon May 27, 2019 8:29 pm
by Captain
JackOats wrote:
Mon May 27, 2019 5:09 pm
Tried this code but still get the same response I'm afraid:
java: 323: error: variable declaration not allowed here
Hmm, I’m pretty sure you accidentally left some extra code somewhere (on line 323, in fact)... make sure you start with a new clean project, just add the 3 GUI controls, then add this line of code (and make sure it’s inside ProcessSample()), and try again. Unfortunately I’m traveling without my computer for the whole week, so I can only try to debug things in my head...

And no problem, glad to help! :)

Re: Scripting error

Posted: Mon May 27, 2019 10:00 pm
by JackOats
Well, as I said, when I delete this line I get an error message that says it can't be "dereferenced".

Please don't waste any more time on this - I really don't want to bug you if your travelling around.

Watch this space! Something will develop I'm sure. :)

Thanks for being so generous with your time. It's really good of you.

Re: Scripting error

Posted: Mon May 27, 2019 11:23 pm
by terrymcg
Hi Jack!

Maybe I'm old-fashioned (! ;) ) but it sounds to me like having a good Java *book* would be a big help in getting you going.

I don't have this one, but have been a fan of O'Reilly's "Animal" books for many (many) years so feel safe in suggesting it:
Learning Java, 4th Edition

(There are lots of others, that's just the first entry-level one I found on first site I searched - the O'Reilly site)

The Java version VM uses is a bit newer, but that's not going to matter to you for a while (if at all). There are some other complications to writing code in the VM environment that won't be covered either, but again, for the most part by the time you need to worry about it you'll be better equipped to do so.

Good luck!

Cheers,
--
Terry McG

Re: Scripting error

Posted: Tue May 28, 2019 8:04 am
by JackOats
Hi Terry,

Thanks for the message.
having a good Java *book* would be a big help in getting you going.
Absolutely! I am doing a video course online at the moment, but having a book to read as well would be a great help.

Just checked out the book you mention & it seems pretty comprehensive.

There's also a 10 day free trial reading - which I might go for first.

Thanks very much for the recommendation. :)

Re: Scripting error

Posted: Thu May 30, 2019 9:20 pm
by JackOats
@terrymcg
@Captain
@CherryDan

Hi Guys - SOLVED!

One aspect of the problem, as you thought, was my rather mixed usage of capitalisation.

As you also spotted - a chunk of code in the Tool Tips section which shouldn't have been there. (Still not sure how it got there)!

There were mistakes too in the GUI design section concerning package file naming etc. which I think is still a problem area for me.

Anyway I got the project to compile today :D so thanks again Guys for all your help & a big thank you to Cherry Dan who very generously checked over my mod file & showed me (in double quick time) where I was going astray.

It's been a stressful few days but I've learned a lot & am extremely grateful for all the unselfish help given.

Very much appreciated Guys - Thank you so much. :)

Re: Scripting error

Posted: Fri Oct 16, 2020 5:07 pm
by fishbowl.555
Good Afternoon,

I know this post is over a year old -- hope folks are still monitoring -- but it's the only post on the forum that references the exact error I'm getting as well.

I too am getting the cannot dereference error from the Volume Knob example on the documentation.

JackOats would you happen to recall the fix you and Cherry Dan discovered?

I've attempted fresh projects multiple times and fairly confident I've typed as accurately as possible. I have a small amount of Java experience years ago so I understand what the error means. But I can't seem to figure it out.

Volatage Modular Designer 2.0.30

openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-46)
OpenJDK 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)

Not sure how to upload txt/java/vmod file. I keep getting an invalid file extension.

EDIT: Here's what I've typed and what is auto-generated based on the GUI designer
--------------
package com.fishbowl555.volumemodule;
...
...
public class VolumeModule extends VoltageModule

{

public VolumeModule( long moduleID, VoltageObjects voltageObjects )
{
super( moduleID, voltageObjects, "Volume Module", ModuleType.ModuleType_Utility, 2.0 );


volumeKnob = new VoltageKnob( "volumeKnob", "Volume Knob", this, 0.0, 2.0, 0.5 );
AddComponent( volumeKnob );
volumeKnob.SetWantsMouseNotifications( false );
volumeKnob.SetPosition( 57, 46 );
volumeKnob.SetSize( 27, 27 );
volumeKnob.SetSkin( "Plastic White" );
volumeKnob.SetRange( 0.0, 2.0, 0.5, false, 0 );
volumeKnob.SetKnobParams( 215, 145 );
volumeKnob.DisplayValueInPercent( true );
volumeKnob.SetKnobAdjustsRing( true );

inputJack = new VoltageAudioJack( "inputJack", "Input Jack", this, JackType.JackType_AudioInput );
AddComponent( inputJack );
inputJack.SetWantsMouseNotifications( false );
inputJack.SetPosition( 18, 257 );
inputJack.SetSize( 37, 37 );
inputJack.SetSkin( "Jack Straight" );

outputJack = new VoltageAudioJack( "outputJack", "Output Jack", this, JackType.JackType_AudioOutput );
AddComponent( outputJack );
outputJack.SetWantsMouseNotifications( false );
outputJack.SetPosition( 92, 257 );
outputJack.SetSize( 37, 37 );
outputJack.SetSkin( "Jack Straight" );


canBeBypassed = false;
SetSkin( "ba05a8acc0a04d04bf6a5f10e5eca2f3" );
}
...
...
@Override
public void Initialize()
{
// add your own code here

volumeValue.SetValue(volumeKnob.GetValue());

}
...
...
@Override
public boolean Notify( VoltageComponent component, ModuleNotifications notification, double doubleValue, long longValue, int x, int y, Object object )
{
// add your own code here
switch( notification )
{
case Knob_Changed: // doubleValue is the new VoltageKnob value
{
if (component == volumeKnob)
{
volumeValue = doubleValue;
}
}
break;
...
...
@Override
public void ProcessSample()
{
// add your own code here

double inputSignal = inputJack.GetValue();
double outputSignal = inputSignal * volumeValue;
outputJack.SetValue(outputSignal);

}
...
...
// Add your own variables and functions here

private double volumeValue;
--------------