[jsyn] Basic Soundtoy in JSyn

jsyn at music.columbia.edu jsyn at music.columbia.edu
Mon Nov 6 11:02:11 EST 2006


On Mon, 2006-11-06 at 09:53 -0500, jsyn at music.columbia.edu wrote:
> (disclaimer: message is pre-coffee)
> 
> I guess it depends on the target audience, but if you're going for  
> simple, this seems to be overkill, and confusing. Making a thread,  
> sleeping it to animate, etc... this is advanced stuff. I know what  
> I'm doing and I don't feel invited to play with this code!
> 
> And it bothers me that the size of the square is just an animation,  
> and not actually bound to the SynthEnvelope. It's a convincing  
> animation, but if students are going to be poring over the code, you  
> might as well make the animation meaningful.

There will be other examples where the animation is bound to the JSyn
code. But I needed something relatively simple to start with. This will
not be their first JSyn GUI application, but the third lecture of about
six just introducing GUI stuff. The first example is a window which
plays back samples (via JSyn) for common window events (maximised,
minimised, etc.) The second uses sliders and buttons to control the
parameters of a simple JSyn synth. There's a simpler version of the
posted program without threads, animation (and without JSyn) given
earlier on in the same lecture. So it's not a dive straight into the
deep end. Also I have an example where a sample is "read" by a smiley
face which opens and closes its mouth, the amount of mouth-opening being
controlled by an envelopefollower tracking the (JSyn) sample playback.
But this would be the first lecture to mix graphics animation and JSyn.

> AND, while I'm throwing my criticism around :p, your coding style is  
> less than conventional (who cares... except you're teaching a class).  
> Indentation, capital letters for variables, mixing AWT and swing, etc.

Hmmm.... Maybe I should be using lower case variable names. But I prefer
the indenting style for people who have never programmed before. In
short, the open and end braces are in the same vertical column. I've
found that this helps students who are confused about the positioning of
braces. And I've had a lot of that. I do recommend that they check out
standard formatting (code beautifiers and the like), but only after they
are confident with programming. Why? I find that the confusion saved by
a more meaningful indentation outweighs the problem of someone more
experienced switching indentation style later on. Though that doesn't
apply to lower case variable names.

When you say that I'm mixing AWT and Swing, could you be more specific.
I have to import various awt classes that are used in Swing, such as
Color and Graphics. I did check as Java changes quite frequently (e.g.
I've only just found out that you don't have to getContentPane() any
more, the change in the Runnable interface some years ago, etc.), but my
programs won't compile without java.awt.* and java.awt.event.* included.
So I can't see that I've mixed more AWT and Swing than I'm forced to.

> Solution? Look at processing [processing.org] for multimedia stuff.  
> It's essentially a simple IDE  with a very neat class that extends  
> Applet and gives you a TON of [fun]ctions in the main namespace. And,  
> you can use jsyn stuff as you normally would. Here's the equivalent  
> processing code to draw your box:

But there's a problem here. If I teach them to use a non-standard class
with special purpose methods, then they won't be able to write "generic"
Java without the IDE.

> int size=0;
> 
> void setup() {
>    size(200,200);
>    rectMode(CENTER);
>    stroke(255);
>    fill(0);
> }
> 
> void draw() {
>    background(0);
>    rect(width/2, height/2, size, size);
>    size++;
> }
> 
> void mousePressed() {
>    size=0;
> }
> 
> It took less than 2 minutes to write, and should be self-explanatory.  
> It took me longer than that to understand what was going on with your  
> code!

I agree that what you write is simpler and easier to write. But it isn't
Java. Effectively it's another language which is cross-compiled (or
otherwise converted) into Java. I'm very hesitant to mix languages in a
single module.

> good morning,
> kevin

Cheers,

Ross-c



More information about the JSyn mailing list