use of jmri.Audio in project JMRI by JMRI.
the class DefaultAudioManager method getSystemNameList.
@Override
public List<String> getSystemNameList(char subType) {
List<String> tempList = getSystemNameList();
List<String> out = new ArrayList<>();
tempList.stream().forEach((tempList1) -> {
Audio audio = this.getBySystemName(tempList1);
if (audio.getSubType() == subType) {
out.add(tempList1);
}
});
return out;
}
use of jmri.Audio in project JMRI by JMRI.
the class DefaultAudioManager method init.
/**
* Method used to initialise the manager
*/
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
// OK to write to static variables as we only do so if not initialised
@Override
public synchronized void init() {
if (!initialised) {
// // First try to initialise LWJGL
// activeAudioFactory = new LWJGLAudioFactory();
// log.debug("Try to initialise LWJGLAudioFactory");
//
// // If LWJGL fails, fall-back to JOAL
// if (!activeAudioFactory.init()) {
activeAudioFactory = new JoalAudioFactory();
log.debug("Try to initialise JoalAudioFactory");
// If JOAL fails, fall-back to JavaSound
if (!activeAudioFactory.init()) {
activeAudioFactory = new JavaSoundAudioFactory();
log.debug("Try to initialise JavaSoundAudioFactory");
// Finally, if JavaSound fails, fall-back to a Null sound system
if (!activeAudioFactory.init()) {
activeAudioFactory = new NullAudioFactory();
log.debug("Try to initialise NullAudioFactory");
activeAudioFactory.init();
}
}
// Create default Listener and save in map
try {
Audio s = createNewAudio("IAL$", "Default Audio Listener");
register(s);
} catch (AudioException ex) {
log.error("Error creating Default Audio Listener: " + ex);
}
// Finally, create and register a shutdown task to ensure clean exit
if (audioShutDownTask == null) {
audioShutDownTask = new QuietShutDownTask("AudioFactory Shutdown") {
@Override
public boolean execute() {
InstanceManager.getDefault(jmri.AudioManager.class).cleanUp();
return true;
}
};
}
if (InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
InstanceManager.getDefault(jmri.ShutDownManager.class).register(audioShutDownTask);
}
initialised = true;
if (log.isDebugEnabled()) {
log.debug("Initialised AudioFactory type: " + activeAudioFactory.getClass().getSimpleName());
}
}
}
use of jmri.Audio in project JMRI by JMRI.
the class NullAudioFactory method cleanup.
@Override
public void cleanup() {
// Stop the command thread
super.cleanup();
// Get the active AudioManager
AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
// Retrieve list of Audio Objects and remove the sources
List<String> audios = am.getSystemNameList();
for (String audioName : audios) {
Audio audio = am.getAudio(audioName);
if (audio.getSubType() == Audio.SOURCE) {
if (log.isDebugEnabled()) {
log.debug("Removing NullAudioSource: " + audioName);
}
// Cast to NullAudioSource and cleanup
((NullAudioSource) audio).cleanUp();
}
}
// Now, re-retrieve list of Audio objects and remove the buffers
audios = am.getSystemNameList();
for (String audioName : audios) {
Audio audio = am.getAudio(audioName);
if (audio.getSubType() == Audio.BUFFER) {
if (log.isDebugEnabled()) {
log.debug("Removing NullAudioBuffer: " + audioName);
}
// Cast to NullAudioBuffer and cleanup
((NullAudioBuffer) audio).cleanUp();
}
}
// Lastly, re-retrieve list and remove listener.
audios = am.getSystemNameList();
for (String audioName : audios) {
Audio audio = am.getAudio(audioName);
if (audio.getSubType() == Audio.LISTENER) {
if (log.isDebugEnabled()) {
log.debug("Removing NullAudioListener: " + audioName);
}
// Cast to NullAudioListener and cleanup
((NullAudioListener) audio).cleanUp();
}
}
// Finally, shutdown NullAudio and close the output device
log.debug("Shutting down NullAudio");
// Do nothing
}
use of jmri.Audio in project JMRI by JMRI.
the class AbstractAudioSource method setAssignedBuffer.
@Override
public void setAssignedBuffer(String bufferSystemName) {
if (!queued) {
AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
Audio a = am.getBySystemName(bufferSystemName);
if (a.getSubType() == Audio.BUFFER) {
setAssignedBuffer((AudioBuffer) a);
} else {
log.warn("Attempt to assign incorrect object type to buffer - AudioBuffer expected.");
this.buffer = null;
this.bound = false;
}
} else {
log.error("Attempted to assign buffer " + bufferSystemName + " to Queued Source " + this.getSystemName());
}
}
use of jmri.Audio in project JMRI by JMRI.
the class AbstractAudioManager method newAudio.
@Override
public Audio newAudio(String systemName, String userName) throws AudioException {
if (log.isDebugEnabled()) {
log.debug("new Audio:" + // NOI18N
((systemName == null) ? "null" : systemName) + ";" + // NOI18N
((userName == null) ? "null" : userName));
}
checkSystemName(systemName, userName);
// is system name in correct format?
if ((!systemName.startsWith("" + getSystemPrefix() + typeLetter() + Audio.BUFFER)) && (!systemName.startsWith("" + getSystemPrefix() + typeLetter() + Audio.SOURCE)) && (!systemName.startsWith("" + getSystemPrefix() + typeLetter() + Audio.LISTENER))) {
log.error("Invalid system name for Audio: " + systemName + " needed either " + getSystemPrefix() + typeLetter() + // NOI18N
Audio.BUFFER + " or " + getSystemPrefix() + typeLetter() + // NOI18N
Audio.SOURCE + " or " + getSystemPrefix() + typeLetter() + // NOI18N
Audio.LISTENER);
throw new AudioException("Invalid system name for Audio: " + systemName + " needed either " + getSystemPrefix() + typeLetter() + Audio.BUFFER + " or " + getSystemPrefix() + typeLetter() + Audio.SOURCE + " or " + getSystemPrefix() + typeLetter() + Audio.LISTENER);
}
// return existing if there is one
Audio s;
if ((userName != null) && ((s = getByUserName(userName)) != null)) {
if (getBySystemName(systemName) != s) {
log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + s.getSystemName() + ")");
}
log.debug("Found existing Audio (" + s.getSystemName() + "). Returning existing (1).");
return s;
}
if ((s = getBySystemName(systemName)) != null) {
if ((s.getUserName() == null) && (userName != null)) {
s.setUserName(userName);
} else if (userName != null) {
log.warn("Found audio via system name (" + systemName + ") with non-null user name (" + userName + // NOI18N
")");
}
log.debug("Found existing Audio (" + s.getSystemName() + "). Returning existing (2).");
return s;
}
log.debug("Existing audio not found. Creating new. (" + systemName + ")");
// doesn't exist, make a new one
s = createNewAudio(systemName, userName);
// save in the maps
if (s != null) {
register(s);
} else {
// must have failed to create
throw new IllegalArgumentException("can't create audio with System Name \"" + systemName + "\"");
}
return s;
}
Aggregations