List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:jmri.jmrit.dispatcher.TrainInfoFile.java
License:Open Source License
public TrainInfo readTrainInfo(String name) throws org.jdom2.JDOMException, java.io.IOException { log.debug("entered readTrainInfo"); TrainInfo tInfo = null;/*from w ww.j a v a2s. c o m*/ // check if file exists if (checkFile(fileLocation + name)) { // file is present. tInfo = new TrainInfo(); root = rootFromName(fileLocation + name); if (root != null) { // there is a file Element traininfo = root.getChild("traininfo"); if (traininfo != null) { // there are train info options defined, read them if (traininfo.getAttribute("transitname") != null) { // there is a transit name selected tInfo.setTransitName(traininfo.getAttribute("transitname").getValue()); } else { log.error("Transit name missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("trainname") != null) { // there is a transit name selected tInfo.setTrainName(traininfo.getAttribute("trainname").getValue()); } else { log.error("Train name missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("dccaddress") != null) { tInfo.setDCCAddress(traininfo.getAttribute("dccaddress").getValue()); } else { log.error("DCC Address missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("trainintransit") != null) { tInfo.setTrainInTransit(true); if (traininfo.getAttribute("trainintransit").getValue().equals("no")) { tInfo.setTrainInTransit(false); } } else { log.error("Train in Transit check box missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("startblockname") != null) { // there is a transit name selected tInfo.setStartBlockName(traininfo.getAttribute("startblockname").getValue()); } else { log.error("Start block name missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("endblockname") != null) { // there is a transit name selected tInfo.setDestinationBlockName(traininfo.getAttribute("endblockname").getValue()); } else { log.error("Destination block name missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("trainfromroster") != null) { tInfo.setTrainFromRoster(true); if (traininfo.getAttribute("trainfromroster").getValue().equals("no")) { tInfo.setTrainFromRoster(false); } } if (traininfo.getAttribute("trainfromtrains") != null) { tInfo.setTrainFromTrains(true); if (traininfo.getAttribute("trainfromtrains").getValue().equals("no")) { tInfo.setTrainFromTrains(false); } } if (traininfo.getAttribute("trainfromuser") != null) { tInfo.setTrainFromUser(true); if (traininfo.getAttribute("trainfromuser").getValue().equals("no")) { tInfo.setTrainFromUser(false); } } if (traininfo.getAttribute("priority") != null) { tInfo.setPriority(traininfo.getAttribute("priority").getValue()); } else { log.error("Priority missing when reading TrainInfoFile " + name); } if (traininfo.getAttribute("resetwhendone") != null) { tInfo.setResetWhenDone(true); if (traininfo.getAttribute("resetwhendone").getValue().equals("no")) { tInfo.setResetWhenDone(false); } if (traininfo.getAttribute("delayedrestart") != null) { if (traininfo.getAttribute("delayedrestart").getValue().equals("no")) { tInfo.setDelayedRestart(ActiveTrain.NODELAY); } else if (traininfo.getAttribute("delayedrestart").getValue().equals("sensor")) { tInfo.setDelayedRestart(ActiveTrain.SENSORDELAY); if (traininfo.getAttribute("delayedrestartsensor") != null) { tInfo.setRestartDelaySensor( traininfo.getAttribute("delayedrestartsensor").getValue()); } } else if (traininfo.getAttribute("delayedrestart").getValue().equals("timed")) { tInfo.setDelayedRestart(ActiveTrain.TIMEDDELAY); if (traininfo.getAttribute("delayedrestarttime") != null) { tInfo.setRestartDelayTime( traininfo.getAttribute("delayedrestarttime").getValue()); } } } } if (traininfo.getAttribute("reverseatend") != null) { tInfo.setReverseAtEnd(true); if (traininfo.getAttribute("reverseatend").getValue().equals("no")) { tInfo.setReverseAtEnd(false); } } if (traininfo.getAttribute("delayedstart") != null) { if (traininfo.getAttribute("delayedstart").getValue().equals("no")) { tInfo.setDelayedStart(ActiveTrain.NODELAY); } else if (traininfo.getAttribute("delayedstart").getValue().equals("sensor")) { tInfo.setDelayedStart(ActiveTrain.SENSORDELAY); } else { //This covers the old versions of the file with "yes" tInfo.setDelayedStart(ActiveTrain.TIMEDDELAY); } } if (traininfo.getAttribute("departuretimehr") != null) { tInfo.setDepartureTimeHr(traininfo.getAttribute("departuretimehr").getValue()); } if (traininfo.getAttribute("departuretimemin") != null) { tInfo.setDepartureTimeMin(traininfo.getAttribute("departuretimemin").getValue()); } if (traininfo.getAttribute("delayedSensor") != null) { tInfo.setDelaySensor(traininfo.getAttribute("delayedSensor").getValue()); } if (traininfo.getAttribute("traintype") != null) { tInfo.setTrainType(traininfo.getAttribute("traintype").getValue()); } if (traininfo.getAttribute("autorun") != null) { tInfo.setRunAuto(true); if (traininfo.getAttribute("autorun").getValue().equals("no")) { tInfo.setRunAuto(false); } } // here retrieve items related only to automatically run trains if present if (traininfo.getAttribute("speedfactor") != null) { tInfo.setSpeedFactor(traininfo.getAttribute("speedfactor").getValue()); } if (traininfo.getAttribute("maxspeed") != null) { tInfo.setMaxSpeed(traininfo.getAttribute("maxspeed").getValue()); } if (traininfo.getAttribute("ramprate") != null) { tInfo.setRampRate(traininfo.getAttribute("ramprate").getValue()); } if (traininfo.getAttribute("resistancewheels") != null) { tInfo.setResistanceWheels(true); if (traininfo.getAttribute("resistancewheels").getValue().equals("no")) { tInfo.setResistanceWheels(false); } } if (traininfo.getAttribute("runinreverse") != null) { tInfo.setRunInReverse(true); if (traininfo.getAttribute("runinreverse").getValue().equals("no")) { tInfo.setRunInReverse(false); } } if (traininfo.getAttribute("sounddecoder") != null) { tInfo.setSoundDecoder(true); if (traininfo.getAttribute("sounddecoder").getValue().equals("no")) { tInfo.setSoundDecoder(false); } } if (traininfo.getAttribute("maxtrainlength") != null) { tInfo.setMaxTrainLength(traininfo.getAttribute("maxtrainlength").getValue()); } if (traininfo.getAttribute("terminatewhendone") != null) { tInfo.setTerminateWhenDone(false); if (traininfo.getAttribute("terminatewhendone").getValue().equals("yes")) { tInfo.setTerminateWhenDone(true); } } } } } return tInfo; }
From source file:jmri.jmrit.vsdecoder.BoolTrigger.java
License:Open Source License
@Override public void setXml(Element e) { // Get common stuff super.setXml(e); // Only do this if this is a BoolTrigger type Element if (e.getAttribute("type").getValue().equals("BOOLEAN")) { match_value = Boolean.parseBoolean(e.getChild("match").getValue()); }/* w w w . j a v a 2 s . c om*/ }
From source file:jmri.jmrit.vsdecoder.ButtonTrigger.java
License:Open Source License
@Override public void setXml(Element e) { // Get common stuff super.setXml(e); // Only do this if this is a ButtonTrigger type Element if (e.getAttribute("type").getValue().equals("BUTTON")) { match_value = Boolean.parseBoolean(e.getChild("match").getValue()); }//from w w w . j a va 2 s . c om }
From source file:jmri.jmrit.vsdecoder.Diesel2Sound.java
License:Open Source License
@Override public void setXml(Element e, VSDFile vf) { Element el;/*w w w . ja v a 2s .co m*/ String fn; NotchSound sb; // Handle the common stuff. super.setXml(e, vf); log.debug("Diesel EngineSound: " + e.getAttribute("name").getValue()); notch_sounds = new HashMap<Integer, NotchSound>(); // Get the notch sounds Iterator<Element> itr = (e.getChildren("notch-sound")).iterator(); int i = 0; while (itr.hasNext()) { el = itr.next(); fn = el.getChildText("file"); int nn = Integer.parseInt(el.getChildText("notch")); //log.debug("Notch: " + nn + " File: " + fn); sb = new NotchSound(vf, fn, "Engine_n" + i, "Engine_" + i); sb.setLooped(true); sb.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); sb.setGain(setXMLGain(el)); sb.setNextNotch(el.getChildText("next-notch")); sb.setPrevNotch(el.getChildText("prev-notch")); sb.setAccelLimit(el.getChildText("accel-limit")); sb.setDecelLimit(el.getChildText("decel-limit")); if (el.getChildText("accel-file") != null) { sb.setAccelSound( new SoundBite(vf, el.getChildText("accel-file"), "Engine_na" + i, "Engine_na" + i)); } else { sb.setAccelSound(null); } if (el.getChildText("decel-file") != null) { sb.setDecelSound( new SoundBite(vf, el.getChildText("decel-file"), "Engine_nd" + i, "Engine_nd" + i)); } else { sb.setDecelSound(null); } // Store in the list. notch_sounds.put(nn, sb); i++; } // Get the start and stop sounds el = e.getChild("start-sound"); if (el != null) { fn = el.getChild("file").getValue(); //log.debug("Start sound: " + fn); start_sound = new SoundBite(vf, fn, "Engine_start", "Engine_Start"); // Handle gain start_sound.setGain(setXMLGain(el)); start_sound.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); start_sound.setLooped(false); } el = e.getChild("shutdown-sound"); if (el != null) { fn = el.getChild("file").getValue(); //log.debug("Shutdown sound: " + fn); shutdown_sound = new SoundBite(vf, fn, "Engine_shutdown", "Engine_Shutdown"); shutdown_sound.setLooped(false); // Handle gain shutdown_sound.setGain(setXMLGain(el)); shutdown_sound.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); } }
From source file:jmri.jmrit.vsdecoder.DieselSound.java
License:Open Source License
@Override public void setXml(Element e, VSDFile vf) { Element el;//from w ww . j a v a2 s .c o m //int num_notches; String fn; SoundBite sb; // Handle the common stuff. super.setXml(e, vf); log.debug("Diesel EngineSound: " + e.getAttribute("name").getValue()); notch_sounds = new HashMap<Integer, SoundBite>(); transition_sounds = new ArrayList<NotchTransition>(); // Get the notch sounds Iterator<Element> itr = (e.getChildren("notch-sound")).iterator(); int i = 0; while (itr.hasNext()) { el = itr.next(); fn = el.getChildText("file"); int nn = Integer.parseInt(el.getChildText("notch")); //log.debug("Notch: " + nn + " File: " + fn); sb = new SoundBite(vf, fn, "Engine_n" + i, "Engine_" + i); sb.setLooped(true); sb.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); sb.setGain(setXMLGain(el)); // Store in the list. notch_sounds.put(nn, sb); i++; } // Get the notch transitions itr = (e.getChildren("notch-transition")).iterator(); i = 0; NotchTransition nt; while (itr.hasNext()) { el = itr.next(); fn = el.getChildText("file"); nt = new NotchTransition(vf, fn, "Engine_nt" + i, "Engine_nt" + i); nt.setPrevNotch(Integer.parseInt(el.getChildText("prev-notch"))); nt.setNextNotch(Integer.parseInt(el.getChildText("next-notch"))); //log.debug("Transition: prev=" + nt.getPrevNotch() + " next=" + nt.getNextNotch() + " File: " + fn); nt.setLooped(false); nt.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); // Handle gain nt.setGain(setXMLGain(el)); transition_sounds.add(nt); i++; } // Get the start and stop sounds el = e.getChild("start-sound"); if (el != null) { fn = el.getChild("file").getValue(); //log.debug("Start sound: " + fn); start_sound = new SoundBite(vf, fn, "Engine_start", "Engine_Start"); // Handle gain start_sound.setGain(setXMLGain(el)); start_sound.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); start_sound.setLooped(false); } el = e.getChild("shutdown-sound"); if (el != null) { fn = el.getChild("file").getValue(); //log.debug("Shutdown sound: " + fn); shutdown_sound = new SoundBite(vf, fn, "Engine_shutdown", "Engine_Shutdown"); shutdown_sound.setLooped(false); // Handle gain shutdown_sound.setGain(setXMLGain(el)); shutdown_sound.setFadeTimes(this.getFadeInTime(), this.getFadeOutTime()); } }
From source file:jmri.jmrit.vsdecoder.IntTrigger.java
License:Open Source License
@Override public void setXml(Element e) { // Grab common stuff. super.setXml(e); // Only do this if this is a BoolTrigger type Element if (e.getAttribute("type").getValue().equals("INT")) { notch = Integer.parseInt(e.getChild("match").getValue()); compare_type = Trigger.CompareType.valueOf(e.getChild("compare-type").getValue().toUpperCase()); }//www . j a v a 2 s . com }
From source file:jmri.jmrit.vsdecoder.SteamSound.java
License:Open Source License
@Override public void setXml(Element e, VSDFile vf) { Element el;/* www .j a v a 2 s. co m*/ //int num_rpms; String fn; SoundBite sb; super.setXml(e, vf); log.debug("Steam EngineSound: " + e.getAttribute("name").getValue()); String n = e.getChild("top-speed").getValue(); if (n != null) { top_speed = Integer.parseInt(n); //log.debug("Top speed: " + top_speed + " MPH"); } n = e.getChildText("driver-diameter"); if (n != null) { driver_diameter = Integer.parseInt(n); //log.debug("Driver diameter: " + driver_diameter + " inches"); } n = e.getChildText("cylinders"); if (n != null) { num_cylinders = Integer.parseInt(n); //log.debug("Num Cylinders: " + num_cylinders); } // For now, num_rpms is not used. /* n = e.getChild("rpm-steps").getValue(); if (n != null) { num_rpms = Integer.parseInt(n); //log.debug("Number of rpm steps: " + num_rpms); } */ rpm_sounds = new ArrayList<RPMSound>(); // Get the RPM steps Iterator<Element> itr = (e.getChildren("rpm-step")).iterator(); int i = 0; while (itr.hasNext()) { el = itr.next(); fn = el.getChildText("file"); int min_r = Integer.parseInt(el.getChildText("min-rpm")); int max_r = Integer.parseInt(el.getChildText("max-rpm")); //log.debug("Notch: " + nn + " File: " + fn); sb = new SoundBite(vf, fn, "Steam_n" + i, "Steam_" + i); sb.setLooped(true); sb.setFadeTimes(100, 100); sb.setGain(setXMLGain(el)); // Store in the list. boolean chuff = false; Element c; if ((c = el.getChild("use-chuff-gen")) != null) { log.debug("Use Chuff Generator " + c.toString()); chuff = true; } rpm_sounds.add(new RPMSound(sb, min_r, max_r, chuff)); i++; } /* // Get the start and stop sounds el = e.getChild("start-sound"); if (el != null) { fn = el.getChild("file").getValue(); log.debug("Start sound: " + fn); start_sound = new SoundBite(vf, fn, "Engine_start", "Engine_Start"); // Handle gain start_sound.setGain(setXMLGain(el)); start_sound.setLooped(false); } */ }
From source file:jmri.jmrit.vsdecoder.VSDecoder.java
License:Open Source License
/** * public void setXML(VSDFile vf, String pn) * * Build this VSDecoder from an XML representation * * @param vf (VSDFile) : VSD File to pull the XML from * @param pn (String) : Parameter Name to find within the VSD File. *//*from ww w .j a v a 2 s .c om*/ @SuppressWarnings({ "cast" }) public void setXml(VSDFile vf, String pn) { Iterator<Element> itr; Element e = null; Element el = null; SoundEvent se; if (vf == null) { log.debug("Null VSD File Name"); return; } log.debug("VSD File Name = " + vf.getName()); // need to choose one. this.setVSDFilePath(vf.getName()); // Find the <profile/> element that matches the name pn // List<Element> profiles = vf.getRoot().getChildren("profile"); // java.util.Iterator i = profiles.iterator(); java.util.Iterator<Element> i = vf.getRoot().getChildren("profile").iterator(); while (i.hasNext()) { e = i.next(); if (e.getAttributeValue("name").equals(pn)) { break; } } // E is now the first <profile/> in vsdfile that matches pn. if (e == null) { // No matching profile name found. return; } // Set this decoder's name. this.setProfileName(e.getAttributeValue("name")); log.debug("Decoder Name = " + e.getAttributeValue("name")); // Read and create all of its components. // Check for default element. if (e.getChild("default") != null) { log.debug("" + getProfileName() + "is default."); is_default = true; } else { is_default = false; } // +++ DEBUG // Log and print all of the child elements. itr = (e.getChildren()).iterator(); while (itr.hasNext()) { // Pull each element from the XML file. el = itr.next(); log.debug("Element: " + el.toString()); if (el.getAttribute("name") != null) { log.debug(" Name: " + el.getAttributeValue("name")); log.debug(" type: " + el.getAttributeValue("type")); } } // --- DEBUG // First, the sounds. String prefix = "" + this.getID() + ":"; log.debug("VSDecoder " + this.getID() + " prefix = " + prefix); itr = (e.getChildren("sound")).iterator(); while (itr.hasNext()) { el = (Element) itr.next(); if (el.getAttributeValue("type") == null) { // Empty sound. Skip. log.debug("Skipping empty Sound."); continue; } else if (el.getAttributeValue("type").equals("configurable")) { // Handle configurable sounds. ConfigurableSound cs = new ConfigurableSound(prefix + el.getAttributeValue("name")); cs.setXml(el, vf); sound_list.put(el.getAttributeValue("name"), cs); } else if (el.getAttributeValue("type").equals("diesel")) { // Handle a Diesel Engine sound DieselSound es = new DieselSound(prefix + el.getAttributeValue("name")); es.setXml(el, vf); sound_list.put(el.getAttributeValue("name"), es); } else if (el.getAttributeValue("type").equals("diesel3")) { // Handle a Diesel Engine sound Diesel3Sound es = new Diesel3Sound(prefix + el.getAttributeValue("name")); es.setXml(el, vf); sound_list.put(el.getAttributeValue("name"), es); } else if (el.getAttributeValue("type").equals("steam")) { // Handle a Diesel Engine sound SteamSound es = new SteamSound(prefix + el.getAttributeValue("name")); es.setXml(el, vf); sound_list.put(el.getAttributeValue("name"), es); } else { // TODO: Some type other than configurable sound. Handle appropriately } } // Next, grab all of the SoundEvents // Have to do the sounds first because the SoundEvent's setXml() will // expect to be able to look it up. itr = (e.getChildren("sound-event")).iterator(); while (itr.hasNext()) { el = (Element) itr.next(); switch (SoundEvent.ButtonType.valueOf(el.getAttributeValue("buttontype").toUpperCase())) { case MOMENTARY: se = new MomentarySoundEvent(el.getAttributeValue("name")); break; case TOGGLE: se = new ToggleSoundEvent(el.getAttributeValue("name")); break; case ENGINE: se = new EngineSoundEvent(el.getAttributeValue("name")); break; case NONE: default: se = new SoundEvent(el.getAttributeValue("name")); } se.setParent(this); se.setXml(el, vf); event_list.put(se.getName(), se); } // Handle other types of children similarly here. // Check for an existing throttle and update speed if it exists. Float s = (Float) InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), "SpeedSetting"); if (s != null) { // Mimic a throttlePropertyChange to propagate the current (init) speed setting of the throttle. log.debug("Existing Throttle found. Speed = " + s); this.throttlePropertyChange(new PropertyChangeEvent(this, "SpeedSetting", null, s)); } else { log.debug("No existing throttle found."); } }
From source file:jmri.jmrit.vsdecoder.VSDecoderPreferences.java
License:Open Source License
public void load(org.jdom2.Element e) { if (e == null) { return;//from w ww . ja v a 2 s . c o m } org.jdom2.Attribute a; org.jdom2.Element c; if ((a = e.getAttribute("isAutoStartingEngine")) != null) { setAutoStartEngine(a.getValue().compareTo("true") == 0); } if ((a = e.getAttribute("isAutoLoadingDefaultVSDFile")) != null) { setAutoLoadDefaultVSDFile(a.getValue().compareTo("true") == 0); } if ((c = e.getChild("DefaultVSDFilePath")) != null) { setDefaultVSDFilePath(c.getValue()); } if ((c = e.getChild("DefaultVSDFileName")) != null) { setDefaultVSDFileName(c.getValue()); } if ((c = e.getChild("ListenerPosition")) != null) { _listenerPosition = new ListeningSpot(c); } else { _listenerPosition = new ListeningSpot(); } if ((c = e.getChild("AudioMode")) != null) { setAudioMode(c.getValue()); } }
From source file:jmri.managers.configurexml.AbstractAudioManagerConfigXML.java
License:Open Source License
/** * 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./* ww w. ja va 2 s .co m*/ * * @param audio Element containing the Audio elements to load. */ @SuppressWarnings("unchecked") public void loadAudio(Element audio) { AudioManager am = InstanceManager.audioManagerInstance(); // 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")); } } }