示例#1
0
  /**
   * Get section by slot index
   *
   * @param slot
   * @return
   */
  public SectionRecord getSectionRecordBySlot(int slot) {
    ListIterator<SectionRecord> k = records.listIterator();
    SectionRecord s = k.next();
    SectionRecord previous = s;
    while (s.getIndex() <= slot && k.hasNext()) {
      previous = s;
      s = k.next();
    }

    s = s.getIndex() <= slot ? s : previous;

    // System.out.println("slot = " + slot + " using s = " + s);
    return s;
  }
示例#2
0
  /**
   * m = nq + r (m-r) sections would get q bars r sections would get q+1 bars
   *
   * <p>m = the original number of bars n = split q = m/n r = m%n
   */
  public boolean nWaySplit(int index, int split) {
    int m;
    if (index + 1 < size()) m = getSectionMeasure(index + 1) - getSectionMeasure(index);
    else m = measures() - getSectionMeasure(index) + 1;
    // System.out.println("m = " + m + ", split = " + split);
    if (m < split) {
      return false;
    }
    int q = m / split;
    int r = m % split;

    SectionRecord delete = getSectionRecordByIndex(index);
    String styleName = delete.getStyleName();
    int newIndex = delete.getIndex(); // slots
    boolean isPhrase = delete.getIsPhrase();

    records.remove(index);

    for (int j = 0; j < split; j++) {
      if (j != 0) styleName = Style.USE_PREVIOUS_STYLE;
      records.add(index + j, new SectionRecord(styleName, newIndex, isPhrase));
      newIndex = measureToSlotIndex(slotIndexToMeasure(newIndex) + q);
    }

    return true;
  }
示例#3
0
 public void reloadStyles() {
   ListIterator<SectionRecord> k = records.listIterator();
   while (k.hasNext()) {
     SectionRecord record = k.next();
     k.remove();
     k.add(new SectionRecord(record.getStyleName(), record.getIndex(), record.getIsPhrase()));
   }
 }
示例#4
0
  public void setSize(int size) {

    Iterator<SectionRecord> k = records.iterator();

    while (k.hasNext()) {
      SectionRecord record = k.next();
      int n = record.getIndex();
      if (n >= size) {
        k.remove();
      }
    }
  }
示例#5
0
  public void newSection(int index) {
    int measureLength = chords.getMeasureLength();

    SectionRecord record = records.get(index);
    int startIndex = record.getIndex();

    int endIndex = chords.size();

    if (index + 1 < size()) {
      SectionRecord nextRecord = records.get(index + 1);
      endIndex = nextRecord.getIndex();
    }

    int measure = (endIndex - startIndex) / measureLength;

    if (measure % 2 == 0) measure /= 2;
    else measure = measure / 2 + 1;

    addSection(
        Style.USE_PREVIOUS_STYLE, startIndex + measure * measureLength, record.getIsPhrase());
  }
示例#6
0
 public int sectionAtSlot(int n) {
   Iterator<SectionRecord> k = records.listIterator();
   while (k.hasNext()) {
     SectionRecord record = k.next();
     if (record.getIndex() == n) {
       if (record.getIsPhrase()) {
         return Block.PHRASE_END;
       } else {
         return Block.SECTION_END;
       }
     }
   }
   return Block.NO_END;
 }
示例#7
0
 @Override
 public String toString() {
   StringBuilder buffer = new StringBuilder();
   for (SectionRecord record : records) {
     buffer.append("(");
     buffer.append(record.getStyleName());
     buffer.append(" ");
     buffer.append(record.getIndex());
     buffer.append(" ");
     buffer.append(record.getIsPhrase());
     buffer.append(") ");
     buffer.append("\n");
   }
   return buffer.toString();
 }
示例#8
0
 /**
  * getStyleNameAtSlot returns the name of the Style operative at a given slot in the ChordPart
  *
  * @param slot
  * @return
  */
 public String getStyleNameAtSlot(int slot) {
   String previousStyleName = "no-style";
   String styleName = previousStyleName;
   for (SectionRecord k : records) {
     styleName = k.getStyleName();
     if (styleName.equals("*")) {
       styleName = previousStyleName;
     }
     if (k.getIndex() >= slot) {
       return styleName;
     }
     previousStyleName = styleName;
   }
   return styleName;
 }
