コード例 #1
0
ファイル: RepeatTest.java プロジェクト: ars18wrw/MahlerJMC
  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");
  }
コード例 #2
0
  public ParseMidiSmart() {
    FileDialog fd;
    Frame f = new Frame();

    // open a MIDI file
    fd = new FileDialog(f, "Open MIDI file or choose cancel to" + " finish.", FileDialog.LOAD);
    fd.show();

    // break out when user presses cancel
    if (fd.getFile() == null) return;
    //        SMF smf = new SMF();
    //        try {
    //            smf.read(new FileInputStream(new File(fd.getDirectory()+fd.getFile())));
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }
    //        Vector vector = smf.getTrackList();
    //        for (int i = 0; i < vector.size(); i++) {
    //            Score score = new Score();
    //            MidiParser.SMFToScore(score, smf);
    //            System.out.println();
    //        }
    Read.midi(s, fd.getDirectory() + fd.getFile());
    s.setTitle(fd.getFile());
    //        try {
    //            System.out.println(MidiSystem.getMidiFileFormat(fd.getFiles()[0]));
    //        } catch (InvalidMidiDataException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }

    Score scoreToWrite = null;
    for (int i = 0; i < s.getSize(); i++) {
      scoreToWrite = new Score();
      scoreToWrite.add(s.getPart(i));
      scoreToWrite.setTempo(200);
      Write.midi(scoreToWrite, String.format(fd.getFile() + "%d.mid", i));

      Part part = s.getPart(i);
      for (int j = 0; j < part.getSize(); j++) {
        Phrase phrase = part.getPhrase(j);
        for (int ii = 0; ii < phrase.getSize(); ii++) {
          System.out.println(phrase.getNote(ii).getNote());
        }
      }
    }

    //            //keep track of the number of scores analysed
    //            scoreCount++;
    //            //reset melody length
    //            int tempLength = 0;
    //            // iterate through each note
    //            //find the highest and lowest notes
    //            Enumeration enum1 = s.getPartList().elements();
    //            while(enum1.hasMoreElements()){
    //                Part nextPt = (Part)enum1.nextElement();
    //                Enumeration enum2 =
    //                        nextPt.getPhraseList().elements();
    //                while(enum2.hasMoreElements()){
    //                    Phrase nextPhr =
    //                            (Phrase)enum2.nextElement();
    //                    Enumeration enum3 =
    //                            nextPhr.getNoteList().elements();
    //                    while(enum3.hasMoreElements()){
    //                        Note nextNote =
    //                                (Note)enum3.nextElement();
    //                        int pitch = nextNote.getPitch();
    //                        //check range
    //                        pitchRange(pitch);
    //                        double rv =
    //                                nextNote.getRhythmValue();
    //                        //check rhythmic values
    //                        rhythmRange(rv);
    //                        //check meldoy length
    //                        tempLength++;
    //                        //check direction
    //                        upOrDown(pitch);
    //                    }
    //                }
    //            }
    // update length extremes
    // musicLength(tempLength);

    //            //output the current stats
    //            System.out.print(PRE_TEXT);
    //            System.out.println("STATS after "+scoreCount+
    //                    " files. Last score called "+
    //                    s.getTitle());
    //            System.out.print(PRE_TEXT);
    //            System.out.println("Lowest note is "+lowNote);
    //            System.out.println("Highest note is "+highNote);
    //            System.out.println("---------------------------------");
    //            System.out.println("Shortest note is "+shortestRhythm);
    //            System.out.println("Longest note is "+longestRhythm);
    //            System.out.println("---------------------------------");
    //            System.out.println("Smallest score contains "+
    //                    shortLength+" notes");
    //            System.out.println("Largest score contains "+longLength+
    //                    " notes");
    //            System.out.println("---------------------------------");
    //            System.out.println("Upward movements were "+ascending);
    //            System.out.println("Downward movements were "+
    //                    descending);
    //            System.out.println("---------------------------------");
  }
コード例 #3
0
ファイル: JBirdGen.java プロジェクト: jasonmel/JMIDIGen
 public void save(String filename) {
   Write.midi(bird_part, filename);
 }