Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1020126 // Play Audio Loop Synced To Another Module [dev.]

JavaX source code (Dynamic Module) - run with: Stefan's OS

1  
!7
2  
3  
import static x30_pkg.x30_util.VF1;
4  
5  
sclass PlaySyncedAudioLoop > DynModule {
6  
  bool enabled = true;
7  
  float gain = 0.5f;
8  
  File file;
9  
  S masterModule;
10  
  double speed = 1;
11  
  
12  
  transient short[] loop;
13  
  transient SyncedStereoSamplesIterator source;
14  
  transient GainSoundSource gainSource;
15  
  
16  
  start {
17  
    dm_addSoundSource(gainSource = GainSoundSource(0));
18  
    onChangeAndNow(r {
19  
      set(gainSource, gain := enabled ? (double) gain : 0.0);
20  
    });
21  
    loadFile(file);
22  
  }
23  
24  
  visualize {
25  
    ret jHandleFileDrop(voidfunc(final File f) enter { thread { loadFile(f); } },
26  
      centerAndSouth(
27  
        vstackWithSpacing(
28  
          withLabel("Master:", dm_moduleSelectorComboBox(dm_fieldLiveValue('masterModule))),
29  
          withLabel("File:", dm_fieldLabel('file))),
30  
        centerAndEast(
31  
          withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })),
32  
          dm_fieldCheckBox('enabled))));
33  
  }
34  
35  
  void loadFile(File f) {
36  
    loop = null;
37  
    setField(file := f);
38  
    print("Loading audio file: " + f);
39  
    pcall { loop = decodeAudioFileToStereoSamples(f); }
40  
    gainSource.replaceSource(source = SyncedStereoSamplesIterator(masterModule, loop));
41  
  }
42  
}

Author comment

Began life as a copy of #1020114

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020126
Snippet name: Play Audio Loop Synced To Another Module [dev.]
Eternal ID of this version: #1020126/1
Text MD5: 880087c815c3a0f812a4f1da13a7e979
Author: stefan
Category: javax / sound
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-08 21:55:02
Source code size: 1253 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 312 / 334
Referenced in: [show references]