Forums > Java

buffer~ in mxj~


August 31, 2007 | 6:27 pm

Hi guys,
I’ve been going through the documentation and I’ve been going through
the JAR but couldn’t figure this out: how do I access a named buffer~
from within mxj~? From the discussion on the list I’m not even sure
it’s possible right now?? My purpose is to load up a couple of files
in buffers, have them quickly resized in mxj~ where I do onset-
detection, normalizing and making sure they start at a zero crossing,
and after this initialization I play with them in Max/MSP.

Cheers

Nik

August 31, 2007 | 11:51 pm

did you look at the MSPBuffer java doc?

Class MSPBuffer

java.lang.Object

com.cycling74.msp.MSPBuffer

public class MSPBuffer
extends java.lang.Object
Provides static methods that get and set buffer data. created on 9-
April-2004

September 1, 2007 | 2:50 pm

Hi Topher,
I looked at it, but I must have been very tired. ;-) I guess I
expected to find something like a constructor MSPBuffer(String
bufferName) and then access it that way and then misunderstood how it
worked. Thanks for pointing me back to it. :-)

Cheers

Nik

On Sep 1, 2007, at 1:51 AM, topher lafata wrote:

> did you look at the MSPBuffer java doc?
>
> Class MSPBuffer
>
> java.lang.Object
>
>
> com.cycling74.msp.MSPBuffer
>
>
> public class MSPBuffer
> extends java.lang.Object
> Provides static methods that get and set buffer data. created on 9-
> April-2004
>
>

February 18, 2015 | 2:24 pm

I know this is really old but can somebody show me the basic code to peek a Buffer object? I’m just confused how to access it without constructing an MSPBuffer object like Niklas’ last comment. I think I must be missing something. Is it something like the following because it’s not working:

float mypeek = MSPBuffer.peek("Buckets");

Do I need to create a new class that extends MSPBuffer? Just really confused about this.

February 18, 2015 | 2:30 pm

Hi Tommy, can’t give a definite answer on this – however I would recommend viewing the source of [mxj buf.Op] I managed to hack something together from that.

February 18, 2015 | 3:01 pm

Thanks Mike, I will dig into that!

January 21, 2016 | 10:57 am

Hey Tommy,
I too had a hair pulling experience with accessing MSPBuffers from mxj! Took me over a month to filter through hundreds of tutorials and example patches. I can help you out… a lot.

Firstly:

The class should extend MaxObject as usual for max object creation from mxj.
like this "public class genInverseFilter extends MaxObject {"

If you want to access a buffer from your patch window in max and you want to supply the name of that buffer
as an argument then you need to create a global variable –
"String bufname = null;"

Then your usual declare inlets and outlets inside your constructor – titled the same as your classname with:
"(Atom[] args)"

Still in the constructor…
"if(args.length>0)
set(args[0].toString()); "

This code will check your arguments to see if they are present.

Your first method will be:
"public void set(String s) {
bufname = s;
}
"

This will set the string variable "bufname" to the argument you supplied when you created the object inside max msp. Sorry this is a long winded explanation..

Now onto the important stuff:
To access the buffer you simply use a single line of code:

"float[] s = MSPBuffer.peek(bufname);"
This will "peek" inot the buffer with the name you have supplied as an argument and that has been set as a global variable. The data will then be stored in the "float[] s" array or whatever you decide to call it. One thing to note – MSPBuffer peek returns float values and not double. This means if you are doing math using java.math you will have to do some annoying casting for loops "(double) ….".

Once you have performed all of the functions neccessary to fill a new buffer or replace the data in the original buffer you have to:

Designate a new buffername or supply the original in the code somehow – this can be as an argument to your method which accesses the buffer or has to be done in the same way as I showed you before.

"int channels = MSPBuffer.getChannels(bufname); // this calculates how many channels are on the original channel.
MSPBuffer.setSize(destBuf, channels, size); // size should be a long type variable and is total number of samples.
MSPBuffer.poke(destBuf, dataArray); "
This is fairly self explanatory. Array has to, as mentioned earlier be a float array.

Hope that helps!

January 21, 2016 | 1:16 pm

Thanks Smellor, good info here! And Mike S’s suggestion of "viewing the source of [mxj buf.Op]" really helped me a lot. Very cool stuff!

Viewing 8 posts - 1 through 8 (of 8 total)

Forums > Java