Please do – a couple of years ago, there were many problems with conversions of string encoding between Windows file system functions and SC’s internal representation (one of the varieties of Unicode… I won’t try to say more than that because at that time, I had said something about “Unicode encoding” and got my hand slapped… I only know, then, that encoding is far too complex and easy to mess up). Virtualdog (no longer an active developer) caught most of the places that need an explicit conversion function, but might have missed this one (understandable, since there were a lot of places).
OK, fair enough – in fact, in a github thread once, I had suggested dropping PathName and focusing on the string methods, but other developers’ opinion was that it would be better to deprecate the string methods and put everything into PathName, so that there is an object that indicates the string’s purpose.
I find that fairly convincing, though I think if we move in that direction, then PathNames should be made usable everywhere.
E.g.
p = PathName(Platform.resourceDir +/+ "sounds/a11wlk01.wav");
File.exists(p);
ERROR: Primitive '_FileExists' failed.
Wrong type.
s.boot;
b = Buffer.read(s, p);
FAILURE IN SERVER /b_allocRead wrong argument type
If it’s a valid complaint that one must call .standardizePath
on a string path explicitly (and if it’s valid to consider PathName
to be better because it does that for you), then IMO it’s an equally valid complaint that you must then call .fullPath
in order to use the PathName anywhere that it actually matters.
So…
+ File { // override
*exists { arg pathName;
_FileExists
// ^this.primitiveFailed
^this.exists(pathName.fullPath)
}
}
+ PathName {
asControlInput { ^this.fullPath } // OSC bundle conversion
}
+ Buffer { // override
allocReadMsg { arg argpath, startFrame = 0, numFrames = -1, completionMessage;
this.cache;
path = argpath;
this.startFrame = startFrame;
^["/b_allocRead", bufnum, path.asControlInput, startFrame.asInteger, (numFrames ? -1).asInteger, completionMessage.value(this)]
}
}
With those changes, the above examples are fine (though it would be better to have a more descriptive error in *exists
, but, eh, not this morning).
PathName should also be made more convenient, e.g.:
// now:
b = Buffer.read(s, thisProcess.nowExecutingPath.dirname +/+ "xyz.wav");
// post-deprecation
// PathName seems *not* to have a method to create an instance
// relative to the current document, btw
b = Buffer.read(s, (PathName(thisProcess.nowExecutingPath).pathOnly +/+ "xyz.wav").fullPath);
I might be forgiven for finding the latter to be both inconvenient and pedantic. What actually is the value-add? You type more but there’s no gain in functionality or expressivity.
Now, it would be better if you could do e.g. b = Buffer.read(s, PathName.relativeToExecutingPath("xyz.wav"))
(and not have to call fullPath
explicitly). This would be more expressive and more convenient.
TL;DR PathName might be the way to go in the future, but I don’t think it’s ready yet.
hjh