[Done 2.7 Beta] Lua: .sample_Buffer:load_From()

Hi,

As previously mentioned here.

Can we please have a flag parameter for the Lua function .Sample_Buffer:Load_From() to additionally import the loop points for 2.7 final. It would greatly assist with my sampler file format import tool.

Thanks

+1 for assistance

Or perhaps you could convert this Xbasic code into Lua code and load the file binary to memory and scan the looppoints yourself…
It wasn’t that hard to write code to find looppoints (throughout the whole file, some WAV files have looppoints defined somewhere else in the file instead of in the header).
Though this one only loads it from different WAV files.

Btw, the code-snippet comes from RiGen.

  
SUB CheckLoop  
 SampleFile = OPEN(fname$, $$RD)  
 G = LOF(SampleFile)  
 IF LOF(SampleFile)< 1 THEN  
 CLOSE (SampleFile)  
 EXIT SUB  
 END IF  
 SEEK (SampleFile,0) 'Go to binary position 0 in the file  
 Header$ = CHR$(0,4) 'read the first four header-bytes  
 done = 0  
  
 DO  
 READ [SampleFile], Header$  
 RIFFOUND = 0  
 SELECT CASE LCASE$(Header$)  
 CASE "riff" 'Wave is RIFF type  
 SEEK (SampleFile, 12) 'Go to binary position 12 (position 13)  
 RIFFOUND = 1  
 CASE "fmt " 'Wave is FMT type, scan chunks  
 READ [SampleFile], ChunkSize 'Read the chunksize  
 SEEK (SampleFile, (POF(SampleFile)+ChunkSize)) 'Skip to the chunksize position  
  
 CASE "smpl" 'Wave is SMP type  
 READ [SampleFile], ChunkSize 'read chunksize  
 SEEK (SampleFile, (POF(SampleFile)+(7*4))) ' sampler header definitions to be skipped.  
 READ [SampleFile],Loop 'Load loopmode property  
 IF Loop THEN  
 SEEK (SampleFile, (POF(SampleFile)+8)) ' SamplerData-size + Loopname-header  
 READ [SampleFile], Type  
 SELECT CASE Type  
 CASE 0  
 LoopMode$ = "Forward"  
 CASE 1  
 LoopMode$ = "PingPong"  
 CASE 2  
 LoopMode$ = "Backward"  
 CASE ELSE  
 LoopMode$ = "Forward"  
 END SELECT  
 READ [SampleFile], LoopStart ' read the sampleposition of the start-loop pointer  
 READ [SampleFile], LoopEnd 'read the sampleposition of the end-loop pointer  
  
 END IF  
 SMPFOUND = 1  
 IF DATAFOUND = 1 THEN  
 done = 1 'And we have to exit our own file-scanning loop ofcourse.  
 END IF  
 CASE "data"  
 READ [SampleFile], ChunkSize  
 SEEK (SampleFile, (POF(SampleFile)+ChunkSize))  
 IF SMPFOUND THEN  
 done = 1 ' This bugged me since smpl structure could as well be somewhere near the end and not at the beginning.  
 END IF  
 DATAFOUND = 1 ' Now we have to take care the loop will not become endless because of the data it still attempts to find.  
  
 CASE ELSE  
 IFZ RIFFOUND THEN  
 done = 1  
 END IF  
  
 END SELECT  
 IF POF(SampleFile) >= LOF(SampleFile) THEN  
 done=1  
 END IF  
  
 LOOP WHILE done < 1  
  
 CLOSE (SampleFile)  
  
END SUB  
  

Hi vV,

I have done something similar (although not as all-encompasing) as the code above here.

It would just make things much easier if loop points could be automagically included when importing audio files of any type. It saves having to do hacky work-arounds for multiple variations of various file formats :D

Indeed. Will try to add this during the 2.7 beta.

Note to self: I should post more often lame xbasic code and lame lua workarounds for lacking functionality :)

I think it can’t hurt if we always load/assign loop settings from files via “sample_buffer:load_from(file)”. If one wants to ignore them, you can disable the loop manually afterwards. Done for the next beta…