示例#9
0
  public void addSection(String styleName, int n, boolean isPhrase) {
    ListIterator<SectionRecord> k = records.listIterator();

    while (k.hasNext()) {
      SectionRecord record = k.next();
      int index = record.getIndex();
      if (index == n) {
        k.remove();
        break;
      } else if (index > n) {
        k.previous();
        break;
      }
    }
    k.add(new SectionRecord(styleName, n, isPhrase));
  }
示例#10
0
  public ArrayList<Block> toBlockList() {
    ArrayList<Block> blocks = new ArrayList<Block>();
    int chordsSize = chords.size();

    int endIndex;

    // m is a second iterator intended to stay one step ahead of k
    // so as to get the start of the next section

    ListIterator<SectionRecord> k = records.listIterator();
    ListIterator<SectionRecord> m = records.listIterator();
    if (m.hasNext()) {
      m.next();
    }

    while (k.hasNext()) // && (endLimitIndex == ENDSCORE || endIndex <= endLimitIndex) )
    {
      SectionRecord record = k.next();
      String styleName = record.getStyleName();
      int startIndex = record.getIndex();

      endIndex = m.hasNext() ? m.next().getIndex() : chordsSize;

      ChordBlock block = null;

      for (int slot = startIndex; slot < endIndex; slot++) {
        Chord chord = chords.getChord(slot);

        if (chord != null) {
          block = new ChordBlock(chord.getName(), chord.getRhythmValue());
          block.setStyleName(styleName);
          blocks.add(block);
        }
      }

      // For last block in section
      if (block != null) {
        block.setSectionEnd(record.getIsPhrase() ? Block.PHRASE_END : Block.SECTION_END);
      }
    }

    return blocks;
  }
示例#11
0
  public Integer getPrevSectionIndex(int n) {
    ListIterator<SectionRecord> k = records.listIterator();
    while (k.hasNext()) {
      SectionRecord record = k.next();
      int index = record.getIndex();
      if (index > n) {
        k.previous();
        index = k.previous().getIndex();
        if (index == n && k.hasPrevious()) {
          return k.previousIndex();
        } else if (index == n) {
          return -1;
        }
        return index;
      }
    }

    return -1;
  }
示例#12
0
  public SectionInfo extract(int first, int last, ChordPart chords) {
    SectionInfo si = new SectionInfo(chords);

    si.records = new ArrayList<SectionRecord>();

    Iterator<SectionRecord> k = records.iterator();

    while (k.hasNext()) {
      SectionRecord record = k.next();
      String styleName = record.getStyleName();
      int index = record.getIndex() - first;
      if (index < 0) {
        si.records.add(new SectionRecord(styleName, 0, record.getIsPhrase()));
      } else if (index <= last - first) {
        si.records.add(new SectionRecord(styleName, index, record.getIsPhrase()));
      }
    }

    return si;
  }
示例#13
0
  /**
   * Returns ArrayList of indices of section starts that are not phrases.
   *
   * @return
   */
  public ArrayList<Integer> getSectionStartIndices() {
    ArrayList<Integer> result = new ArrayList<Integer>();
    boolean isStart = true; // The first Section Record must be a Section Start

    for (SectionRecord record : records) {
      if (isStart == true) {
        result.add(record.getIndex());
      }
      if (!record.getIsPhrase()) {
        // Any Section Record that follows a Section Record that is
        // not a phrase must be a Section Start
        isStart = true;
      } else {
        // Otherwise, if a Section Record is a Phrase, i.e.,
        // ends with a breath mark as opposed to a double bar line,
        // the next Section Record cannot be a Section Start
        isStart = false;
      }
    }
    return result;
  }
