예제 #1
0
파일: MusicReader.java 프로젝트: rdp/zong
 /** Reads the given barline element. Currently only left and right barlines are supported. */
 private static MusicReaderContext readBarline(MusicReaderContext context, MxlBarline mxlBarline) {
   MxlRightLeftMiddle location = mxlBarline.getLocation();
   MxlRepeat repeat = mxlBarline.getRepeat();
   int measureIndex = context.getMP().getMeasure();
   BarlineStyle style = null;
   if (mxlBarline.getBarStyle() != null)
     style = BarlineStyleReader.read(mxlBarline.getBarStyle().getBarStyle());
   if (repeat != null) {
     // repeat barline
     if (location == MxlRightLeftMiddle.Left) {
       // left barline
       if (repeat.getDirection() == MxlBackwardForward.Forward) {
         style = notNull(style, BarlineStyle.HeavyLight);
         context =
             context.withScore(
                 ScoreController.writeColumnStartBarline(
                     context.getScore(), measureIndex, createForwardRepeatBarline(style)));
       }
     } else if (location == MxlRightLeftMiddle.Right) {
       // right barline
       if (repeat.getDirection() == MxlBackwardForward.Backward) {
         style = notNull(style, BarlineStyle.LightHeavy);
         int times = notNull(repeat.getTimes(), 1).intValue();
         context =
             context.withScore(
                 ScoreController.writeColumnEndBarline(
                     context.getScore(), measureIndex, createBackwardRepeatBarline(style, times)));
       }
     }
   } else {
     // regular barline
     style = notNull(style, BarlineStyle.Regular);
     if (location == MxlRightLeftMiddle.Left) {
       // left barline
       context =
           context.withScore(
               ScoreController.writeColumnStartBarline(
                   context.getScore(), measureIndex, createBarline(style)));
     } else if (location == MxlRightLeftMiddle.Right) {
       // right barline
       context =
           context.withScore(
               ScoreController.writeColumnEndBarline(
                   context.getScore(), measureIndex, createBarline(style)));
     }
   }
   return context;
 }
예제 #2
0
파일: MusicReader.java 프로젝트: rdp/zong
  /** Reads the given print element. */
  private static MusicReaderContext readPrint(MusicReaderContext context, MxlPrint mxlPrint) {
    MxlPrintAttributes mxlPA = mxlPrint.getPrintAttributes();

    // system and page break
    Boolean newSystem = mxlPA.getNewSystem();
    SystemBreak systemBreak =
        (newSystem == null ? null : (newSystem ? SystemBreak.NewSystem : SystemBreak.NoNewSystem));
    Boolean newPage = mxlPA.getNewPage();
    PageBreak pageBreak =
        (newPage == null ? null : (newPage ? PageBreak.NewPage : PageBreak.NoNewPage));
    context =
        context.withScore(
            ScoreController.writeColumnElement(
                context.getScore(),
                atMeasure(context.getMP().getMeasure()),
                new Break(pageBreak, systemBreak)));

    // we assume that custom system layout information is just used in combination with
    // forced system/page breaks. so we ignore system-layout elements which are not combined
    // with system/page breaks.
    // the first measure of a score is also ok.
    if (context.getMP().getMeasure() == 0
        || systemBreak == SystemBreak.NewSystem
        || pageBreak == PageBreak.NewPage) {

      // first page or new page?
      boolean isPageBreak = pageBreak == PageBreak.NewPage;
      boolean isPageStarted = (context.getMP().getMeasure() == 0 || isPageBreak);
      if (isPageBreak) {
        // increment page index
        context = context.incPageIndex();
      }

      // first system or new system?
      boolean isSystemBreak = isPageBreak || systemBreak == SystemBreak.NewSystem;
      if (isSystemBreak) {
        // increment system index
        context = context.incSystemIndex();
      }

      // read system layout, if there
      MxlSystemLayout mxlSystemLayout = mxlPrint.getLayout().getSystemLayout();
      if (mxlSystemLayout != null) {
        SystemLayoutReader.Value sl =
            SystemLayoutReader.read(mxlSystemLayout, context.getTenthMm());
        SystemLayout systemLayout = sl.systemLayout;

        // for first systems on a page, use top-system-distance
        if (isPageStarted) {
          systemLayout = systemLayout.withSystemDistance(sl.topSystemDistance);
        }

        // apply values
        ScoreHeader scoreHeader =
            context
                .getScore()
                .getScoreHeader()
                .withSystemLayout(context.getSystemIndex(), systemLayout);
        context = context.withScore(context.getScore().withScoreHeader(scoreHeader));
      }
    }

    // staff layouts
    for (MxlStaffLayout mxlStaffLayout : mxlPrint.getLayout().getStaffLayouts()) {
      int staffIndex = mxlStaffLayout.getNumberNotNull() - 1;
      context =
          context.withScore(
              ScoreController.withStaffLayout(
                  context.getScore(),
                  context.getSystemIndex(),
                  context.getPartStavesIndices().getStart() + staffIndex,
                  readStaffLayout(mxlStaffLayout, context.getTenthMm()).staffLayout));
    }

    return context;
  }