XML Feeds

.

[java-dev] SOLUTION! Long Filename Support in Max with Java

Rick Burnett grimepoch at mac.com
Wed Aug 15 14:33:59 MDT 2007


For the past week I have been trying to get a solution to this problem because I use Java for all my directory listings and such tied to a JSUI.  The way I have set this up to work is that right before you send the filename with path to an object that is going to use it, like jit.qt.movie, you use this java with external to convert it

The first thing you need is my jnilib, this file needs to be placed in /Library/Java/Extensions.  I am sure there are other ways to do this, but this is to get you going, you can figure out how to change where the JVM looks and then let me know because that I have not figured out (I want to store the jnilib in the same location the patch is loaded from).

http://www.asylumstudioproductions.com/jni/libMaxMSPFileNameConverterJNILib.jnilib

next you will need to create your [mxj convertFilename] object and put this code into it:

import com.cycling74.max.*;
import java.io.IOException;

public class convertFilename extends MaxObject
{		
	static { 
		
		System.loadLibrary( "MaxMSPFileNameConverterJNILib" ); 
	}
	public native String getMyFullName(String s);

	private static final String[] INLET_ASSIST = new String[]{
		"inlet 1 help"
	};
	private static final String[] OUTLET_ASSIST = new String[]{
		"outlet 1 help"
	};
	
	public convertFilename(Atom[] args)
	{
		declareInlets(new int[]{DataTypes.ALL});
		declareOutlets(new int[]{DataTypes.ALL});
		
		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);

	}
    
	public void convert(String s1)
	{	String s2 = getMyFullName( s1 );	
	    outlet(0,Atom.newAtom(s2));
	}
    
	public void inlet(int i)
	{
	}
    
	public void inlet(float f)
	{
	}
    
    
	public void list(Atom[] list)
	{
	}
    
}


Then what i do is just prepend 'convert' to the message with just the path after it and out will come a path that max can recognize. 

So in summary it takes

/this is a long filename that i have/with a long file too .mov

and converts that to

MacintoshHD:/thisisalong#85934/withalongfile#340593.mov
(generic sample)

It is based on the FSSpec, FSref and CF functions provided in the OSX frameworks.  Obviously, this is not needed on the WinXP side of filenames so when I cross-develop, I will add to this what I did to make a transparent class available on the windows side.

Let me know if you have any questions or find any problems.  Note, there is little error checking at the moment so I will post when I update the code to check.  If you give an invalid path, garbage is going to come out of it at the moment so validate your paths.

Also, the reason it is better to convert the name at the last minute to the HFS style name is that these names change based on things going on in the OS, so to make sure it is always valid, it is recommended to convert immediately before you use it.  

Rick Burnett
Asylum Studio Productions

* This code and library is free to use, feel free to just give me a little credit in there somewhere :)















More information about the java-dev mailing list