package com.haxademic.core.media.audio;

import beads.AudioContext;
import beads.AudioServerIO;
import beads.JavaSoundAudioIO;

public class AudioUtil {

	public static int DEFAULT_AUDIO_MIXER_INDEX = 4;
	
	public static void printMixerInfo() {
		JavaSoundAudioIO.printMixerInfo();
	}
	
	// Beads defaut AudioContext init got weird with the switch from Java 8 to 11.
	// Thanks to @hamoid for the solution: 
	// https://discourse.processing.org/t/solution-beads-audio-library-error-java-lang-illegalargumentexception-line-unsupported/9454/6
	
	public static AudioContext getBeadsContext() {
		return getBeadsContext(DEFAULT_AUDIO_MIXER_INDEX);
	}
	
	public static AudioContext getBeadsContextJavaSound() {
		return new AudioContext(new AudioServerIO.JavaSound());
	}
	
	public static AudioContext getBeadsContextBeadsJavaSound() {
		return new AudioContext(new beads.JavaSoundAudioIO());
	}
	
	public static AudioContext getBeadsContext(int mixerIndex) {
		JavaSoundAudioIO jsaIO = new JavaSoundAudioIO();
		jsaIO.selectMixer(mixerIndex);
		AudioContext ctx = new AudioContext(jsaIO);
		return ctx;
	}
}

@@ -34,16 +34,125 @@
 audio;%0A%0A
+import javax.sound.sampled.AudioSystem;%0Aimport javax.sound.sampled.Mixer;%0A%0Aimport com.haxademic.core.app.P;%0A%0A
 import b
@@ -387,16 +387,536 @@
 o();%0A%09%7D%0A
+%09%0A%09public static int getAudioMixerIndex(String mixerSearchString) %7B%0A%09%09if(mixerSearchString != null) %7B%0A%09%09%09Mixer.Info%5B%5D mixerInfo = AudioSystem.getMixerInfo();%0A%09%09%09for(int i = 0; i %3C mixerInfo.length; i++) %7B%0A%09%09%09%09String mixerName = mixerInfo%5Bi%5D.getName();%0A%09%09%09%09P.out(%22%5B%22+i+%22%5D%22 + %22 - %22 + mixerName);%0A%09%09%09%09if(mixerName.indexOf(mixerSearchString) == 0) %7B%0A%09%09%09%09%09P.out(%22SELECTED!%22 + %22 - %22 + mixerName);%0A%09%09%09%09%09// Mixer mixer = AudioSystem.getMixer(mixerInfo%5Bi%5D);%0A%09%09%09%09%09return i;%0A%09%09%09%09%7D%0A%09%09%09%7D %0A%09%09%7D%0A%09%09return DEFAULT_AUDIO_MIXER_INDEX;%0A%09%7D%0A%0A
 %09%0A%09// Be

Add fuzzy audio device search