Created
May 20, 2017 23:18
-
-
Save meksor/612baa6a30a6c4b82621c23b8afe1771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.SocketException; | |
import java.util.List; | |
import java.net.InetAddress; | |
import artnet4j.ArtNet; | |
import artnet4j.ArtNetException; | |
import artnet4j.ArtNetNode; | |
import artnet4j.events.ArtNetDiscoveryListener; | |
import artnet4j.packets.ArtDmxPacket; | |
public class ArtNetClient { | |
private int sequenceId; | |
private ArtNet artnet; | |
private ArtNetNode receiver; | |
public ArtNetClient() | |
{ | |
artnet = new ArtNet(); | |
} | |
public void open() | |
{ | |
open(null, null); | |
} | |
public void open(InetAddress in, String address) | |
{ | |
try | |
{ | |
// sender | |
artnet.start(in); | |
setReceiver(address); | |
} | |
catch (SocketException e) { | |
e.printStackTrace(); | |
} | |
catch (ArtNetException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void setReceiver(String address) | |
{ | |
if (null == address) | |
receiver = null; | |
try | |
{ | |
receiver = new ArtNetNode(); | |
receiver.setIPAddress(InetAddress.getByName(address)); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public void close() | |
{ | |
artnet.stop(); | |
} | |
public void send(int universe, byte[] data) | |
{ | |
send(receiver, universe, data); | |
} | |
public void send(ArtNetNode node, int universe, byte[] data) | |
{ | |
ArtDmxPacket dmx = new ArtDmxPacket(); | |
dmx.setUniverse(0, universe); | |
dmx.setSequenceID(sequenceId % 256); | |
dmx.setDMX(data, data.length); | |
if (receiver != null) { | |
artnet.unicastPacket(dmx, node); | |
} else { | |
artnet.broadcastPacket(dmx); | |
} | |
sequenceId++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.effects.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.spi.*; | |
import ddf.minim.ugens.*; | |
import java.net.InetAddress; | |
import java.util.Enumeration; | |
ArtNetClient artnet; | |
Minim minim; | |
AudioInput lineIn; | |
FFT fft; | |
int i = 0; | |
byte[] buffer = new byte[512]; | |
void setup() | |
{ | |
frameRate(120); | |
size(500, 500); | |
minim = new Minim(this); | |
lineIn = minim.getLineIn(Minim.STEREO, 4096, 44100, 8); | |
fft = new FFT(lineIn.bufferSize(), lineIn.sampleRate()); | |
try | |
{ | |
artnet = new ArtNetClient(); | |
byte[] ipAddr = new byte[]{10, 20, (byte)255, (byte)255}; | |
InetAddress address = InetAddress.getByAddress(ipAddr); | |
artnet.open(null, "10.20.255.255"); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
void draw() | |
{ | |
fft.forward( lineIn.mix ); | |
float c = map(fft.calcAvg(50, 500), 0, 9, 0, 1); | |
float d = map((fft.calcAvg(500, 3000)), 0, 1, 0, 1); | |
float e = map((fft.calcAvg(500, 1000)), 0, 1, 0, 1); | |
for(i=0; i<12; i++) { | |
int[] rgb = Wheel(((i * 256 / 12) + (frameCount % 256)) & 255); | |
buffer[i*5] = (byte)(rgb[0]); //r | |
buffer[(i*5)+1] = (byte)(rgb[1]); //g | |
buffer[(i*5)+2] = (byte)(rgb[2]); //b | |
//buffer[(i*5)+3] = (byte)0; //ww | |
//buffer[(i*5)+4] = (byte)0;//kw | |
} | |
artnet.send(3, buffer); | |
//i = (i + 1) % 256; | |
} | |
void stop() | |
{ | |
artnet.close(); | |
} | |
int[] Wheel(int pos) { | |
pos = 255 - pos; | |
if(pos < 85) { | |
return new int[]{255 - pos * 3, 0, pos * 3}; | |
} | |
if(pos < 170) { | |
pos -= 85; | |
return new int[]{0, pos * 3, 255 - pos * 3}; | |
} | |
pos -= 170; | |
return new int[]{pos * 3, 255 - pos * 3, 0}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment