Class VSDecoder

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener

    public class VSDecoder
    extends java.lang.Object
    implements java.beans.PropertyChangeListener
    Implements a software "decoder" that responds to throttle inputs and generates sounds in responds to them.

    Each VSDecoder implements exactly one Sound Profile (describes a particular type of locomotive, say, an EMD GP7).


    This file is part of JMRI.

    JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

    JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    • Constructor Detail

      • VSDecoder

        public VSDecoder​(VSDConfig cfg)
        Construct a VSDecoder with the given system name (id) and configuration (config)
        Parameters:
        cfg - (VSDConfig) Configuration
      • VSDecoder

        public VSDecoder​(java.lang.String id,
                         java.lang.String name,
                         java.lang.String path)
        Construct a VSDecoder with the given system name (id), profile name and VSD file path
        Parameters:
        id - (String) System name for this VSDecoder
        name - (String) Profile name
        path - (String) Path to a VSD file to pull the given Profile from
    • Method Detail

      • getId

        public java.lang.String getId()
        Get the ID (System Name) of this VSDecoder
        Returns:
        (String) system name of this VSDecoder
      • isInitialized

        public boolean isInitialized()
        Check whether this VSDecoder has completed initialization
        Returns:
        (boolean) true if initialization is complete.
      • setVSDFilePath

        public void setVSDFilePath​(java.lang.String p)
        Set the VSD File path for this VSDecoder to use
        Parameters:
        p - (String) path to VSD File
      • getVSDFilePath

        public java.lang.String getVSDFilePath()
        Get the current VSD File path for this VSDecoder
        Returns:
        (String) path to VSD file
      • shutdown

        public void shutdown()
        Shut down this VSDecoder and all of its associated sounds.
      • throttlePropertyChange

        protected void throttlePropertyChange​(java.beans.PropertyChangeEvent event)
        Handle the details of responding to a PropertyChangeEvent from a throttle.
        Parameters:
        event - (PropertyChangeEvent) Throttle event to respond to
      • setAddress

        public void setAddress​(LocoAddress l)
        Set this VSDecoder's LocoAddress, and register to follow events from the throttle with this address.
        Parameters:
        l - (LocoAddress) LocoAddress to be followed
      • getAddress

        public LocoAddress getAddress()
        Get the currently assigned LocoAddress
        Returns:
        the currently assigned LocoAddress
      • getDecoderVolume

        public float getDecoderVolume()
        Get the current decoder volume setting for this VSDecoder
        Returns:
        (float) volume level (0.0 - 1.0)
      • setDecoderVolume

        public void setDecoderVolume​(float decoder_volume)
        Set the decoder volume for this VSDecoder
        Parameters:
        decoder_volume - (float) volume level (0.0 - 1.0)
      • isMuted

        public boolean isMuted()
        Is this VSDecoder muted?
        Returns:
        true if muted
      • mute

        public void mute​(boolean m)
        Mute or un-mute this VSDecoder
        Parameters:
        m - (boolean) true to mute, false to un-mute
      • setPosition

        public void setPosition​(PhysicalLocation p)
        set the x/y/z position in the soundspace of this VSDecoder Translates the given position to a position relative to the listener for the component VSDSounds.

        The idea is that the user-preference Listener Position (relative to the USER's chosen origin) is always the OpenAL Context's origin.

        Parameters:
        p - (PhysicalLocation) location relative to the user's chosen Origin.
      • getPosition

        public PhysicalLocation getPosition()
        Get the current x/y/z position in the soundspace of this VSDecoder
        Returns:
        PhysicalLocation location of this VSDecoder
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Respond to property change events from this VSDecoder's GUI
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Parameters:
        evt - (PropertyChangeEvent) event to respond to
      • getTrainPosition

        protected PhysicalLocation getTrainPosition​(Train t)
        Get the physical location of the given Operations Train
        Parameters:
        t - (Train) the Train to interrogate
        Returns:
        PhysicalLocation location of the train
      • getSound

        public VSDSound getSound​(java.lang.String name)
        Retrieve the VSDSound with the given system name
        Parameters:
        name - (String) System name of the requested VSDSound
        Returns:
        VSDSound the requested sound
      • setProfileName

        public void setProfileName​(java.lang.String pn)
        Set the profile name to the given string
        Parameters:
        pn - (String) : name of the profile to set
      • getProfileName

        public java.lang.String getProfileName()
        get the currently selected profile name
        Returns:
        (String) name of the currently selected profile
      • enable

        public void enable()
        Enable this VSDecoder.
      • disable

        public void disable()
        Disable this VSDecoder.
      • getEngineSound

        public EngineSound getEngineSound()
        Get a reference to the EngineSound associated with this VSDecoder
        Returns:
        EngineSound The EngineSound reference for this VSDecoder or null
      • getEventList

        public java.util.Collection<SoundEventgetEventList()
        Get a Collection of SoundEvents associated with this VSDecoder
        Returns:
        Collection<SoundEvent> collection of SoundEvents
      • getXml

        public org.jdom2.Element getXml()
        Get an XML representation of this VSDecoder Includes a subtree of Elements for all of the associated SoundEvents, Triggers, VSDSounds, etc.
        Returns:
        Element XML Element for this VSDecoder
      • setXml

        public void setXml​(VSDFile vf,
                           java.lang.String pn)
        Build this VSDecoder from an XML representation
        Parameters:
        vf - (VSDFile) : VSD File to pull the XML from
        pn - (String) : Parameter Name to find within the VSD File.
      • setLocation

        void setLocation​(java.awt.geom.Point2D location)