Forums > Java

Announce: Python for MaxMSP (beta)

February 29, 2008 | 9:02 pm

After a hectic flurry of activity, I now have a port of Python to
MaxMSP, using the Jython package and MXJ.

It was something of a refactoring effort, but there’s now a common
base of code supporting both the Groovy and Jython systems, which
means that from a Max perspective they look very similar: the same
interface, attributes and parameters. I even managed to port all the
example patchers and scripts from the Groovy release into Jython. (At
least one of the sub-patchers is identical in both systems.)

There’s a release at

http://www.loadbang.net/space/Software/net.loadbang.jython

I’ve labelled it a beta since there are one or two things I need to
tidy up (involving threading and module reloading), but it would be
good if folks could bash on it a little. The javadocs are online and
the sources are included in the release, but I still need to package
up the sources of the common scripting code. The javadocs are also a
bit unfinished (I fully expect to find some occurrences of "Groovy"
where it should say "Jython", for example).

As an aside, I’m rather getting to like Python. It’s a bit basic, but
it’s simple, clear and reliable, rather like a 2CV or an old labrador.

– N.

Nick Rothwell / Cassiel.com Limited
http://www.cassiel.com
http://www.myspace.com/cassieldotcom
http://www.last.fm/music/cassiel
http://www.reverbnation.com/cassiel
http://www.linkedin.com/in/cassiel
http://www.loadbang.net


March 1, 2008 | 12:44 am

You, sir, are being quite prolific of late.

Good job.

b

On Feb 29, 2008, at 1:02 PM, Nick Rothwell wrote:

> After a hectic flurry of activity, I now have a port of Python to
> MaxMSP, using the Jython package and MXJ.
>
> It was something of a refactoring effort, but there’s now a common
> base of code supporting both the Groovy and Jython systems, which
> means that from a Max perspective they look very similar: the same
> interface, attributes and parameters. I even managed to port all the
> example patchers and scripts from the Groovy release into Jython.
> (At least one of the sub-patchers is identical in both systems.)
>
> There’s a release at
>
> http://www.loadbang.net/space/Software/net.loadbang.jython
>
> I’ve labelled it a beta since there are one or two things I need to
> tidy up (involving threading and module reloading), but it would be
> good if folks could bash on it a little. The javadocs are online and
> the sources are included in the release, but I still need to package
> up the sources of the common scripting code. The javadocs are also a
> bit unfinished (I fully expect to find some occurrences of "Groovy"
> where it should say "Jython", for example).
>
> As an aside, I’m rather getting to like Python. It’s a bit basic,
> but it’s simple, clear and reliable, rather like a 2CV or an old
> labrador.
>
> – N.
>
>
> Nick Rothwell / Cassiel.com Limited
> http://www.cassiel.com
> http://www.myspace.com/cassieldotcom
> http://www.last.fm/music/cassiel
> http://www.reverbnation.com/cassiel
> http://www.linkedin.com/in/cassiel
> http://www.loadbang.net
>

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web: http://www.barrythrew.com


March 1, 2008 | 9:35 am

On 1 Mar 2008, at 00:44, barry threw wrote:

> You, sir, are being quite prolific of late.

Yep – it’s called "being between jobs." You can blame the sub-prime
mortgage crisis for this potpourri of scripting languages…

– N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com



Nat
May 8, 2008 | 7:18 pm

I have done this by mail but why not repeat myself :)
Thanks a lot for this package, I have been using it a lot and it saved me a lot of time.

I’m a bit surprised however when you say Python is "Basic" ? We coded full-fledged audio apps for the One Laptop Per Child project using Python and it works quite well.

The one sad thing about jython is that it’s currently based on an old release of python and it lacks some pretty useful things like generators. I believe the jython team is working on adapting python 2.5 though.

Thanks again for this great package !


May 9, 2008 | 9:48 pm



Nat
May 9, 2008 | 10:34 pm

It supports list comprehensions in the form
[x for x in range(30) if x > 10]
which will return a list, but it doesn’t support generators in the form (x for x in range(30) if x > 10) which return a generator object and is much faster to iterate through.

The other small thing it doesn’t support that I use a lot is the sorted function :

mylist = [2,3,1,4,5,7,90]
mysortedlist = sorted(2 * x for x in mylist)

but then, that’s not a big turn off, I still code much faster using python within max than using JavaScript…

Nat


February 25, 2009 | 2:54 pm

Hello,
I’m using Javascript for scripting in Maxmsp, is there any advantage on using Python instead of Javascript?
which one is faster for example?

Cole



Nat
February 25, 2009 | 5:59 pm

