Trying to run SCMIRAudioFile

Hi all, I am trying to run SCMIRAudioFile, for some machine learning experiments (now that I am exploring the 2nd edition of the supercollider book). I have the sc3-plugins installed as well as the extensions found here: GitHub - sicklincoln/SCMIR. However, I try to run an example of SCMIRAudioFile and it throws me this error:

ERROR: Failed to write OSC score file: Could not open /tmp/NRTanalysis for writing

I am working on Windows, any ideas on what could be the problem here? Thanks!

I guess it’s due to a non-existing /tmp folder on Windows. The temporary folder is defined in SCMIR.sc, line 55, by setting the tempdir variable.

I guess the easiest fix would be to make the tempdir variable settable (change line 8 to classvar <>tempdir) and then setting the path to a suitable location from outside the class definition (here using the default sc temp dir):
SCMIR.tempdir = Platform.defaultTempDir

Hope that works!

No luck. The /tmp folder is there. As I understand it, SCRMIR should create the NRTanalysis folder within it. I just thought that the problem might be that Windows denies permissions to write to certain folders because of antiviruses or something similar. I have tried changing permissions to read and write (or full control) to this folder but no luck again. Any further advice would be appreciated. Thanks!

It would be worth a try to modify the class file as jpburstrom suggested – to add a setter method for the tempDir, and then set it to a location that you know you can write to (which may be different from the normal tmp directory).

I’m not at the computer now, though, so I can’t go into more detail at the moment. Perhaps someone else? Or I could later.

hjh

No luck again. Made a simple, naive test. Using File.write I tested whether I could create a text file in my Documents. I succeeded. After I modified the class as suggested and setting the tempDir: SCMIR.tempdir = "~/Documents"; I tried e = SCMIRAudioFile("C:/Users/Alejandro Frannco/Documents/3C03-2024/Session3/MONO-000.wav", [[MFCC, 13], [Chromagram, 12]]);, which succeeds. But then I try e.extractFeatures() and it throws back the error:

ERROR: Failed to write OSC score file: Could not open /tmp/NRTanalysis for writing

I do not believe anymore it has to do with Widnows permissions. Any advice would be appreciated. Thanks!

Ah, sorry. I just realised tempdir is only used in *initClass, so the change won’t make a difference. Try to set the SCMIR.nrtanalysisfilename variable instead, to the full path to a file within an existing, writable directory. The variable is already settable so no need to hack the class file. Hope that works!

Thanks a lot for your help! I got some progress here. I changed the path for the nrtanalysisfilename to
SCMIR.nrtanalysisfilename = "C:/Users/Alejandro Frannco/Documents/testingWriteFiles/NRTanalysis";
and it gets me a whole new different error: ERROR: Primitive '_FileGetInt32LE' failed. Failed. RECEIVER: a SCMIRFile
There is a thread in the mailing list that could imply the problem is still the path, but I can now see a file called NRTanalysis being written in the path shown here. The content of it looks like this: 0#bundle /g_new ,iii  €#bundle l/b_allocRead ,isii C:/Users/Alejandro Frannco/Documents/3C03-2024/Session3/MONO-000.wav ³€ h#bundle T/s_new ,siiisisf SCMIRAudioFileFeatures è playbufnum length @ù‡ T#bundle \( @/u_cmd ,iiss è createfile /tmp/MONO-000features.data 8#bundle È´9X $/u_cmd ,iis è closefile (#bundle È´9X /c_set ,ii #bundle È´9X  ,

So, I a not sure if this means that the path problem is solved and now I have to deal with _FileGetInt32LE. Many thanks for the help!

Lines 680 to 757 of SCMIRAudiFile.sc seems to be the place where things break. Specially here:

file.readLE(featuredata);

		if((featuredata.size) != temp) {

			file.close;

			featuredata = nil;

			SCMIR.clearResources;

			file = SCMIRFile(analysisfilename,"rb");
			file.getInt32LE;
			file.getInt32LE;

			onsetdata = FloatArray.newClear(temp);
			file.readLE(featuredata);
		};

SCMIR is great. Definitely where I started thinking about MIR. I’ve since started using FluCoMa (full disclosure I worked on the project). But I think it’s well documented, very stable and does the kinds of things SCMIR does. Might be worth checking out.

My guess is that it isn’t waiting for the NRT process to finish, and it’s trying to read a file that isn’t written yet.

I’m not going to test this, but SCMIR’s *waitOnUnixCmd method could be rewritten like this, to use more modern sync methods. I’m not certain this will fix it, but I’m willing to bet that the old version’s dependence on the unix command ps is probably incompatible with Windows, while this version “should” be better for Windows.

(Edit: delete unused processname.)

	*waitOnUnixCmd { |command, limit=2000|
		var cond = CondVar.new;
		var exit;

		// we know when the process exited b/c of the action function
		// and CondVar implements a timeout
		// so the whole while-loop wait and `ps` check can go away
		command.unixCmd({ |exitcode|
			exit = exitcode;
			cond.signalAll;
		});

		cond.waitFor(limit * 0.1, { exit.notNil });

		// here, you *could* use 'exit' to check for success,
		// but that seems not to be part of this method's interface

		0.01.wait;
	}

hjh