Commit 96acfb10 authored by moll's avatar moll

Adaptions to tulip-cps 1.4.0; trigger sound not in paint

parent df185030
......@@ -28,12 +28,12 @@
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -31,8 +31,9 @@ bootstrapping.root = circuit_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
equation.system = circuit_scenario.xml
scenario.description = circuit_scenario.xml
......
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1920
windowHeight = 1080
fullScreen = false
font = Arial
fontSize = 13
colour = BLACK
centred = false
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = light_scenario.xml
# Properties for the equation system
#scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
#scriptEngine.workingDir = model
executor.class=lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
variable.class=lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
equation.system = light_scenario.xml
scenario.description = light_scenario.xml
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1920
windowHeight = 1080
fullScreen = false
font = Arial
fontSize = 13
colour = BLACK
centred = false
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = light_scenario.xml
# Properties for the equation system
executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
logic.variable.class = lu.list.itis.dkd.tui.cps.variable.BooleanVariable
......@@ -26,6 +26,7 @@ import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.cps.system.Equation;
import lu.list.itis.dkd.tui.cps.system.Mapping;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
......@@ -77,6 +78,7 @@ public class Scene extends Content {
private boolean triggered = false;
private AudioInputStream audioIn;
private AudioInputStream audioStream;
private boolean isPlaying;
/**
* Constructor initializing all fields.
......@@ -110,10 +112,12 @@ public class Scene extends Content {
variables.add(triggerVariable);
}
final LinkedHashSet<Variable> triggerVariables = new LinkedHashSet<Variable>();
// trigger = new Equation(new Mapping(variables, triggerVariable), triggerCondition);
triggerVariables.add(triggerVariable);
trigger = new Equation(new Mapping(variables, triggerVariables), triggerCondition);
final LinkedHashSet<Variable> outputs = new LinkedHashSet<>();
outputs.add(triggerVariable);
trigger = new Equation(new Mapping(variables, outputs), triggerCondition);
trigger.setExecutor(new JavascriptExecutor());
try {
final Element imageNode = element.getChild(Externalization.IMAGE_ELEMENT);
......@@ -132,7 +136,6 @@ public class Scene extends Content {
final Element imageBase64Node = element.getChild(Externalization.IMAGE_BASE64_ELEMENT);
if ((null != imageBase64Node) && (imageBase64Node.getText() != "")) { //$NON-NLS-1$
final String[] tokens = (imageBase64Node.getText()).split(","); //$NON-NLS-1$
// System.out.println(tokens[1]);
byte[] imageByte;
imageByte = Base64.getDecoder().decode(tokens[1]);
final ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
......@@ -170,9 +173,10 @@ public class Scene extends Content {
final Element soundBase64Node = element.getChild(Externalization.SOUND_BASE64_NODE);
if ((null != soundBase64Node) && (soundBase64Node.getText() != "")) { //$NON-NLS-1$
final String[] tokens = (soundBase64Node.getText()).split(","); //$NON-NLS-1$
// System.out.println(tokens[1]);
final byte[] soundByte = Base64.getDecoder().decode(tokens[1]);
audioIn = AudioSystem.getAudioInputStream(new ByteArrayInputStream(soundByte));
final byte[] soundByte = Base64.getDecoder().decode(tokens[1]).clone();
final ByteArrayInputStream ais = new ByteArrayInputStream(soundByte);
audioIn = AudioSystem.getAudioInputStream(ais);
audioClip = AudioSystem.getClip();
audioClip.open(audioIn);
......@@ -211,26 +215,21 @@ public class Scene extends Content {
triggered = false;
}
if (triggerVariable.getValue() && !triggered) {
playSound();
}
return triggerVariable.getValue();
}
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
// canvas.drawImage(scenery, 0, 0, null);
if (scenery != null) {
scenery.paintIcon(null, canvas, 0, 0);
}
if ((!triggered) && (audioClip != null)) {
audioClip.setFramePosition(0);
audioClip.start();
triggered = true;
}
}
/** {@inheritDoc} */
@Override
public void initialise() {
......@@ -239,4 +238,21 @@ public class Scene extends Content {
/**
* @throws IOException
* @throws LineUnavailableException
*
*/
public void playSound() {
if (audioClip != null && !isPlaying && !triggered) {
triggered = true;
audioClip.setFramePosition(0);
audioClip.start();
// audioClip.drain();
// audioClip.loop(1);
}
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.cps.system.executor.Executor;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
import lu.list.itis.dkd.tui.event.ContentEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
*/
@NonNullByDefault
public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();
private static Map<String, Scene> scenes;
// private static ScriptEngine scriptEngine;
private static Executor scriptEngine;
ArrayList<Content> drawableContents = new ArrayList<>();
private StageManager() {
scriptEngine = new JavascriptExecutor();
// scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
}
/**
* Method for returning the single instance of this manger class.
*
* @return The unique instance of this manager implementing the Singleton pattern.
*/
public static StageManager getInstance() {
return INSTANCE;
}
/**
* @param _scenes
*/
public static void setScenes(Map<String, Scene> _scenes) {
scenes = _scenes;
// scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
scenes.values().forEach(scene -> scene.getTrigger().setExecutor(scriptEngine));
}
/** {@inheritDoc} */
@Override
public void contentUpdated(ContentEvent event) {
// This particular stage manager is not driven by the content. It is the variables tied to
// the content that change underlying conditions to draw the stage.
}
/** {@inheritDoc} */
@Override
public Collection<Content> getDrawableContents() {
drawableContents.clear();
for (final Scene scene : scenes.values()) {
if (scene.evaluateTrigger()) {
drawableContents.add(scene);
}
}
Collections.sort(drawableContents);
return drawableContents;
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
*/
@NonNullByDefault
public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();
private static Map<String, Scene> scenes;
private static ScriptEngine scriptEngine;
ArrayList<Content> drawableContents = new ArrayList<>();
private StageManager() {
scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
}
/**
* Method for returning the single instance of this manger class.
*
* @return The unique instance of this manager implementing the Singleton pattern.
*/
public static StageManager getInstance() {
return INSTANCE;
}
/**
* @param _scenes
*/
public static void setScenes(Map<String, Scene> _scenes) {
scenes = _scenes;
// scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
}
/** {@inheritDoc} */
@Override
public void contentUpdated(ContentEvent event) {
// This particular stage manager is not driven by the content. It is the variables tied to
// the content that change underlying conditions to draw the stage.
}
/** {@inheritDoc} */
@Override
public Collection<Content> getDrawableContents() {
drawableContents.clear();
for (final Scene scene : scenes.values()) {
if (scene.evaluateTrigger()) {
drawableContents.add(scene);
}
}
Collections.sort(drawableContents);
return drawableContents;
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment