/Users/lyon/j4p/src/sound/MidiFileInfo.java
|
1 package sound;
2
3 import javax.sound.midi.MidiFileFormat;
4 import javax.sound.midi.Sequence;
5 import java.awt.*;
6
7 // to get this to import on a mac,
8 // add to the class path:
9 // /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Classes/ui.jar
10
11 public class MidiFileInfo {
12 private static final int LOAD_METHOD_STREAM = 1;
13 private static final int LOAD_METHOD_FILE = 2;
14 private static final int LOAD_METHOD_URL = 3;
15
16 public static String getReadFile() {
17 FileDialog fd = new FileDialog(new Frame(), "select a midifile");
18 fd.show();
19 fd.hide();
20 return fd.getDirectory() + fd.getFile();
21 }
22
23
24 public static void main(String[] args) {
25 int nLoadMethod = LOAD_METHOD_FILE;
26 boolean bCheckSequence = false;
27 int nCurrentArg = 0;
28 String strSource = getReadFile();
29 String strFilename = strSource;
30 MidiFileFormat fileFormat = null;
31 Sequence sequence = null;
32
33 /*
34 * And now, we output the data.
35 */
36 if (fileFormat == null) {
37 System.out.println("Cannot determine format");
38 } else {
39 System.out.println("---------------------------------------------------------------------------");
40 System.out.println("Source: " + strFilename);
41 System.out.println("Midi File Type: " + fileFormat.getType());
42
43 float fDivisionType = fileFormat.getDivisionType();
44 String strDivisionType = null;
45 if (fDivisionType == Sequence.PPQ) {
46 strDivisionType = "PPQ";
47 } else if (fDivisionType == Sequence.SMPTE_24) {
48 strDivisionType = "SMPTE, 24 frames per second";
49 } else if (fDivisionType == Sequence.SMPTE_25) {
50 strDivisionType = "SMPTE, 25 frames per second";
51 } else if (fDivisionType == Sequence.SMPTE_30DROP) {
52 strDivisionType = "SMPTE, 29.97 frames per second";
53 } else if (fDivisionType == Sequence.SMPTE_30) {
54 strDivisionType = "SMPTE, 30 frames per second";
55 }
56
57 System.out.println("DivisionType: " + strDivisionType);
58
59 String strResolutionType = null;
60 if (fileFormat.getDivisionType() == Sequence.PPQ) {
61 strResolutionType = " ticks per beat";
62 } else {
63 strResolutionType = " ticks per frame";
64 }
65 System.out.println("Resolution: " + fileFormat.getResolution() + strResolutionType);
66
67 String strFileLength = null;
68 if (fileFormat.getByteLength() != MidiFileFormat.UNKNOWN_LENGTH) {
69 strFileLength = "" + fileFormat.getByteLength() + " bytes";
70 } else {
71 strFileLength = "unknown";
72 }
73 System.out.println("Length: " + strFileLength);
74
75 String strDuration = null;
76 if (fileFormat.getMicrosecondLength() != MidiFileFormat.UNKNOWN_LENGTH) {
77 strDuration = "" + fileFormat.getMicrosecondLength() + " microseconds)";
78 } else {
79 strDuration = "unknown";
80 }
81 System.out.println("Duration: " + strDuration);
82
83 if (bCheckSequence) {
84 System.out.println("[Sequence says:] Length: " + sequence.getTickLength() + " ticks (= " + sequence.getMicrosecondLength() + " us)");
85 }
86 System.out.println("---------------------------------------------------------------------------");
87 }
88 }
89
90 }
91
92
93 /*** MidiFileInfo.java ***/
94