!7 import static x30_pkg.x30_util.VF1; sclass PlayAudioLoop > DynPrintLog { bool enabled = true; float gain = 0.5f; transient short[] loop; transient VF1 source; transient GainSoundSource gainSource; start { // download & load WAV loop = decodeWAVToStereoSamples(loadLibrary(#1400093)); onChange(r { set(gainSource, gain := enabled ? (double) gain : 0.0); }); // Make sound source & add to audio output module dm_addSoundSource( gainSource = GainSoundSource(gain, source = stereoSamplesIterator(loop))); } visualize { ret jHandleFileDrop(voidfunc(final File f) enter { thread { loadFile(f); } }, centerAndSouth(super.visualize(), centerAndEast( withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })), dm_fieldCheckBox('enabled)))); } void loadFile(File f) { if (!isWAVFile(f)) ret with infoBox("Not a WAV file: " + f); print("Loading WAV: " + f); loop = decodeWAVToStereoSamples(f); gainSource.replaceSource(source = stereoSamplesIterator(loop)); } }