Skip to content

Commit

Permalink
bidirektionale MIDI-Verbindung, JavaFX-Bug bei schneller Fader-Bewegu…
Browse files Browse the repository at this point in the history
…ng, refs #3, #7
  • Loading branch information
SnowballThrower committed Feb 19, 2016
1 parent 6fbaadd commit 75db3ad
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MidiHandler implements Receiver {
@Override
public void send(MidiMessage message, long timeStamp) {
System.out.println("got message");
//handle((ShortMessage) message);
handle((ShortMessage) message);
}

@Override
Expand All @@ -40,6 +40,7 @@ private void handle(ShortMessage message) {
if (message.getCommand() == CONTROL_CHANGE) {
int fader = message.getChannel();
int value = message.getData2() + message.getData1() * 32;
System.out.println("CC " + fader + " " + value);
manager.handleMidiFader(fader, value);
}
if (message.getCommand() == NOTE_ON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SnowballThrower.dmxsoftware.Surface.Fader;
import java.util.LinkedList;
import java.util.List;
import javafx.application.Platform;

/**
*
Expand All @@ -31,7 +32,11 @@ public void setValue(int value) {

public void act() {
for (Fader fader : faders) {
fader.act();
try {
fader.act();
} catch (Exception e) {
System.out.println("Fehler bei fader aktualisieren.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Channels(Manage manager, List<Device> devices) {
for (DMXChannel channel : device.getChannels()) {
if (channel != null) {
channel.addManager(manager);
channels[channel.adress] = channel;
channels[channel.getAdress()] = channel;
}
}
}
Expand All @@ -37,4 +37,12 @@ public Channels(Manage manager, List<Device> devices) {
public DMXChannel[] getAll() {
return channels;
}

public DMXChannel get(int index) {
try {
return channels[index];
} catch (Exception ex) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Devices {
Channels channels;

public Devices(Manage mng) {
mng.setDevs(this);
XMLReader xml = new XMLReader();
types = xml.getTypes();
devices = xml.getDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@
import SnowballThrower.dmxsoftware.Communicate.MidiConnection;
import SnowballThrower.dmxsoftware.Communicate.SerialConnection;
import SnowballThrower.dmxsoftware.Database.Channel;
import SnowballThrower.dmxsoftware.Database.DMXChannel;
import SnowballThrower.dmxsoftware.Surface.ControlSurface;

/**
*
* @author Sven
*/
public class Manage {

ControlSurface cs;
MidiConnection mc;
SerialConnection sc;
Devices devs;

public Manage() {
mc = new MidiConnection(this);
}

public void send(int channel, int value) { //channl <16 * 12
if (channel < 1024 && channel >= 0 && value >= 0 && value < 256) {
mc.change(channel, value);
}
}

public void handle(String id, int value) {
try {
int ch = Integer.parseInt(id);
Expand All @@ -42,47 +43,51 @@ public void handle(String id, int value) {
System.out.println("no id: " + id);
}
}

public void handle(int channel, int value) {
send(channel - 1, value);
}

public void startMidi() {
try {
mc.start();
} catch (Exception ex) {
System.out.println("Error in startMidi");
}
}

public void barExtend() {

}

void setDispText(String line2, String line1) {
for (int i = 0; i < line1.length(); i++) {
mc.sendDisp(0, i, line1.charAt(i));
}

for (int i = 0; i < line2.length(); i++) {
mc.sendDisp(1, i, line2.charAt(i));
}
}

public void handleMidiFader(int fader, int value) {
try {
Channel[] chn = devs.devices.get(0).getChannels();
chn[fader].setValue(value / 4);

devs.getChannels().get(fader+1).setValue(value / 4);
} catch (IndexOutOfBoundsException | NullPointerException ex) {

System.out.println("nö");
}
}

public void handleMidiAction(int data1, boolean b) {
if (b) {
System.out.println("Pressed Button " + data1);
} else {
System.out.println("Released Button " + data1);
}
}

void setDevs(Devices aThis) {
devs = aThis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public void setValue(int value) {

public void act() {
this.value = channel.getValue();
head.setTranslateY(-((height - 2 * frameY) / max) * value);
try {
head.setTranslateY(-((height - 2 * frameY) / max) * value);
} catch (Exception ex) {

}
meaning.setText(device.getMeaning(channel.getNumber() - 1));
name.setText(device.getChannelName(channel.getNumber() - 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class toggleHandler implements EventHandler<ActionEvent> {

@Override
public void handle(ActionEvent t) {
cs.toggle(func, i);
//cs.toggle(func, i);
}

}

0 comments on commit 75db3ad

Please sign in to comment.