Replace binary file contents with JS?
I’m looking for a method to replace the contents of one external binary preset file with the contents of another. I know about the Shell external, but I’m hoping there’s a way to achieve this with JS that would maintain platform independence. Thanks.
duplicate and rename ?
I’m trying to avoid file renaming, as that gets into shell commands that will likely be OS-specific. I see that the JS “file” operator has a write mode, so I’m wondering if I can just replace the file contents in place. I’m new to JS, so I don’t know how to achieve this, and the solutions I’ve found online use features that aren’t available in M4L’s limited JS environment.
I don't see why so complicated.
File A has 222 333 444
stored
File B whatever.
You want to replace B with contents of A
Read A save as B
if you use write with full path, no warnings about file existing will get displayed.
....
But if you want to bother using js, then have fun with it.
Just realized that I didn’t mention the preset files are in the VST’s native format - not Ableton presets. As far as I’m aware, there are no M4L tools to save/modify them without JS or an external?
If this is all you forgot to mention,
same applies to any file format.
if you can read it into vst~ ,
then you can also write it.
Just make sure to keep original bank or preset
kind afxb or afxp.
Or you maybe forgot to say that you want to use presets 11 22 33
from bank A and overwrite presets 11 22 33 in Bank B ?
Which would make a difference.
In this case, I can’t read the preset into the VST~ via M4L because it isn’t an .fxp file - it’s an unknown binary format. Sending it to the VST~ via “read” does nothing. The primary aim of this patcher is to recreate the VST’s considerable preset navigation and filtering functions on the Push 2. I’ve worked out a method to read in the VST’s thousands of preset names, metadata, and filepaths from its database file and then successfully filter/navigate them with the Push knobs. What I don’t have is a way to force the actual preset change once it’s selected.
I‘ve found that the VST2 version does allow the user to send bank/pgm change messages to select specific presets from its internal user playlists. (Ableton doesn’t appear to pass bank/pgm msgs to VST3’s) Adding a preset to a playlist causes the VST to copy the preset file to a specific location. My thought was to create a dummy playlist/preset and then replace that file on the fly with the contents of the preset currently selected on the Push, triggering its load with the relevant bank/pgm msg.
That’a where I’m stuck, as I can’t find a method to replace that file that doesn’t require calling out to a shell.
This all sounds complicated to me because I don't use Live
and don't suffer it's limitations.
If you think that using java to copy files,
I mean to read a file and save it under other name
try if this can help you
but I would prefer to use shell rather than any java stuff
P.S.
I guess you will send path to file to read and allways rewrite same
destination file, which can be done by modding a bit the help file
which reads a file then opens a dialog to store it under new name keeping same file extension
Thanks very much for sharing this. It’s exactly what I’m trying to do, but wouldn’t a Java.class have the same issue as Shell in the sense that the end user would have additional files to install if I were to distribute the patcher as an M4L device?
I personally don't use java at all, not js, not mxj, and not node.js
There is allways a workarround without it.
If you would use shell or js, you would need to freeze
the java classes or shell externals (mxo and mxe64) into amxd, that part is not a problem.
Problem could be that JAVA JRE might not be installed or be wrong version.
You would maybe have more problems than advantages,
trying to fix problems on both platforms with that issue.
If you go with shell, then you need platform detection to adapt
syntax to copy files and to deal with absolute paths.
In both cases, you might get some restrictions on MacOS due to security
if files to be rewritten are in "protected" folders.
P.S.
I am not sure, but does node.js run without JRE ?
there is filesystem in node examples,
maybe you can use that ?
The tricky part is that the patcher is building live.menus and live.dials from the user’s preset database at instantiation via loadbang, so I don’t think I can freeze. However, I think I can also generate JS files dynamically in the user’s path with loadbang, which is why I’m leaning towards that method for the file replace. I believe JS also gets around the path slash issue, and if I can just use a file overwrite instead of delete or rename, I don’t have to be aware of the OS.