|
| 1 | +package com.coniferproductions.sevenator; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.nio.file.Files; |
| 5 | +import java.nio.file.Paths; |
| 6 | +import java.util.List; |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.nio.ByteOrder; |
| 9 | + |
| 10 | +public class App { |
| 11 | + public static void main(String[] args) { |
| 12 | + System.out.println("System byte order = " + ByteOrder.nativeOrder()); |
| 13 | + |
| 14 | + Channel channel = new Channel(1); |
| 15 | + System.out.println("Channel value = " + channel); |
| 16 | + System.out.println(String.format("Channel = [%d, %d]", Channel.TYPE.first(), Channel.TYPE.last())); |
| 17 | + System.out.println("Channel contains -7? " + Channel.TYPE.contains(-7)); |
| 18 | + System.out.println("Channel contains 10? " + Channel.TYPE.contains(10)); |
| 19 | + |
| 20 | + Channel channel1 = new Channel(1); |
| 21 | + Channel channel2 = new Channel(2); |
| 22 | + if (channel1.equals(channel2)) { |
| 23 | + System.out.println("Same channel."); |
| 24 | + } else { |
| 25 | + System.out.println("Different channel."); |
| 26 | + } |
| 27 | + |
| 28 | + //RangedInteger ri = new RangedInteger(); // abstract class, can't instantiate |
| 29 | + //BadChannel bc = new BadChannel(10); // internally inconsistent, throws exception |
| 30 | + //Level level = new Level(100); // initial value out of range, throws exception |
| 31 | + |
| 32 | + MIDINote middleC = new MIDINote(60); |
| 33 | + System.out.println("Middle C is MIDI note number " + middleC.value() |
| 34 | + + ", or " + middleC); |
| 35 | + |
| 36 | + for (int value = middleC.last(); value >= middleC.first(); value--) { |
| 37 | + MIDINote note = new MIDINote(value); |
| 38 | + MIDINote.octave = Octave.ROLAND; |
| 39 | + System.out.print(value + " = " + note + " / "); |
| 40 | + MIDINote.octave = Octave.YAMAHA; |
| 41 | + System.out.println(note); |
| 42 | + } |
| 43 | + System.out.println(); |
| 44 | + |
| 45 | + System.out.println(String.format("Level = [%d, %d]", Level.TYPE.first(), Level.TYPE.last())); |
| 46 | + Level level1 = new Level(50); |
| 47 | + Level level2 = new Level(50); |
| 48 | + if (level1.equals(level2)) { |
| 49 | + System.out.println("The levels are equal."); |
| 50 | + } else { |
| 51 | + System.out.println("The levels are not equal."); |
| 52 | + } |
| 53 | + |
| 54 | + List<UInt8> data = new ArrayList<>(); |
| 55 | + try { |
| 56 | + byte[] contents = Files.readAllBytes(Paths.get(args[0])); |
| 57 | + |
| 58 | + for (byte b : contents) { |
| 59 | + int value = b & 0xff; |
| 60 | + data.add(new UInt8(value)); |
| 61 | + } |
| 62 | + |
| 63 | + System.out.printf("%02X ... %02X", contents[0], contents[contents.length - 1]); |
| 64 | + |
| 65 | + Message message = Message.parse(data); |
| 66 | + System.out.printf("%nMessage information:%n"); |
| 67 | + System.out.printf("payload = %d bytes%n%n", message.getPayload().size()); |
| 68 | + |
| 69 | + Header header = Header.parse(message.getPayload()); |
| 70 | + System.out.println("Header: format = " + header.getFormat()); |
| 71 | + System.out.println("byte count = " + header.getByteCount()); |
| 72 | + System.out.println("channel = " + header.getChannel()); |
| 73 | + |
| 74 | + } catch (IOException ioe) { |
| 75 | + ioe.printStackTrace(); |
| 76 | + } |
| 77 | + |
| 78 | + /* |
| 79 | + for (UInt8 b : data) { |
| 80 | + System.out.print(String.format("%02x", b.value())); |
| 81 | + System.out.print(" "); |
| 82 | + } |
| 83 | + System.out.println(); |
| 84 | + */ |
| 85 | + |
| 86 | + Runtime runtime = Runtime.getRuntime(); |
| 87 | + long totalMemory = runtime.totalMemory(); |
| 88 | + long freeMemory = runtime.freeMemory(); |
| 89 | + long usedMemory = totalMemory - freeMemory; |
| 90 | + System.out.println(String.format("Total memory: %10d", totalMemory)); |
| 91 | + System.out.println(String.format("Free memory: %10d", freeMemory)); |
| 92 | + System.out.println(String.format("Used memory: %10d", usedMemory)); |
| 93 | + } |
| 94 | +} |
0 commit comments