-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d48110e
commit 05acfd5
Showing
9 changed files
with
243 additions
and
34 deletions.
There are no files selected for viewing
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
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
101 changes: 101 additions & 0 deletions
101
DMXSoftware/src/main/java/SnowballThrower/dmxsoftware/Communicate/MidiConnection.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package SnowballThrower.dmxsoftware.Communicate; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.sound.midi.InvalidMidiDataException; | ||
import javax.sound.midi.MidiDevice; | ||
import javax.sound.midi.MidiDevice.Info; | ||
import javax.sound.midi.MidiMessage; | ||
import javax.sound.midi.MidiSystem; | ||
import javax.sound.midi.MidiUnavailableException; | ||
import javax.sound.midi.ShortMessage; | ||
import static javax.sound.midi.ShortMessage.CONTROL_CHANGE; | ||
|
||
/** | ||
* | ||
* @author Sven | ||
*/ | ||
public class MidiConnection extends Thread { | ||
|
||
static final int MAX_CH = 1000; | ||
MidiDevice dmxController; | ||
private int[] valOld; | ||
int[] valNew; | ||
boolean stop; | ||
|
||
public MidiConnection() { | ||
stop = false; | ||
valOld = new int[MAX_CH]; | ||
valNew = new int[MAX_CH]; | ||
Info[] infos = MidiSystem.getMidiDeviceInfo(); | ||
for (int i = 0; i < infos.length; i++) { | ||
System.out.println(infos[i].getName()); | ||
if (infos[i].getName().contains("Cable")) { | ||
try { | ||
dmxController = MidiSystem.getMidiDevice(infos[i]); | ||
} catch (MidiUnavailableException ex) { | ||
Logger.getLogger(MidiConnection.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
} | ||
if (dmxController != null) { | ||
if (!dmxController.isOpen()) { | ||
try { | ||
dmxController.open(); | ||
} catch (MidiUnavailableException ex) { | ||
Logger.getLogger(MidiConnection.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void change(int channel, int value) { | ||
if (value < 256 && value >= 0 && channel >= 0 && channel < MAX_CH) { | ||
valNew[channel] = value; | ||
} | ||
} | ||
|
||
private void send(int channel, int value) { | ||
System.out.println("Midi send: " + channel + " ," + value / 2); | ||
System.out.println("Midi send: " + (CONTROL_CHANGE + channel / 128) + " ," + channel % 128 + " ," + value / 2); | ||
try { | ||
ShortMessage message = new ShortMessage(CONTROL_CHANGE, channel / 128, channel % 128, value / 2); | ||
try { | ||
dmxController.getReceiver().send(message, -1); | ||
} catch (MidiUnavailableException ex) { | ||
System.out.println("No Midi " + channel + " ," + value); | ||
//stop = true; | ||
//stop(); | ||
} catch (NullPointerException np) { | ||
System.out.println("midi=null"); | ||
} | ||
} catch (InvalidMidiDataException ex) { | ||
Logger.getLogger(MidiConnection.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
private void loop() { | ||
int i; | ||
for (i = 0; i < MAX_CH; i++) { | ||
if (valOld[i] != valNew[i]) { | ||
send(i, valNew[i]); | ||
valOld[i] = valNew[i]; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (!stop) { | ||
loop(); | ||
} | ||
if (dmxController != null) { | ||
dmxController.close(); | ||
} | ||
} | ||
} |
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
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
52 changes: 52 additions & 0 deletions
52
DMXSoftware/src/main/java/SnowballThrower/dmxsoftware/Processing/Manage.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package SnowballThrower.dmxsoftware.Processing; | ||
|
||
import SnowballThrower.dmxsoftware.Communicate.MidiConnection; | ||
import SnowballThrower.dmxsoftware.Communicate.SerialConnection; | ||
import SnowballThrower.dmxsoftware.Surface.ControlSurface; | ||
|
||
/** | ||
* | ||
* @author Sven | ||
*/ | ||
public class Manage { | ||
|
||
ControlSurface cs; | ||
MidiConnection mc; | ||
SerialConnection sc; | ||
|
||
public Manage() { | ||
mc = new MidiConnection(); | ||
} | ||
|
||
public void send(int channel, int value) { | ||
if (channel < 16 * 12 && channel > 0 && value > 0 && value < 256) { | ||
mc.change(channel, value); | ||
} | ||
} | ||
|
||
public void handle(String id, int value) { | ||
try { | ||
int ch = Integer.parseInt(id); | ||
if (ch < 1000) { | ||
System.out.println("Change: " + id + " ," + value); | ||
send(ch - 1, value); | ||
return; | ||
} | ||
} catch (Exception ex) { | ||
|
||
} | ||
} | ||
|
||
public void startMidi() { | ||
try { | ||
mc.start(); | ||
} catch (Exception ex) { | ||
System.out.println("Error in startMidi"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.