001package jmri.jmrit.audio; 002 003import javax.vecmath.Vector3f; 004import org.slf4j.Logger; 005import org.slf4j.LoggerFactory; 006 007/** 008 * Null audio system implementation of the Audio Source sub-class. 009 * <p> 010 * For now, no system-specific implementations are forseen - this will remain 011 * internal-only 012 * <hr> 013 * This file is part of JMRI. 014 * <p> 015 * JMRI is free software; you can redistribute it and/or modify it under the 016 * terms of version 2 of the GNU General Public License as published by the Free 017 * Software Foundation. See the "COPYING" file for a copy of this license. 018 * <p> 019 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY 020 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 021 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 022 * 023 * @author Matthew Harris copyright (c) 2009 024 */ 025public class NullAudioSource extends AbstractAudioSource { 026 027 /** 028 * True if we've been initialised. 029 */ 030 private boolean initialised = false; 031 032 /** 033 * Constructor for new NullAudioSource with system name. 034 * 035 * @param systemName AudioSource object system name (e.g. IAS1) 036 */ 037 public NullAudioSource(String systemName) { 038 this(systemName,null); 039 } 040 041 /** 042 * Constructor for new NullAudioSource with system name and user name. 043 * 044 * @param systemName AudioSource object system name (e.g. IAS1) 045 * @param userName AudioSource object user name 046 */ 047 public NullAudioSource(String systemName, String userName) { 048 super(systemName, userName); 049 log.debug("New NullAudioSource: {} ({})", userName, systemName); 050 initialised = init(); 051 } 052 053 @Override 054 boolean bindAudioBuffer(AudioBuffer audioBuffer) { 055 // Don't actually need to do anything specific here 056 log.debug("Bind NullAudioSource ({}) to NullAudioBuffer ({})", this.getSystemName(), audioBuffer.getSystemName()); 057 return true; 058 } 059 060 /** 061 * Initialise this AudioSource. 062 * 063 * @return True if initialised 064 */ 065 private boolean init() { 066 return true; 067 } 068 069 @Override 070 protected void changePosition(Vector3f pos) { 071 // Do nothing 072 } 073 074 @Override 075 protected void doPlay() { 076 log.debug("Play NullAudioSource ({})", this.getSystemName()); 077 if (initialised && isBound()) { 078 doRewind(); 079 doResume(); 080 } 081 } 082 083 @Override 084 protected void doStop() { 085 log.debug("Stop NullAudioSource ({})", this.getSystemName()); 086 if (initialised && isBound()) { 087 doRewind(); 088 } 089 } 090 091 @Override 092 protected void doPause() { 093 log.debug("Pause NullAudioSource ({})", this.getSystemName()); 094 this.setState(STATE_STOPPED); 095 } 096 097 @Override 098 protected void doResume() { 099 log.debug("Resume NullAudioSource ({})", this.getSystemName()); 100 this.setState(STATE_PLAYING); 101 } 102 103 @Override 104 protected void doRewind() { 105 log.debug("Rewind NullAudioSource ({})", this.getSystemName()); 106 this.setState(STATE_STOPPED); 107 } 108 109 @Override 110 protected void doFadeIn() { 111 log.debug("Fade-in JoalAudioSource ({})", this.getSystemName()); 112 if (initialised && isBound()) { 113 doPlay(); 114 } 115 } 116 117 @Override 118 protected void doFadeOut() { 119 log.debug("Fade-out JoalAudioSource ({})", this.getSystemName()); 120 if (initialised && isBound()) { 121 doStop(); 122 } 123 } 124 125 @Override 126 protected void cleanup() { 127 log.debug("Cleanup NullAudioSource ({})", this.getSystemName()); 128 } 129 130 @Override 131 protected void calculateGain() { 132 // do nothing 133 } 134 135 private static final Logger log = LoggerFactory.getLogger(NullAudioSource.class); 136 137}