001package jmri.jmrit.vsdecoder.listener; 002 003import javax.vecmath.Vector3f; 004import jmri.AudioManager; 005import jmri.jmrit.audio.AudioFactory; 006import jmri.jmrit.audio.AudioListener; 007import org.slf4j.Logger; 008import org.slf4j.LoggerFactory; 009 010/** 011 * VSD listener. 012 * 013 * <hr> 014 * This file is part of JMRI. 015 * <p> 016 * JMRI is free software; you can redistribute it and/or modify it under 017 * the terms of version 2 of the GNU General Public License as published 018 * by the Free Software Foundation. See the "COPYING" file for a copy 019 * of this license. 020 * <p> 021 * JMRI is distributed in the hope that it will be useful, but WITHOUT 022 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 023 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 024 * for more details. 025 * 026 * @author Mark Underwood Copyright (C) 2012 027 * @author Klaus Killinger Copyright (C) 2018 028 */ 029public class VSDListener { 030 031 // Only one Audio Listener can exist, and it is already present in the Audio Table 032 public final static String ListenerSysName = "IAL$"; 033 034 private AudioFactory af; 035 private AudioListener listener; 036 private String sysname; 037 private String username; 038 private ListeningSpot location; 039 040 public VSDListener() { 041 // Initialize the AudioManager (if it isn't already) and get the Listener. 042 AudioManager am = jmri.InstanceManager.getDefault(jmri.AudioManager.class); 043 am.init(); 044 af = am.getActiveAudioFactory(); 045 if (af != null) { 046 listener = af.getActiveAudioListener(); 047 log.debug("Default listener: {}, system name: {}", listener, listener.getSystemName()); 048 setSystemName(listener.getSystemName()); 049 setUserName(listener.getUserName()); 050 } else { 051 log.warn("AudioFactory not available"); 052 } 053 } 054 055 public String getSystemName() { 056 return sysname; 057 } 058 059 public String getUserName() { 060 return username; 061 } 062 063 public ListeningSpot getLocation() { 064 return location; 065 } 066 067 void setSystemName(String s) { 068 sysname = s; 069 } 070 071 void setUserName(String u) { 072 username = u; 073 } 074 075 public void setLocation(ListeningSpot l) { 076 location = l; 077 listener.setPosition(new Vector3f(l.getLocation())); 078 listener.setOrientation(new Vector3f(l.getLookAtVector()), new Vector3f(l.getUpVector())); 079 // Set position here 080 } 081 082 private final static Logger log = LoggerFactory.getLogger(VSDListener.class); 083 084}