//Author: John T. Rine //05-02-2011 import java.io.*; public class orca_Protocol { public static void main(String[] args) throws IOException { FileInputStream in = null; try { System.out.print("Enter filename: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String fileName = null; fileName = br.readLine(); in = new FileInputStream(fileName); int c; StringBuffer strContent = new StringBuffer(); int count = 0; while (count != 4) { c = in.read(); strContent.append((char)c); count++; } System.out.println(strContent); String temp = strContent.toString(); if(temp.equals("MThd")) System.out.println("Midi Header"); long dummy = 0; c = 0; int shift = 0; long result = 0; for (int i = 0; i != 4; i++) { c = in.read(); dummy = 0; dummy = (long) c; switch(i) { case 0: shift = 24; break; case 1: shift = 16; break; case 2: shift = 8; break; case 3: shift = 0; break; } dummy = dummy << shift; result = result | dummy; } System.out.println("Header Length = " + result); c = 0; shift = 0; int resultt = 0; for (int i = 0; i != 2; i++) { c = in.read(); switch(i) { case 0: shift = 8; break; case 1: shift = 0; break; } c = c << shift; resultt = resultt | c; } String fileType; switch(c) { case 0: fileType = "single track file format"; break; case 1: fileType = "multiple track file format"; break; case 2: fileType = "multiple song file format (i.e., a series of type 0 files)"; break; default: fileType = "Error"; } System.out.println("Midi File Type = " + c + " " + "File Type: " + fileType); c = 0; shift = 0; resultt = 0; for (int i = 0; i != 2; i++) { c = in.read(); switch(i) { case 0: shift = 8; break; case 1: shift = 0; break; } c = c << shift; resultt = resultt | c; } System.out.println("Number of track chunks that follow the header chunk = " + c); c = 0; shift = 0; resultt = 0; for (int i = 0; i != 2; i++) { c = in.read(); switch(i) { case 0: shift = 8; break; case 1: shift = 0; break; } c = c << shift; resultt = resultt | c; } System.out.println("Division = " + c); System.out.println("Unit of time for delta timing."); System.out.println("If the value is positive, then it represents the units per beat."); System.out.println("For example, +96 would mean 96 ticks per beat."); System.out.println("If the value is negative, delta times are in SMPTE compatible units."); } finally { if (in != null) { in.close(); } } } }