001package jmri.jmrix.loconet.sdf;
002
003/**
004 * Implement the DELAY_SOUND macro from the Digitrax sound definition language
005 *
006 * @author Bob Jacobsen Copyright (C) 2007, 2008
007 */
008public class DelaySound extends SdfMacro {
009
010    public DelaySound(int byte1, int byte2) {
011        this.mode = byte2 & 0x80;
012        this.value = byte2 & 0x7F;
013        this.glbl = byte1 & 0x01;
014        this.byte1 = byte1;
015        this.byte2 = byte2;
016    }
017
018    @Override
019    public String name() {
020        return "DELAY_SOUND"; // NOI18N
021    }
022
023    int mode;
024    int value;
025    int glbl;
026    int byte1, byte2;
027
028    @Override
029    public int length() {
030        return 2;
031    }
032
033    static public SdfMacro match(SdfBuffer buff) {
034        if ((buff.getAtIndex() & 0xFE) != 0xB4) {
035            return null;
036        }
037        int byte1 = buff.getAtIndexAndInc();
038        int byte2 = buff.getAtIndexAndInc();
039        return new DelaySound(byte1, byte2);
040    }
041
042    /**
043     * Store into a buffer.
044     */
045    @Override
046    public void loadByteArray(SdfBuffer buffer) {
047        // data
048        buffer.setAtIndexAndInc(byte1);
049        buffer.setAtIndexAndInc(byte2);
050
051        // store children
052        super.loadByteArray(buffer);
053    }
054
055    @Override
056    public String toString() {
057        return "Delay Sound\n"; // NOI18N
058    }
059
060    @Override
061    public String oneInstructionString() {
062        String modeVal = (DELAY_THIS == mode) ? "DELAY_THIS" : "DELAY_CV"; // NOI18N
063        String valueVal = (DELAY_THIS == mode) ? "" + value : "CV=" + value; // NOI18N
064        String glblVal = (glbl == 1) ? "DELAY_GLOBAL" : "0";  // what should 0 case be? // NOI18N
065        return name() + ' ' + modeVal + "," + valueVal + "," + glblVal + '\n'; // NOI18N
066    }
067
068    @Override
069    public String allInstructionString(String indent) {
070        return indent + oneInstructionString();
071    }
072}