예제 #1
0
  /**
   * Make a Brick from a Polylist in the external representation of a RoadMap
   *
   * @param blockPolylist
   * @return
   */
  public static Block fromPolylist(Polylist blockPolylist) {
    // Need to populate sub-blocks before calling constructor!
    Polylist temp;
    temp = blockPolylist.assoc("name");

    String name = (String) temp.second();
    temp = blockPolylist.assoc("variant");
    String variant = temp.rest().nonEmpty() ? (String) temp.second() : DEFAULT_VARIANT;

    temp = blockPolylist.assoc("type");
    String type = (String) temp.second();

    temp = blockPolylist.assoc("key");
    String key = (String) temp.second();

    temp = blockPolylist.assoc("duration");
    int duration = ((Number) temp.second()).intValue();

    temp = blockPolylist.assoc("overlap");
    boolean overlap = temp.second().equals("true");

    temp = blockPolylist.assoc("end");
    int endValue = ((Number) temp.second()).intValue();

    temp = blockPolylist.assoc("mode");
    String mode = (String) temp.second();

    temp = blockPolylist.assoc("blocks");
    ArrayList<Block> blocks = new ArrayList<Block>();

    Polylist polyBlocks = temp.rest();
    while (polyBlocks.nonEmpty()) {
      Polylist polyBlock = (Polylist) polyBlocks.first();
      Block block = Block.fromPolylist(polyBlock);
      blocks.add(block);
      polyBlocks = polyBlocks.rest();
    }

    Brick brick = new Brick(name, variant, BrickLibrary.keyNameToNum(key), type, blocks, mode);
    brick.setOverlap(overlap);
    brick.setSectionEnd(endValue);
    // Above, we are targeting this constructor:
    //
    //   public Brick(String brickName,
    //                 long brickKey,
    //                 String type,
    //                 List<Block> brickList)

    return brick;
  }
예제 #2
0
  // Sets probabilities of note types into an array from a polylist
  private int[] setProb(Polylist probs) {

    int chord, color, random, scale;
    chord = Integer.parseInt((String) probs.first().toString());
    color = Integer.parseInt((String) probs.second().toString());
    random = Integer.parseInt((String) probs.third().toString());
    scale = Integer.parseInt((String) probs.fourth().toString());

    int[] result = new int[4];
    result[0] = chord;
    result[1] = color;
    result[2] = random;
    result[3] = scale;
    return result;
  }