Class SdfMacro

java.lang.Object
jmri.jmrix.loconet.sdf.SdfMacro
All Implemented Interfaces:
SdfConstants
Direct Known Subclasses:
BranchTo, ChannelStart, CommentMacro, DelaySound, EndSound, FourByteMacro, GenerateTrigger, InitiateSound, LabelMacro, LoadModifier, MaskCompare, Play, SdlVersion, SkemeStart, SkipOnTrigger, TwoByteMacro

public abstract class SdfMacro extends Object implements SdfConstants
Common base for all the SDF macros defined by Digitrax for their sound definition language.

Each macro has a number of descriptive forms:

name()
Just the name, in MPASM form.
toString()
A brief description, with a terminating newline
oneInstructionString()
The entire single instruction in MPASM from, with a terminating newline
allInstructionString()
The instruction and all those logically grouped within it.
SdfMacro and its subclasses don't do the notification needed to be Models in an MVC edit paradyme. This is because there are a lot of SdfMacros in realistic sound file, and the per-object overhead needed would be too large. Hence (or perhaps because of no need), there is no support for simultaneous editing of a single macro instruction updating multiple windows. You can have multiple editors open on a single SdfBuffer, but these are not interlocked against each other. (We could fix this by having a shared pool of "objects to be notified of changes in the SdfBuffer, acccessed by reference during editing (to avoid another dependency), but that's a project for another day)
  • Field Details

  • Constructor Details

  • Method Details

    • name

      public abstract String name()
      Name used by the macro in the SDF definition
      Returns:
      Fixed name associated with this type of instructio
    • length

      public abstract int length()
      Provide number of bytes defined by this macro
      Returns:
      Fixed numher of bytes defined (a constant for the instruction type)
    • toString

      public abstract String toString()
      Provide a single-line simplified representation, including the trailing newline. This is used e.g. in the tree format section of the EditorFrame.
      Overrides:
      toString in class Object
      Returns:
      newline-terminated string; never null
    • oneInstructionString

      public abstract String oneInstructionString()
      Provide single instruction in MPASM format, including the trailing newline.
      Returns:
      Newline terminated string, never null
    • allInstructionString

      public abstract String allInstructionString(String indent)
      Provide instructions in MPASM format, including the trailing newline and all nested instructions.
      Parameters:
      indent - String inserted at the start of each output line, typically some number of spaces.
      Returns:
      Newline terminated string, never null
    • getChildren

      Access child (nested) instructions.
      Returns:
      List of children, which will be null except in case of nesting.
    • totalLength

      public int totalLength()
      Total length, including contained instructions
      Returns:
      length of all parts
    • loadByteArray

      public void loadByteArray(SdfBuffer buffer)
      Store into a buffer.

      This provides a default implementation for children, but each subclass needs to store its own data with setAtIndexAndInc().

      Parameters:
      buffer - load with all children
    • decodeInstruction

      public static SdfMacro decodeInstruction(SdfBuffer buff)
      Get the next instruction macro in a buffer.

      Note this uses the index contained in the SdfBuffer implementation, and has the side-effect of bumping that forward.

      Parameters:
      buff - The SdfBuffer being scanned for instruction macros.
      Returns:
      Object of SdfMacro subtype for specific next instruction
    • decodeFlags

      String decodeFlags(int input, int[] values, int[] masks, String[] labels)
      Service method to unpack various bit-coded values for display, using a mask array.

      Note that multiple values can be returned, e.g. this can be used to scan for individual bits set in a variable.

      Parameters:
      input - Single value to be matched
      values - Array of possible values which the input might match
      masks - Array of masks to be applied when comparing against the corresponding items in the values array. This is separate for each possible value to e.g. allow the encoding of a set of independent bits.
      labels - Should there be a match-under-mask of a value, the corresponding label is returned
      Returns:
      "+" separated list of labels, or "<ERROR>" if none matched
    • decodeState

      String decodeState(int input, int[] values, String[] labels)