示例#1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private static void noteOn(
      int phrIndex,
      Note[] curNote,
      SMFTools smf,
      int i,
      double[] currentLength,
      double startTime,
      Vector phrVct,
      short midiChannel,
      short pitch,
      int dynamic,
      Vector evtList) {

    phrIndex = -1;
    // work out what phrase is ready to accept a note
    for (int p = 0; p < phrVct.size(); p++) {
      // Warning 0.02 should really be fixed
      if (currentLength[p] <= (startTime + 0.08)) {
        phrIndex = p;
        break;
      }
    }
    // need to create new phrase for a new voice?
    if (phrIndex == -1) {
      phrIndex = phrVct.size();
      phrVct.addElement(new Phrase(startTime));
      currentLength[phrIndex] = startTime;
    }
    // Do we need to add a rest ?
    if ((startTime > currentLength[phrIndex]) && (curNote[phrIndex] != null)) {
      double newTime = startTime - currentLength[phrIndex];
      // perform a level of quantisation first
      if (newTime < 0.25) {
        double length = curNote[phrIndex].getRhythmValue();
        curNote[phrIndex].setRhythmValue(length + newTime);
      } else {
        Note restNote = new Note(REST, newTime, 0);
        restNote.setPan(midiChannel);
        restNote.setDuration(newTime);
        restNote.setOffset(0.0);
        ((Phrase) phrVct.elementAt(phrIndex)).addNote(restNote);
      }
      currentLength[phrIndex] += newTime;
    }
    // get end time
    double time = MidiUtil.getEndEvt(pitch, evtList, i) / (double) smf.getPPQN();
    // create the new note
    Note tempNote = new Note(pitch, time, dynamic);
    tempNote.setDuration(time);
    curNote[phrIndex] = tempNote;
    ((Phrase) phrVct.elementAt(phrIndex)).addNote(curNote[phrIndex]);
    currentLength[phrIndex] += curNote[phrIndex].getRhythmValue();
  }
示例#2
0
文件: Note.java 项目: timaschew/omt
 /**
  * Returns a copy of this note
  *
  * @return Note
  */
 public Note copy() {
   Note note;
   if (pitchType == MIDI_PITCH) {
     note = new Note(this.getPitch(), this.rhythmValue, this.dynamic);
   } else note = new Note(this.getFrequency(), this.rhythmValue, this.dynamic);
   note.setPan(this.pan);
   note.setDuration(this.duration);
   note.setOffset(this.offset);
   note.setSampleStartTime(this.sampleStartTime);
   note.setMyPhrase(this.myPhrase);
   for (int i = 0; i < breakPoints.length; i++) {
     if (this.breakPoints[i] != null) note.setBreakPoints(i, this.getBreakPoints(i));
   }
   return note;
 }
示例#3
0
 private static Score adjustTempo(Score paramScore) {
   Enumeration localEnumeration1 = paramScore.getPartList().elements();
   double d1 = 60.0D / paramScore.getTempo();
   while (localEnumeration1.hasMoreElements()) {
     Part localPart = (Part) localEnumeration1.nextElement();
     double d2 = d1;
     if (localPart.getTempo() != 0.0D) {
       d2 = 60.0D / localPart.getTempo();
     }
     Enumeration localEnumeration2 = localPart.getPhraseList().elements();
     while (localEnumeration2.hasMoreElements()) {
       Phrase localPhrase = (Phrase) localEnumeration2.nextElement();
       Enumeration localEnumeration3 = localPhrase.getNoteList().elements();
       while (localEnumeration3.hasMoreElements()) {
         Note localNote = (Note) localEnumeration3.nextElement();
         localNote.setRhythmValue(localNote.getRhythmValue() * d2);
         localNote.setDuration(localNote.getDuration() * d2);
       }
     }
   }
   return paramScore;
 }
