001package jmri.jmrit.audio; 002 003import jmri.Audio; 004 005/** 006 * Represents a queued command for later processing in the AudioController 007 * thread. 008 * 009 * <hr> 010 * This file is part of JMRI. 011 * <p> 012 * JMRI is free software; you can redistribute it and/or modify it under the 013 * terms of version 2 of the GNU General Public License as published by the Free 014 * Software Foundation. See the "COPYING" file for a copy of this license. 015 * <p> 016 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY 017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 018 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 019 * 020 * @author Matthew Harris copyright (c) 2009 021 */ 022public class AudioCommand { 023 024 /** 025 * Private variables containing command parameters 026 */ 027 private final Audio audio; 028 029 private final int command; 030 031 /** 032 * Constructor to process a command on an Audio object 033 * 034 * @param audio Audio object to process 035 * @param command Action to perform 036 */ 037 public AudioCommand(Audio audio, int command) { 038 this.audio = audio; 039 this.command = command; 040 } 041 042 /** 043 * Return the Audio object that this command refers to 044 * 045 * @return Audio object to process 046 */ 047 public synchronized Audio getAudio() { 048 return this.audio; 049 } 050 051 /** 052 * Return the action to perform 053 * 054 * @return Action 055 */ 056 public synchronized int getCommand() { 057 return this.command; 058 } 059 060 @Override 061 public String toString() { 062 if (this.audio != null) { 063 return "Command " + commandString() + " for Audio " + audio.getSystemName(); 064 } else { 065 return "Command " + commandString() + " for null object"; 066 } 067 } 068 069 /** 070 * Returns a string representation of the assigned command 071 * 072 * @return a string representation 073 */ 074 private String commandString() { 075 switch (this.command) { 076 case Audio.CMD_INIT_FACTORY: 077 return "Initialise Factory (0x" + Integer.toHexString(this.command) + ")"; 078 case Audio.CMD_LOAD_SOUND: 079 return "Load Sound (0x" + Integer.toHexString(this.command) + ")"; 080 case Audio.CMD_BIND_BUFFER: 081 return "Bind buffer (0x" + Integer.toHexString(this.command) + ")"; 082 case Audio.CMD_QUEUE_BUFFERS: 083 return "Queue buffers (0x" + Integer.toHexString(this.command) + ")"; 084 case Audio.CMD_UNQUEUE_BUFFERS: 085 return "Unqueue buffers (0x" + Integer.toHexString(this.command) + ")"; 086 case Audio.CMD_PLAY: 087 return "Play (0x" + Integer.toHexString(this.command) + ")"; 088 case Audio.CMD_PAUSE: 089 return "Pause (0x" + Integer.toHexString(this.command) + ")"; 090 case Audio.CMD_PLAY_TOGGLE: 091 return "Play/Stop toggle (0x" + Integer.toHexString(this.command) + ")"; 092 case Audio.CMD_PAUSE_TOGGLE: 093 return "Pause/Resume toggle (0x" + Integer.toHexString(this.command) + ")"; 094 case Audio.CMD_RESUME: 095 return "Resume (0x" + Integer.toHexString(this.command) + ")"; 096 case Audio.CMD_STOP: 097 return "Stop (0x" + Integer.toHexString(this.command) + ")"; 098 case Audio.CMD_REWIND: 099 return "Rewind (0x" + Integer.toHexString(this.command) + ")"; 100 case Audio.CMD_FADE_IN: 101 return "Fade-in (0x" + Integer.toHexString(this.command) + ")"; 102 case Audio.CMD_FADE_OUT: 103 return "Fade-out (0x" + Integer.toHexString(this.command) + ")"; 104 default: 105 return "Unknown (0x" + Integer.toHexString(this.command) + ")"; 106 } 107 } 108 109 //private static final Logger log = LoggerFactory.getLogger(AudioCommand.class); 110}