/*
 *	ej.mtof by Emmanuel Jourdan, Ircam  02 2005
 *	MIDI to Frequency (with tuning adjustment)
 *
 *	$Revision: 1.1 $
 *	$Date: 2006/04/27 16:58:16 $
 */

package ej;

import com.cycling74.max.Atom;

public class mtof extends ej {
	private static final String[] INLET_ASSIST = new String[]{ "MIDI note number in (int/float/list)" };
	private static final String[] OUTLET_ASSIST = new String[]{ "Frequency out"};

	private float tuning = 440;
	private int pitch_reference = 69;
	
	public mtof(float[] args) {
		declareTypedIO("a", "l");
		createInfoOutlet(true);
		
		argsManager(args);
		declareAttribute("tuning", "getTunnig", "setTunnig");
		declareAttribute("pitch_reference", "getPitchReference", "setPitchReference");
		
		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);
	}
	
	private void argsManager(float[] args) {
		switch (args.length) {
			case 1:
				setTunnig(args[0]);
				break;
			case  2:
				setPitchReference((int) args[1]);
				break;
		}
	}	

	private void setTunnig(float f) {
		if (f > 0 && f < 20000)
			tuning = f;
	}
	
	private float getTunnig() {
		return tuning;
	}

	private void setPitchReference(int i) {
		if (i > 0 && i < 127) {
			pitch_reference = i;
		}
	}
	
	private int getPitchReference() {
		return pitch_reference;
	}
	
	public void bang() {
		error("ej.mtof: doesn't understand bang");
	}
	
	public void inlet(float f) {
		outlet(0, (float) (tuning * Math.pow(2,(f - pitch_reference)/12)) );
	}

	public void list(float[] list) {
		for (int i = 0; i < list.length; i++) {
			list[i] = (float) (tuning * Math.pow(2,(list[i] - pitch_reference) / 12));
		}
		
		outlet(0, list);
	}
	
	public void anything(String s, Atom[] args) {
		error("ej.mtof: doesn't understand " + s + " " + Atom.toOneString(args));
	}	
}
@@ -108,17 +108,17 @@
 sion: 1.
-1
+2
  $%0A *%09$D
@@ -138,21 +138,66 @@
 27 1
-6:58:16 $%0A */
+8:42:22 $%0A */%0A%0A// test de commit depuis ecplise sur mac...
 %0A%0Apa

test de commit depuis eclipse sur mac