Forums > MaxMSP

path conversion troubles

May 2, 2006 | 3:58 pm

I need to convert back and forth between max style pathnames and real Unix paths.
This has always been an incredible pain in the behind.

I searched the archives but the MXJ solution I found is a bit above my head/immediately froze Max.

Is there an easier way to convert between the 2 styles without resorting to MXJ?

UNIX (the shell object) doesn’t like the G5: (diskname) part nor spaces in pathnames. Escaping with doesn’t seem to work.

All in all, another afternoon lost.

Yes, I tried absolutepath/relativepath etc.

It would be great if there was no difference for the user between UNIX and Max paths

Also, relative and absolute paths in Max are rather messy.


May 2, 2006 | 8:12 pm

maybe not what you are looking for, cause it’s java, but the class
below always worked well for me. if you want, give it a try,
send a message [maxToUnix myMaxPath]
resp. [unixToMax myUnixPath]
hth.
volker.

// name it "vConformPath"

import com.cycling74.max.*;

public class vConformPath extends MaxObject
{
String ppath;

vConformPath () {
declareInlets(new int[] { DataTypes.ALL });
declareOutlets(new int[] { DataTypes.ALL });
}

// convert max-style path to unix-style
public void maxToUnix(String p) {
ppath = MaxSystem.maxPathToNativePath(p); //pretty straight forward
outlet(0, ppath);
System.out.println(ppath);
}

// convert unix-style to max-style path (not so easy, if path is on
a partition)
public void unixToMax(String p) {
ppath = testForPartition(p);
outlet(0, ppath);
System.out.println(ppath);
}

public String testForPartition(String p) {
String partition = null;
String path = null;
int idx = p.indexOf("/Volumes");
if(idx == -1) //not an external partition path
return MaxSystem.nameConform(p, MaxSystem.PATH_STYLE_MAX,
MaxSystem.PATH_TYPE_ABSOLUTE);
idx = p.indexOf("/", 9); //9 is the first char after "/Volumes/";
partition = p.substring(9,idx);
path = p.substring(9 + partition.length());
return new String(partition+":"+path);

}
}


May 3, 2006 | 5:46 am

Look into conformpath, part of the standard distri…

Stefan

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


May 3, 2006 | 6:43 am

On 03 May 2006, at 07:46, Stefan Tiedje wrote:

> Zip Boterbloem wrote:
>> Is there an easier way to convert between the 2 styles without
>> resorting to MXJ?
>
> Look into conformpath, part of the standard distri…

the request was about max/unix-style conversion. conformpath can’t
handle that.
v


May 3, 2006 | 8:47 am

vb wrote:
>> Look into conformpath, part of the standard distri…
>
>
> the request was about max/unix-style conversion. conformpath can’t
> handle that.

what is missing with output type "boot" and style "slash"?
I am not the expert for Unix styl paths, but looking at the help file
for shell, conform path seems at least be able to get most of the work
done…

Stefan

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


May 3, 2006 | 10:03 am

Hi Stefan,

I tried conformpath, but it doesn’t resolve disknames(volumes, in
Unix). It just replaces the pathseparators.

Best,

Zip Boterbloem
Media Mechanics
Zwaluwstraat 54
2025 VR Haarlem
The Netherlands
+31627014758
zip@knoware.nl


May 3, 2006 | 10:03 am

Right.

Zip Boterbloem
Media Mechanics
Zwaluwstraat 54
2025 VR Haarlem
The Netherlands
+31627014758
zip@knoware.nl


May 3, 2006 | 10:05 am

Hm. Outputstyle boot seems to do the trick.. Nice. I’ll do some more
tests.

Best,

Zip Boterbloem
Media Mechanics
Zwaluwstraat 54
2025 VR Haarlem
The Netherlands
+31627014758
zip@knoware.nl


May 3, 2006 | 10:10 am

Thanks, vb. I did some reading up on MXJ last night & your example came in really handy. Thanks!


May 3, 2006 | 3:52 pm

On 03 May 2006, at 10:47, Stefan Tiedje wrote:

> vb wrote:
>>> Look into conformpath, part of the standard distri…
>> the request was about max/unix-style conversion. conformpath
>> can’t handle that.
>
> what is missing with output type "boot" and style "slash"?

as zip pointed out, this works correctly only for files and folders
on the boot volume.
with other discs or partitions you get the dreaded :/ again.


May 3, 2006 | 4:10 pm

On May 3, 2006, at 5:52 PM, vb wrote:

> as zip pointed out, this works correctly only for files and folders
> on the boot volume.
> with other discs or partitions you get the dreaded :/ again.

Can be handled with a regular expression, mapping "name:/" to "/
Volumes/name/" from the output o the boot mode. In future versions we
may support an OS X native file string (note that /Volumes/ is not
unix standard, but OS X specific).

-Joshua


May 3, 2006 | 4:31 pm

On 03 May 2006, at 18:10, Joshua Kit Clayton wrote:

>
> On May 3, 2006, at 5:52 PM, vb wrote:
>
>> as zip pointed out, this works correctly only for files and
>> folders on the boot volume.
>> with other discs or partitions you get the dreaded :/ again.
>
> Can be handled with a regular expression, mapping "name:/" to "/
> Volumes/name/" from the output o the boot mode.
yes, that’s exactly what the java snippet i posted earlier is doing
(actually based on an example by topher).


May 4, 2006 | 5:55 am

