Get Sample Filename from Sampler using custom Sample Maps.
-
@trillbilly
Sampler1.Filename
should beSampler.FileName
Here's a working example, just drop a sample into the sampler and you'll see the name in the label
HiseSnippet 1303.3ocyX0sSabDEdVLKE6lD0DkK5E8hsV8B6JpwFHjphZiwFHBULXgIQUppxZX2w1iX2YVMyrN3VwaQeP5iPejxaP6Ylcs8tFKhwMIMnnn872LeybNmuy.sEbWhTxEHq7WLJjfrdfcmQL0flCvTF53CPVOxtEVpHBmXUMFEhkRhGxxJ2K0JrxuJx7yaeQCrOl4RlpBgdMm5RNgFPUS01t9OS88OB6QtfFjx6cperKm0j6yi.7jytJJD6dEtO4Tr1sUrQVqcnGUwEcTXEQB9zf6Mpy.9aXw9+ZpjdoOQKTC0AVnX0nlCn9dsGeVkHjkc6om7bwm7mZ2h5Qmne5MvWXL3LMhz2AVqbWPp18.RVofzpwP5w1cbEzP0TKZ7741GyfDROLbUmFJw9hV46VwtIG7fopDfuhbj.DlDQocqVcCG3+JuWgBv0sT4LDKb5fCB8IhZN+niI+WoOQknqTwwFKlMlSvWR70QLd2fXZxCB4LPnTwXyyDSaL6thI1rIl3OqHIpS3XOJqeSru+kPAQodQLWEkyJQksED+XqkK7GExS64T5qypMOnNudmk5iVxAohqf.oqNDeR7JUrx2Vr7uV821CbF9mdcnxCH8nLhWIYYXYLqS93yjFTkJpHWqJtgiTeDJMYkOh5apWKWVuV2nWtaJbS48FCZGN6TthbFqjAwEtofyrl50at1z2XBtuNiLOy5dIwcEXIVTvkDwFPdvOhLwQnXKaE7ZKVErabBLkib1wLp5rPRh7QbeOcko96aWuiRp.fud0wGfUXcKPhNvuPhPQ0vw5.xPfCItgHu8AD4UJdHPGLorA5lUFqOLocwjkPTXqW2NNigtdJMyA0GMU3mpqSiHqF1aNfGP1zCOjrIbMn1reDUgEPuSWFWDf86t81c8FwvAT2ZcEhs555ykjt9bAUV4M3g5CzD.sZV.YpkS.TbcsFP1V+fEBMR+weZ3EuU+Ov7v8h7wprzQZd2DCPFNCGftOmIopQo4kuGbTUuSNpEEhO1tMU4NX9Xbk4fQH2+g.iIL6Oz9vd8fN8o.bU6i9kkkFew29uJd6ehcGEv2D.7QIzDFLTvdLow6igpgK7P0D1wNzeOka+c8FQvcjHq1+ptYq1OfGwxrWIH+bRHviBo4Twrd8yO+kBdT3rQ81WXJJtP.b3vUQZCmwHvcsJ8YrofKk8fiiYsjoM0NRzWeWMUy4jgDgLqtSiBf7MCZ1j5NLKMOijnyuT2VXkfdcZuM6R0KvlbL7RCibsYj2ZF4smQdmYje1Lx6Ni7ymJaYms96yVLR3V3PCeRJOaPSpx.awZxRWjx0I2wFbj5cTy40Iq8g5ASqtXcZuigIe5ycl48c4GiwNTcp5P1PnmDznw3SfYb8vQ9pwZyxOzhy3gC3Lpa1N.nhteehHM1m6AZekBZ.mp4o0OGdFDVlpE9apeB7vGrHai885t39+V24lu9R6X35nI0b9uj29nVlcmy+xsPy+dui2keV3G0qtGkLUzA1cg5S777CrM73N5wt+eA0y4QJXb53QZ1vbuNvrdWR5oeqnmnFKWUKqATGByyH7OvOIFqMdTo1XswFQtiWJ3rk7s4E6V4HL8nCyy57ggv9oKokvKJzPBFugjljZ.LR5iChCvtBdW23eyGMtW2nAPLy7GSHucKsrSMj42FJMrCfYWcccytT2JvsV1.2dYCbmkMvmsrAt6xF3yW1.+92cf5mVrejhGDSrhPsZeXbwn0gSJFyg9W.bilFGA
-
@d-healey Great. This did work. Thank you!
Now I have another issue.
It is replacing the saved samplemap names with the sample file name instead.
This isnt a huge issue except for
- it shows the entire file path
- It doesnt change the name of the sample being played within the saved sample map (RRs)
Can I have it display both saved samplemaps + custom import samples?
-
@trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:
it shows the entire file path
Use the various string functions to get what you want from the full path.
@trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:
It doesnt change the name of the sample being played within the saved sample map (RRs)
I don't think you asked for that :)
@trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:
Can I have it display both saved samplemaps + custom import samples?
It can only ever display one thing, what do you want it to show when a factory sample map is loaded?
-
@d-healey you're right, I didnt ask for each sample loaded from an internal samplmemap. I'd rather it show the internal sample map name and then the custom sample name.
So internal samplemap is loaded, you see the samplemap name.
Custom sample loaded, you see the sample name.
-
@trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:
So internal samplemap is loaded, you see the samplemap name.
Ok so how are you selecting the sample map to load?
-
@d-healey like this
const var list = Sampler.getSampleMapList(); inline function onSampleViewer1Control(component, value)//viewport { Sampler1.loadSampleMap(list[value]); SampleName1.setValue(list[value]);//label };
-
@trillbilly Oh yeah I remember you posted that before. So you're already setting the label to the sample map name. What's missing?
-
@d-healey I'm not sure because it's changing it from the internal samplemap name to the only the loaded sample name/location.
It displays the samplename quickly at first, then changes to the folder name/location.
I assume I need to add this to the loader callback we made for the sample name?
Sorry, I'm on mobile now so I seem a bit choppy.
-
@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?