mirror of
https://github.com/sigmasternchen/Dionysus
synced 2025-03-14 23:58:54 +00:00
i did some stuff
This commit is contained in:
parent
fedf152a19
commit
6b33b9f51d
61 changed files with 826 additions and 0 deletions
10
.classpath
Normal file
10
.classpath
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
23
.project
Normal file
23
.project
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Dionysus</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
13
pom.xml
Normal file
13
pom.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.persei.dionysus</groupId>
|
||||
<artifactId>Dionysus</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>uk.co.caprica</groupId>
|
||||
<artifactId>vlcj</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
45
src/main/java/net/persei/dionysus/AudioPlayer.java
Normal file
45
src/main/java/net/persei/dionysus/AudioPlayer.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
import uk.co.caprica.vlcj.component.AudioMediaPlayerComponent;
|
||||
import uk.co.caprica.vlcj.player.MediaPlayer;
|
||||
|
||||
public class AudioPlayer implements Player {
|
||||
|
||||
private AudioMediaPlayerComponent player;
|
||||
private boolean loop = false;
|
||||
private String name;
|
||||
|
||||
public AudioPlayer(String name) {
|
||||
this.name = name;
|
||||
player = new AudioMediaPlayerComponent();
|
||||
}
|
||||
|
||||
public boolean isLoop() {
|
||||
return loop;
|
||||
}
|
||||
|
||||
public void playFile(String file) {
|
||||
getMediaPlayer().playMedia(file);
|
||||
}
|
||||
|
||||
public void play() {
|
||||
getMediaPlayer().play();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
getMediaPlayer().pause();
|
||||
}
|
||||
|
||||
public void setLoop(boolean loop) {
|
||||
this.loop = loop;
|
||||
getMediaPlayer().setRepeat(loop);
|
||||
}
|
||||
|
||||
public MediaPlayer getMediaPlayer() {
|
||||
return player.getMediaPlayer();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
27
src/main/java/net/persei/dionysus/Main.java
Normal file
27
src/main/java/net/persei/dionysus/Main.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
import net.persei.dionysus.exceptions.LibrariesNotFoundException;
|
||||
import uk.co.caprica.vlcj.binding.LibVlc;
|
||||
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static final String TITLE = "Dionysus";
|
||||
private static PlayerGUI playerGUI;
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws LibrariesNotFoundException
|
||||
*/
|
||||
public static void main(String[] args) throws LibrariesNotFoundException {
|
||||
if (!findLibs())
|
||||
throw new LibrariesNotFoundException();
|
||||
|
||||
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
|
||||
}
|
||||
|
||||
private static boolean findLibs() {
|
||||
return new NativeDiscovery().discover();
|
||||
}
|
||||
|
||||
}
|
5
src/main/java/net/persei/dionysus/MidiTrigger.java
Normal file
5
src/main/java/net/persei/dionysus/MidiTrigger.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
public class MidiTrigger {
|
||||
|
||||
}
|
13
src/main/java/net/persei/dionysus/Player.java
Normal file
13
src/main/java/net/persei/dionysus/Player.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
import uk.co.caprica.vlcj.player.MediaPlayer;
|
||||
|
||||
public interface Player {
|
||||
boolean isLoop();
|
||||
void playFile(String file);
|
||||
void play();
|
||||
void pause();
|
||||
void setLoop(boolean loop);
|
||||
MediaPlayer getMediaPlayer();
|
||||
String getName();
|
||||
}
|
79
src/main/java/net/persei/dionysus/PlayerGUI.java
Normal file
79
src/main/java/net/persei/dionysus/PlayerGUI.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
|
||||
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
|
||||
|
||||
public class PlayerGUI extends JFrame implements Player {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6068058949441154348L;
|
||||
|
||||
private EmbeddedMediaPlayerComponent player = new EmbeddedMediaPlayerComponent();
|
||||
|
||||
private boolean loop = false;
|
||||
private boolean fullscreen = false;
|
||||
|
||||
public boolean isFullscreen() {
|
||||
return fullscreen;
|
||||
}
|
||||
|
||||
public PlayerGUI(boolean fullscreen) throws HeadlessException {
|
||||
this();
|
||||
dispose();
|
||||
if (fullscreen) {
|
||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
setUndecorated(true);
|
||||
}
|
||||
setVisible(true);
|
||||
}
|
||||
public PlayerGUI() throws HeadlessException {
|
||||
super(Main.TITLE);
|
||||
setBounds(100, 100, 600, 400);
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
setContentPane(player);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
player.release();
|
||||
System.out.println("release");
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isLoop() {
|
||||
return loop;
|
||||
}
|
||||
|
||||
public void setLoop(boolean loop) {
|
||||
this.loop = loop;
|
||||
getMediaPlayer().setRepeat(loop);
|
||||
}
|
||||
|
||||
public void playFile(String file) {
|
||||
getMediaPlayer().playMedia(file);
|
||||
}
|
||||
|
||||
public void play() {
|
||||
getMediaPlayer().play();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
getMediaPlayer().pause();
|
||||
}
|
||||
|
||||
public EmbeddedMediaPlayer getMediaPlayer() {
|
||||
return player.getMediaPlayer();
|
||||
}
|
||||
}
|
37
src/main/java/net/persei/dionysus/Setup.java
Normal file
37
src/main/java/net/persei/dionysus/Setup.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package net.persei.dionysus;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.persei.dionysus.blocks.InitialBlock;
|
||||
|
||||
public class Setup {
|
||||
private List<InitialBlock> initBlocks = new LinkedList<InitialBlock>();
|
||||
private List<Player> players = new LinkedList<Player>();
|
||||
|
||||
// ugly, but necessary for flexible states
|
||||
private List<String> states = new LinkedList<String>(){{
|
||||
push("none");
|
||||
}};
|
||||
private int state = 0;
|
||||
|
||||
public List<InitialBlock> getInitBlocks() {
|
||||
return initBlocks;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return states.get(state);
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public List<String> getStates() {
|
||||
return states;
|
||||
}
|
||||
}
|
29
src/main/java/net/persei/dionysus/blocks/Block.java
Normal file
29
src/main/java/net/persei/dionysus/blocks/Block.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.persei.dionysus.exceptions.UnexpectedDataTypeException;
|
||||
|
||||
public abstract class Block {
|
||||
protected String name;
|
||||
protected BlockType type;
|
||||
protected List<Lane> lanes = new LinkedList<Lane>();
|
||||
|
||||
public List<Lane> getOutputLanes() {
|
||||
return lanes;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public BlockType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean preMagic (Data input, Lane lane) throws Exception {
|
||||
BlockHelper.addPassLog(input, "blocks", this);
|
||||
return magic(input, lane);
|
||||
}
|
||||
|
||||
abstract public boolean magic(Data input, Lane lane) throws Exception;
|
||||
}
|
111
src/main/java/net/persei/dionysus/blocks/BlockCondition.java
Normal file
111
src/main/java/net/persei/dionysus/blocks/BlockCondition.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.persei.dionysus.Setup;
|
||||
import net.persei.dionysus.exceptions.DataValueNotAvailableException;
|
||||
import net.persei.dionysus.exceptions.MalformedBlockConditionException;
|
||||
|
||||
public class BlockCondition {
|
||||
|
||||
private String condition;
|
||||
|
||||
public BlockCondition(String condition) {
|
||||
condition = condition.replace(" ", "");
|
||||
condition = condition.replace(" ", "");
|
||||
condition = condition.replace("\n", "");
|
||||
condition = condition.replace("\r", "");
|
||||
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public boolean parse(Data input) throws MalformedBlockConditionException, DataValueNotAvailableException {
|
||||
String tmp = new String(condition);
|
||||
|
||||
while(true) {
|
||||
if (tmp.indexOf("(") < 0)
|
||||
break;
|
||||
|
||||
int open = 0;
|
||||
while(tmp.indexOf("(", open + 1) >= 0) {
|
||||
open = tmp.indexOf("(", open + 1);
|
||||
}
|
||||
int close = tmp.indexOf(")", open);
|
||||
|
||||
if (close == -1)
|
||||
throw new MalformedBlockConditionException();
|
||||
|
||||
String sub = tmp.substring(open + 1, close - 1);
|
||||
String before = tmp.substring(0, open - 1);
|
||||
String after = tmp.substring(close + 1);
|
||||
tmp = before + (minTerm(sub, input)) + after;
|
||||
}
|
||||
|
||||
return minTerm(tmp, input);
|
||||
}
|
||||
private boolean minTerm(String sub, Data input) throws DataValueNotAvailableException, MalformedBlockConditionException {
|
||||
if (sub.equals("true"))
|
||||
return true;
|
||||
if (sub.equals("false"))
|
||||
return false;
|
||||
if (sub.indexOf("&") >= 0)
|
||||
return minTerm(sub.substring(0, sub.indexOf("&")), input) &&
|
||||
minTerm(sub.substring(sub.indexOf("&") + 1), input);
|
||||
if (sub.indexOf("|") >= 0)
|
||||
return minTerm(sub.substring(0, sub.indexOf("|")), input) ||
|
||||
minTerm(sub.substring(sub.indexOf("|") + 1), input);
|
||||
if (sub.indexOf("^") >= 0)
|
||||
return minTerm(sub.substring(0, sub.indexOf("^")), input) ^
|
||||
minTerm(sub.substring(sub.indexOf("^") + 1), input);
|
||||
if (sub.indexOf("!") >= 0)
|
||||
return ! minTerm(sub.substring(sub.indexOf("!") + 1), input);
|
||||
if (sub.indexOf("==") >= 0)
|
||||
return stringValue(sub.substring(0, sub.indexOf("==")), input).equals(stringValue(sub.substring(sub.indexOf("==") + 1), input));
|
||||
if (sub.indexOf(">") >= 0)
|
||||
return intValue(sub.substring(0, sub.indexOf(">")), input) > intValue(sub.substring(sub.indexOf(">") + 1), input);
|
||||
if (sub.indexOf("<") >= 0)
|
||||
return intValue(sub.substring(0, sub.indexOf("<")), input) < intValue(sub.substring(sub.indexOf("<") + 1), input);
|
||||
if (sub.indexOf(">=") >= 0)
|
||||
return intValue(sub.substring(0, sub.indexOf(">=")), input) >= intValue(sub.substring(sub.indexOf(">=") + 1), input);
|
||||
if (sub.indexOf("<=") >= 0)
|
||||
return intValue(sub.substring(0, sub.indexOf("<=")), input) >= intValue(sub.substring(sub.indexOf("<=") + 1), input);
|
||||
if (sub.indexOf("data") >= 0)
|
||||
return minTerm(getDataValue(sub, input), input);
|
||||
|
||||
throw new MalformedBlockConditionException();
|
||||
}
|
||||
|
||||
private int intValue(String substring, Data input) {
|
||||
try {
|
||||
return Integer.parseInt(substring);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(getDataValue(substring, input));
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
||||
private String getDataValue(String string, Data input) throws DataValueNotAvailableException {
|
||||
if (string.equals("setup.state"))
|
||||
return ((Setup) input.getEntry("setup")).getState();
|
||||
if (string.indexOf("data.") == 0) {
|
||||
String key = string.substring("data.".length() + 1);
|
||||
if (input.getEntry("blockData") != null) {
|
||||
Map<String, String> blockData = (Map<String, String>) input.getEntry("blockData");
|
||||
if (blockData.get(key) != null)
|
||||
return blockData.get(key);
|
||||
}
|
||||
}
|
||||
throw new DataValueNotAvailableException();
|
||||
}
|
||||
|
||||
private String stringValue(String string, Data input) throws DataValueNotAvailableException {
|
||||
if (string.substring(0, 1).equals("\"") && string.substring(string.length() - 1).equals("\""))
|
||||
return string.substring(1, string.length() - 1);
|
||||
|
||||
return getDataValue(string, input);
|
||||
}
|
||||
}
|
21
src/main/java/net/persei/dionysus/blocks/BlockHelper.java
Normal file
21
src/main/java/net/persei/dionysus/blocks/BlockHelper.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.persei.dionysus.exceptions.UnexpectedDataTypeException;
|
||||
|
||||
public class BlockHelper {
|
||||
static void addPassLog(Data input, String type, Object object) throws UnexpectedDataTypeException {
|
||||
Object obj = input.getEntry(type);
|
||||
List<Object> log;
|
||||
if (obj == null) {
|
||||
log = new LinkedList<Object>();
|
||||
} else if (! (obj instanceof List)) {
|
||||
throw new UnexpectedDataTypeException(type);
|
||||
} else {
|
||||
log = (List<Object>) obj;
|
||||
}
|
||||
log.add(object);
|
||||
}
|
||||
}
|
8
src/main/java/net/persei/dionysus/blocks/BlockType.java
Normal file
8
src/main/java/net/persei/dionysus/blocks/BlockType.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
public enum BlockType {
|
||||
PassiveBlock,
|
||||
ActiveBlock,
|
||||
ConditionalBlock,
|
||||
MultiplexingBlock
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
public abstract class ConditionalBlock extends Block {
|
||||
}
|
15
src/main/java/net/persei/dionysus/blocks/Data.java
Normal file
15
src/main/java/net/persei/dionysus/blocks/Data.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Data {
|
||||
private Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
public Object getEntry(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
public Object setEntry(String key, Object obj) {
|
||||
return map.put(key, obj);
|
||||
}
|
||||
}
|
27
src/main/java/net/persei/dionysus/blocks/DelayBlock.java
Normal file
27
src/main/java/net/persei/dionysus/blocks/DelayBlock.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
public class DelayBlock extends Block {
|
||||
private long sleepTime = 1000;
|
||||
|
||||
public long getSleepTime() {
|
||||
return sleepTime;
|
||||
}
|
||||
|
||||
public void setSleepTime(long sleepTime) {
|
||||
this.sleepTime = sleepTime;
|
||||
}
|
||||
|
||||
public DelayBlock() {
|
||||
super();
|
||||
name = "DelayBlock";
|
||||
type = BlockType.PassiveBlock;
|
||||
lanes.add(new Lane("delayed lane"));
|
||||
}
|
||||
|
||||
public boolean magic(Data input, Lane lane) throws Exception {
|
||||
Thread.sleep(sleepTime);
|
||||
|
||||
return lanes.get(0).invoke(input);
|
||||
}
|
||||
|
||||
}
|
24
src/main/java/net/persei/dionysus/blocks/IfElseBlock.java
Normal file
24
src/main/java/net/persei/dionysus/blocks/IfElseBlock.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
public class IfElseBlock extends ConditionalBlock {
|
||||
|
||||
private BlockCondition condition;
|
||||
|
||||
public IfElseBlock(BlockCondition condition) {
|
||||
super();
|
||||
this.name = "IfElseBlock";
|
||||
this.type = BlockType.ConditionalBlock;
|
||||
|
||||
this.condition = condition;
|
||||
this.lanes.add(new Lane("false lane")); // 0
|
||||
this.lanes.add(new Lane("true lane")); // 1
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean magic(Data input, Lane lane) throws Exception {
|
||||
if (condition.parse(input))
|
||||
return lanes.get(1).invoke(input);
|
||||
else
|
||||
return lanes.get(0).invoke(input);
|
||||
}
|
||||
}
|
23
src/main/java/net/persei/dionysus/blocks/InitialBlock.java
Normal file
23
src/main/java/net/persei/dionysus/blocks/InitialBlock.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.persei.dionysus.MidiTrigger;
|
||||
import net.persei.dionysus.Setup;
|
||||
import net.persei.dionysus.exceptions.UnexpectedDataTypeException;
|
||||
|
||||
public abstract class InitialBlock extends Block {
|
||||
protected List<MidiTrigger> triggers = new LinkedList<MidiTrigger>();
|
||||
|
||||
public List<MidiTrigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
public boolean trigger(MidiTrigger trigger, Setup setup) throws Exception {
|
||||
Data input = new Data();
|
||||
input.setEntry("trigger", trigger);
|
||||
input.setEntry("setup", setup);
|
||||
return preMagic(input, null);
|
||||
}
|
||||
}
|
41
src/main/java/net/persei/dionysus/blocks/Lane.java
Normal file
41
src/main/java/net/persei/dionysus/blocks/Lane.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.persei.dionysus.exceptions.UnexpectedDataTypeException;
|
||||
|
||||
public class Lane {
|
||||
private List<Block> attachedBlocks = new LinkedList<Block>();
|
||||
static private int count = 1;
|
||||
final private int id;
|
||||
final private String name;
|
||||
|
||||
public List<Block> getAttachedBlocks() {
|
||||
return attachedBlocks;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Lane(String name) {
|
||||
super();
|
||||
this.id = count++;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void attach(Block block) {
|
||||
attachedBlocks.add(block);
|
||||
}
|
||||
|
||||
public boolean invoke(Data input) throws Exception {
|
||||
BlockHelper.addPassLog(input, "lanes", this);
|
||||
|
||||
boolean res = true;
|
||||
for (Block block : attachedBlocks) {
|
||||
res = block.preMagic(input, this) & res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
32
src/main/java/net/persei/dionysus/blocks/SetDataBlock.java
Normal file
32
src/main/java/net/persei/dionysus/blocks/SetDataBlock.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SetDataBlock extends Block {
|
||||
|
||||
private String data;
|
||||
private String key;
|
||||
|
||||
public SetDataBlock(String key, String data) {
|
||||
super();
|
||||
name = "SetDateBlock";
|
||||
type = BlockType.ActiveBlock;
|
||||
this.key = key;
|
||||
this.data = data;
|
||||
lanes.add(new Lane("lane"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean magic(Data input, Lane lane) throws Exception {
|
||||
Map<String, String> blockData = (Map<String, String>) input.getEntry("blockData");
|
||||
if (blockData == null) {
|
||||
input.setEntry("blockData", new HashMap<String, String>());
|
||||
blockData = (Map<String, String>) input.getEntry("blockData");
|
||||
}
|
||||
blockData.put(key, data);
|
||||
|
||||
return this.lanes.get(0).invoke(input);
|
||||
}
|
||||
|
||||
}
|
30
src/main/java/net/persei/dionysus/blocks/SetStateBlock.java
Normal file
30
src/main/java/net/persei/dionysus/blocks/SetStateBlock.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import net.persei.dionysus.Setup;
|
||||
|
||||
public class SetStateBlock extends Block {
|
||||
|
||||
private String state;
|
||||
|
||||
public SetStateBlock(String status) {
|
||||
super();
|
||||
name = "SetStateBlock";
|
||||
type = BlockType.ActiveBlock;
|
||||
this.state = status;
|
||||
lanes.add(new Lane("lane"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean magic(Data input, Lane lane) throws Exception {
|
||||
Setup setup = ((Setup) input.getEntry("setup"));
|
||||
int i = setup.getStates().indexOf(state);
|
||||
if (i >= 0)
|
||||
setup.setState(i);
|
||||
else {
|
||||
setup.getStates().add(state);
|
||||
setup.setState(setup.getStates().indexOf(state));
|
||||
}
|
||||
return this.lanes.get(0).invoke(input);
|
||||
}
|
||||
|
||||
}
|
63
src/main/java/net/persei/dionysus/blocks/SetupParser.java
Normal file
63
src/main/java/net/persei/dionysus/blocks/SetupParser.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
import net.persei.dionysus.Setup;
|
||||
import net.persei.dionysus.exceptions.MalformedSetupFileException;
|
||||
import net.persei.dionysus.exceptions.WhatTheFuckException;
|
||||
|
||||
public class SetupParser {
|
||||
private enum Mode {
|
||||
none, players, triggers, blocks
|
||||
}
|
||||
static public Setup parse(String file) throws MalformedSetupFileException, WhatTheFuckException {
|
||||
String lines[] = file.split("\n");
|
||||
|
||||
Mode mode = Mode.none;
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = lines[i];
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
String tokens[] = line.split(" ");
|
||||
for (int j = 0; j < tokens.length; j++) {
|
||||
String token = tokens[j];
|
||||
if (token.length() == 0)
|
||||
continue;
|
||||
|
||||
// comment line
|
||||
if (token.substring(0, 1).equals("#"))
|
||||
break;
|
||||
|
||||
// mode selection
|
||||
if (token.equals("*players")) {
|
||||
mode = Mode.players;
|
||||
break;
|
||||
}
|
||||
if (token.equals("*triggers")) {
|
||||
mode = Mode.triggers;
|
||||
break;
|
||||
}
|
||||
if (token.equals("*blocks")) {
|
||||
mode = Mode.blocks;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO
|
||||
switch(mode) {
|
||||
case blocks:
|
||||
break;
|
||||
case players:
|
||||
break;
|
||||
case triggers:
|
||||
break;
|
||||
case none:
|
||||
throw new MalformedSetupFileException();
|
||||
default:
|
||||
throw new WhatTheFuckException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
23
src/main/java/net/persei/dionysus/blocks/SplitterBlock.java
Normal file
23
src/main/java/net/persei/dionysus/blocks/SplitterBlock.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package net.persei.dionysus.blocks;
|
||||
|
||||
public class SplitterBlock extends Block {
|
||||
|
||||
public SplitterBlock(int n) {
|
||||
super();
|
||||
for (int i = 0; i < n; i++) {
|
||||
this.lanes.add(new Lane("split lane " + i));
|
||||
}
|
||||
this.name = "SplitterBlock";
|
||||
this.type = BlockType.MultiplexingBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean magic(Data input, Lane lane) throws Exception {
|
||||
boolean res = true;
|
||||
for (Lane l : lanes) {
|
||||
res = l.invoke(input) && res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package net.persei.dionysus.controlroom;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.persei.dionysus.Setup;
|
||||
import net.persei.dionysus.blocks.InitialBlock;
|
||||
|
||||
public class ControlRoom extends JFrame {
|
||||
|
||||
private ControlRoomPanel panel;
|
||||
private Setup setup;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7130672040530068619L;
|
||||
|
||||
public ControlRoom(Setup setup) {
|
||||
super();
|
||||
this.setup = setup;
|
||||
setBounds(50, 50, 1000, 800);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
panel = new ControlRoomPanel();
|
||||
|
||||
setContentPane(panel);
|
||||
}
|
||||
|
||||
private class ControlRoomPanel extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7915937062340285742L;
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponents(g);
|
||||
g.setColor(Color.BLACK);
|
||||
List<InitialBlock> initBlocks = setup.getInitBlocks();
|
||||
|
||||
for (int i = 0; i < initBlocks.size(); i++) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class DataValueNotAvailableException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3826451107086625794L;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class LibrariesNotFoundException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1839814203088638288L;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class MalformedBlockConditionException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8751303849610920723L;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class MalformedSetupFileException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2464874594169642335L;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class UnexpectedDataTypeException extends Exception {
|
||||
|
||||
private String dataKey = null;
|
||||
|
||||
public String getDataKey() {
|
||||
return dataKey;
|
||||
}
|
||||
|
||||
public UnexpectedDataTypeException(String string) {
|
||||
dataKey = string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3634084166179938086L;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.persei.dionysus.exceptions;
|
||||
|
||||
public class WhatTheFuckException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2453004182880966130L;
|
||||
|
||||
}
|
BIN
target/classes/net/persei/dionysus/AudioPlayer.class
Normal file
BIN
target/classes/net/persei/dionysus/AudioPlayer.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/Main.class
Normal file
BIN
target/classes/net/persei/dionysus/Main.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/MidiTrigger.class
Normal file
BIN
target/classes/net/persei/dionysus/MidiTrigger.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/Player.class
Normal file
BIN
target/classes/net/persei/dionysus/Player.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/PlayerGUI$1.class
Normal file
BIN
target/classes/net/persei/dionysus/PlayerGUI$1.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/PlayerGUI.class
Normal file
BIN
target/classes/net/persei/dionysus/PlayerGUI.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/Setup$1.class
Normal file
BIN
target/classes/net/persei/dionysus/Setup$1.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/Setup.class
Normal file
BIN
target/classes/net/persei/dionysus/Setup.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/Block.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/Block.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/BlockCondition.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/BlockCondition.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/BlockHelper.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/BlockHelper.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/BlockType.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/BlockType.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/ConditionalBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/ConditionalBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/Data.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/Data.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/DelayBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/DelayBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/IfElseBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/IfElseBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/InitialBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/InitialBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/Lane.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/Lane.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/SetDataBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/SetDataBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/SetStateBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/SetStateBlock.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/SetupParser$Mode.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/SetupParser$Mode.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/SetupParser.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/SetupParser.class
Normal file
Binary file not shown.
BIN
target/classes/net/persei/dionysus/blocks/SplitterBlock.class
Normal file
BIN
target/classes/net/persei/dionysus/blocks/SplitterBlock.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/classes/net/persei/dionysus/controlroom/ControlRoom.class
Normal file
BIN
target/classes/net/persei/dionysus/controlroom/ControlRoom.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue