Esempio n. 1
0
  // markermarkermarker
  public void adjustEndOfSection(
      int index, int endIndex, boolean isPhrase, boolean usePreviousStyleChecked) {
    // *
    if (endIndex <= 0) return;

    SectionRecord record = records.get(index);

    int endTemp = (index + 1 < size()) ? getSectionMeasure(index + 1) - 1 : measures();

    int nextSectionEnd = (index + 2 < size()) ? getSectionMeasure(index + 2) - 1 : measures();

    if (index < size() - 1 && endIndex >= nextSectionEnd) return;

    if (endIndex < getSectionMeasure(index)) return;

    // if user wants to change end index to what it is already -_-
    if (endIndex == endTemp) {
      record.setIsPhrase(isPhrase);
      if (usePreviousStyleChecked) record.setUsePreviousStyle();
      return;
    }

    String styleName = usePreviousStyleChecked ? Style.USE_PREVIOUS_STYLE : record.getStyleName();

    if (size() <= 1) return;
    if (index < size() - 1) {
      SectionRecord nextRecord = records.get(index + 1);
      nextRecord.setIndex(measureToSlotIndex(endIndex + 1));
    }
    // */

  }
Esempio n. 2
0
 public ArrayList<String> getSectionRecordStyleNames() {
   ArrayList<String> secRecStyles = new ArrayList<String>();
   for (SectionRecord sr : records) {
     secRecStyles.add(sr.getStyleName());
   }
   return secRecStyles;
 }
Esempio n. 3
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;
  }
Esempio n. 4
0
  // row      , startIndex
  public void adjustSection(
      int index, int newMeasure, boolean isPhrase, boolean usePreviousStyleChecked) {
    // System.out.println("1 records = " + records);

    // Do not move first record
    // Its phrase value can be set in place

    if (newMeasure <= 0) return;

    if (index > 0 && newMeasure <= getSectionMeasure(index - 1)) return;

    int endTemp = (index + 1 < size()) ? getSectionMeasure(index + 1) - 1 : measures();

    if (newMeasure > endTemp) return;

    SectionRecord record = records.get(index);
    // gets the start measure # of the section
    // if user wants to change start index to what it is already -_-
    if (getSectionMeasure(index) == newMeasure) {
      record.setIsPhrase(isPhrase);
      if (usePreviousStyleChecked) record.setUsePreviousStyle();
      return;
    }

    String styleName = usePreviousStyleChecked ? Style.USE_PREVIOUS_STYLE : record.getStyleName();
    deleteSection(index);
    addSection(styleName, measureToSlotIndex(newMeasure), isPhrase);
  }
Esempio n. 5
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()));
   }
 }
Esempio n. 6
0
  public String getInfo(int index) {
    SectionRecord record = records.get(index);

    String styleName = record.getStyleName();
    int startIndex = getSectionMeasure(index);
    int endIndex = measures();
    if (index + 1 < size()) endIndex = getSectionMeasure(index + 1) - 1;

    String info = "mm. " + startIndex + "-" + endIndex + ": " + styleName;
    if (startIndex == endIndex) info = "m. " + startIndex + ": " + styleName;

    return info;
  }
Esempio n. 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();
 }
Esempio n. 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;
 }
Esempio n. 9
0
  private void saveSectionInfo(BufferedWriter out, SectionRecord record) throws IOException {
    String styleName = record.getUsePreviousStyle() ? "" : " " + record.getStyleName();

    if (record.getIsPhrase()) {
      out.newLine();
      out.write("(phrase (style" + styleName + ")) ");
      out.newLine();
    } else {
      out.newLine();
      out.newLine();
      out.write("(section (style" + styleName + ")) ");
      out.newLine();
      out.newLine();
    }
  }
Esempio n. 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;
  }
Esempio n. 11
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;
  }