示例#14
0
  public long render(
      MidiSequence seq,
      long time,
      Track track,
      int transposition,
      boolean useDrums,
      int endLimitIndex,
      boolean constantBass)
      throws InvalidMidiDataException {
    // to trace sequencing info:
    // System.out.println("Sequencing SectionInfo time = "
    // + time + " endLimitIndex = " + endLimitIndex + " useDrums = " + useDrums);

    // Iterate over list of sections, each a Style

    int chordsSize = chords.size();

    int endIndex;

    // m is a second iterator intended to stay one step ahead of k
    // so as to get the start of the next section

    Style mostRecentStyle = new Style();

    ListIterator<SectionRecord> k = records.listIterator();
    ListIterator<SectionRecord> m = records.listIterator();
    if (m.hasNext()) {
      m.next();
    }

    while (k.hasNext()) // && (endLimitIndex == ENDSCORE || endIndex <= endLimitIndex) )
    {
      SectionRecord record = k.next();
      Style style;
      if (record.getUsePreviousStyle()) {
        style = mostRecentStyle;
        // System.out.println("using previous style " + style);
      } else {
        style = record.getStyle();
        mostRecentStyle = style;
      }

      int startIndex = record.getIndex();

      endIndex = m.hasNext() ? m.next().getIndex() : chordsSize;

      if (style != null) {
        time =
            style.render(
                seq,
                time,
                chords,
                startIndex,
                endIndex,
                transposition,
                useDrums,
                endLimitIndex,
                constantBass);
      }
    }
    return time;
  }
示例#15
0
  /**
   * Writes the Part to the passed BufferedWriter in Leadsheet notation.
   *
   * @param out the BufferedWriter to write the Part onto
   */
  public void saveLeadsheet(BufferedWriter out, String type) throws IOException {
    out.write("(part");
    out.newLine();
    out.write("    (type " + type + ")");
    out.newLine();
    out.write("    (title " + title + ")");
    out.newLine();
    out.write("    (composer " + composer + ")");
    out.newLine();
    out.write("    (instrument " + instrument + ")");
    out.newLine();
    out.write("    (volume " + volume + ")");
    out.newLine();
    out.write("    (key " + keySig + ")");
    out.newLine();

    if (this instanceof MelodyPart) {
      out.write("    (stave " + staveType.toString().toLowerCase() + ")");
      out.newLine();
    }
    // For now, saving roadmaps is disabled
    //    else
    //    {
    //        out.write(Formatting.prettyFormat(4, ((ChordPart)this).getRoadMap() == null ? "" :
    // ((ChordPart)this).getRoadmapPoly()));
    //        out.newLine();
    //    }

    out.write(")");
    out.newLine();

    Note.initializeSaveLeadsheet();

    Part.PartIterator i = iterator();

    // Should be refactored into separate methods for each derived class

    if (this instanceof MelodyPart) {
      while (i.hasNext()) {
        i.next().saveLeadsheet(out, metre);
      }
    } else {
      SectionInfo sectionInfo = ((ChordPart) this).getSectionInfo();

      Iterator<SectionRecord> sec = sectionInfo.iterator();

      SectionRecord record = sec.next();

      boolean lastSection = !sec.hasNext();

      Chord residualChord = null;

      int slot = 0;

      int slotLimit = size();

      int nextSectionStart;

      // iSystem.out.println("slotLimit = " + slotLimit);

      Chord chord = null;

      int sectionsToGo = sectionInfo.size();

      do // do-while
      {
        // System.out.println("\nrecord = " + record);

        // Save the section record
        saveSectionInfo(out, record);

        // Get the next section record, if any.
        if (sec.hasNext()) {
          record = sec.next();
          nextSectionStart = record.getIndex();
        } else {
          nextSectionStart = slotLimit;
        }

        // System.out.println("next section start = " + nextSectionStart);

        // Pack Chords into section

        while ((chord != null || i.hasNext()) && slot < nextSectionStart) {
          if (chord == null) {
            Chord nextChord = (Chord) i.next();
            if (nextChord != null) {
              chord = nextChord.copy();
            }
          }
          // Otherwise use the residue of previous chord

          assert chord != null;
          // Where the next slot would normally be
          int nextSlot = slot + chord.getRhythmValue();

          if (nextSlot <= nextSectionStart) {
            // This chord fits in the current section.

            chord.saveLeadsheet(out, metre);
            chord = null;
            slot = nextSlot;
          } else {
            // This chord does not fit in the current section.
            // Calculate how much of this section can be used.
            int available = nextSectionStart - slot;
            chord.setRhythmValue(available);
            chord.saveLeadsheet(out, metre);

            // Determine what is left over.
            int residual = nextSlot - nextSectionStart;
            chord.setRhythmValue(residual);

            // System.out.println("overflow at slot " + slot + ", next section start = " +
            // nextSectionStart + " " + chord + ", residual = " + residual);

            // This should force the end of this while, among other things

            slot = nextSectionStart;
          }
        }
        sectionsToGo--;
      } while (sectionsToGo > 0); // end of do-while
    }
  }