B4J Question [Solved] Problem wrapping 'beads project' library

stevel05

Expert
Licensed User
Longtime User
I am wrapping an audio processing package called beadsproject and have come up against a problem wrapping one class, the Function class : http://www.beadsproject.net/doc/net/beadsproject/beads/ugens/Function.html

My code works in release mode but not in Debug. The java code is:

B4X:
package com.stevel05.beads;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import net.beadsproject.beads.core.UGen;
import net.beadsproject.beads.ugens.Function;


@Author("Steve Laming")
@Version(1.0f)
@Events(values={"Calculate (X() As Float) As Float"})
@ShortName("Function")
public class FunctionWrapper{
    Function function;
 
    public void Initialize(final BA ba, final String EventName, UGen ug){
        function = new Function(ug){
            final String s = EventName.toLowerCase(BA.cul) + "_calculate";
            @Override
            public float calculate() {
                return (float) ba.raiseEvent(this, s, x);
            }
        };
    }
    //Get the object
    public Object GetObject(){
        return (Object)function;
    }
};

So not a huge class, As I say in release mode it works as expected, in debug mode I get the error:
java.lang.NullPointerException
at com.stevel05.beads.FunctionWrapper$1.calculate(FunctionWrapper.java:24)
at net.beadsproject.beads.ugens.Function.calculateBuffer(Unknown Source)
at net.beadsproject.beads.core.UGen.update(Unknown Source)
at net.beadsproject.beads.ugens.WavePlayer.calculateBuffer(Unknown Source)
at net.beadsproject.beads.core.UGen.update(Unknown Source)
at net.beadsproject.beads.core.UGen.pullInputs(Unknown Source)
at net.beadsproject.beads.core.UGen.update(Unknown Source)
at net.beadsproject.beads.core.UGen.pullInputs(Unknown Source)
at net.beadsproject.beads.core.UGen.update(Unknown Source)
at net.beadsproject.beads.core.AudioContext.update(Unknown Source)
at net.beadsproject.beads.core.AudioIO.update(Unknown Source)
at net.beadsproject.beads.core.io.JavaSoundAudioIO.runRealTime(Unknown Source)
at net.beadsproject.beads.core.io.JavaSoundAudioIO.access$000(Unknown Source)
at net.beadsproject.beads.core.io.JavaSoundAudioIO$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)

and can't work out why, the event calculate is raised in Debug mode, and it fails just after.

I did try extending ABSObjectWrapper, with the same results. I also tried adding @RaisesAsynchroniousEvents, but with no change.

The project and required jar files (including this lib) are attached. It is likely I've missed something silly I haven't done any 'real' java for quite a while.

Thanks in advance.
 

Attachments

  • beads.zip
    18.6 KB · Views: 261
  • beadsjars.zip
    179.9 KB · Views: 238

DonManfred

Expert
Licensed User
Longtime User
Get a new Bead object, add a BeadListener and inside the Listener-Event....

Bead()
Instantiates a new bead.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Unfortunately listeners don't appear to be implemented that way as the beads are chainable, input to output,
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I´ll have a deeper look after work. Just did a very quick look at the zip i downloaded...

I would think that you need to use it kind of this way

B4X:
   public void Initialize(final BA ba, final String EventName, UGen ug){
        function = new Function(ug);
[...]
}
public resulttyp calc(Float x, String y){ 'or whatever parameter needed
  return function.calculate(x,y) 'see above
}

But that´s only a guess based on the fact that i did just a quick look
I´ll check the Lib and Example later more deeper :)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thanks, I'm pretty sure it's an issue somewhere with the RaiseEvent call, if I put the calculation in the library, it works in release and debug, but I want to delegate the calculation to a B4j sub.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thanks Erel, it returns : Thread[Thread-6,10,main]
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If I put a log statement in the B4j sub, it displays one value for x(0) before the null pointer error so it's getting called at least once.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thanks Erel, this falls firmly into the 'can't debug classes using Thread category'. If I need to, I'll look for an alternate setup.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This one is processing real-time audio so the events are very rapid. I would be interested to know how to do it though for future reference, I know the threading library can raise an event on the main thread, but wasn't sure how to go about it from java.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top