I use Python mainly because it’s much easier to deal with the os/filesystem from python. Regarding speed, it’s hard to tell, but it’s probably similar.


March 1, 2009 | 2:01 pm
robotpapier wrote on Wed, 25 February 2009 14:54
which one is faster for example?

That depends what you’re doing.

I’ve been using Jython to build step sequencing systems over a set of Java libraries, driving a thread-based scrolling window system for a monome, and the timing seems fine.

One other comment: I’ve found that Javascript’s Overdrive support is not reliable. Jython’s is.


April 27, 2009 | 12:17 am

Hi, thanks for your comments, so I’ve been experimenting advantages and disadvantages of javascript and jython. Indeed, I can use Java classes to include in a jython script which is a great advantage for what I want to do (querying mysql database by using java.mysql)

But I have some troubles using maxmsp java classes.

Here’s part of my code:

from com.cycling74.max import *

and then when I do

print MaxSystem.post("test")

it works, the code is posting as if we use post() in JS

But when I try

self.MaxPatcher = MaxPatcher(20,20,50,50)

it says "name self error"

Is there something to do with java class construction in jython?
I’ve tried to use another java class that is not part of maxmsp and it works too (java.sql)

I would like to use all the com.cycling74.max classes with jython, does anyone know how?

Cole


April 27, 2009 | 8:33 pm
robotpapier wrote on Mon, 27 April 2009 01:17
But when I try
self.MaxPatcher = MaxPatcher(20,20,50,50)

it says "name self error"

OK… so what’s "self" here? The name is a Python convention when doing OO programming – every method takes "self" as a formal first argument.

I did this:

from com.cycling74.max import *

class Fooble:
    def myMethod(self):
        self.MaxPatcher = MaxPatcher(50, 50, 200, 200)

x = Fooble()
x.myMethod()

and it compiles and runs fine (although it doesn’t do much).


April 28, 2009 | 12:56 am

Hi,

Yeah it doesn’t show any error, but it doesn’t do what it is supposed to do -> create a new patcher.

I’m having a hard time trying to do what I was doing in js with jython.

For instance, in JS, when you want to identify your patcher and then use its methods, you just write in the js file:

current_patcher = this.patcher;
create_toggle_in_current_patcher = current_patcher.newobject("toggle",122,90);

and then the toggle object appears in the current patcher at position (122,90)

In Jython used with maxmsp, it is not that simple.
Do you have to embed the java class in a jython class? Is it what you did? And so is there a way to retrieve the value of the current patch in which the mxj is beeing executed? I don’t quite get it and moreover I’m not familiar with jython nor java.

Here ‘s the different testing I did, refering to the Maxmsp Java classes API, that maybe can help figuring out my issue:

#AttributeInfo
	# boolean
	print AttributeInfo.gettable # OK
	# java.lang.String
	print AttributeInfo.getter # OK
	#  java.lang.String
	print AttributeInfo.toString("test") # OK

#MXJClassLoader
	# static MXJClassLoader
	print MXJClassLoader.getInstance() # OK
	# java.lang.String[]
	print MXJClassLoader.getCurrentClassPath() # TypeError: getCurrentClassPath(): expected 1 args; got 0
	# protected  java.lang.String[]
	print MXJClassLoader.getDynamicClassPath() # "AttributeError: class com.cycling74.max.MXJClassLoader has no attribute getDynamicClassPath"
	# protected  void
	print MXJClassLoader.zap() #  "AttributeError: class com..cycling74.max.MXJClassLoader has no attribute zap"

# MaxSystem class
	# static void
	MaxSystem.post("test max post console") # OK

And I also tried to trnaslate the java syntax into jython refering to how you call the maxmsp java class through jython (if it is what you did)

Here is the java code

public class MaxClockExample extends MaxObject() {
 	MaxClock cl;

 	MaxClockExample() {
 		cl = new MaxClock(this, "runForever");
 	}

 	public void bang() {
  	cl.delay(500.);
 	}

 	public void runForever() {
 		post("forever");
 		cl.delay(500.);
 	}

 	public notifyDeleted() {
 		post("never");
 		cl.release();
 	}
 }

Here is what I did, of course it doesn’t work

class MaxClockExample(MaxObject):
	def __init__(self):
		pass

	def MaxClockExample(self):
		self.MaxClock = MaxClock(self,"runForever")

	def runForever(self):
		MaxSystem.post("forever")
		self.MaxClock.delay(500)

x = MaxClockExample()
x.MaxClockExample()

# maxmsp console : "java programming error : bad method / signature for Callback"

Do you see what I’m trying to do? Use maxmsp java library or
at least make some thispatcher scripting with jython…

Cole


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