Search in sources :

Example 1 with AudioManager

use of jmri.AudioManager in project JMRI by JMRI.

the class JoalAudioFactory 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 JoalAudioSource: " + audioName);
            }
            // Cast to JoalAudioSource and cleanup
            ((JoalAudioSource) 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 JoalAudioBuffer: " + audioName);
            }
            // Cast to JoalAudioBuffer and cleanup
            ((JoalAudioBuffer) 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 JoalAudioListener: " + audioName);
            }
            // Cast to JoalAudioListener and cleanup
            ((JoalAudioListener) audio).cleanUp();
        }
    }
    // Finally, shutdown OpenAL and close the output device
    log.debug("Shutting down OpenAL");
    ALut.alutExit();
}
Also used : AudioManager(jmri.AudioManager) Audio(jmri.Audio)

Example 2 with AudioManager

use of jmri.AudioManager in project JMRI by JMRI.

the class JavaSoundAudioListener method recalculateSources.

/**
     * Private method to loop through all sources and recalculate gain & pan
     */
private void recalculateSources() {
    // Loop through each AudioSource and recalculate their gain & pan
    AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
    for (String sysName : am.getSystemNameList()) {
        Audio audio = am.getBySystemName(sysName);
        if (audio.getSubType() == Audio.SOURCE && audio instanceof JavaSoundAudioSource) {
            ((JavaSoundAudioSource) audio).calculateGain();
            ((JavaSoundAudioSource) audio).calculatePan();
            if (log.isDebugEnabled()) {
                log.debug("Recalculating gain & pan for JavaSoundAudioSource " + audio.getSystemName());
            }
        }
    }
}
Also used : AudioManager(jmri.AudioManager) Audio(jmri.Audio)

Example 3 with AudioManager

use of jmri.AudioManager in project JMRI by JMRI.

the class JavaSoundAudioFactory method cleanup.

@Override
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "OK to write to static variable mixer as we are cleaning up")
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 JavaSoundAudioSource: " + audioName);
            }
            // Cast to JavaSoundAudioSource and cleanup
            ((JavaSoundAudioSource) 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 JavaSoundAudioBuffer: " + audioName);
            }
            // Cast to JavaSoundAudioBuffer and cleanup
            ((JavaSoundAudioBuffer) 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 JavaSoundAudioListener: " + audioName);
            }
            // Cast to JavaSoundAudioListener and cleanup
            ((JavaSoundAudioListener) audio).cleanUp();
        }
    }
    // Finally, shutdown JavaSound and close the output device
    log.debug("Shutting down JavaSound");
    mixer = null;
}
Also used : AudioManager(jmri.AudioManager) Audio(jmri.Audio) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with AudioManager

use of jmri.AudioManager in project JMRI by JMRI.

the class AudioBufferFrame method applyPressed.

void applyPressed(ActionEvent e) {
    String user = userName.getText();
    if (user.equals("")) {
        user = null;
    }
    String sName = sysName.getText().toUpperCase();
    AudioBuffer b;
    try {
        AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
        try {
            b = (AudioBuffer) am.provideAudio(sName);
        } catch (IllegalArgumentException ex) {
            throw new AudioException("Problem creating buffer");
        }
        if (newBuffer && am.getByUserName(user) != null) {
            am.deregister(b);
            synchronized (lock) {
                counter--;
            }
            throw new AudioException("Duplicate user name - please modify");
        }
        b.setUserName(user);
        b.setStreamed(stream.isSelected());
        if (newBuffer || !b.getURL().equals(url.getText())) {
            b.setURL(url.getText());
            log.debug("After load, end loop point = " + b.getEndLoopPoint());
        //b.setStartLoopPoint((Long)loopStart.getValue());
        //b.setEndLoopPoint((Long)loopEnd.getValue());
        } else {
            if (!b.getURL().equals(url.getText())) {
                log.debug("Sound changed from: " + b.getURL());
                b.setURL(url.getText());
            }
        }
        // Update streaming checkbox if necessary
        stream.setSelected(b.isStreamed());
        //(!b.isStreamedForced());
        stream.setEnabled(false);
        // Notify changes
        model.fireTableDataChanged();
    } catch (AudioException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), Bundle.getMessage("AudioCreateErrorTitle"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : AudioManager(jmri.AudioManager) AudioException(jmri.AudioException) AudioBuffer(jmri.jmrit.audio.AudioBuffer)

Example 5 with AudioManager

use of jmri.AudioManager in project JMRI by JMRI.

the class AudioSourceFrame method applyPressed.

void applyPressed(ActionEvent e) {
    String user = userName.getText();
    if (user.equals("")) {
        user = null;
    }
    String sName = sysName.getText().toUpperCase();
    AudioSource s;
    try {
        AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
        try {
            s = (AudioSource) am.provideAudio(sName);
        } catch (IllegalArgumentException ex) {
            throw new AudioException("Problem creating source");
        }
        if (newSource && am.getByUserName(user) != null) {
            am.deregister(s);
            synchronized (lock) {
                counter--;
            }
            throw new AudioException("Duplicate user name - please modify");
        }
        s.setUserName(user);
        if (assignedBuffer.getSelectedIndex() > 0) {
            Audio a = am.getAudio((String) assignedBuffer.getSelectedItem());
            s.setAssignedBuffer(a.getSystemName());
        }
        s.setMinLoops(loopInfinite.isSelected() ? AudioSource.LOOP_CONTINUOUS : (Integer) loopMin.getValue());
        s.setMaxLoops(loopInfinite.isSelected() ? AudioSource.LOOP_CONTINUOUS : (Integer) loopMax.getValue());
        //            s.setMinLoopDelay((Integer) loopMinDelay.getValue());
        //            s.setMaxLoopDelay((Integer) loopMaxDelay.getValue());
        s.setPosition(position.getValue());
        s.setPositionRelative(positionRelative.isSelected());
        s.setVelocity(velocity.getValue());
        s.setGain(gain.getValue());
        s.setPitch(pitch.getValue());
        s.setReferenceDistance((Float) refDistance.getValue());
        s.setMaximumDistance((Float) maxDistance.getValue());
        s.setRollOffFactor((Float) rollOffFactor.getValue());
        s.setFadeIn((Integer) fadeInTime.getValue());
        s.setFadeOut((Integer) fadeOutTime.getValue());
        // Notify changes
        model.fireTableDataChanged();
    } catch (AudioException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), Bundle.getMessage("AudioCreateErrorTitle"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : AudioSource(jmri.jmrit.audio.AudioSource) AudioManager(jmri.AudioManager) AudioException(jmri.AudioException) Audio(jmri.Audio)

Aggregations

AudioManager (jmri.AudioManager)12 Audio (jmri.Audio)8 AudioException (jmri.AudioException)4 AudioSource (jmri.jmrit.audio.AudioSource)4 AudioBuffer (jmri.jmrit.audio.AudioBuffer)3 AudioListener (jmri.jmrit.audio.AudioListener)2 Element (org.jdom2.Element)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Vector3f (javax.vecmath.Vector3f)1 AbstractAudio (jmri.implementation.AbstractAudio)1 Attribute (org.jdom2.Attribute)1