[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] error when using .gui method on an Instr





hmm.

the one thing I would say is that its actually lastExecutedFile, not nowExecutingPath

the distinction is important if we are making assumptions about what just got processed.

we aren't currently executing it, and in fact if you load an Instr from a file
and then create an instr by selecting and executing code, the path would be set to the last file that was loaded.

using Document.current.path would fix that, but its an assumption about the way that people work,
and it could easily get broken.  Instr can be created dynamically by code, and that code may or may not be
on the document page that you are working on.  you could have called a method that did things like that.

but maybe it is a useful assumption.

the safest way is the way that it was doing it : when it loads from disk, set the path at that point knowing exactly what that path was.

maybe if Instr-init guesses and then Instr-objectAt explicitly sets it anyway (because it knows for sure) then its ok.

right now I can't see why it wouldn't have worked before.

I commented out 

Instr-init

/*if(path.isNil,{

path = thisProcess.nowExecutingPath; //  ?? { Document.current.path };

});*/



and tested, and everything assigns path as it should:




//load from disk in my own Instr folder

Instr("bassEfx2.monoBass").path

/Users/crucial/Documents/SC3docs/Instr/bassEfx2.rtf



// load from disk in a quark folder

Instr([\allBands,\slewlock ]).path

/Users/crucial/Library/Application Support/SuperCollider/Extensions/quarks/cxaudio/Instr/allBands.scd



but this was/is broken :

Instr([\allBands,\threes ,\gated])


because it assumes that allBands is a directory and threes is the file and gated is the instr within that.

so it can't load those.



that needs to be fixed, but it would involve searching all the combinations to figure out if you meant folder or were merely adding extra dots into the name.




Then, to fix Instr:

init { arg specs,outsp;
path = Main.currentFile; // this line is new
this.makeSpecs(specs ? #[]);
if(outsp.isNil,{
outSpec = nil;
},{
outSpec = outsp.asSpec;
});
this.class.put(this);
}

Or maybe Instr:init should have

path = Main.currentFile ?? { Document.current.path };

Any issues with this? I think it's generally useful.

Oh yes, and guiBody needs to check path.notNil before calling File.exists(path) -- because it's legit to have an Instr with no path (if you create it in an unsaved document).

cool