Beispiel #1
0
 /**
  * toRoadmapSave is used to create a Polylist for saving to a RoadMap This is NOT the same as the
  * Polylist usedd to save in the dictionary. Returns a Polylist representation of a Brick.
  *
  * @return a Polylist containing the Brick's contents
  */
 @Override
 public Polylist toRoadmapSave() {
   PolylistBuffer buffer = new PolylistBuffer();
   buffer.append(BRICK_KEYWORD);
   buffer.append(Polylist.list("name", dashed(name)));
   buffer.append(Polylist.list("variant", variant));
   buffer.append(Polylist.list("type", type));
   buffer.append(Polylist.list("key", BrickLibrary.keyNumToName(key)));
   buffer.append(Polylist.list("mode", mode));
   buffer.append(Polylist.list("duration", duration));
   buffer.append(Polylist.list("overlap", overlap));
   buffer.append(Polylist.list("end", endValue));
   buffer.append(subBlocksToRoadmapSave());
   return buffer.toPolylist();
 }
Beispiel #2
0
  /**
   * toBrickDefinition Returns a Polylist formatted specifically to replicate the Brick's original
   * definition format
   *
   * @return a Polylist containing the Brick's definition information
   */
  public Polylist toBrickDefinition() {
    PolylistBuffer buffer = new PolylistBuffer();

    for (Block b : getSubBlocks()) {
      buffer.append(b.toPolylist());
    }
    if (!variant.equals("")) {
      return Polylist.list(
              BrickLibrary.DEF_BRICK,
              dashed(name) + "(" + variant + ")",
              mode,
              dashed(type),
              BrickLibrary.keyNumToName(key))
          .append(buffer.toPolylist());
    } else {
      return Polylist.list(
              BrickLibrary.DEF_BRICK,
              dashed(name),
              mode,
              dashed(type),
              BrickLibrary.keyNumToName(key))
          .append(buffer.toPolylist());
    }
  }
  /* Called from chooseNote in Lickgen
   * Given an interval, the desired type of note,
   * the types of notes in the interval, and the occurences of each type of note,
   * looks up the probabilities for what type of note to choose in a table
   * and returns a note chosen based on the probabilities
   * attempts is a counter for the number of times we have tried to get all pitches within range
   */
  public int getNote(
      int minPitch,
      int maxPitch,
      int low,
      int high,
      int type,
      int[] numTypes,
      int[] noteTypes,
      int attempts) {

    if (type == CHORD) type = 0;
    if (type == COLOR) type = 1;
    if (type == RANDOM) type = 2;
    if (type == SCALE) type = 3;

    Polylist prob = new Polylist();

    // integers representing whether a certain type is present
    int haveChord, haveColor, haveRandom;
    if (numTypes[0] != 0) haveChord = 1;
    else haveChord = 0;
    if (numTypes[1] != 0) haveColor = 1;
    else haveColor = 0;
    if (numTypes[2] != 0) haveRandom = 1;
    else haveRandom = 0;

    // special case for chord tones - they are more important than staying
    // in the interval
    // if(type == 0 && haveChord == 0) {
    //   for(int i = low - 4; i <= low + 4; i++) {
    //
    //   }
    // }

    Polylist identifier = Polylist.list(type, haveChord, haveColor, haveRandom);

    // look for match
    for (Polylist L = probabilities; L.nonEmpty(); L = L.rest()) {
      // get first list in probabilities
      Polylist tempProb = (Polylist) L.first();
      // chop off the probabilities so we just have the identifier
      Polylist tempIdentifier = tempProb.prefix(4);
      if (identifier.equals(tempIdentifier)) {
        prob = tempProb.coprefix(4);
      }
    }

    // put the matched probabilities into an array
    int[] probs = setProb(prob);

    Random rand = new Random();

    // generate note type from probabilities
    int randNum = rand.nextInt(100) + 1;
    int newType = 0; // -1;
    for (int i = 0; i < probs.length; i++) {
      randNum = randNum - probs[i];
      if (randNum <= 0) {
        newType = i;
        i = probs.length;
      }
    }

    // get note pitch
    randNum = rand.nextInt(numTypes[newType]) + 1;
    int pitchdiff = 0;
    for (int i = 0; i < noteTypes.length; i++) {
      if (noteTypes[i] == typeMap[newType]
          || (newType == 3 && (noteTypes[i] == CHORD || noteTypes[i] == COLOR))) {
        randNum--;
      }
      if (randNum <= 0) {
        pitchdiff = i;
        i = noteTypes.length;
      }
    }
    int finalPitch = low + pitchdiff;

    if (attempts >= LickGen.MELODY_GEN_LIMIT - 1 && doNotSwitchOctave == false) {
      // raise or lower by an octave if outside bounds
      while (finalPitch > maxPitch) {
        finalPitch -= 12;
      }
      while (finalPitch < minPitch) {
        finalPitch += 12;
      }
    }
    return finalPitch;
  }
Beispiel #4
0
 /**
  * toPolylist Returns a Polylist representation of a Brick.
  *
  * @return a Polylist containing the Brick's contents
  */
 @Override
 public Polylist toPolylist() {
   return Polylist.list(BRICK_KEYWORD, dashed(name), BrickLibrary.keyNumToName(key), duration);
 }
Beispiel #5
0
 public void setDefaultLayout() {
   this.layout = Polylist.list(DEFAULT_BARS_PER_LINE);
 }