vb wrote:
> as zip pointed out, this works correctly only for files and folders on
> the boot volume.
> with other discs or partitions you get the dreaded :/ again.

yes, but for solving problems we use Max…
A solution called "JavaAvoidingConformUnixPath"

Give it a test, I have no second partition on my Powerbook….

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 117 333 120 196617 sprintf /Volumes/%s%s;
#P newex 117 285 50 196617 zl ecils 1;
#P newex 90 356 37 196617 zl reg;
#P newex 170 285 50 196617 itoa;
#P newex 90 186 50 196617 atoi;
#P message 90 402 268 196617 /Volumes/My HD/Users/ST/Opera 7
Preferences.new;
#P newex 90 380 67 196617 prepend set;
#P newex 117 307 50 196617 itoa;
#P newex 117 263 63 196617 zl slice;
#P newex 90 208 139 196617 t b l l 0;
#P newex 170 231 50 196617 zl sub 58;
#P button 90 109 15 0;
#P newex 90 133 54 196617 opendialog;
#P newex 149 110 50 196617 loadbang;
#P message 225 134 79 196617 pathstyle slash;
#P message 149 134 73 196617 pathtype boot;
#P newex 90 163 98 196617 conformpath;
#P fasten 13 0 14 1 175 353 122 353;
#P connect 13 0 16 1;
#P connect 3 0 1 0;
#P fasten 3 0 2 0 154 130 230 130;
#P connect 9 0 16 0;
#P connect 16 0 14 1;
#P connect 14 0 10 0;
#P connect 7 0 14 0;
#P connect 7 2 6 0;
#P connect 7 1 8 0;
#P fasten 7 3 8 1 224 254 175 254;
#P connect 12 0 7 0;
#P connect 8 1 13 0;
#P connect 0 0 12 0;
#P connect 15 0 9 0;
#P connect 8 0 15 0;
#P connect 6 0 8 1;
#P connect 10 0 11 0;
#P connect 4 0 0 0;
#P connect 5 0 4 0;
#P fasten 1 0 0 0 154 157 95 157;
#P fasten 2 0 0 0 230 157 95 157;
#P window clipboard copycount 17;

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


May 4, 2006 | 9:59 am

On 4 mai 06, at 07:55, Stefan Tiedje wrote:

> vb wrote:
>> as zip pointed out, this works correctly only for files and
>> folders on the boot volume.
>> with other discs or partitions you get the dreaded :/ again.
>
> yes, but for solving problems we use Max…
> A solution called "JavaAvoidingConformUnixPath"

Hi Stefan,

You may have problems with spaces. I know it’s just you made you
never put spaces in your filenames :-) You can fix that easly while
adding the symout argument to the sprintf obect (this is quite
recent, an documented).

The version bellow uses quite human readable regular expression.

Best,
ej

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 90 317 67 196617 prepend set;
#P message 123 234 143 196617 substitute /Volumes/%1/%2;
#P newex 90 291 51 196617 tosymbol;
#P newex 90 259 90 196617 regexp (.*):/(.*);
#P message 90 342 292 196617 "/Volumes/iPod/Data/my File.txt";
#P button 90 109 15 0;
#P newex 90 133 54 196617 opendialog;
#P newex 149 110 50 196617 loadbang;
#P message 225 134 79 196617 pathstyle slash;
#P message 149 134 73 196617 pathtype boot;
#P newex 90 163 98 196617 conformpath;
#P fasten 3 0 9 0 154 130 314 130 314 210;
#P connect 3 0 1 0;
#P fasten 3 0 2 0 154 130 230 130;
#P connect 0 0 7 0;
#P connect 10 0 6 0;
#P connect 8 0 10 0;
#P connect 7 0 8 0;
#P connect 7 3 8 0;
#P connect 9 0 7 0;
#P fasten 2 0 0 0 230 157 95 157;
#P fasten 1 0 0 0 154 157 95 157;
#P connect 5 0 4 0;
#P connect 4 0 0 0;
#P window clipboard copycount 11;


May 5, 2006 | 6:39 pm

Joshua Kit Clayton wrote:
> Can be handled with a regular expression, mapping "name:/" to
> "/Volumes/name/" from the output o the boot mode. In future versions we
> may support an OS X native file string (note that /Volumes/ is not unix
> standard, but OS X specific).

To be fair, "volume:/path" is much further from a Unix standard. The
unix standard is that volumes are mounted in some subdirectory of the
root filesystem. On OS X this happens to default to /Volumes, but
regardless of where a file system is mounted, its unix path should look
like "/path/to/somevolume".

The thing that bothers me the most is that many objects (such as
jit.qt.movie) don’t even understand the /Volumes path. The files are
there on the filesystem under /Volumes… Why can’t I send jit.qt.movie
"read /Volumes/myvolume/file" instead of "read myvolume:/file"?

At any rate, the feature will be greatly appreciated if/when it is added.

-charlie


May 5, 2006 | 9:41 pm

On 5 May 2006, at 19:39, Charlie wrote:

> Why can’t I send jit.qt.movie
> "read /Volumes/myvolume/file" instead of "read myvolume:/file"?

For all I know, the former might well work (even on Windows if you’ve
only got one device), but the idea behind the whole conformpath thing
(volume:path) is portability: a common designation and syntax for
(multiple) volumes and files which makes sense both for Mac and Windows.

There’s a pile of conversion machinery in MXJ, and of course
[conformpath] in the Max world; it’s irritating to have to deal with
the stuff, but difficult to avoid if you want portable code.

– N.

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


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