Esempio n. 1
0
  public static void main(String[] args) {
    Phrase phr = new Phrase();

    // create a random walk
    int pitch = 60;
    for (int i = 0; i < 12; i++) {
      Note n = new Note(pitch += (int) (Math.random() * 8 - 4), SQ * (int) (Math.random() * 2 + 1));
      phr.addNote(n);
    }

    // repeat the whole thing three times
    Mod.repeat(phr, 3);

    // see the result at this stage
    View.show(phr);

    // repeat beats 2 - 4 three times
    Mod.repeat(phr, 3, 2.0, 4.0);

    // see the result of this change
    View.show(phr, 50, 50);

    // hear the result
    Part p = new Part();
    Score s = new Score();
    p.addPhrase(phr);
    s.addPart(p);
    s.setTempo(140.0);

    Play.midi(s, false);
    // false so that it doesn't close everything, the view.show() window
    // in particular

    Write.midi(s, "Repeat.mid");
  }
Esempio n. 2
0
 public void generate() {
   // Bird
   bird_num = 0;
   for (int i = 0; i < bar_num * 4; i++) {
     bird_jnote[i].pitch = (int) (Math.random() * 48) + 36;
     bird_jnote[i].duration = 120;
     bird_jnote[i].velocity = 60;
   }
   for (int i = 0; i < bar_num * 4; i++) {
     if ((int) (Math.random() * 3) == 0 || i == bar_num * 4 - 1) {
       bird_num++;
     } else {
       bird_jnote[bird_num].duration += 120;
     }
   }
 }