From nick at cassiel.com Sat Mar 1 02:35:50 2008 From: nick at cassiel.com (Nick Rothwell) Date: Sat Mar 1 02:35:42 2008 Subject: [java-dev] Announce: Python for MaxMSP (beta) In-Reply-To: <3CBBA76A-8584-4EEF-9A45-7D8B31BE3799@gmail.com> References: <3CBBA76A-8584-4EEF-9A45-7D8B31BE3799@gmail.com> Message-ID: 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:// www.cassiel.com From spondoo at hotmail.com Sat Mar 1 08:24:03 2008 From: spondoo at hotmail.com (Adam) Date: Sat Mar 1 08:24:06 2008 Subject: [java-dev] Help! Acceleration data peak finder Message-ID: <202e5.47c97512@www.cycling74.com> Hi! My situation: I currently have a max msp patch that uses 2 "ctlin" objects (one for x values and one for y values) to get x and y acceleration data from an external device. The data is being transfered via osculator and is sending midi signals to the patch. My aim: I want to end up with a patch that allows x and y acceleration data to be able to control a midi file, e.g play a drum sound. However, I only want the file to be played if the incoming acceleration values satisfy a number of conditions. The java/max msp object: * I want to create java script that will be able to be used as an object in max msp. * The object should continually analyze incoming x and y acceleration values. * In the objects left inlet, I want to be able to set and adjust the trigger-range e.g. a low and high trigger threshold. The low value will be the minimum value able to trigger a midi file at a low volume and the high value will be the maximum value able to trigger a midi file at the highest volume. * Also in the left inlet, I want to be able to set and adjust the minimum-peak-gap. This will consist of two things, a value in milliseconds and another value that the acceleration data may not exceed by within that time frame. E.g. for 30 milliseconds the acceleration data may not increase by more than 20. * Therefore only data that fulfills the above conditions, will emerge from the outlet of the object, causing the midifile to play. My skills: I am not very experienced when it comes to programming and have no idea where to start or what to use? If anyone could offer help or show me some examples, I would really appreciate it! Thanks A From adamjmurray at gmail.com Tue Mar 4 00:45:07 2008 From: adamjmurray at gmail.com (Adam Murray) Date: Tue Mar 4 00:45:13 2008 Subject: [java-dev] getParentPatcher().getPath() does not always work in the constructor Message-ID: <2045c.47ccfe03@www.cycling74.com> I noticed some inconsistent behavior with getParentPatcher().getPath() when used inside a constructor. When I open the patch for the first time, it will return null. If I delete the mxj object and undo, then it will return the correct path. It's like the parent patcher doesn't initialize until after the mxj object, which seems backwards to me. Is it a bug? I can work around this problem by using a MaxQelem, which so far seems to work flawlessly. import com.cycling74.max.Executable; import com.cycling74.max.MaxObject; import com.cycling74.max.MaxQelem; public class test extends MaxObject { public test() { post("path: " + getParentPatcher().getPath()); initializer.set(); } private MaxQelem initializer = new MaxQelem(new Executable() { public void execute() { post("inside qelem, path: " + getParentPatcher().getPath()); } }); protected void notifyDeleted() { initializer.release(); } } -- Adam Murray compusition.com From topher at topher.com Tue Mar 4 09:23:36 2008 From: topher at topher.com (topher lafata) Date: Tue Mar 4 09:23:40 2008 Subject: [java-dev] getParentPatcher().getPath() does not always work in the constructor In-Reply-To: <2045c.47ccfe03@www.cycling74.com> References: <2045c.47ccfe03@www.cycling74.com> Message-ID: <4C52AB64-C509-478A-A5DD-F7CACE2DAB8D@topher.com> seems like a good workaround. i don't know exactly why this happens but i remember similar behavior when i was working on that stuff. its like the pointer to the parent patcher isn't initialized until the entire patcher loads. you could also see if it is valid in the loadbang() method. t On Mar 3, 2008, at 23:45 PM, Adam Murray wrote: > > I noticed some inconsistent behavior with getParentPatcher().getPath > () when used inside a constructor. > > When I open the patch for the first time, it will return null. If I > delete the mxj object and undo, then it will return the correct > path. It's like the parent patcher doesn't initialize until after > the mxj object, which seems backwards to me. Is it a bug? > > I can work around this problem by using a MaxQelem, which so far > seems to work flawlessly. > > > import com.cycling74.max.Executable; > import com.cycling74.max.MaxObject; > import com.cycling74.max.MaxQelem; > > public class test extends MaxObject { > > public test() { > post("path: " + getParentPatcher().getPath()); > initializer.set(); > } > > private MaxQelem initializer = new MaxQelem(new Executable() { > public void execute() { > post("inside qelem, path: " + getParentPatcher().getPath()); > } > }); > > protected void notifyDeleted() { > initializer.release(); > } > > } > > > -- > Adam Murray > compusition.com > _______________________________________________ > java-dev mailing list > java-dev@cycling74.com > http://www.cycling74.com/mailman/listinfo/java-dev From cycling74forum at opuslocus.net Tue Mar 4 15:41:18 2008 From: cycling74forum at opuslocus.net (John Pitcairn) Date: Tue Mar 4 15:41:20 2008 Subject: [java-dev] Re: getParentPatcher().getPath() does not always work in the constructor In-Reply-To: <2045c.47ccfe03@www.cycling74.com> Message-ID: <204c5.47cdd00d@www.cycling74.com> It's the same in JavaScript, where you can't get this.patcher's parent patcher immediately, it needs to be done from the js loadbang(). And there are similar issues in native C, we can't even rely on loadbang(), we need to defer_low() if we want to know anything about the patcher structure. Seems the parent heirarchy isn't fully discoverable until some time after the patcher loadbangs its contained objects. There was some discussion of this on the dev-list recently. From adamjmurray at gmail.com Tue Mar 4 16:20:34 2008 From: adamjmurray at gmail.com (Adam Murray) Date: Tue Mar 4 16:20:36 2008 Subject: [java-dev] Re: getParentPatcher().getPath() does not always work in the constructor In-Reply-To: <204c5.47cdd00d@www.cycling74.com> Message-ID: <204cb.47cdd942@www.cycling74.com> Quote: johnpitcairn wrote on Tue, 04 March 2008 14:41 ---------------------------------------------------- > It's the same in JavaScript, where you can't get this.patcher's parent patcher immediately, it needs to be done from the js loadbang(). > > And there are similar issues in native C, we can't even rely on loadbang(), we need to defer_low() if we want to know anything about the patcher structure. Seems the parent heirarchy isn't fully discoverable until some time after the patcher loadbangs its contained objects. There was some discussion of this on the dev-list recently. ---------------------------------------------------- Too bad the Max APIs don't provide an onPatchInit() callback. -- Adam Murray compusition.com From i.m.klif at gmail.com Wed Mar 5 16:31:55 2008 From: i.m.klif at gmail.com (ivan marusic) Date: Wed Mar 5 16:31:58 2008 Subject: [java-dev] net.mail problems Message-ID: <2055a.47cf2d6b@www.cycling74.com> i use max for aprox 10 years, but i have no knowledge of java, and i need some help here. trying to load net.mail help files, i get the following errors: • error: java.lang.NoClassDefFoundError: javax/mail/MessagingException • error: (mxj) unable to alloc instance of net.mail.send • error: java.lang.NoClassDefFoundError: javax/mail/MessagingException • error: (mxj) unable to alloc instance of net.mail.recv i found some info in java tutorials (tutorial 9)- it seemed i miss some libraries. i managed to install java.mail - i simply copied mail.jar to java/lib directory. i'm lost when it comes to "JavaBeans Activation Framework". I have no idea what to download and how to install...... with only mail.jar installed, net.mail.recv initiates fine, but still fails to check mail. i get the following errors: javax.mail.MessagingException: Connect failed; nested exception is: java.net.ConnectException: Operation timed out at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:161) at javax.mail.Service.connect(Service.java:288) at javax.mail.Service.connect(Service.java:169) at net.mail.recv.saveMessage(recv.java:43) Caused by: java.net.ConnectException: Operation timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:430) at java.net.Socket.connect(Socket.java:520) at java.net.Socket.connect(Socket.java:470) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189) at com.sun.mail.pop3.Protocol.(Protocol.java:94) at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:214) at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:157) ... 3 more exceptions: javax.mail.MessagingException: Connect failed; nested exception is: java.net.ConnectException: Operation timed out From nick at cassiel.com Wed Mar 5 16:48:24 2008 From: nick at cassiel.com (Nick Rothwell) Date: Wed Mar 5 16:48:30 2008 Subject: [java-dev] net.mail problems In-Reply-To: <2055a.47cf2d6b@www.cycling74.com> References: <2055a.47cf2d6b@www.cycling74.com> Message-ID: On 5 Mar 2008, at 23:31, ivan marusic wrote: > javax.mail.MessagingException: Connect failed; > nested exception is: > java.net.ConnectException: Operation timed out > at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:161) That pretty much tells you what you need to know: you're trying to do POP3 mail and the connection to the server is timing out. Error messages can be useful: sometimes a cigar is just a cigar. nick rothwell -- composition, systems, performance -- http:// www.cassiel.com From i.m.klif at gmail.com Wed Mar 5 17:03:33 2008 From: i.m.klif at gmail.com (ivan marusic) Date: Wed Mar 5 17:03:34 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: Message-ID: <20563.47cf34d5@www.cycling74.com> thank you for your prompt reply :) i'm still confused about missing javabean activation.jar file??? i'm quite sure it is not installed on my machine. have no idea what package to download and where from?? From i.m.klif at gmail.com Wed Mar 5 17:59:01 2008 From: i.m.klif at gmail.com (ivan marusic) Date: Wed Mar 5 17:59:03 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: Message-ID: <2056a.47cf41d5@www.cycling74.com> i'm probably just tired, or it is a really bad day. it took me 2 hours to find Javabeans activation framework download at Sun.com. I found it. it works. Only, help file doesn't want to check gmail account with the same error that i allready posted. Any hints?? Or experiences with other free mail services? From mdk at relivethefuture.com Thu Mar 6 03:02:22 2008 From: mdk at relivethefuture.com (mdk) Date: Thu Mar 6 03:02:24 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <2056a.47cf41d5@www.cycling74.com> Message-ID: <20588.47cfc12d@www.cycling74.com> whats the default timeout? maybe try increasing it. if its still not getting anywhere i would try to manually telnet to the POP3 server and see if it responds, then if that appears to work but the java code doesnt then use a network monitor to see whats happening on the wire, e.g. wireshark : http://www.wireshark.org/ Are you trying the code from within max or from your development setup? From i.m.klif at gmail.com Thu Mar 6 03:45:56 2008 From: i.m.klif at gmail.com (ivan marusic) Date: Thu Mar 6 03:46:14 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <20588.47cfc12d@www.cycling74.com> Message-ID: <2058b.47cfcb5a@www.cycling74.com> hmmmmm. as i said, i'm a complete novice when it comes to java. i managed to check mail on small local server, but couldn't do it on gmail. i checked it on max. i have no idea where to change timeout settings. i checked net.mail.recv code, but don't remember seeing anything that looked like timeout value. thanx for your help From mdk at relivethefuture.com Thu Mar 6 04:21:14 2008 From: mdk at relivethefuture.com (mdk) Date: Thu Mar 6 04:21:15 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <2058b.47cfcb5a@www.cycling74.com> Message-ID: <20590.47cfd3aa@www.cycling74.com> right, i think the problem is that pop3 access to google mail requires SSL, if you look here for details : http://mail.google.com/support/bin/answer.py?answer=13287 this page is a bit easier to read : http://www.runpcrun.com/google-pop3-access I havent used the max net.mail classes so I dont know how much it exposes of the underlying mail library, but hopefully you can set the right configuration. From morgan at morgansutherland.net Mon Mar 10 17:31:18 2008 From: morgan at morgansutherland.net (Morgan Sutherland) Date: Mon Mar 10 17:31:20 2008 Subject: [java-dev] filter algorithm in mxj~ Message-ID: <9b850fd0803101631k3c700805uaa84dcc9f457047d@mail.gmail.com> I'm currently trying to implement the following filter algorithm from music-dsp (for school ;): --------------------------------------------------------- r = rez amount, from sqrt(2) to ~ 0.1 f = cutoff frequency (from ~0 Hz to SampleRate/2 - though many synths seem to filter only up to SampleRate/4) The filter algo: out(n) = a1 * in + a2 * in(n-1) + a3 * in(n-2) - b1*out(n-1) - b2*out(n-2) Lowpass: c = 1.0 / tan(pi * f / sample_rate); a1 = 1.0 / ( 1.0 + r * c + c * c); a2 = 2* a1; a3 = a1; b1 = 2.0 * ( 1.0 - c*c) * a1; b2 = ( 1.0 - r * c + c * c) * a1; Hipass: c = tan(pi * f / sample_rate); a1 = 1.0 / ( 1.0 + r * c + c * c); a2 = -2*a1; a3 = a1; b1 = 2.0 * ( c*c - 1.0) * a1; b2 = ( 1.0 - r * c + c * c) * a1; --------------------------------------------------------- My code compiles, but I'm not getting any sound from the outlet. I suspect this is because of the algorithm, which uses input and output values from 'back in time': out[i] = ( a1 * in[i] + a2 * in[i-1] + a3 * in[i-2] - b1*out[i-1] - b2*out[i-2] ); Do I need to rewrite this with temp variables? My code looks like this: --------------------------------------------------------- import com.cycling74.max.*; import com.cycling74.msp.*; import java.lang.Math.*; public class filt extends MSPPerformer { private float freq = 500.0f; private float c = 0.0f; private float r = 0.1f; private float a1 = 0.0f; private float a2 = 0.0f; private float a3 = 0.0f; private float b1 = 0.0f; private float b2 = 0.0f; private float tin1 = 0.0f, tin2 = 0.0f, to3 = 0.0f, to4 = 0.0f; private float pi = 3.1415926f; private double sr; private static final String[] INLET_ASSIST = new String[]{ "input (sig)" }; private static final String[] OUTLET_ASSIST = new String[]{ "output (sig)" }; public filt(float gain) { declareInlets(new int[]{SIGNAL, DataTypes.FLOAT}); declareOutlets(new int[]{SIGNAL}); setInletAssist(0, "signal input"); setInletAssist(1, "freq"); setOutletAssist(OUTLET_ASSIST); } public void inlet(float f) { freq = f; } public void dspsetup(MSPSignal[] ins, MSPSignal[] outs) { //Max gives us the sample-rate 'sr' on load sr = ins[0].sr; post("dspsetup was called.'"); } public void perform(MSPSignal[] ins, MSPSignal[] outs) { c = 1.0f / (float)Math.tan((double)(pi * freq / (float)sr)); a1 = 1.0f / ( 1.0f + r * c + c * c); a2 = 2f* a1; a3 = a1; b1 = 2.0f * ( 1.0f - c*c) * a1; b2 = ( 1.0f - r * c + c * c) * a1; int i; float[] in = ins[0].vec; float[] out = outs[0].vec; int vec_size = ins[0].n; for(i = 0; i < vec_size; i++) { out[i] = ( a1 * in[i] + a2 * in[i-1] + a3 * in[i-2] - b1*out[i-1] - b2*out[i-2] ); } } } --------------------------------------------------------- -- Morgan Sutherland From morgan at morgansutherland.net Mon Mar 10 18:06:57 2008 From: morgan at morgansutherland.net (Morgan Sutherland) Date: Mon Mar 10 18:07:02 2008 Subject: [java-dev] Re: filter algorithm in mxj~ In-Reply-To: <9b850fd0803101631k3c700805uaa84dcc9f457047d@mail.gmail.com> References: <9b850fd0803101631k3c700805uaa84dcc9f457047d@mail.gmail.com> Message-ID: <9b850fd0803101706m631771edy1dfd1d0c6de2df5e@mail.gmail.com> Resolved my problem with variable swapping: import com.cycling74.max.*; import com.cycling74.msp.*; import java.lang.Math.*; public class filt extends MSPPerformer { private float freq = 500.0f; private float c = 0.0f; private float r = 0.1f; private float a1 = 0.0f; private float a2 = 0.0f; private float a3 = 0.0f; private float b1 = 0.0f; private float b2 = 0.0f; private float tin1 = 0.0f, tin2 = 0.0f, tout1 = 0.0f, tout2 = 0.0f; private float pi = 3.1415926f; private double sr; private static final String[] INLET_ASSIST = new String[]{ "input (sig)" }; private static final String[] OUTLET_ASSIST = new String[]{ "output (sig)" }; public filt(float gain) { declareInlets(new int[]{SIGNAL, DataTypes.FLOAT}); declareOutlets(new int[]{SIGNAL}); setInletAssist(0, "signal input"); setInletAssist(1, "freq"); setOutletAssist(OUTLET_ASSIST); } public void inlet(float f) { freq = f; } public void dspsetup(MSPSignal[] ins, MSPSignal[] outs) { //Max gives us the sample-rate 'sr' on load sr = ins[0].sr; post("dspsetup was called.'"); } public void perform(MSPSignal[] ins, MSPSignal[] outs) { c = 1.0f / (float)Math.tan((double)(pi * freq / (float)sr)); a1 = 1.0f / ( 1.0f + r * c + c * c); a2 = 2f* a1; a3 = a1; b1 = 2.0f * ( 1.0f - c*c) * a1; b2 = ( 1.0f - r * c + c * c) * a1; int i; float[] in = ins[0].vec; float[] out = outs[0].vec; int vec_size = ins[0].n; for(i = 0; i < vec_size; i++) { out[i] = ( a1 * in[i] + a2 * tin1 + a3 * tin2 - b1*tout1 - b2*tout2 ); tin2 = tin1; tin1 = in[i]; tout2 = tout1; tout1 = out[i]; } } } On Mon, Mar 10, 2008 at 7:31 PM, Morgan Sutherland wrote: > I'm currently trying to implement the following filter algorithm from > music-dsp (for school ;): > > --------------------------------------------------------- > r = rez amount, from sqrt(2) to ~ 0.1 > f = cutoff frequency > (from ~0 Hz to SampleRate/2 - though many > synths seem to filter only up to SampleRate/4) > > The filter algo: > out(n) = a1 * in + a2 * in(n-1) + a3 * in(n-2) - b1*out(n-1) - b2*out(n-2) > > Lowpass: > c = 1.0 / tan(pi * f / sample_rate); > > a1 = 1.0 / ( 1.0 + r * c + c * c); > a2 = 2* a1; > a3 = a1; > b1 = 2.0 * ( 1.0 - c*c) * a1; > b2 = ( 1.0 - r * c + c * c) * a1; > > Hipass: > c = tan(pi * f / sample_rate); > > a1 = 1.0 / ( 1.0 + r * c + c * c); > a2 = -2*a1; > a3 = a1; > b1 = 2.0 * ( c*c - 1.0) * a1; > b2 = ( 1.0 - r * c + c * c) * a1; > --------------------------------------------------------- > > My code compiles, but I'm not getting any sound from the outlet. I > suspect this is because of the algorithm, which uses input and output > values from 'back in time': > > out[i] = ( a1 * in[i] + a2 * in[i-1] + a3 * in[i-2] - b1*out[i-1] - > b2*out[i-2] ); > > Do I need to rewrite this with temp variables? > > > My code looks like this: > > --------------------------------------------------------- > import com.cycling74.max.*; > import com.cycling74.msp.*; > import java.lang.Math.*; > > public class filt extends MSPPerformer > { > private float freq = 500.0f; > private float c = 0.0f; > private float r = 0.1f; > > private float a1 = 0.0f; > private float a2 = 0.0f; > private float a3 = 0.0f; > private float b1 = 0.0f; > private float b2 = 0.0f; > > private float tin1 = 0.0f, tin2 = 0.0f, to3 = 0.0f, to4 = 0.0f; > > private float pi = 3.1415926f; > > private double sr; > > private static final String[] INLET_ASSIST = new String[]{ > "input (sig)" > }; > private static final String[] OUTLET_ASSIST = new String[]{ > "output (sig)" > }; > > > public filt(float gain) > { > declareInlets(new int[]{SIGNAL, DataTypes.FLOAT}); > declareOutlets(new int[]{SIGNAL}); > > setInletAssist(0, "signal input"); > setInletAssist(1, "freq"); > setOutletAssist(OUTLET_ASSIST); > } > > public void inlet(float f) > { > > freq = f; > > > } > > public void dspsetup(MSPSignal[] ins, MSPSignal[] outs) > { > //Max gives us the sample-rate 'sr' on load > > sr = ins[0].sr; > > post("dspsetup was called.'"); > > } > > public void perform(MSPSignal[] ins, MSPSignal[] outs) > { > > c = 1.0f / (float)Math.tan((double)(pi * freq / (float)sr)); > > a1 = 1.0f / ( 1.0f + r * c + c * c); > a2 = 2f* a1; > a3 = a1; > b1 = 2.0f * ( 1.0f - c*c) * a1; > b2 = ( 1.0f - r * c + c * c) * a1; > > int i; > float[] in = ins[0].vec; > float[] out = outs[0].vec; > int vec_size = ins[0].n; > > for(i = 0; i < vec_size; i++) > { > > out[i] = ( a1 * in[i] + a2 * in[i-1] + a3 * in[i-2] - b1*out[i-1] - > b2*out[i-2] ); > > > } > } > } > --------------------------------------------------------- > > > > > -- > Morgan Sutherland > -- Morgan Sutherland From adamjmurray at gmail.com Fri Mar 21 10:25:11 2008 From: adamjmurray at gmail.com (Adam Murray) Date: Fri Mar 21 10:25:21 2008 Subject: [java-dev] pattr support in Max 5? Message-ID: <20d47.47e3e166@www.cycling74.com> Is MXJ getting any pattr support in Max 5? Just wondering... -- Adam Murray compusition.com From vboehm at gmx.ch Sat Mar 22 05:30:15 2008 From: vboehm at gmx.ch (=?ISO-8859-1?Q?volker_b=F6hm?=) Date: Sat Mar 22 05:28:13 2008 Subject: [java-dev] Bug in AudioFileBuffer with different sample sizes? Message-ID: <4B22B36C-030D-4626-A02D-6374CBD66B81@gmx.ch> hallo, i'm using AudioFileBuffer from the max mxj api to read soundfiles with varying sample sizes. when i try to output the floating point data from the buf field, i get correct results only for 16 bit files. 8 bit, 24 bit and 32 bit are all wrong, which to me looks like errors in int-to-float-conversion. do i overlook something here? thanks, volker. simple test class: import com.cycling74.max.*; import com.cycling74.msp.*; public class test_afb extends MaxObject { private AudioFileBuffer afb = null; public test_afb (Atom[] args) { declareInlets(new int[]{DataTypes.ALL}); declareOutlets(new int[]{DataTypes.ALL}); } /* load soundfile----------------------------------------------------*/ publicvoid open( String path ) { String fname = MaxSystem.locateFile(path); post("filename: "+fname); try { afb = new AudioFileBuffer(fname); System.out.println("frame length: "+ afb.getFrameLength()); System.out.println("samp size in bits: "+ afb.getSampleSizeInBits ()); System.out.println("num channels: "+ afb.getChannels()); System.out.println("big endian: "+ afb.isBigEndian()); System.out.println("sample rate: "+ afb.getSampleRate()); } catch(Exception e) { error("mxj test_afb: sorry, can't open that file!"); } } /* output sample value at index from channel 1-------------------*/ publicvoid inlet (int index) { outlet(0, afb.buf[0][index]); } } simple test patch: #P window setfont "Sans Serif" 9.; #P flonum 225 196 67 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P flonum 93 194 67 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 225 121 44 9 0 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0; #P window linecount 1; #P newex 225 166 54 196617 peek~ aha; #P newex 93 117 68 196617 prepend open; #P newex 93 166 93 196617 mxj test_afb; #P newex 351 118 81 196617 prepend replace; #P button 93 39 15 0; #P newex 93 62 56 196617 opendialog; #P newex 351 140 83 196617 buffer~ aha 100; #P comment 217 105 100 196617 sample index; #P fasten 8 0 5 0 230 151 98 151; #P connect 8 0 7 0; #P connect 5 0 9 0; #P connect 6 0 5 0; #P connect 3 0 2 0; #P connect 2 0 6 0; #P connect 7 0 10 0; #P fasten 2 0 4 0 98 88 356 88; #P connect 4 0 1 0; #P window clipboard copycount 11; From topher at topher.com Sat Mar 22 11:44:42 2008 From: topher at topher.com (topher lafata) Date: Sat Mar 22 11:50:45 2008 Subject: [java-dev] Bug in AudioFileBuffer with different sample sizes? In-Reply-To: <4B22B36C-030D-4626-A02D-6374CBD66B81@gmx.ch> References: <4B22B36C-030D-4626-A02D-6374CBD66B81@gmx.ch> Message-ID: <99B3C7F1-64EC-4818-86FF-B45090AAB1B1@topher.com> i dont think you have overlooked anything. it is very possible there are bugs with those bit depths. Regardless here is the source for the class. You could copy it and make your own. package com.cycling74.msp; import com.cycling74.max.MessageReceiver; import javax.sound.sampled.*; import java.io.FileNotFoundException; import java.io.*; /** * A utility class for loading audio data off of disk and into memory. The data is translated from the * native file format into the the floating point format used by msp. * @author Topher LaFata */ public class AudioFileBuffer { /** * If an instance of MessageReceiver is passed into the constructor the FINISHED_READING message will be * sent to it when the requested file is successfully loaded into memory. File loading occurs asynchronously. */ public static final int FINISHED_READING = 1; //file writing is not yet implemented //public static final int FINISHED_WRITING = 2; private File _file; private AudioInputStream _ais; private AudioFormat _aformat; private int _num_channels; private long _framelength; //length of current file is frames private int _framesize;//size of each frame in bytes private int _sample_size_in_bits; private boolean _big_endian; private float _sr; /** * buf contains the audio samples loaded off of disk deinterleaved by channel into a 2 dimensional * floating point array. The first dimension corresponds to the audio channel and the second dimension * corresponds to the audio data itself. Thus a stereo audio file would have the samples for the left channel * at buf[0][0...framelength - 1] and the right channel at buf[1] [0...framelength - 1] */ public float[][] buf; //this is affected by sample rate private MessageReceiver _client = null; private buf_filler _bft; /** * Constructor. * @param filename Absolute native path of the audio file to be loaded into memory. */ public AudioFileBuffer(String filename)throws FileNotFoundException, IOException, UnsupportedAudioFileException { _client = null; openmp3(filename); } /** * Constructor. * @param filename Absolute native path of the audio file to be loaded into memory. * @param client instance of MessageReceiver which will be notified when file is finished being loaded into memory. * This information may or may not be relevant since the member buffer,buf[][], containing the audio data will be valid and zero filled * when the constructor returns. */ public AudioFileBuffer(String filename, MessageReceiver client) throws FileNotFoundException, IOException, UnsupportedAudioFileException { _client = client; open(filename); } public void openmp3(String filename)throws FileNotFoundException, IOException, UnsupportedAudioFileException { _file = new File(filename); if(!_file.exists()) throw new FileNotFoundException("Unable to find file "+filename); kill_buf_filler(); AudioFileFormat baseFileFormat = null; AudioFormat baseFormat = null; baseFileFormat = AudioSystem.getAudioFileFormat(_file); baseFormat = baseFileFormat.getFormat(); // Audio type such as MPEG1 Layer3, or Layer 2, or ... System.out.println("FORMAT "+baseFileFormat.getType().toString()); // System.out.println("sr is "+baseFormat.getSampleRate()); // System.out.println("channels is "+baseFormat.getChannels()); // System.out.println("frame rate is "+baseFormat.getFrameRate()); // System.out.println("frame size is "+baseFormat.getFrameSize()); // System.out.println("is big endian "+baseFormat.isBigEndian()); AudioInputStream in = AudioSystem.getAudioInputStream(_file); System.out.println("ms is "+in.markSupported()); System.out.println("mp3 fl is "+in.getFrameLength()); //AudioFormat baseFormat = in.getFormat(); AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels()*2, baseFormat.getSampleRate(),true) ; _ais = AudioSystem.getAudioInputStream(decodedFormat, in); //find the length of the converted mp3 in frames. //unfortunately we don't get this with the whole new _ais decoded crap //we make ll one frame in length int framelength = baseFormat.getChannels()*2; System.out.println("framelength is "+framelength); byte[] ll = new byte[framelength]; int l = ll.length; int totframes = 0; int bytesread = 0; while((bytesread = _ais.read(ll,0,framelength)) != -1) { totframes++; if(bytesread < framelength) { System.out.println("read lesss than framelength "+bytesread); } } System.out.println("frame length is "+totframes); System.out.println("ais is "+_ais.markSupported()); _ais = AudioSystem.getAudioInputStream(decodedFormat, in); _aformat = _ais.getFormat(); // System.out.println("sr is "+_aformat.getSampleRate()); // System.out.println("channels is "+_aformat.getChannels()); // System.out.println("frame rate is "+_aformat.getFrameRate()); // System.out.println("frame length is "+_ais.getFrameLength()); // System.out.println("frame size is "+_aformat.getFrameSize()); // System.out.println("is big endian "+_aformat.isBigEndian()); // System.out.println("s size in bits "+_aformat.getSampleSizeInBits ()); _sr = _aformat.getSampleRate(); _num_channels = _aformat.getChannels(); _framelength = totframes; _framesize = framelength; _sample_size_in_bits = _aformat.getSampleSizeInBits(); _big_endian = _aformat.isBigEndian(); buf = new float[_num_channels][(int)_framelength]; _bft = new buf_filler(this); _bft.start(); } /** * Load a different audio file into memory using this instance of AudioFileBuffer. Previous audio data is disgarded and * buf[][] member variable reflects the number of channels and framesize of the new audio file.. * @param filename Absolute native path of the audio file to be loaded into memory. */ public void open(String filename)throws FileNotFoundException, IOException, UnsupportedAudioFileException { _file = new File(filename); if(!_file.exists()) throw new FileNotFoundException("Unable to find file "+filename); //kill the previous buf filler if it is already running kill_buf_filler(); //This is so we have mark supported and get efficiency in our disk reads InputStream fileInputStream = new FileInputStream(_file); InputStream inputStream = new BufferedInputStream(fileInputStream); try{ _ais = AudioSystem.getAudioInputStream(inputStream); }catch(IOException ioe) { throw ioe; } catch(UnsupportedAudioFileException uafe) { throw uafe; } _aformat = _ais.getFormat(); if(_aformat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { throw new UnsupportedAudioFileException("AudioBuffer currently only supports"+ " PCM_SIGNED encodings"); } _sr = _aformat.getSampleRate(); _num_channels = _aformat.getChannels(); _framelength = _ais.getFrameLength(); _framesize = _aformat.getFrameSize(); _sample_size_in_bits = _aformat.getSampleSizeInBits(); _big_endian = _aformat.isBigEndian(); buf = new float[_num_channels][(int)_framelength]; _bft = new buf_filler(this); _bft.start(); } /** * Get the sample rate of the current audio file. It is important to note that * the current msp sampling rate is currently not considered when the audio file * is being decoded from disk. This means that an audio file saved with a different * sampling rate from the current msp sampling rate needs additional sample rate conversion * done on its audio data after it is loaded to play back at the expected speed. * This conversion is currently not done by default. */ public float getSampleRate() { return _sr; } /* public AudioFormat getAudioFormat() { return _aformat; } */ /** * Get the sample size in bits of the current audio file. For example, 8,16,24. */ public int getSampleSizeInBits() { return _sample_size_in_bits; } /** * Was the current audio file big endian format. */ public boolean isBigEndian() { return _big_endian; } /** * Get the number of sample frames in the audio file.A frame consists of * sample data for all channels at a particular instant in time.Thus a mono * audio file which has 1000 samples will have a frame length of 1000 with * each frame containing one sample. A stereo audio file with 2000 samples would * have a frame length of 1000 with each frame containing 2 samples, one for each * the left and right channels. */ public long getFrameLength() { return _framelength; } /** * Get the number of channels of the current audio file. */ public int getChannels() { return _num_channels; } /** *Get the length of the current audio file in milliseconds. * This is equivalent to: *
	* frame length / (sample rate / 1000)
	*
