Ejemplo n.º 1
0
  public void saveToXml(Element ele) {
    Document doc = ele.getOwnerDocument();

    ele.setAttribute("id", String.valueOf(partNumber));
    SaveUtil.appendChildTextElement(ele, "title", String.valueOf(title));
    SaveUtil.appendChildTextElement(ele, "instrument", String.valueOf(instrument));
    for (int t = 0; t < getTrackCount(); t++) {
      if (!isTrackEnabled(t)) continue;

      TrackInfo trackInfo = abcSong.getSequenceInfo().getTrackInfo(t);

      Element trackEle = (Element) ele.appendChild(doc.createElement("track"));
      trackEle.setAttribute("id", String.valueOf(t));
      if (trackInfo.hasName()) trackEle.setAttribute("name", trackInfo.getName());

      if (trackTranspose[t] != 0)
        SaveUtil.appendChildTextElement(trackEle, "transpose", String.valueOf(trackTranspose[t]));
      if (trackVolumeAdjust[t] != 0)
        SaveUtil.appendChildTextElement(
            trackEle, "volumeAdjust", String.valueOf(trackVolumeAdjust[t]));

      if (instrument.isPercussion) {
        BitSet[] enabledSetByTrack = isCowbellPart() ? cowbellsEnabled : drumsEnabled;
        BitSet enabledSet = (enabledSetByTrack == null) ? null : enabledSetByTrack[t];
        if (enabledSet != null) {
          Element drumsEnabledEle = ele.getOwnerDocument().createElement("drumsEnabled");
          trackEle.appendChild(drumsEnabledEle);

          if (isCowbellPart()) {
            drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(false));

            // Only store the drums that are enabled
            for (int i = enabledSet.nextSetBit(0); i >= 0; i = enabledSet.nextSetBit(i + 1)) {
              Element drumEle = ele.getOwnerDocument().createElement("note");
              drumsEnabledEle.appendChild(drumEle);
              drumEle.setAttribute("id", String.valueOf(i));
              drumEle.setAttribute("isEnabled", String.valueOf(true));
            }
          } else {
            drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(true));

            // Only store the drums that are disabled
            for (int i = enabledSet.nextClearBit(0); i >= 0; i = enabledSet.nextClearBit(i + 1)) {
              if (i >= MidiConstants.NOTE_COUNT) break;

              Element drumEle = ele.getOwnerDocument().createElement("note");
              drumsEnabledEle.appendChild(drumEle);
              drumEle.setAttribute("id", String.valueOf(i));
              drumEle.setAttribute("isEnabled", String.valueOf(false));
            }
          }
        }

        if (!isCowbellPart()) {
          if (drumNoteMap[t] != null)
            drumNoteMap[t].saveToXml((Element) trackEle.appendChild(doc.createElement("drumMap")));
        }
      }
    }
  }
Ejemplo n.º 2
0
  private int findTrackNumberByName(String trackName) {
    if (trackName.equals("")) return -1;

    int namedTrackNumber = -1;
    for (TrackInfo trackInfo : abcSong.getSequenceInfo().getTrackList()) {
      if (trackInfo.hasName() && trackName.equals(trackInfo.getName())) {
        if (namedTrackNumber == -1) {
          namedTrackNumber = trackInfo.getTrackNumber();
        } else {
          // Found multiple tracks with the same name; don't know which one it could be
          return -1;
        }
      }
    }
    return namedTrackNumber;
  }