Exemplo n.º 1
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;
  }