Get length / duration of sample in samples
-
Hey all, I've been searching for an API call to get the length of each sample within a sampler, but have yet to find one. There are so many other properties options available (see this post), but I can't seem to find a function for getting the total duration in samples.
I discovered this in the core HISE code
getSampleLength()
but it might serve a different purpose.Essentially, I need a way to set the sample ends to a percentage of the total length of each sample. Any suggestions? Thanks!
-
SampleEnd - SampleStart?
-
@Christoph-Hart Will that work if you've previously set the sample start or end to a range that isn't the sample's full length? I'm thinking you'd need to make sure they always started at the min/max you would ever need and then keep track of any changes you make after.
-
@Lunacy-Audio
I discovered this in the core HISE code
getSampleLength()
but it might serve a different purpose.That function is for audio processors, not for individual samples. Samples use properties with the
.get
command but sample length isn't an available property so it would need to be implemented. -
Ah yes, that makes sense. Thanks guys.
@Christoph-Hart Yes that would do it, but would yield inaccurate results in the case that the user changes the sample start first.
@d-healey Agreed. Sounds like I'll need to track all the sample lengths in an array the instant a sample map is loaded using the method @Christoph-Hart mentioned above.
Appreciate the responses!
-
@Christoph-Hart
Searching SampleEnd or SampleStart in the manual I don't come up with anything.
How would you get those via script? -
These are the basics of setting sample properties programatically:
https://forum.hise.audio/topic/64/fun-with-regex?_=1619473727777
However the API has been extended to support Javascript-style loops so I recommend using this syntax instead:
for(s in Sampler.createSelection(".*")) s.set(Sampler.SampleEnd, 12000);
-
That's what I was looking for, Thanks.
-
I just discovered you can set the SampleStart to a negative number and it will delay the start....
Would this be a wise thing to do? -
@d-healey Do you know if there is a way to do this now? Just like you said the sample length is overwritten whenever SampleStart or SampleEnd is changed and I can't find a way to get at the original sample length. Even when loading custom samples I can't really figure out how to snatch it before initAfterSampleLoad() which is called every time the sample is updated.
I'm drawing on a panel on top of an AudioWaveform and need to find a way to calculate the relative position and size of the selected range within the total view. Resize the panel to only cover the selected range in other words.
Figured one way to do it was to work with the AudioWaveform, but getRangeStart() and getRangeEnd() return 0.
-
@audiolyf It's not something I've explored.