Ejemplo n.º 1
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("---------------------------------");
  }