Package nu.xom

Examples of nu.xom.Elements


     */
    public Document getMusicXMLDoc()
    {   finishCurrentVoice();

      //  remove empty measures
    Elements elDocParts = root.getChildElements("part");
    for (int xP = 0; xP < elDocParts.size(); ++xP)
    {  Element elDocPart = elDocParts.get(xP);
      Elements elPartMeasures = elDocPart.getChildElements("measure");
      for (int xM = 0; xM < elPartMeasures.size(); ++xM)
        if (elPartMeasures.get(xM).getChildCount() < 1)
          elDocPart.removeChild(xM);
    }
    //  create the Document
    Document xomDoc = new Document(root);
    DocType docType = new DocType("score-partwise",
View Full Code Here


        if (sReqVoice.compareTo(sCurPartID) == 0)
          return;
     
      //  check if the requested voice already exists
      boolean bNewVoiceExists = false;
      Elements elParts = root.getChildElements("part");
      Element elExistingNewPart = null;
      for (int x = 0; x < elParts.size(); ++x)
      {  Element elP = elParts.get(x);
        String sPID = elP.getAttribute("id").getValue();
       
        if (sPID.compareTo(sReqVoice) == 0)
        {  bNewVoiceExists = true;
          elExistingNewPart = elP;
View Full Code Here

    {
      String sCurPartID = (elCurPart == null)
                ? null
                : elCurPart.getAttribute("id").getValue();
      boolean bCurVoiceExists = false;
      Elements elParts = root.getChildElements("part");
      Element elExistingCurPart = null;

      for (int x = 0; x < elParts.size(); ++x)
      {  Element elP = elParts.get(x);
        String sPID = elP.getAttribute("id").getValue();
       
        if (sPID.compareTo(sCurPartID) == 0)
        {  bCurVoiceExists = true;
          elExistingCurPart = elP;
View Full Code Here

      //  otherwise, add the new one
      if (elCurMeasure.getParent() == null)
          elCurPart.appendChild(elCurMeasure);
        else
        int sCurMNum = Integer.parseInt(elCurMeasure.getAttributeValue("number"));
          Elements elMeasures = elCurPart.getChildElements("measure");
          for (int x = 0; x < elMeasures.size(); ++x)
          {  Element elM = elMeasures.get(x);
            int sMNum = Integer.parseInt(elM.getAttributeValue("number"));
            if (sMNum == sCurMNum)
              elCurPart.replaceChild(elM, elCurMeasure);
          }
        }
View Full Code Here

    private void newMeasure()
    {  Integer nextNumber = 1;
      boolean bNewMeasure = true;
      //   if there aren't any notes in the measure,
    //  continue to use the current measure
      Elements elMeasures = elCurPart.getChildElements("measure");
      Element elLastMeasure = null;
    if (elMeasures.size() > 0)
    {  elLastMeasure = elMeasures.get(elMeasures.size()-1);
      //  get the new measure number from the last one
      Attribute elNumber = elLastMeasure.getAttribute("number");
      if (elLastMeasure.getChildElements("note").size() < 1)
        bNewMeasure = false;
      else
View Full Code Here

  DocType docType = xomDoc.getDocType();
    Element  root = xomDoc.getRootElement();
 
    if (docType.getRootElementName().compareToIgnoreCase("score-partwise") == 0)
    {  Element partlist = root.getFirstChildElement("part-list");
      Elements parts = partlist.getChildElements();
      XMLpart[] partHeaders = new XMLpart[parts.size()];
      for (int p = 0; p < parts.size(); ++p)
      {  partHeaders[p] = new XMLpart();
        parsePartHeader(parts.get(p), partHeaders[p]);
      }
      parts = root.getChildElements("part");
      for (int p = 0; p < parts.size(); ++p)
      {  parsePart(p, parts.get(p), partHeaders);
      }
    }
  }
View Full Code Here

    partHeader.part_name = partName.getValue();
    //  may or may not have 1 or more score-instrument and
    //  midi-instrument elements
    //  score-instruments
    int x;
    Elements scoreInsts = part.getChildElements("score-instrument");
    for (x = 0; x < scoreInsts.size(); ++x )
    {  partHeader.score_instruments += scoreInsts.get(x).getValue();
      if (x < scoreInsts.size()-1)
        partHeader.score_instruments += "~";
    }
    //  midi-instruments
    Elements midiInsts = part.getChildElements("midi-instrument");
    for (x = 0; x < midiInsts.size(); ++x )
    {  Element midi_instrument = midiInsts.get(x);
      Element midi_channel = midi_instrument.getFirstChildElement("midi-channel");
      String midiChannel = (midi_channel == null) ? "" : midi_channel.getValue();
      if (midiChannel.length() > 0)
      {  partHeader.midi_instruments += midiChannel;
        partHeader.midi_instruments += "|";
      }
      Element midi_inst = midi_instrument.getFirstChildElement("midi-name");
      String midiInst = (midi_inst == null) ? "" : midi_inst.getValue();
      if (midiInst.length() < 1)
      {  Element midi_bank = midi_instrument.getFirstChildElement("midi-bank");
        midiInst = (midi_bank == null) ? "" : midi_bank.getValue();
        if (midiInst.length() < 1)
        {  Element midi_program = midi_instrument.getFirstChildElement("program");
          midiInst = (midi_program == null) ? "" : midi_program.getValue();
        }
      }
      partHeader.midi_instruments += midiInst;
      if (x < midiInsts.size()-1)
        partHeader.midi_instruments += "~";
    }
  }
View Full Code Here

          parsePartElementInstruments(p, partHeaders[x].midi_instruments);
       
        }
      }
    }
    Elements measures = part.getChildElements("measure");
    for (int m = 0; m < measures.size(); ++m)
    {  Element measure = measures.get(m);
      Element attributes = measure.getFirstChildElement("attributes");

      if (attributes != null)
      {  //  default key = Cmaj
        byte key = 0, scale = 0//  scale 0 = minor, 1 = major
        Element attr = attributes.getFirstChildElement("key");
        if (attr != null)
        {  Element eKey = attr.getFirstChildElement("fifths");
          if (eKey != null)
            key = Byte.parseByte(eKey.getValue());
          Element eMode = attr.getFirstChildElement("mode");
          if (eMode != null)
          {  String mode = eMode.getValue();
            if (mode.compareToIgnoreCase("major") == 0)
              scale = 0;
            else if (mode.compareToIgnoreCase("minor") == 0)
              scale = 1;
            else
                    throw new JFugueException(JFugueException.KEYSIG_EXC, mode);
          }
        }
        else
          scale = 0//  default = major
            fireKeySignatureEvent(new KeySignature(key, scale));
           
            //  divisions and beats used to calculate duration when note type not present
            Element element_divisions = attributes.getFirstChildElement("divisions");
            if (element_divisions != null)
              this.divisions = Byte.valueOf(element_divisions.getValue());
            Element element_time = attributes.getFirstChildElement("time");
            if (element_time != null)
            {  Element element_beats = element_time.getFirstChildElement("beats");
              if (element_beats != null)
                this.beats = Byte.valueOf(element_beats.getValue());
            }
      }
     
          //  tempo
      Element direction = measure.getFirstChildElement("direction");
      if (direction != null)
      {  Element directionType = direction.getFirstChildElement("direction-type");
        if (directionType != null)
        {  Element metronome = directionType.getFirstChildElement("metronome");
          if (metronome != null)
          {  Element beatUnit = metronome.getFirstChildElement("beat-unit");
            String sBeatUnit = beatUnit.getValue();
            if (sBeatUnit.compareToIgnoreCase("quarter") != 0)
              throw new JFugueException(JFugueException.BEAT_UNIT_MUST_BE_QUARTER, sBeatUnit);
            Element bpm = metronome.getFirstChildElement("per-minute");
            if (bpm != null)
            {  this.setTempo(BPMtoPPM(Float.parseFloat(bpm.getValue())));
              fireTempoEvent(new Tempo(this.getTempo()));
            }
          }
        }
      }

          //  notes
          Elements notes = measure.getChildElements("note");
//          totalMeasurePct = 0.f;
          for (int n = 0; n < notes.size(); ++n)
            parseNote(p, notes.get(n));
/*  attempt to adjust for rounding errors with un-supported durations
          //  if the total length of all the notes doesn't equal a full measure,
          //  add a pad rest
          float  minDif = (1.f / (beats * divisions));
          double  padDur = (1. - totalMeasurePct);
View Full Code Here

   * </pre>
   */
  public static void generateTestData(String[] args) throws Exception {
    Document doc = new Builder().build(new File(args[0])); // e.g. "romeo.xml"
    int times = Integer.parseInt(args[1]);    // e.g. 100
    Elements children = doc.getRootElement().getChildElements();
    for (int k=0; k < times; k++) {
      for (int i=0; i < children.size(); i++) {
        doc.getRootElement().appendChild(children.get(i).copy());
      }
    }
   
    FileOutputStream out = new FileOutputStream(args[2]); // e.g. "romeo100.xml"
    Serializer ser = new Serializer(out);
View Full Code Here

      this.doc = new Document(new Element(file.getName()));
    }
  }
 
  public void put(String rowName, String columnName, String value) {
    Elements rows = doc.getRootElement().getChildElements(rowName);
    if (rows.size() == 0) {
      doc.getRootElement().appendChild(new Element(rowName));
      rows = doc.getRootElement().getChildElements(rowName);
    }
   
    Elements cols = rows.get(0).getChildElements(columnName);
    if (cols.size() == 0) {
      rows.get(0).appendChild(new Element(columnName));
      cols = rows.get(0).getChildElements(columnName);
    }
   
    Element col = cols.get(0);
    col.removeChildren();
    col.appendChild(value);
  }
View Full Code Here

TOP

Related Classes of nu.xom.Elements

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.