示例#1
0
 public boolean[] getCurrentEnharmonics(int index) {
   Polylist tones = new Polylist();
   Chord currentChord = chordProg.getCurrentChord(index);
   if (currentChord != null && !currentChord.getName().equals(NOCHORD)) {
     try {
       tones = chordProg.getCurrentChord(index).getPriority();
     } catch (NullPointerException e) {
       tones = new Polylist();
       Trace.log(2, "Null pointer exception should be fixed in Score.getCurrentEnharmonics.");
       Trace.log(2, e.getStackTrace().toString());
     }
   }
   return getCurrentEnharmonics(index, tones);
 }
 /** Empties the destination and copies the section of the source into the destination. */
 public void execute() {
   Trace.log(2, "executing CopyCommand");
   Part newPart = source.extract(startSlot, endSlot);
   Part.PartIterator i = newPart.iterator();
   dest.empty();
   while (i.hasNext()) dest.addUnit(i.next());
 }
示例#3
0
  /**
   * Returns an exact copy of this Part
   *
   * @return Part copy
   */
  public Part copy() {
    Trace.log(3, "copying part of size " + size);

    Part newPart = new Part(size);
    /*
     * PartIterator i = iterator(); while(i.hasNext())
     * newPart.slots.set(i.nextIndex(), i.next().copy());
     */

    for (int i = 0; i < size; i++) {
      Unit unit = slots.get(i);
      if (unit != null) {
        unit = unit.copy();
      }
      newPart.slots.set(i, unit);
    }

    newPart.unitCount = unitCount;
    newPart.title = title;
    newPart.volume = volume;
    newPart.instrument = instrument;
    newPart.swing = swing;
    newPart.setMetre(metre[0], metre[1]);
    newPart.keySig = keySig;
    return newPart;
  }
示例#4
0
  /**
   * Overwrites a section of the Part (starting at the specified index) with the slots contained in
   * the given Part.
   *
   * @param part the Part to paste into this
   * @param index the slot at which to start pasting over
   */
  public void pasteSlots(Part part, int index) {
    if (part == null) return;
    Trace.log(2, "pasting part of length " + part.size() + " at index " + index);

    for (int i = 0; i < part.size(); i++) {
      if (slots.get(index + i) != null) unitCount--;
      if (part.slots.get(i) != null) unitCount++;
      slots.set(index + i, part.slots.get(i));
    }

    int prevIndex = this.getPrevIndex(index);
    if (prevIndex == -1) prevIndex = 0;
    int rv = getUnitRhythmValue(prevIndex);
    Trace.log(3, "in pasteSlots, setting rhythmValue");
    getUnit(prevIndex).setRhythmValue(rv);
  }
示例#5
0
 /**
  * Adds the specified Part to the Score.
  *
  * @param part Part to add
  */
 public void addPart(MelodyPart part) {
   Trace.log(2, "adding existing melody part to score");
   if (length < part.size()) {
     setLength(part.size());
   }
   partList.add(part);
 }
示例#6
0
 /**
  * Sets the key signature of the Score
  *
  * @param keySig the key signature to set the Score to
  */
 public void setKeySignature(int keySig) {
   Trace.log(2, "setting key signature of score to " + keySig);
   this.keySig = keySig;
   chordProg.setKeySignature(keySig);
   ListIterator<MelodyPart> i = partList.listIterator();
   while (i.hasNext()) {
     i.next().setKeySignature(keySig);
   }
 }
 /**
  * Creates a new Command that can paste a source Part over a section of a destination Part.
  *
  * @param source the Part to paste
  * @param dest the Part to paste over
  * @param startSlot the slot to start pasting over in the dest
  * @param undoable the boolean to see if the action is undoable
  */
 public SideSlipCommand(
     MelodyPart source,
     boolean undoable,
     String direction,
     int distance,
     int keySig,
     CommandManager cm) {
   this(source, direction, distance, keySig, cm);
   this.undoable = undoable;
   Trace.log(2, "creating SideSlipCommand");
 }
