Ejemplo n.º 1
0
 /**
  * 無駄な情報を削除する
  *
  * @param maxStep
  */
 public void trim(int maxStep) {
   if (_type == InstrumentType.NONE) {
     return;
   }
   if (_volume.isEmpty()) {
     _volume.add(new StepValue<Integer>(0, 99));
   } else {
     Collections.sort(_volume, StepValue.STEP_COMPARATOR);
     StepValue<Integer> sv = _volume.get(0);
     sv.setStep(0);
     for (int i = _volume.size() - 1; i > 0; i--) {
       StepValue<Integer> step = _volume.get(i);
       if (step.getStep() > maxStep) {
         _volume.remove(i);
       }
     }
   }
   if (_type == InstrumentType.SINGLE) {
     if (_bass.isEmpty()) {
       _bass.add(new StepValue<Integer>(0, 24));
     } else {
       Collections.sort(_bass, StepValue.STEP_COMPARATOR);
       StepValue<Integer> sv = _bass.get(0);
       sv.setStep(0);
       for (int i = _bass.size() - 1; i > 0; i--) {
         StepValue<Integer> step = _bass.get(i);
         if (step.getStep() > maxStep) {
           _bass.remove(i);
         } else {
           // 同じ値が連続しているなら削除
           StepValue<Integer> step2 = _bass.get(i - 1);
           if (step.getValue() == step2.getValue()) {
             _bass.remove(i);
           }
         }
       }
     }
     if (_button.isEmpty()) {
       _button.add(new StepValue<Integer>(0, 0));
     } else {
       Collections.sort(_button, StepValue.STEP_COMPARATOR);
       StepValue<Integer> sv = _button.get(0);
       sv.setStep(0);
       for (int i = _button.size() - 1; i > 0; i--) {
         StepValue<Integer> step = _button.get(i);
         if (step.getStep() > maxStep) {
           _button.remove(i);
         } else {
           // 同じ値が連続しているなら削除
           StepValue<Integer> step2 = _button.get(i - 1);
           if (step.getValue() == step2.getValue()) {
             _button.remove(i);
           }
         }
       }
     }
     if (_clef.isEmpty()) {
       _clef.add(new StepValue<Clef>(0, Clef.G2));
     } else {
       Collections.sort(_clef, StepValue.STEP_COMPARATOR);
       StepValue<Clef> sv = _clef.get(0);
       sv.setStep(0);
       for (int i = _clef.size() - 1; i > 0; i--) {
         StepValue<Clef> step = _clef.get(i);
         if (step.getStep() > maxStep) {
           _clef.remove(i);
         } else {
           // 同じ値が連続しているなら削除
           StepValue<Clef> step2 = _clef.get(i - 1);
           if (step.getValue() == step2.getValue()) {
             _clef.remove(i);
           }
         }
       }
     }
   } else if (_type == InstrumentType.GUITAR || _type == InstrumentType.PIANO) {
     if (!_chordSetList.isEmpty()) {
       Collections.sort(_chordSetList, StepValue.STEP_COMPARATOR);
       StepValue<List<Chord>> sv = _chordSetList.get(0);
       sv.setStep(0);
       for (int i = _chordSetList.size() - 1; i > 0; i--) {
         StepValue<List<Chord>> step = _chordSetList.get(i);
         if (step.getStep() > maxStep) {
           _chordSetList.remove(i);
         } else {
           // 同じ値が連続しているなら削除
           StepValue<List<Chord>> step2 = _chordSetList.get(i - 1);
           if (step.getValue().equals(step2.getValue())) {
             _chordSetList.remove(i);
           }
         }
       }
     }
   }
   if (_type == InstrumentType.PIANO) {
     if (!_voicing.isEmpty()) {
       Collections.sort(_voicing, StepValue.STEP_COMPARATOR);
       StepValue<Voicing> sv = _voicing.get(0);
       sv.setStep(0);
       for (int i = _voicing.size() - 1; i > 0; i--) {
         StepValue<Voicing> step = _voicing.get(i);
         if (step.getStep() > maxStep) {
           _voicing.remove(i);
         } else {
           // 同じ値が連続しているなら削除
           StepValue<Voicing> step2 = _voicing.get(i - 1);
           if (step.getValue().equals(step2.getValue())) {
             _voicing.remove(i);
           }
         }
       }
     }
   }
 }