!7 import static x30_pkg.x30_util.VF1; sclass PlaySyncedAudioLoop > DynModule { bool enabled = true; float gain = 0.5f; File file; S masterModule; double speed = 1; transient short[] loop; transient SyncedStereoSamplesIterator source; transient GainSoundSource gainSource; start { dm_addSoundSource(gainSource = GainSoundSource(0)); onChangeAndNow(r { set(gainSource, gain := enabled ? (double) gain : 0.0); }); loadFile(file); } visualize { ret jHandleFileDrop(voidfunc(final File f) enter { thread { loadFile(f); } }, centerAndSouth( vstackWithSpacing( withLabel("Master:", dm_moduleSelectorComboBox(dm_fieldLiveValue('masterModule))), withLabel("File:", dm_fieldLabel('file))), centerAndEast( withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })), dm_fieldCheckBox('enabled)))); } void loadFile(File f) { loop = null; setField(file := f); print("Loading audio file: " + f); pcall { loop = decodeAudioFileToStereoSamples(f); } gainSource.replaceSource(source = SyncedStereoSamplesIterator(masterModule, loop)); } }