示例#8
0
  /**
   * Returns a Part that contains the slots with in the range specified.
   *
   * @param first the first slot in the range
   * @param last the last slot in the range
   * @return Part the Part that contains the extracted chunk
   */
  public Part extractSlots(int first, int last) {
    Trace.log(3, "extractSlots from " + first + " to " + last);
    if (last > size - 1) last = size - 1;

    Part newPart = new Part(last - first + 1);

    for (int i = first; i < last; i++) // was <=, changed May 13 2012
    newPart.slots.set(i - first, slots.get(i));
    // I'm getting an ArrayIndexOutOfBoundsException -1 here, 21 June 2012

    return newPart;
  }
示例#9
0
 public void setLength(int newLength) {
   if (newLength == length) {
     return; // avoid unnecessary setting
   }
   Trace.log(3, "setting score length to " + newLength);
   length = newLength;
   if (chordProg != null) {
     chordProg.setSize(length);
   }
   Iterator<MelodyPart> i = partList.listIterator();
   while (i.hasNext()) {
     i.next().setSize(length);
   }
 }
  /** applies the transformation to the source MelodyPart */
  public void execute() {
    Trace.log(2, "executing SideSlipCommand");

    int start = original.getSize();

    if (direction.equals("up")) { // slide up
      cm.execute(new ShiftPitchesCommand(distance, dest, 0, start, 0, 128, keySig));
    } else if (direction.equals("down")) { // slide down
      cm.execute(new ShiftPitchesCommand(-1 * distance, dest, 0, start, 0, 128, keySig));
    }

    // add two of the same melodies with one transposed
    source.setSize(dest.getSize() * 2);
    source.pasteOver(dest, start);
  }
示例#11
0
  public void saveLeadsheet(BufferedWriter out, int[] metre, boolean lineBreaks)
      throws IOException {
    String outString = toLeadsheet();

    Trace.log(3, "saving note to leadsheet: " + outString);

    // Format for a maximum rhythm value per line.

    if (lineBreaks && accumulatedRhythmValue >= maxRhythmValuePerLine) {
      out.newLine();
      out.newLine();
      accumulatedRhythmValue -= maxRhythmValuePerLine;
    }

    out.write(" ");
    out.write(outString);
    accumulatedRhythmValue += rhythmValue;
  }
示例#12
0
 public Part fitPart(int freeSlots) {
   if (freeSlots == 0) return null;
   Part fitPart = this.copy();
   while (fitPart.size() > freeSlots) {
     Part scaledPart = new Part();
     Part.PartIterator i = fitPart.iterator();
     while (i.hasNext()) {
       Unit unit = i.next();
       if (unit.getRhythmValue() != 1) {
         Trace.log(3, "in fitPart, setting rhythmValue");
         unit.setRhythmValue(unit.getRhythmValue() / 2);
         if (unit.getRhythmValue() <= MIN_RHYTHM_VALUE) return null;
       }
       scaledPart.addUnit(unit);
     }
     fitPart = scaledPart;
   }
   return fitPart;
 }
示例#13
0
  /**
   * A rewritten version of pastOver
   *
   * @param part the Part to paste into this
   * @param index the slot at which to start pasting over
   */
  public void newPasteOver(Part part, int index) {
    Trace.log(3, "pasteOver " + part + " onto " + index + " " + this.hashCode());
    int limit = size();
    int incoming = part.size();
    //        if( index + incoming < limit )
    //          {
    //          limit = index + incoming;
    //          }

    int i = 0;
    int j = index;
    for (; i < incoming && j < limit; i++, j++) {
      Unit unit = part.getUnit(i);
      if (unit == null) {
        newSetUnit(j, null);
      } else {
        newSetUnit(j, unit.copy());
      }
    }
  }