Search in sources :

Example 1 with AudioException

use of jmri.AudioException in project JMRI by JMRI.

the class AudioListenerFrame method applyPressed.

void applyPressed(ActionEvent e) {
    String user = userName.getText();
    if (user.equals("")) {
        user = null;
    }
    String sName = sysName.getText().toUpperCase();
    AudioListener l;
    try {
        l = (AudioListener) InstanceManager.getDefault(jmri.AudioManager.class).provideAudio(sName);
        l.setUserName(user);
        l.setPosition(position.getValue());
        l.setVelocity(velocity.getValue());
        l.setOrientation(oriAt.getValue(), oriUp.getValue());
        l.setGain(gain.getValue());
        l.setMetersPerUnit(AbstractAudio.roundDecimal((Float) metersPerUnit.getValue(), 4d));
        // Notify changes
        model.fireTableDataChanged();
    } catch (AudioException | IllegalArgumentException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), Bundle.getMessage("AudioCreateErrorTitle"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : AudioListener(jmri.jmrit.audio.AudioListener) AudioException(jmri.AudioException)

Example 2 with AudioException

use of jmri.AudioException 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 3 with AudioException

use of jmri.AudioException 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)

Example 4 with AudioException

use of jmri.AudioException in project JMRI by JMRI.

the class AbstractAudioManagerConfigXML method loadAudio.

/**
     * Utility method to load the individual Audio objects. If there's no
     * additional info needed for a specific Audio type, invoke this with the
     * parent of the set of Audio elements.
     *
     * @param audio Element containing the Audio elements to load.
     */
@SuppressWarnings("unchecked")
public void loadAudio(Element audio) {
    AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
    // Count number of loaded Audio objects
    int loadedObjects = 0;
    // Load buffers first
    List<Element> audioList = audio.getChildren("audiobuffer");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Buffer objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioBuffer ab = (AudioBuffer) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(ab, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("url")) != null) {
                ab.setURL(ce.getValue());
            }
            if ((ce = e.getChild("looppoint")) != null) {
                if ((value = ce.getAttributeValue("start")) != null) {
                    ab.setStartLoopPoint(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("end")) != null) {
                    ab.setEndLoopPoint(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("streamed")) != null) {
                ab.setStreamed(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioBuffer (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Now load sources
    audioList = audio.getChildren("audiosource");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Source objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioSource as = (AudioSource) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(as, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("position")) != null) {
                as.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("velocity")) != null) {
                as.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("assignedbuffer")) != null) {
                if (ce.getValue().length() != 0 && !ce.getValue().equals("null")) {
                    as.setAssignedBuffer(ce.getValue());
                }
            }
            if ((ce = e.getChild("gain")) != null && ce.getValue().length() != 0) {
                as.setGain(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("pitch")) != null && ce.getValue().length() != 0) {
                as.setPitch(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("distances")) != null) {
                if ((value = ce.getAttributeValue("ref")) != null) {
                    as.setReferenceDistance(Float.parseFloat(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaximumDistance(Float.parseFloat(value));
                }
            }
            if ((ce = e.getChild("loops")) != null) {
                if ((value = ce.getAttributeValue("min")) != null) {
                    as.setMinLoops(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaxLoops(Integer.parseInt(value));
                }
            //                    if ((value = ce.getAttributeValue("mindelay"))!=null)
            //                        as.setMinLoopDelay(Integer.parseInt(value));
            //                    if ((value = ce.getAttributeValue("maxdelay"))!=null)
            //                        as.setMaxLoopDelay(Integer.parseInt(value));
            }
            if ((ce = e.getChild("fadetimes")) != null) {
                if ((value = ce.getAttributeValue("in")) != null) {
                    as.setFadeIn(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("out")) != null) {
                    as.setFadeOut(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("dopplerfactor")) != null && ce.getValue().length() != 0) {
                as.setDopplerFactor(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("positionrelative")) != null) {
                as.setPositionRelative(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioSource (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Finally, load Listeners if needed
    if (loadedObjects > 0) {
        audioList = audio.getChildren("audiolistener");
        if (log.isDebugEnabled()) {
            log.debug("Found " + audioList.size() + " Audio Listener objects");
        }
        for (int i = 0; i < audioList.size(); i++) {
            Element e = audioList.get(i);
            String sysName = getSystemName(e);
            if (sysName == null) {
                log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
                break;
            }
            String userName = getUserName(e);
            if (log.isDebugEnabled()) {
                log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
            }
            try {
                AudioListener al = (AudioListener) am.newAudio(sysName, userName);
                // load common parts
                loadCommon(al, e);
                // load sub-type specific parts
                // Transient object for reading child elements
                Element ce;
                if ((ce = e.getChild("position")) != null) {
                    al.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("velocity")) != null) {
                    al.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("orientation")) != null) {
                    al.setOrientation(new Vector3f(Float.parseFloat(ce.getAttributeValue("atX")), Float.parseFloat(ce.getAttributeValue("atY")), Float.parseFloat(ce.getAttributeValue("atZ"))), new Vector3f(Float.parseFloat(ce.getAttributeValue("upX")), Float.parseFloat(ce.getAttributeValue("upY")), Float.parseFloat(ce.getAttributeValue("upZ"))));
                }
                if ((ce = e.getChild("gain")) != null) {
                    al.setGain(Float.parseFloat(ce.getValue()));
                }
                if ((ce = e.getChild("metersperunit")) != null) {
                    al.setMetersPerUnit(Float.parseFloat((ce.getValue())));
                }
            } catch (AudioException ex) {
                log.error("Error loading AudioListener (" + sysName + "): " + ex);
            }
        }
        Attribute a;
        if ((a = audio.getAttribute("distanceattenuated")) != null) {
            am.getActiveAudioFactory().setDistanceAttenuated(a.getValue().equals("yes"));
        }
    }
}
Also used : AudioSource(jmri.jmrit.audio.AudioSource) AudioManager(jmri.AudioManager) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) AudioException(jmri.AudioException) Vector3f(javax.vecmath.Vector3f) AudioListener(jmri.jmrit.audio.AudioListener) AudioBuffer(jmri.jmrit.audio.AudioBuffer)

Example 5 with AudioException

use of jmri.AudioException in project JMRI by JMRI.

the class DefaultAudioManager method createNewAudio.

@Override
protected synchronized Audio createNewAudio(String systemName, String userName) throws AudioException {
    if (activeAudioFactory == null) {
        log.debug("Initialise in createNewAudio");
        init();
    }
    Audio a = null;
    log.debug("sysName: " + systemName + " userName: " + userName);
    if (userName != null && _tuser.containsKey(userName)) {
        throw new AudioException("Duplicate name");
    }
    switch(systemName.charAt(2)) {
        case Audio.BUFFER:
            {
                if (countBuffers >= MAX_BUFFERS) {
                    log.error("Maximum number of buffers reached (" + countBuffers + ") " + MAX_BUFFERS);
                    throw new AudioException("Maximum number of buffers reached (" + countBuffers + ") " + MAX_BUFFERS);
                }
                countBuffers++;
                a = activeAudioFactory.createNewBuffer(systemName, userName);
                break;
            }
        case Audio.LISTENER:
            {
                if (countListeners >= MAX_LISTENERS) {
                    log.error("Maximum number of Listeners reached (" + countListeners + ") " + MAX_LISTENERS);
                    throw new AudioException("Maximum number of Listeners reached (" + countListeners + ") " + MAX_LISTENERS);
                }
                countListeners++;
                a = activeAudioFactory.createNewListener(systemName, userName);
                break;
            }
        case Audio.SOURCE:
            {
                if (countSources >= MAX_SOURCES) {
                    log.error("Maximum number of Sources reached (" + countSources + ") " + MAX_SOURCES);
                    throw new AudioException("Maximum number of Sources reached (" + countSources + ") " + MAX_SOURCES);
                }
                countSources++;
                a = activeAudioFactory.createNewSource(systemName, userName);
                break;
            }
        default:
            throw new IllegalArgumentException();
    }
    return a;
}
Also used : AudioException(jmri.AudioException) Audio(jmri.Audio)

Aggregations

AudioException (jmri.AudioException)9 Audio (jmri.Audio)5 AudioManager (jmri.AudioManager)4 AudioBuffer (jmri.jmrit.audio.AudioBuffer)3 AudioListener (jmri.jmrit.audio.AudioListener)2 AudioSource (jmri.jmrit.audio.AudioSource)2 AL (com.jogamp.openal.AL)1 ALException (com.jogamp.openal.ALException)1 ALut (com.jogamp.openal.util.ALut)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ByteOrder (java.nio.ByteOrder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Vector3f (javax.vecmath.Vector3f)1 QuietShutDownTask (jmri.implementation.QuietShutDownTask)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1