import com.google.common.collect.Multiset;
public class MidiAnalyzer {
public static void main(String[] args) {
Score score = new Score();
Read.midi(score, "C:\\workspace\\music\\analysis\\midi\\jarre\\EQUINOX3.MID");
for (Part part : score.getPartArray()) {
System.out.println(part.getTitle() + " : " + part.getInstrument());
}
Part part = score.getPart(1);
System.out.println(part.getInstrument());
part.setTempo(160);
int previousPitch = 0;
int prePreviousPitch = 0;
System.out.println(score.getTimeSignature());
Multiset<Integer> uniqueIntervals = HashMultiset.create();
int directionChanges = 0;
int directionRetentions = 0;
LinkedList<Double> noteLengths = new LinkedList<>();
for (Note note : part.getPhrase(0).getNoteArray()) {
System.out.println(note.getPitch());
if (!note.isRest()) {
if (prePreviousPitch != 0) {
int previousDiff = previousPitch - prePreviousPitch;
int diff = note.getPitch() - previousPitch;
if (Math.signum(previousDiff) != Math.signum(diff) && diff != 0 && previousDiff != 0) {
directionChanges++;
System.out.println(prePreviousPitch + ":" + previousPitch + ":" + note.getPitch());
} else if (diff != 0 && previousDiff != 0) {
directionRetentions++;
}
}
if (note.getPitch() - previousPitch != 0) {
prePreviousPitch = previousPitch;
}
uniqueIntervals.add(previousPitch - note.getPitch());
previousPitch = note.getPitch();
}
noteLengths.add(note.getRhythmValue());
}
double normalizedBeatSize = 1d * score.getNumerator() * 4 / score.getDenominator();
System.out.println("Beat size: " + normalizedBeatSize);
double currentBeatSize = 0;
int beats = 0;
int beatsWithPerfectHalves = 0;
// reverse, to avoid off-beats
for (Iterator<Double> it = noteLengths.descendingIterator(); it.hasNext();) {
currentBeatSize += it.next();;
if (currentBeatSize >= normalizedBeatSize) {
currentBeatSize = 0;
beats++;
}
if (currentBeatSize == normalizedBeatSize / 2) {
beatsWithPerfectHalves++;
}
}
System.out.println("Beats:beats with perfect halves -- " + beats + ":" + beatsWithPerfectHalves);
Hashtable<String, Object> table = PhraseAnalysis.getAllStatistics(score.getPart(1).getPhrase(0), 1, 0, Scales.MAJOR_SCALE);
for (Entry<String, Object> entry : table.entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
for (Integer interval : uniqueIntervals.elementSet()) {
System.out.println(interval + " : " + uniqueIntervals.count(interval));