Skip to content

Commit

Permalink
Fader und Midi, refs #3, #5
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowballThrower committed Feb 12, 2016
1 parent d48110e commit 05acfd5
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 34 deletions.
23 changes: 16 additions & 7 deletions DMXSoftware/Data/DeviceTypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,23 @@
</Device>

<Device Id="3">
<Name>"Renkforce RDM Par_5"</Name>
<Name>"Renkforce RDM Par_10"</Name>
<Type>"Par"</Type>
<Power>"60"</Power>
<Symbol>"Data/Pictures/RenkforceRDM_5.png"</Symbol>

<Channels No="5">
<Channels No="10">

<Channel Nr="1" F="Red">
<Channel Nr="1" F="Dimmer">
<ChName>"Dimmer"</ChName>
<Values case="0">
<conditions>
</conditions>
<Value low="0" high="255">"1:1"</Value>
</Values>
</Channel>

<Channel Nr="2" F="Red">
<ChName>"Red"</ChName>
<Values case="0">
<conditions>
Expand All @@ -145,31 +154,31 @@
</Values>
</Channel>

<Channel Nr="2" F="Green">
<Channel Nr="3" F="Green">
<ChName>"Green"</ChName>
<Values case="0">
<conditions>
</conditions>
<Value low="0" high="255">"1:1"</Value>
</Values>
</Channel>
<Channel Nr="3" F="Blue">
<Channel Nr="4" F="Blue">
<ChName>"Blue"</ChName>
<Values case="0">
<conditions>
</conditions>
<Value low="0" high="255">"1:1"</Value>
</Values>
</Channel>
<Channel Nr="4" F="White">
<Channel Nr="5" F="White">
<ChName>"White"</ChName>
<Values case="0">
<conditions>
</conditions>
<Value low="0" high="255">"1:1"</Value>
</Values>
</Channel>
<Channel Nr="5" F="Amber">
<Channel Nr="6" F="Amber">
<ChName>"Amber"</ChName>
<Values case="0">
<conditions>
Expand Down
6 changes: 3 additions & 3 deletions DMXSoftware/Data/Devices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
<Name>"BAR 1"</Name>
<Additional>"Kuhstall Tor-Seite Mistfall"</Additional>
</Device>
<Device Id="5" Channel="125">
<Device Id="5" Channel="124">
<Type Id="4"></Type>
<Name>"BAR 2"</Name>
<Additional>"Kuhstall Tor-Seite Deele"</Additional>
</Device>
<Device Id="6" Channel="150">
<Device Id="6" Channel="148">
<Type Id="4"></Type>
<Name>"BAR 3"</Name>
<Additional>"Kuhstall Haus-Seite Mistfall"</Additional>
</Device>
<Device Id="7" Channel="175">
<Device Id="7" Channel="172">
<Type Id="4"></Type>
<Name>"BAR 4"</Name>
<Additional>"Kuhstall Haus-Seite Deele"</Additional>
Expand Down
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public DeviceType getType() {
public String getImagePath() {
return type.picturePath;
}

public int getStartCh() {
return this.startChannel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
*/
package SnowballThrower.dmxsoftware;

import SnowballThrower.dmxsoftware.Database.Function;
import SnowballThrower.dmxsoftware.Processing.Devices;
import SnowballThrower.dmxsoftware.Database.XMLReader;
import SnowballThrower.dmxsoftware.Processing.Manage;
import SnowballThrower.dmxsoftware.Surface.ControlSurface;
import SnowballThrower.dmxsoftware.Surface.Fader;
import SnowballThrower.dmxsoftware.Surface.FaderListener;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
Expand All @@ -28,15 +24,17 @@ public class HelloWorldMain extends Application {

@Override
public void start(Stage primaryStage) {
Manage mng = new Manage();
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
mng.startMidi();
Devices devices = new Devices();
new ControlSurface(devices.getDevices());
ControlSurface cs = new ControlSurface(mng, devices.getDevices());
}
});

Expand Down
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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import SnowballThrower.dmxsoftware.Database.Channel;
import SnowballThrower.dmxsoftware.Database.Device;
import SnowballThrower.dmxsoftware.Processing.Manage;
import java.util.List;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.InputEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
Expand All @@ -35,30 +38,50 @@ public class ControlSurface extends Application {
List<Device> devices;
double windowHeight;
double windowWidth;
Manage manager;

public ControlSurface(List<Device> devices) {
public ControlSurface(Manage mng, List<Device> devices) {
manager = mng;
this.devices = devices;
stage = new Stage();
ScrollPane pane = allDevs();
pane.setLayoutY(50);
Group buttons = new Group();
StackPane devSceneGroup = new StackPane(pane, buttons);
faders = new Scene(devSceneGroup, 1000, 800);
stage.setScene(faders);
//pane.setMaxHeight(stage.getHeight());
stage.show();
}
ScrollPane allDevs(){

int dev = 0;
double sizeX = 70;
double sizeY = 200;
double distY = 20;
this.devices = devices;
int dev = 0;
ScrollPane pane = new ScrollPane();
pane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
FaderListener fl = new FaderListener();
pane.addEventFilter(InputEvent.ANY, (event) -> {
if (event.getEventType().toString().contains("SCROLL")) {
//System.out.println(event.getEventType());
event.consume();
}
});
FaderListener fl = new FaderListener(manager);
Group faderGroup = new Group();
for (Device device : devices) {
Group picture;
System.out.println(device.getImagePath());
try {
Image image = new Image(device.getImagePath());
ImageView imV = new ImageView(image);
imV.setFitHeight(2*sizeX);
imV.setFitWidth(2*sizeX);
imV.setFitHeight(2 * sizeX);
imV.setFitWidth(2 * sizeX);
imV.setLayoutY(dev * (sizeY + distY));
picture = new Group(imV);
} catch (Exception ex){
} catch (Exception ex) {
System.out.println(ex);
Rectangle rect = new Rectangle(0,dev * (sizeY + distY),sizeX*2,sizeX*2);
Rectangle rect = new Rectangle(0, dev * (sizeY + distY), sizeX * 2, sizeX * 2);
rect.setFill(Color.WHITE);
picture = new Group(rect);
}
Expand All @@ -67,7 +90,8 @@ public ControlSurface(List<Device> devices) {
System.out.println(device.getName());
for (Channel channel : device.getType().getChannels()) {
if (channel != null) {
Fader fader = new Fader(ch * sizeX, dev * (sizeY + distY), sizeX, sizeY, channel);
Fader fader = new Fader("" + (device.getStartCh() + ch - 2),
ch * sizeX, dev * (sizeY + distY), sizeX, sizeY, channel);
fl.addFader(fader);
faderGroup.getChildren().add(fader.getFader());
}
Expand All @@ -77,17 +101,21 @@ public ControlSurface(List<Device> devices) {
}
Group group = new Group(faderGroup);
pane.setContent(group);
Scene faders = new Scene(pane, 1000, 800);
group.setOnMouseClicked(fl);
group.setOnMousePressed(fl);
group.setOnMouseDragged(fl);
stage = new Stage();
stage.setScene(faders);
stage.show();
return pane;
}

@Override
public void start(Stage primaryStage) throws Exception {
System.out.println("Start");
}

public void setManager(Manage mng) {
manager = mng;
}

public void send(int channel, int value) {

}
}
Loading

0 comments on commit 05acfd5

Please sign in to comment.