// Path: src/main/java/nodebox/client/MinimInputApplet.java
// public class MinimInputApplet extends PApplet {
//     private Minim minim;
//     private AudioInput input;
//     private BeatDetect beat;
// 
//     public void setup() {
//         minim = new Minim(this);
//         input = minim.getLineIn();
//         beat = new BeatDetect(input.bufferSize(), input.sampleRate());
//         input.setVolume(0);
//         input.setGain(-64);
//     }
// 
//     public AudioInput getInput() {
//         if (input == null) return null;
//         return input;
//     }
// 
//     public BeatDetect getBeatDetect() {
//         return beat;
//     }
// 
//     public void draw() {
//         beat.detect(input.mix);
//     }
// 
//     @Override
//     public void stop() {
//         if (input != null)
//             input.close();
//         input = null;
//         if (minim != null)
//             minim.stop();
//     }
// }
// 
// Path: src/main/java/nodebox/node/Device.java
// public class Device {
//     public static final String TYPE_OSC = "osc";
//     public static final String TYPE_AUDIOPLAYER = "audioplayer";
//     public static final String TYPE_AUDIOINPUT = "audioinput";
// 
//     public static final String TIMELINE_SYNC = "sync_with_timeline";
// 
//     public static final ImmutableList<String> deviceTypes = ImmutableList.of(TYPE_OSC, TYPE_AUDIOPLAYER, TYPE_AUDIOINPUT);
// 
//     private final String name;
//     private final String type;
//     private final ImmutableMap<String, String> properties;
// 
//     private static final Pattern OSC_PROPERTY_NAMES_PATTERN = Pattern.compile("^(port|sync_with_timeline)$");
//     private static final Pattern AUDIOPLAYER_PROPERTY_NAMES_PATTERN = Pattern.compile("^(filename|sync_with_timeline|loop)$");
//     private static final Pattern AUDIOINPUT_PROPERTY_NAMES_PATTERN = Pattern.compile("^(sync_with_timeline)$");
// 
//     private final transient int hashCode;
// 
//     private static final Map<String, Pattern> validPropertyNames;
// 
//     static {
//         ImmutableMap.Builder<String, Pattern> builder = new ImmutableMap.Builder<String, Pattern>();
//         builder.put(TYPE_OSC, OSC_PROPERTY_NAMES_PATTERN);
//         builder.put(TYPE_AUDIOPLAYER, AUDIOPLAYER_PROPERTY_NAMES_PATTERN);
//         builder.put(TYPE_AUDIOINPUT, AUDIOINPUT_PROPERTY_NAMES_PATTERN);
//         validPropertyNames = builder.build();
//     }
// 
//     public static Device oscDevice(String name, long port, boolean syncWithTimeline) {
//         return new Device(name, TYPE_OSC, ImmutableMap.<String, String>of("port", String.valueOf(port), TIMELINE_SYNC, String.valueOf(syncWithTimeline)));
//     }
// 
//     public static Device deviceForType(String name, String type) {
//         checkNotNull(type, "Type cannot be null.");
//         checkArgument(deviceTypes.contains(type), "%s is not a valid device type.", type);
//         // If the type is not found in the default values, get() returns null, which is what we need for custom types.
//         return new Device(name, type, ImmutableMap.<String, String>of());
//     }
// 
//     private Device(final String name, final String type, final ImmutableMap<String, String> properties) {
//         this.name = name;
//         this.type = type;
//         this.properties = properties;
//         this.hashCode  = Objects.hashCode(name, type, properties);
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public boolean hasProperty(String name) {
//         return properties.containsKey(name);
//     }
// 
//     public String getProperty(String name) {
//         return properties.get(name);
//     }
// 
//     public Map<String, String> getProperties() {
//         return properties;
//     }
// 
//     public String getProperty(String name, String defaultValue) {
//         if (hasProperty(name)) {
//             return properties.get(name);
//         } else {
//             return defaultValue;
//         }
//     }
// 
//     public Device withProperty(String name, String value) {
//         checkArgument(isValidProperty(name), "Property name '%s' is not valid.", name);
//         Map<String, String> b = new HashMap<String, String>();
//         b.putAll(properties);
//         b.put(name, value);
//         return new Device(this.name, this.type, ImmutableMap.copyOf(b));
//     }
// 
//     private boolean isValidProperty(String name) {
//         checkNotNull(name);
//         if (!validPropertyNames.containsKey(getType())) return false;
//         return validPropertyNames.get(getType()).matcher(name).matches();
//     }
// 
//     //// Object overrides ////
// 
//     @Override
//     public int hashCode() {
//         return hashCode;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (!(o instanceof Device)) return false;
//         final Device other = (Device) o;
//         return Objects.equal(name, other.name)
//                 && Objects.equal(type, other.type)
//                 && Objects.equal(properties, other.properties);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("<Device %s (%s)>", name, type);
//     }
// 
// }


import nodebox.client.MinimInputApplet;
import nodebox.node.Device;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Map;
package nodebox.client.devicehandler;



public class AudioInputDeviceHandler implements DeviceHandler {

    private String name;
    private boolean syncWithTimeline;
    private JFrame frame = null;

// Path: src/main/java/nodebox/client/MinimInputApplet.java
// public class MinimInputApplet extends PApplet {
//     private Minim minim;
//     private AudioInput input;
//     private BeatDetect beat;
// 
//     public void setup() {
//         minim = new Minim(this);
//         input = minim.getLineIn();
//         beat = new BeatDetect(input.bufferSize(), input.sampleRate());
//         input.setVolume(0);
//         input.setGain(-64);
//     }
// 
//     public AudioInput getInput() {
//         if (input == null) return null;
//         return input;
//     }
// 
//     public BeatDetect getBeatDetect() {
//         return beat;
//     }
// 
//     public void draw() {
//         beat.detect(input.mix);
//     }
// 
//     @Override
//     public void stop() {
//         if (input != null)
//             input.close();
//         input = null;
//         if (minim != null)
//             minim.stop();
//     }
// }
// 
// Path: src/main/java/nodebox/node/Device.java
// public class Device {
//     public static final String TYPE_OSC = "osc";
//     public static final String TYPE_AUDIOPLAYER = "audioplayer";
//     public static final String TYPE_AUDIOINPUT = "audioinput";
// 
//     public static final String TIMELINE_SYNC = "sync_with_timeline";
// 
//     public static final ImmutableList<String> deviceTypes = ImmutableList.of(TYPE_OSC, TYPE_AUDIOPLAYER, TYPE_AUDIOINPUT);
// 
//     private final String name;
//     private final String type;
//     private final ImmutableMap<String, String> properties;
// 
//     private static final Pattern OSC_PROPERTY_NAMES_PATTERN = Pattern.compile("^(port|sync_with_timeline)$");
//     private static final Pattern AUDIOPLAYER_PROPERTY_NAMES_PATTERN = Pattern.compile("^(filename|sync_with_timeline|loop)$");
//     private static final Pattern AUDIOINPUT_PROPERTY_NAMES_PATTERN = Pattern.compile("^(sync_with_timeline)$");
// 
//     private final transient int hashCode;
// 
//     private static final Map<String, Pattern> validPropertyNames;
// 
//     static {
//         ImmutableMap.Builder<String, Pattern> builder = new ImmutableMap.Builder<String, Pattern>();
//         builder.put(TYPE_OSC, OSC_PROPERTY_NAMES_PATTERN);
//         builder.put(TYPE_AUDIOPLAYER, AUDIOPLAYER_PROPERTY_NAMES_PATTERN);
//         builder.put(TYPE_AUDIOINPUT, AUDIOINPUT_PROPERTY_NAMES_PATTERN);
//         validPropertyNames = builder.build();
//     }
// 
//     public static Device oscDevice(String name, long port, boolean syncWithTimeline) {
//         return new Device(name, TYPE_OSC, ImmutableMap.<String, String>of("port", String.valueOf(port), TIMELINE_SYNC, String.valueOf(syncWithTimeline)));
//     }
// 
//     public static Device deviceForType(String name, String type) {
//         checkNotNull(type, "Type cannot be null.");
//         checkArgument(deviceTypes.contains(type), "%s is not a valid device type.", type);
//         // If the type is not found in the default values, get() returns null, which is what we need for custom types.
//         return new Device(name, type, ImmutableMap.<String, String>of());
//     }
// 
//     private Device(final String name, final String type, final ImmutableMap<String, String> properties) {
//         this.name = name;
//         this.type = type;
//         this.properties = properties;
//         this.hashCode  = Objects.hashCode(name, type, properties);
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public boolean hasProperty(String name) {
//         return properties.containsKey(name);
//     }
// 
//     public String getProperty(String name) {
//         return properties.get(name);
//     }
// 
//     public Map<String, String> getProperties() {
//         return properties;
//     }
// 
//     public String getProperty(String name, String defaultValue) {
//         if (hasProperty(name)) {
//             return properties.get(name);
//         } else {
//             return defaultValue;
//         }
//     }
// 
//     public Device withProperty(String name, String value) {
//         checkArgument(isValidProperty(name), "Property name '%s' is not valid.", name);
//         Map<String, String> b = new HashMap<String, String>();
//         b.putAll(properties);
//         b.put(name, value);
//         return new Device(this.name, this.type, ImmutableMap.copyOf(b));
//     }
// 
//     private boolean isValidProperty(String name) {
//         checkNotNull(name);
//         if (!validPropertyNames.containsKey(getType())) return false;
//         return validPropertyNames.get(getType()).matcher(name).matches();
//     }
// 
//     //// Object overrides ////
// 
//     @Override
//     public int hashCode() {
//         return hashCode;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (!(o instanceof Device)) return false;
//         final Device other = (Device) o;
//         return Objects.equal(name, other.name)
//                 && Objects.equal(type, other.type)
//                 && Objects.equal(properties, other.properties);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("<Device %s (%s)>", name, type);
//     }
// 
// }


// Path: src/main/java/nodebox/client/devicehandler/AudioInputDeviceHandler.java
import nodebox.client.MinimInputApplet;
import nodebox.node.Device;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Map;

package nodebox.client.devicehandler;



public class AudioInputDeviceHandler implements DeviceHandler {

    private String name;
    private boolean syncWithTimeline;
    private JFrame frame = null;

    private MinimInputApplet applet = null;