예제 #1
0
 public void setScore(Score score) {
   ScoreInfo info = score.getInfo();
   lblTitle.setText(info.getTitle());
   txtWorkNumber.setText(info.getWorkNumber());
   txtWorkTitle.setText(info.getWorkTitle());
   txtMovementNumber.setText(info.getMovementNumber());
   txtMovementTitle.setText(info.getMovementTitle());
   // creators
   String s = "-";
   if (info.getCreators().size() > 0) {
     s = "";
     for (Creator creator : info.getCreators())
       s += (creator.getType() != null ? creator.getType() + ": " : "") + creator.getName() + "\n";
   }
   txtCreators.setText(s);
   // rights
   s = "-";
   if (info.getRights().size() > 0) {
     s = "";
     for (Rights rights : info.getRights())
       s += (rights.getType() != null ? rights.getType() + ": " : "") + rights.getText() + "\n";
   }
   txtRights.setText(s);
   // parts
   s = "-";
   if (score.getStavesList().getParts().size() > 0) {
     s = "";
     for (int i : range(score.getStavesList().getParts())) {
       Part part = score.getStavesList().getParts().get(i);
       s += i + ": " + part.getName() + "\n";
     }
   }
   txtParts.setText(s);
 }
예제 #2
0
파일: Test33i.java 프로젝트: JasonLil/Zong
 @Before
 public void before() {
   Score score = getScore();
   for (int iMeasure : range(5)) {
     chords[iMeasure] = (Chord) score.getVoice(atVoice(0, iMeasure, 0)).getElement(0);
   }
 }
예제 #3
0
파일: Test21c.java 프로젝트: JasonLil/Zong
 @Test
 public void test() {
   Score score = getScore();
   MP mp = mp0;
   for (int i = 0; i < expectedChords.length; i++) {
     Chord chord = (Chord) score.getVoice(mp).getElementAt(mp.beat);
     assertEquals("chord " + i, expectedChords[i].getNotes(), chord.getNotes());
     assertEquals("chord " + i, expectedChords[i].getDuration(), chord.getDuration());
     mp = mp.withBeat(mp.beat.add(expectedChords[i].getDuration()));
     if (mp.beat.compareTo(_1) >= 0) {
       mp = mp.withMeasure(mp.measure + 1).withBeat(_0);
     }
   }
 }
예제 #4
0
파일: MusicReader.java 프로젝트: rdp/zong
  /** Reads the given MusicXML document and returns the score. */
  public static Score read(
      MxlScorePartwise doc, Score baseScore, ErrorProcessing err, boolean ignoreErrors) {
    MusicReaderContext context =
        new MusicReaderContext(baseScore, new MusicReaderSettings(err, ignoreErrors));

    // read the parts
    int staffIndexOffset = 0;
    It<MxlPart> mxlParts = it(doc.getParts());
    for (MxlPart mxlPart : mxlParts) {
      // clear part-dependent context values
      int stavesCount =
          baseScore.getStavesList().getParts().get(mxlParts.getIndex()).getStavesCount();
      context = context.beginNewPart(mxlParts.getIndex());
      staffIndexOffset += stavesCount;
      // read the measures
      It<MxlMeasure> mxlMeasures = it(mxlPart.getMeasures());
      for (MxlMeasure mxlMeasure : mxlMeasures) {
        try {
          context = readMeasure(context, mxlMeasure, mxlMeasures.getIndex());
        } catch (MusicReaderException ex) {
          throw new RuntimeException("Error at " + ex.getContext().toString(), ex);
        } catch (Exception ex) {
          throw new RuntimeException("Error (roughly) around " + context.toString(), ex);
        }
      }
    }

    // go through the whole score, and fill empty measures (that means, measures where
    // voice 0 has no single VoiceElement) with rests
    Fraction measureDuration = fr(1, 4);
    for (int iStaff = 0; iStaff < context.getScore().getStavesCount(); iStaff++) {
      Staff staff = context.getScore().getStaff(atStaff(iStaff));
      for (int iMeasure = 0; iMeasure < staff.getMeasures().size(); iMeasure++) {
        Measure measure = staff.getMeasures().get(iMeasure);
        Time newTime = context.getScore().getScoreHeader().getColumnHeader(iMeasure).getTime();
        if (newTime != null) {
          // time signature has changed
          if (newTime instanceof NormalTime) {
            measureDuration = ((NormalTime) newTime).getBeatsPerMeasure();
          } else {
            measureDuration = fr(1, 4); // default: 1/4
          }
        }
        Voice voice0 = measure.getVoices().get(0);
        if (voice0.isEmpty()) {
          // TODO: "whole rests" or split. currently, also 3/4 rests are possible
          context =
              context.withScore(
                  ScoreController.writeVoiceElement(
                      context.getScore(), mp(iStaff, iMeasure, 0, _0), new Rest(measureDuration)));
        }
      }
    }

    return context.getScore();
  }