Skip to content

Commit

Permalink
Merge 5e09dad into 892b346
Browse files Browse the repository at this point in the history
  • Loading branch information
klk32003 committed Feb 11, 2018
2 parents 892b346 + 5e09dad commit 19f323d
Show file tree
Hide file tree
Showing 16 changed files with 427 additions and 354 deletions.
214 changes: 93 additions & 121 deletions java/src/jmri/jmrit/vsdecoder/Diesel3Sound.java

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions java/src/jmri/jmrit/vsdecoder/EnginePane.java
@@ -1,6 +1,10 @@
package jmri.jmrit.vsdecoder;

/*
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;

/**
* <hr>
* This file is part of JMRI.
* <P>
Expand All @@ -15,13 +19,9 @@
* for more details.
* <P>
*
* @author Mark Underwood Copyright (C) 2011
*
* @author Mark Underwood Copyright (C) 2011
* @author Klaus Killinger Copyright (C) 2018
*/
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class EnginePane extends JPanel {
// Superclass for Diesel, Steam, Electric panes.
Expand All @@ -47,7 +47,6 @@ public EnginePane() {
}

public void init() {

}

public void initContext(Object context) {
Expand All @@ -59,7 +58,7 @@ public void initComponents() {

@Override
public String getName() {
return (name);
return name;
}

@Override
Expand All @@ -68,7 +67,7 @@ public void setName(String n) {
}

public EngineSoundEvent getEngine() {
return (engine);
return engine;
}

public void setEngine(EngineSoundEvent e) {
Expand All @@ -78,6 +77,15 @@ public void setEngine(EngineSoundEvent e) {
public void setThrottle(int t) {
}

public void setSpeed(float s) {
}

public void startButtonClick() {
}

public void setButtonDelay(long t) {
}

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
listenerList.add(PropertyChangeListener.class, listener);
Expand Down
113 changes: 71 additions & 42 deletions java/src/jmri/jmrit/vsdecoder/EngineSound.java
@@ -1,6 +1,13 @@
package jmri.jmrit.vsdecoder;

/*
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SwingUtilities;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <hr>
* This file is part of JMRI.
* <P>
Expand All @@ -15,15 +22,9 @@
* for more details.
* <P>
*
* @author Mark Underwood Copyright (C) 2011
*
* @author Mark Underwood Copyright (C) 2011
* @author Klaus Killinger Copyright (C) 2018
*/
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// Usage:
// EngineSound() : constructor
// play() : plays short horn pop
Expand All @@ -35,12 +36,14 @@ class EngineSound extends VSDSound {
boolean initialized = false;
boolean engine_started = false;
boolean auto_start_engine = false;
boolean is_auto_start; // Can be used in config.xml
boolean is_first = false;

int fade_length = 100;
int fade_in_time = 100;
int fade_out_time = 100;

javax.swing.Timer t;
EnginePane engine_pane;

public EngineSound(String name) {
super(name);
Expand All @@ -51,25 +54,25 @@ public EngineSound(String name) {

public boolean init() {
auto_start_engine = VSDecoderManager.instance().getVSDecoderPreferences().isAutoStartingEngine();
return (true);
return true;
}

// Note: Play and Loop do the same thing, since all of the notch sounds are set to loop.
@Override
public void play() {
log.debug("EngineSound Play");
if (engine_started || auto_start_engine) {
is_playing = true;
}
//if (engine_started || auto_start_engine) {
// is_playing = true;
//}
}

// Note: Play and Loop do the same thing, since all of the notch sounds are set to loop.
@Override
public void loop() {
log.debug("EngineSound Loop");
if (engine_started || auto_start_engine) {
is_playing = true;
}
//if (engine_started || auto_start_engine) {
// is_playing = true;
//}
}

@Override
Expand All @@ -88,11 +91,11 @@ public void fadeOut() {
}

public int getFadeInTime() {
return (this.fade_in_time);
return this.fade_in_time;
}

public int getFadeOutTime() {
return (this.fade_out_time);
return this.fade_out_time;
}

protected void setFadeInTime(int t) {
Expand All @@ -107,7 +110,7 @@ protected void setFadeInTime(String s) {
try {
this.setFadeInTime(Integer.parseInt(s));
} catch (NumberFormatException e) {
log.debug("setFadeInTime Failed to parse int from: " + s);
log.debug("setFadeInTime Failed to parse int from: {}", s);
}
}

Expand All @@ -134,9 +137,8 @@ static final public int calcEngineNotch(final float throttle) {
if (notch < 1) {
notch = 1;
}
log.debug("Throttle: " + throttle + " Notch: " + notch);
return (notch);

log.debug("Throttle: {}, Notch: {}", throttle, notch);
return notch;
}

static final public int calcEngineNotch(final double throttle) {
Expand All @@ -145,34 +147,34 @@ static final public int calcEngineNotch(final double throttle) {
if (notch < 1) {
notch = 1;
}
//log.warn("Throttle: " + throttle + " Notch: " + notch);
return (notch);

//log.warn("Throttle: {}, Notch: {}", throttle, notch);
return notch;
}

// This is the default behavior. Subclasses can do fancier things
// if they want.
public void handleSpeedChange(Float s, EnginePane e) {
e.setThrottle(EngineSound.calcEngineNotch(s));
engine_pane = e;
engine_pane.setSpeed(s);
}

@Override
protected Timer newTimer(int time, boolean repeat, ActionListener al) {
t = new Timer(time, al);
t.setRepeats(repeat);
return (t);
void setFirstSpeed(boolean f) {
is_first = f;
}

boolean getFirstSpeed() {
return is_first;
}

public void startEngine() {
log.debug("Starting Engine");
}

public void stopEngine() {
engine_started = false;
}

public boolean isEngineStarted() {
return (engine_started);
return engine_started;
}

public void setEngineStarted(boolean es) {
Expand All @@ -194,15 +196,42 @@ public void setVolume(float v) {
// do nothing.
}

// Note: We have to invoke engine_pane later because everything's not really setup yet
// Need some more time to get the speed from the assigned throttle
void autoStartCheck() {
if (auto_start_engine || is_auto_start) {
SwingUtilities.invokeLater(() -> {
t = newTimer(40, false, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (engine_pane != null && getFirstSpeed()) {
engine_pane.startButtonClick();
} else {
log.warn("engine pane or speed not found");
}
}
});
t.start();
});
}
}

protected boolean setXMLAutoStart(Element e) {
String a = e.getChildText("auto-start");
if ((a != null) && (a.equals("yes"))) {
return true;
} else {
return false;
}
}

protected float setXMLGain(Element e) {
String g = e.getChildText("gain");
log.debug(" gain: " + g);
if ((g != null) && !(g.equals(""))) {
return (Float.parseFloat(g));
log.debug(" gain: {}", g);
if ((g != null) && !(g.isEmpty())) {
return Float.parseFloat(g);
} else {
return (default_gain);
return default_gain;
}

}

@Override
Expand All @@ -211,7 +240,7 @@ public Element getXml() {
me.setAttribute("name", this.getName());
me.setAttribute("type", "engine");
// Do something, eventually...
return (me);
return me;
}

public void setXml(Element e, VSDFile vf) {
Expand All @@ -222,8 +251,8 @@ public void setXml(Element e, VSDFile vf) {
//log.debug("EngineSound: " + this.getName());
this.setFadeInTime(e.getChildText("fade-in-time"));
this.setFadeOutTime(e.getChildText("fade-out-time"));
log.debug("Name: " + this.getName() + "Fade-In-Time: " + this.getFadeInTime()
+ " Fade-Out-Time: " + this.getFadeOutTime());
log.debug("Name: {}, Fade-In-Time: {}, Fade-Out-Time: {}", this.getName(),
this.getFadeInTime(), this.getFadeOutTime());
}

private static final Logger log = LoggerFactory.getLogger(EngineSound.class);
Expand Down

0 comments on commit 19f323d

Please sign in to comment.