*/ public float getLengthMs() { return (float)(_framelength / (getSampleRate() / 1000)); } private void fill_buf() { System.out.println("filling buf"); byte[] tmp = new byte[2048]; int bytesread = 0; short ss = 0; int si = 0; int wh = 0;//points to sample frame try{ while((bytesread = _ais.read(tmp,0,tmp.length)) > 0) { if(wh % 1000 == 0) System.out.println("wh is "+wh); for(int i = 0; i < bytesread;i+= _framesize) { //if it is not bigendian make it so now... //this is happening per frame..maybe not the best approach if(!_big_endian && _sample_size_in_bits > 8) { byte t1 = 0; switch(_sample_size_in_bits) { case 16: for(int ii = i; ii < i + _framesize;ii += 2) { t1 = tmp[ii]; tmp[ii] = tmp[ii+1]; tmp[ii +1] = t1; } break; case 24: for(int ii = i; ii < i + _framesize;ii += 3) { t1 = tmp[ii]; tmp[ii] = tmp[ii+3]; tmp[ii +3] = t1; } break; default: } } //deinterleave and convert to float for(int c = 0;c < _num_channels;c++) { int ch_offset = (c * _num_channels); switch (_sample_size_in_bits) { case 8: ss = (short)(tmp[i+c] & 0xff); buf[c][wh] = (float)ss/16384; break; case 16: ss = (short)(((tmp[i+ch_offset] & 0xff) << 8) | (tmp[i +ch_offset+1] & 0xff)); buf[c][wh] = (float)ss/Short.MAX_VALUE; if(wh % 1024 == 0) System.out.println(ss); break; case 24: si = (int)( ((tmp[i+ch_offset] & 0xff) << 16) | ((tmp[i +ch_offset+1] & 0xff) << 8) | (tmp[i+ch_offset+2] & 0xff)); buf[c][wh] = (float)si/8388608; break; default: } } wh++; } } _ais.close(); if(_client != null) { System.out.println("done converting to float"); _client.messageReceived(this,FINISHED_READING,null); } }catch(Exception e) { e.printStackTrace(); } } t On Mar 22, 2008, at 04:30 AM, volker b?hm wrote: > hallo, > i'm using AudioFileBuffer from the max mxj api to read soundfiles > with varying sample sizes. > when i try to output the floating point data from the buf field, i > get correct results only for 16 bit files. > 8 bit, 24 bit and 32 bit are all wrong, which to me looks like > errors in int-to-float-conversion. > do i overlook something here? > thanks, volker. > > simple test class: > > import com.cycling74.max.*; > import com.cycling74.msp.*; > > public class test_afb extends MaxObject > { > private AudioFileBuffer afb = null; > > public test_afb (Atom[] args) { > declareInlets(new int[]{DataTypes.ALL}); > declareOutlets(new int[]{DataTypes.ALL}); > } > > /* load > soundfile----------------------------------------------------*/ > publicvoid open( String path ) { > String fname = MaxSystem.locateFile(path); > post("filename: "+fname); > > try { > afb = new AudioFileBuffer(fname); > System.out.println("frame length: "+ afb.getFrameLength()); > System.out.println("samp size in bits: "+ > afb.getSampleSizeInBits()); > System.out.println("num channels: "+ afb.getChannels()); > System.out.println("big endian: "+ afb.isBigEndian()); > System.out.println("sample rate: "+ afb.getSampleRate()); > } > catch(Exception e) { > error("mxj test_afb: sorry, can't open that file!"); > } > } > > /* output sample value at index from channel 1-------------------*/ > publicvoid inlet (int index) { > outlet(0, afb.buf[0][index]); > } > } > > > simple test patch: > > #P window setfont "Sans Serif" 9.; > #P flonum 225 196 67 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P flonum 93 194 67 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P number 225 121 44 9 0 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P window linecount 1; > #P newex 225 166 54 196617 peek~ aha; > #P newex 93 117 68 196617 prepend open; > #P newex 93 166 93 196617 mxj test_afb; > #P newex 351 118 81 196617 prepend replace; > #P button 93 39 15 0; > #P newex 93 62 56 196617 opendialog; > #P newex 351 140 83 196617 buffer~ aha 100; > #P comment 217 105 100 196617 sample index; > #P fasten 8 0 5 0 230 151 98 151; > #P connect 8 0 7 0; > #P connect 5 0 9 0; > #P connect 6 0 5 0; > #P connect 3 0 2 0; > #P connect 2 0 6 0; > #P connect 7 0 10 0; > #P fasten 2 0 4 0 98 88 356 88; > #P connect 4 0 1 0; > #P window clipboard copycount 11; > _______________________________________________ > java-dev mailing list > java-dev@cycling74.com > http://www.cycling74.com/mailman/listinfo/java-dev From vboehm at gmx.ch Sun Mar 23 12:28:36 2008 From: vboehm at gmx.ch (=?ISO-8859-1?Q?volker_b=F6hm?=) Date: Sun Mar 23 12:26:36 2008 Subject: [java-dev] Bug in AudioFileBuffer with different sample sizes? In-Reply-To: <99B3C7F1-64EC-4818-86FF-B45090AAB1B1@topher.com> References: <4B22B36C-030D-4626-A02D-6374CBD66B81@gmx.ch> <99B3C7F1-64EC-4818-86FF-B45090AAB1B1@topher.com> Message-ID: On 22 Mar 2008, at 18:44, topher lafata wrote: > i dont think you have overlooked anything. it is very possible > there are bugs with those bit depths. > Regardless here is the source for the class. You could copy it and > make your own. hi topher, thanks for the class file - interesting to look inside. i think i found the reason, why the conversion didn't work correctly, although i don't fully understand it... it seems that the fact it works for 16bit files is rather a fortunate coincidence, but which concealed why the others don't work. in fill_buf() you do: si = (int)( ((tmp[i+ch_offset] & 0xff) << 16) | ((tmp[i+ch_offset+1] & 0xff) << 8) | (tmp[i+ch_offset+2] & 0xff)); where i found that the MSB needs to stay a signed byte in order for the two's complement to work. so omitting '& 0xff' in the MSB fixes the 24bit inconsistencies for me. si = (int)( ((tmp[i+ch_offset]) << 16) | ((tmp[i+ch_offset+1] & 0xff) << 8) | (tmp[i+ch_offset+2] & 0xff)); i also found that this is the same for the other bit depths. the 16bit case simply worked because of the explicit cast to short. aha, and the division of the 8bit values should of course be 128 (or 127). there is no handling for 32 bit files. for the sake of completeness, this should be added, i think. i have fixed this in my own class for now, but it would certainly be nice to have a fix in AudioFileBuffer some time in the future. thanks, volker. From topher at topher.com Sun Mar 23 12:39:29 2008 From: topher at topher.com (topher lafata) Date: Sun Mar 23 12:39:53 2008 Subject: [java-dev] Bug in AudioFileBuffer with different sample sizes? In-Reply-To: References: <4B22B36C-030D-4626-A02D-6374CBD66B81@gmx.ch> Message-ID: <1206297572.2908990A@dh11.dngr.org> Thanks a lot for the info. What you are saying totally makes sense. It was a fortunate circumstance that made 16 bit work and that was the only one I got to test because I was in the middle of something else when that class was busted out.if you fix anything else or do the 32 bit case please re post the code and I will get jkc to check stuff back into the trunk so it makes it into the next release. /* FROM SIDEKICK LX*/ From myernore at yahoo.com Tue Mar 25 01:17:01 2008 From: myernore at yahoo.com (Myer) Date: Tue Mar 25 01:17:05 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <20590.47cfd3aa@www.cycling74.com> Message-ID: <20f0b.47e8a6ea@www.cycling74.com> Hello, A while ago I created a mxj program to email mp3s of performances as attachments to gmails. I've attached everything. Let me know if you have suggestions or comments. Myer note - you need to 1.) start pop3 support in your gmail account settings 2.) get activation.jar and mail.jar, and put them in your mxj classpath, and edit the config file so it loads the jars to get this to work ************************************ ********BPATCHER IMPLEMENTATION***** ************************************ max v2; #N vpatcher 27 84 746 317; #P origin 10 -49; #P window setfont "Sans Serif" 18.; #P window linecount 1; #P hidden comment 725 107 171 9109522 <-- handy bpatcher; #P window setfont "Sans Serif" 10.; #P comment 109 5 580 9109514 you have to enable pop3 email in your gmail settings and install mail.jar and activation.jar from sun in the mxj classpath.; #P window setfont "Sans Serif" 18.; #P window linecount 3; #P hidden comment 218 370 140 9109522 dependencies: mail.jar activation.jar; #P window setfont "Sans Serif" 14.; #P window linecount 2; #P hidden comment 360 383 347 9109518 Myer Nore 2008 \, with generous help from day 11 of Sams "Teach Yourself J2EE in 21 Days."; #P window setfont "Sans Serif" 9.; #P window linecount 1; #P hidden comment 925 32 62 9109513 filename; #N comlet filename to attach; #P hidden inlet 908 32 15 0; #N comlet bang: deliver email with current settings; #P hidden inlet 711 32 15 0; #P comment 27 28 48 9109513 username; #P user textedit 11 119 341 158 32968 139 9; #P comment 289 107 43 9109513 filename; #P hidden newex 147 390 48 9109513 print info; #P hidden newex 11 390 51 9109513 print gmail; #P hidden newex 68 390 75 9109513 print exception; #P user textedit 353 41 510 62 32968 139 9; #P user textedit 182 41 339 62 32968 139 9; #P user textedit 11 41 103 62 32968 139 9; #P user textedit 11 80 103 100 32968 139 9; #P comment 25 67 48 9109513 password; #P comment 353 29 18 9109513 cc; #P user textedit 524 41 679 62 32968 139 9; #P comment 524 29 23 9109513 bcc; #P comment 101 44 58 9109513 @gmail.com; #P comment 182 29 16 9109513 to; #P user textedit 11 177 338 197 32968 139 9; #P user textedit 351 75 678 199 32968 139 9; #P window setfont "Sans Serif" 18.; #P message 200 77 70 9109522 deliver; #P window setfont "Sans Serif" 9.; #P message 132 81 32 9109513 clear; #P comment 326 74 30 9109513 body; #P comment 290 165 42 9109513 subject; #P window setfont "Sans Serif" 12.; #P hidden newex 11 361 85 9109516 mxj MXJGmail; #P window setfont "Sans Serif" 9.; #P hidden newex 711 55 27 9109513 t b b; #P hidden comment 728 32 62 9109513 bang delivers; #P hidden newex 908 53 57 9109513 prepend set; #N vpatcher 59 47 1206 485; #P window setfont "Sans Serif" 12.; #P window linecount 4; #P comment 829 197 88 9109516 replace "text" with the appropriate field; #P outlet 350 378 15 0; #P inlet 734 57 15 0; #P window setfont "Sans Serif" 9.; #P window linecount 1; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 734 88 89 9109513 p gate_blank_fields; #P inlet 638 57 15 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 638 88 89 9109513 p gate_blank_fields; #P inlet 542 57 15 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 542 88 89 9109513 p gate_blank_fields; #P inlet 446 57 15 0; #P inlet 350 57 15 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 350 88 89 9109513 p gate_blank_fields; #P inlet 254 57 15 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 254 88 89 9109513 p gate_blank_fields; #P inlet 158 57 15 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 158 88 89 9109513 p gate_blank_fields; #P inlet 62 57 15 0; #P hidden newex 254 175 124 9109513 mxj list.Replace 0 fileName; #P hidden newex 734 315 102 9109513 mxj list.Replace 0 text; #P hidden newex 158 147 125 9109513 mxj list.Replace 0 password; #P hidden newex 638 287 109 9109513 mxj list.Replace 0 bcc; #P hidden newex 542 259 104 9109513 mxj list.Replace 0 cc; #P hidden newex 62 119 127 9109513 mxj list.Replace 0 username; #P hidden newex 350 203 125 9109513 mxj list.Replace 0 subject; #P window linecount 0; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 62 88 89 9109513 p gate_blank_fields; #P window linecount 1; #N vpatcher 15 55 271 367; #P outlet 60 263 15 0; #P inlet 60 38 15 0; #P window setfont "Sans Serif" 9.; #P newex 60 128 69 9109513 mxj list.Length; #P newex 60 173 27 9109513 > 1; #P newex 60 218 27 9109513 gate; #P newex 60 83 27 9109513 t l l; #P connect 4 0 0 0; #P fasten 0 1 3 0 82 115 65 115; #P connect 3 0 2 0; #P connect 2 0 1 0; #P connect 1 0 5 0; #P fasten 0 0 1 1 65 107 50 107 50 203 82 203; #P pop; #P newobj 446 88 89 9109513 p gate_blank_fields; #P hidden newex 446 231 103 9109513 mxj list.Replace 0 to; #P window setfont "Sans Serif" 12.; #P window linecount 2; #P comment 829 69 166 9109516 only let messages through if they aren't blank; #P connect 11 0 3 0; #P connect 3 0 5 0; #P connect 13 0 12 0; #P connect 12 0 8 0; #P connect 15 0 14 0; #P connect 14 0 10 0; #P connect 17 0 16 0; #P connect 16 0 4 0; #P connect 4 0 25 0; #P connect 5 0 25 0; #P connect 8 0 25 0; #P connect 10 0 25 0; #P connect 1 0 25 0; #P connect 6 0 25 0; #P connect 7 0 25 0; #P connect 9 0 25 0; #P connect 18 0 2 0; #P connect 2 0 1 0; #P connect 20 0 19 0; #P connect 19 0 6 0; #P connect 22 0 21 0; #P connect 21 0 7 0; #P connect 24 0 23 0; #P connect 23 0 9 0; #P pop; #P hidden newobj 11 320 339 9109513 p testArgLength; #P window linecount 2; #P hidden comment 356 314 232 9109513 username password filename subject to cc bcc body \; see inside to see how arguments are passed; #P bpatcher 5 25 685 181 0 0 0; #P window setfont "Sans Serif" 14.; #P window linecount 1; #P comment 3 3 107 9109518 MXJGmail note:; #P hidden fasten 6 1 21 0 733 25 16 25; #P lcolor 6; #P hidden fasten 10 0 21 0 137 107 -3 107 -3 19 16 19; #P lcolor 4; #P hidden fasten 6 1 20 0 733 25 5 25 5 68 16 68; #P lcolor 6; #P hidden fasten 10 0 20 0 137 107 -3 107 -3 68 16 68; #P lcolor 4; #P hidden fasten 6 1 28 0 733 26 5 26 5 107 16 107; #P lcolor 6; #P hidden fasten 10 0 28 0 137 107 16 107; #P lcolor 4; #P hidden fasten 4 0 28 0 913 22 -12 22 -12 115 16 115; #P hidden fasten 6 1 13 0 733 26 4 26 4 164 16 164; #P lcolor 6; #P hidden fasten 10 0 13 0 137 107 -3 107 -3 164 16 164; #P lcolor 4; #P hidden fasten 21 0 3 0 16 263 16 263; #P lcolor 8; #P hidden fasten 6 0 7 0 716 360; #P hidden connect 3 0 7 0; #P hidden connect 7 0 25 0; #P hidden fasten 20 0 3 1 16 209 63 209; #P lcolor 8; #P hidden connect 7 1 24 0; #P hidden fasten 28 0 3 2 16 231 110 231; #P lcolor 8; #P hidden connect 7 2 26 0; #P hidden fasten 13 0 3 3 16 263 157 263; #P lcolor 8; #P hidden fasten 6 1 22 0 733 25 187 25; #P lcolor 6; #P hidden fasten 10 0 22 0 137 107 167 107 167 19 187 19; #P lcolor 4; #P hidden fasten 22 0 3 4 187 231 204 231; #P lcolor 8; #P hidden fasten 23 0 3 5 358 286 251 286; #P lcolor 8; #P hidden fasten 17 0 3 6 529 233 298 233; #P lcolor 8; #P hidden fasten 12 0 3 7 356 258 345 258; #P lcolor 8; #P hidden fasten 6 1 12 0 733 25 346 25 346 67 356 67; #P lcolor 6; #P hidden fasten 10 0 12 0 137 107 191 107 191 68 356 68; #P lcolor 4; #P hidden fasten 6 1 23 0 733 25 358 25; #P lcolor 6; #P hidden fasten 10 0 23 0 137 107 168 107 168 19 358 19; #P lcolor 4; #P hidden fasten 6 1 17 0 733 25 529 25; #P lcolor 6; #P hidden fasten 10 0 17 0 137 107 167 107 167 19 529 19; #P lcolor 4; #P hidden connect 30 0 6 0; #P hidden fasten 11 0 6 0 205 112 176 112 176 13 703 13 703 51 716 51; #P lcolor 1; #P hidden connect 31 0 4 0; #P pop; *********************************** *********MXJGmail.java************* *********************************** import com.cycling74.max.*; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class MXJGmail extends MaxObject { private static final String SMTP_HOST_NAME = "smtp.gmail.com"; private static final int SMTP_HOST_PORT = 465; private static final int NORMAL_OUTLET = 0; private static final int EXCEPTION_OUTLET = 1; private String username = null; private String password = null; private String to = null; private String cc = null; private String bcc = null; private String from = "nobody"; private String subject = null; private String text = null; private String fileName = null; private String contentType = "text/html"; public MXJGmail( Atom args[] ) { declareIO( 1,2 ); declareAttribute("username"); declareAttribute("password"); declareAttribute("to"); declareAttribute("cc"); declareAttribute("bcc"); declareAttribute("subject"); declareAttribute("text"); declareAttribute("fileName"); from = username + "@gmail.com"; } public void bang () { deliver(); } public void clear( String message, Atom args[] ) { username = password = to = cc = bcc = subject = text = fileName = null; from = "nobody"; } public void deliver() { //Get System Properties object Properties props = System.getProperties(); // Define properties // it MUST be smtpS for gmail props.put( "mail.transport.protocol", "smtps" ); props.put( "mail.smtps.host", SMTP_HOST_NAME ); props.put( "mail.smtps.auth", "true" ); // tells the system NOT to wait for verification // of sent status from gmail props.put( "mail.smtps.quitwait", "false" ); try { // Get a mail Session object // Pass SMTP properties to private constructor of new // Session object Session session = Session.getDefaultInstance( props ); // deal with transport directly because of tls and ssl // which are required for gmail Transport transport = session.getTransport(); // Create a new Message object MimeMessage message = new MimeMessage( session ); //Pass the Mail Session as an argument and construct //a MimeMessage with the Session // Populate Message object if ( from != "nobody" ) { message.setFrom( new InternetAddress( from ) ); } else { message.setFrom(); } if ( to != null ) { message.addRecipients( Message.RecipientType.TO, InternetAddress.parse( to ) ); } if ( cc != null ) { message.addRecipients( Message.RecipientType.CC, InternetAddress.parse( cc ) ); } if ( bcc != null ) { message.addRecipients( Message.RecipientType.BCC, InternetAddress.parse( bcc )); } if ( subject != null ) { message.setSubject( subject ); } //Create message body part BodyPart messageBodyPart = new MimeBodyPart(); //Specify that we want a Part interface for a new //MIME object; construct object and assign it to //messageBodyPart if ( text != null ) { messageBodyPart.setText( text ); } if ( fileName != null ) { //create a Multipart object to hold the BodyPart Multipart multipart = new MimeMultipart(); multipart.addBodyPart( messageBodyPart ); //pass the textset BodyPart as an argument to the //addBodyPart method of the multipart object //Create the attachment body part messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource( fileName ); //make a capsule for the file that //was referenced in the arguments messageBodyPart.setDataHandler( new DataHandler(source) ); //pass DataSource to DataHandler so it can be //interpreted by messageBodyPart messageBodyPart.setFileName( fileName ); //create an official name for the file name //referenced in the arguments - so that the //MIME reader on the other end knows //what to call it multipart.addBodyPart( messageBodyPart ); //pass the BodyPart to the addBodyPart() method of the //Multipart object so it can be added; //insert the multipart into the message message.setContent( multipart ); } //send the message with mail transport object transport.connect( SMTP_HOST_NAME, SMTP_HOST_PORT, username, password ); transport.sendMessage( message, message.getRecipients( Message.RecipientType.TO ) ); transport.close(); outlet(NORMAL_OUTLET, "sent"); } catch ( AddressException ae ) { showException( null, ae ); outlet( EXCEPTION_OUTLET, "AddressException" ); } catch ( MessagingException me ) { showException( null, me ); outlet( EXCEPTION_OUTLET, "MessagingException" ); } } } -- "To Dwell is to Garden" - Martin Heidegger -------------- next part -------------- A non-text attachment was scrubbed... Name: MXJGmail.class Type: application/octet-stream Size: 4046 bytes Desc: not available Url : http://www.cycling74.com/pipermail/java-dev/attachments/20080325/8876b276/MXJGmail.obj From myernore at yahoo.com Tue Mar 25 01:18:54 2008 From: myernore at yahoo.com (Myer) Date: Tue Mar 25 01:18:59 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <20f0b.47e8a6ea@www.cycling74.com> Message-ID: <20f0c.47e8a75e@www.cycling74.com> Sorry, forgot to mention: activation.jar: http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html mail.jar: http://java.sun.com/products/javamail/downloads/index.html Myer -- "To Dwell is to Garden" - Martin Heidegger From i.m.klif at gmail.com Thu Mar 27 02:03:37 2008 From: i.m.klif at gmail.com (ivan marusic) Date: Thu Mar 27 02:03:41 2008 Subject: [java-dev] Re: net.mail problems In-Reply-To: <20f0c.47e8a75e@www.cycling74.com> Message-ID: <21044.47eb54d9@www.cycling74.com> thanks a lot! i'll check it out today. klif From jbmaxwell at rubato-music.com Sat Mar 29 10:34:51 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 10:34:59 2008 Subject: [java-dev] MXJ getting wrong inlet Message-ID: <21181.47ee6faa@www.cycling74.com> I have an mxj object which is incorrectly identifying the inlet of a message. I placed a "post(getInlet())" at the top of my "public void list()" method, and ran a trace. I can see, during the trace, that the message is clearly being sent to inlet 0, but the mxj is identifying it as "inlet 1" (which causes an error in my patch). What's even more confusing is that another instance of the mxj, loading exactly the same code, doesn't have this problem. So it appears to be some sort of messaging error in the max patcher itself. I tried cleaning the Eclipse project, deleting and re-instantiating the mxj, and even opening the max patch as text and doing "new from clipboard." None of these 'solutions' worked. Any ideas? J. From jbmaxwell at rubato-music.com Sat Mar 29 10:37:38 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 10:37:46 2008 Subject: [java-dev] Re: MXJ getting wrong inlet In-Reply-To: <21181.47ee6faa@www.cycling74.com> Message-ID: <21182.47ee7052@www.cycling74.com> I should mention that I'm on a Mac Pro 2.8, 10.5.2, so maybe this is a Leopard bug of some kind... From jbmaxwell at rubato-music.com Sat Mar 29 11:40:42 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 11:40:50 2008 Subject: [java-dev] Re: MXJ getting wrong inlet In-Reply-To: <21181.47ee6faa@www.cycling74.com> Message-ID: <2118e.47ee7f1a@www.cycling74.com> Just in case this was an installation-specific problem, I tried it on my laptop. Same result. Mind you, it's also running 10.5.2... Looking more closely at the output, it seems that this particular mxj instance is reporting the most recent inlet to receive input whenever it gets input from inlet 0. Weird. So, if the last inlet used was input 2, then the message to inlet 0 reports inlet 2, if the last inlet used was inlet 1, it reports inlet 1 when inlet 0 gets a message... very odd. Maybe I'll try re-building the max patch from scratch, just to see if anything changes. J. From jbmaxwell at rubato-music.com Sat Mar 29 12:05:45 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 12:05:53 2008 Subject: [java-dev] Re: MXJ getting wrong inlet In-Reply-To: <21181.47ee6faa@www.cycling74.com> Message-ID: <21194.47ee84f8@www.cycling74.com> Okay, so I built a smaller version of the patch. It's a network-like patch, and my original topology had 4 input nodes, 2 layer 2 nodes, and 1 layer 3 node. Node 1 of layer 2 was reporting the wrong inlet. I built another network, with a smaller topology of just 2 input nodes and 1 layer 2 node. Same error, and same topological location; that is, first node in layer directly below top layer (or, in Max terms, "the mxj instance on the left"). Exact same problem: trace shows the message going to inlet 0, but mxj's getInlet() reports inlet 1. Looking for updates I noticed that 10.5 is still "officially" not supported, so I assume I'm on my own. But this should be filed as a bug anyway. Also, Max won't gracefully exit from tracing - it becomes unresponsive to menu clicks (no spinning ball), then crashes. Mac Pro 2.8 8-core 16 GB RAM Apogee duet MaxMSP 4.6.3 OS X 10.5.2 with all updates cheers, J. From jbmaxwell at rubato-music.com Sat Mar 29 12:53:33 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 12:53:41 2008 Subject: [java-dev] Re: MXJ getting wrong inlet In-Reply-To: <21181.47ee6faa@www.cycling74.com> Message-ID: <211a0.47ee902d@www.cycling74.com> Just for kicks I made a patch and mxj to replicate the problem. On my system this demonstrates both the mxj getInlet() problem, and the trace crashing max problem. The interesting thing for me, though, is that it doesn't explain why one instance of my full network patch actually worked correctly... very strange, indeed. The patch deliberately makes a loop, so run it with trace enabled! Then you can end your test session with max crashing on the trace problem! ;-) It would be interesting to see whether this problem is 10.5 (or 10.5.2) specific. J. -------------- next part -------------- A non-text attachment was scrubbed... Name: outletMania.zip Type: application/zip Size: 2130 bytes Desc: not available Url : http://www.cycling74.com/pipermail/java-dev/attachments/20080329/48ba26f3/outletMania.zip From nick at cassiel.com Sat Mar 29 13:46:19 2008 From: nick at cassiel.com (Nick Rothwell) Date: Sat Mar 29 13:46:37 2008 Subject: [java-dev] Re: MXJ getting wrong inlet In-Reply-To: <211a0.47ee902d@www.cycling74.com> References: <211a0.47ee902d@www.cycling74.com> Message-ID: This may not be the reason, but in your example you're doing declareInlets and declareOutlets (1 of each) followed by an argv- populated declareIO. I don't know what happens if you do both. -- N. Nick Rothwell - nick@cassiel.com - www.cassiel.com --- open-source goodies for MaxMSP: Python, Groovy, Nixie Tubes, --- rotatable text bricks, databases: all at www.loadbang.net From jbmaxwell at rubato-music.com Sat Mar 29 15:03:34 2008 From: jbmaxwell at rubato-music.com (jbmaxwell) Date: Sat Mar 29 15:03:40 2008 Subject: [java-dev] Re: Re: MXJ getting wrong inlet In-Reply-To: Message-ID: <211b2.47eeaea6@www.cycling74.com> Hmmm... Interesting thought. I really just threw that together with quickie, forgetting to delete the declareInlets stuff. But I just tried deleting everything but the declareIO(). Same problem. J. Quote: nick rothwell / cassiel wrote on Sat, 29 March 2008 19:46 ---------------------------------------------------- > This may not be the reason, but in your example you're doing > declareInlets and declareOutlets (1 of each) followed by an argv- > populated declareIO. I don't know what happens if you do both. > > -- N. > > > Nick Rothwell - nick@cassiel.com - www.cassiel.com > --- open-source goodies for MaxMSP: Python, Groovy, Nixie Tubes, > --- rotatable text bricks, databases: all at www.loadbang.net > > > > ----------------------------------------------------