示例#4
0
  @Override
  public void handleScore(Score score, ScoreContext ctx) {
    Part part = ctx.getParts().get(PartType.ARPEGGIO);
    if (part == null) {
      return;
    }
    Part mainPart = ctx.getParts().get(PartType.MAIN);
    double currentMeasureSize = 0;
    double normalizedMeasureSize = ctx.getNormalizedMeasureSize();
    SpecialNoteType specialNoteType = null;
    for (Phrase phrase : mainPart.getPhraseArray()) {
      if (Chance.test(20)) { // change the special note type
        if (Chance.test(60)) { // to a new value
          specialNoteType =
              SpecialNoteType.values()[random.nextInt(SpecialNoteType.values().length)];
        } else { // reset
          specialNoteType = null;
        }
      }

      Phrase arpeggioPhrase = new Phrase();
      arpeggioPhrase.setTitle("Arpeggio phrase");
      Scale currentScale = ((ExtendedPhrase) phrase).getScale();
      // get copies of the static ones, so that we can shuffle them without affecting the original
      List<Chord> scaleChords = new ArrayList<Chord>(ChordUtils.chords.get(currentScale));
      Collections.shuffle(scaleChords, random);
      Note[] notes = phrase.getNoteArray();
      List<ToneType> firstToneTypes = new ArrayList<>();

      int measures = 0;
      Note[] currentNotes = null;
      boolean useTwoNoteChords = Chance.test(14);
      Chord chord = null;
      for (int i = 0; i < notes.length; i++) {
        Note currentNote = notes[i];
        if (currentNote.getRhythmValue() == 0) {
          continue; // rhythm value is 0 for the first notes of a (main-part) chord. So progress to
                    // the next
        }
        boolean lastMeasure = measures == ctx.getMeasures() - 1;
        if (currentMeasureSize == 0 && !currentNote.isRest() && !lastMeasure) {
          boolean preferStable =
              ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.UNSTABLE);
          boolean preferUnstable =
              ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.STABLE);
          // change the chord only in 1/4 of the cases
          if (currentNotes == null || Chance.test(25)) {
            // no alternatives for now - only 3-note chords
            Chord previous = chord;
            chord =
                ChordUtils.getChord(
                    ctx,
                    currentNote.getPitch(),
                    previous,
                    scaleChords,
                    scaleChords,
                    scaleChords,
                    preferStable,
                    preferUnstable);
            if (chord != null) {
              int[] pitches = chord.getPitches();
              // remove the middle note in some cases (but make it possible to have three-note
              // chords in a generally two-note phrase)
              if (pitches.length == 3 && useTwoNoteChords && Chance.test(90)) {
                pitches = ArrayUtils.remove(pitches, 1);
              }
              int count = Chance.test(90) ? (Chance.test(80) ? 4 : 2) : (Chance.test(80) ? 3 : 5);

              currentNotes = new Note[count];
              double length = normalizedMeasureSize / count;
              for (int k = 0; k < count; k++) {
                Note note = NoteFactory.createNote(pitches[random.nextInt(pitches.length)], length);
                note.setDynamic(
                    InstrumentGroups.getInstrumentSpecificDynamics(
                        65 + random.nextInt(10), part.getInstrument()));
                if (specialNoteType != null) {
                  note.setDuration(note.getRhythmValue() * specialNoteType.getValue());
                }
                currentNotes[k] = note;
              }
            }
          }
          if (Chance.test(85) && currentNotes != null) {
            for (Note note : currentNotes) {
              arpeggioPhrase.addNote(note);
            }
          } else {
            arpeggioPhrase.addRest(new Rest(normalizedMeasureSize));
          }
        } else if (currentMeasureSize == 0 && (currentNote.isRest() || lastMeasure)) {
          arpeggioPhrase.addRest(new Rest(normalizedMeasureSize));
        }

        currentMeasureSize += currentNote.getRhythmValue();
        if (currentMeasureSize >= normalizedMeasureSize) {
          currentMeasureSize = 0;
          measures++;
        }
      }
      part.add(arpeggioPhrase);
    }
  }
示例#5
0
文件: Note.java 项目: timaschew/omt
 /**
  * Sets the rhythmValue, and optionally change the duration at the same time.
  *
  * @param factorDuration wether or not to change the duration to be a multiple of the rhythm value
  *     as well
  */
 public void setRhythmValue(double rv, boolean factorDuration) {
   setRhythmValue(rv);
   if (factorDuration) {
     setDuration(rv * DEFAULT_DURATION_MULTIPLIER);
   }
 }