Get Sample Filename from Sampler using custom Sample Maps.
-
@trillbilly Oh I see. You can just put a reg variable at the top of your script called
currentSampleMapName
and when you load the sample map you set the variable to its name, and when you are importing a sample you set the name to "custom". Then in the loading callback you can check the variable and if it's not custom you can just exit the function. -
@d-healey OK thanks. I'll try this when I'm back in studio tomorrow. I'm sure I will f*ck something up and be back.
Thanks again, David.
-
This post is deleted! -
@d-healey Hi David, I've got it to work like this:
//SAMPLE NAME LOADING CALLBACK const var samplepanel = Content.addPanel("SamplePanel", 0, 0); samplepanel.setLoadingCallback(function(isPreloading) { if (!isPreloading) { var s = Sampler1.createSelection(".*")[0]; } if (isDefined(list)) { SampleViewer1.set("items", list.join("\n")); } if (isCustomMap) { SampleName1.set("text", s.get(Sampler1.FileName)); } });
Does this look solid?
If so, I am on to trying to decipher the issue of showing only the filename rather than the file location for custom loaded samples.
Thanks again.
-
@trillbilly I think it could be improved. You don't need to do anything in the preload callback to display the name of sample maps, since you already have that working. All you need to do is check that it's not a sample map before you display the sample name.
Something like this:
if (!isPreloading && isCustomMap) { var s = Sampler1.createSelection(".*")[0]; SampleName1.set("text", s.get(Sampler1.FileName)); }
-
@d-healey Cool, thank you! If you've got it handy, could you point me to where the sting options for filenames are? Thanks.
-
@trillbilly Just search
string
in the API browser and you'll see all the string functions. They apply to all strings regardless of if they are file names. To get the name of a file object as a string you can use thetoString()
function https://docs.hise.audio/scripting/scripting-api/file/index.html#tostring -
@d-healey Hi David, I had to rebuild my plugin and now am having issues with this again. Could you take a look at this?
I have this in my onInit:
const var Sampler1 = Synth.getSampler("Sampler1"); const var list = Sampler.getSampleMapList(); const var SampleViewer1 = Content.getComponent("SampleViewer1");//viewport const var SampleName1 = Content.getComponent("SampleName1");//label SampleViewer1.set("useList", true); SampleViewer1.set("items", list.join("\n")); inline function onSampleViewer1Control(component, value) { Sampler1.loadSampleMap(list[value]); SampleName1.setValue(list[value]); }; Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
This is loading Samplemaps via the Viewport. It is supposed to update the label with the name of the Samplemap as well but fails to do so upon clicking the Samplemap in the Viewport.
I have this in the SampleLoadSave.js:
const var samplepanel = Content.addPanel("SamplePanel", 0, 0); samplepanel.setLoadingCallback(function(isPreloading) { if (!isPreloading && isCustomMap) { var s = Sampler1.createSelection(".*")[0]; SampleName1.set("text", s.get(Sampler1.FileName)); } });
This is the code you kindly provided me above. It sets the name of the label to the Custom Sample Filename/Path.
Everything works as it should except the Label not updating upon clicking the Samplemap in the Viewport.
Can you spot an issue?
All the best!
-
@trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:
you are going to have to start to debug your own code I think, so start like this:
const var Sampler1 = Synth.getSampler("Sampler1"); const var list = Sampler.getSampleMapList(); const var SampleViewer1 = Content.getComponent("SampleViewer1");//viewport const var SampleName1 = Content.getComponent("SampleName1");//label SampleViewer1.set("useList", true); SampleViewer1.set("items", list.join("\n")); inline function onSampleViewer1Control(component, value) { Sampler1.loadSampleMap(list[value]); SampleName1.setValue(list[value]); Console.print("I think Im loading:" + list[value]); }; Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
and
samplepanel.setLoadingCallback(function(isPreloading) { if (!isPreloading && isCustomMap) { var s = Sampler1.createSelection(".*")[0]; SampleName1.set("text", s.get(Sampler1.FileName)); Console.print("I think Im setting the label to:" + s.get(Sampler1.FileName)); } });
So all I'm doing there is checking its working, and working with values i expect... try that and see what you get..
-
@Lindon Hi Lindon, thanks for the help! You're right, I should be doing this long before I come to the forum. I will for items like this going forward.
As for the issue, the Dynamic Sample loading seems to be working perfect, it just calling the samplemap name from the viewport that isnt correct,
When I use the console.print command, it does print a value that I know but it always just prints the first Samplemap name, no matter which I have selected in the viewport. Its just catching me off guard because we had it working previously with this exact code structure. I quadruple checked to insure I didnt change anything, and it all looks correct.
I'll keep looking over it again and try a few different things to see what the results are.
Again, I appreciate the help and time!
Best.
-
@trillbilly well you cant do this for a start:
SampleName1.setValue(list[value]);
-
@Lindon Hi Lindon. I used this now and its working as expected.
inline function onSampleViewer1Control(component, value) { if (value > 0) { local id = Sampler1.getSampleMapList()[value - 1]; Sampler1.loadSampleMap(list[value]); SampleName1.setValue(list[value]); Sampler1.loadSampleMap(id); } }; Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
If I take out the part you said was incorrect, then it stops working again.
Is there a different way I should go about this now?