-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMxMReader.java
104 lines (86 loc) · 2.89 KB
/
MxMReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.io.*;
import java.util.*;
/**
*
* @author mwillson
*
* @description reads a file containing MxM (Musical Exploration Machine) output
* , translates it, and writes it into standard LEABRA input file for Emergent.
*/
public class MxMReader {
private static ArrayList<Note> notes = null;
private static ArrayList<Timbre> timbres = null;
private static int numRows = 0;
private static Timbre currentTimbre = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
Scanner s = null;
PrintWriter out = null;
Token current = new Token("");
notes = new ArrayList<Note>();
timbres = new ArrayList<Timbre>();
try {
// Scan and classify tokens
s = new Scanner
(new BufferedReader (new FileReader
("gamelan.txt"))
);
while ( s.hasNext() ) {
// set text variable of token for further processing
current.setText(s.next());
//embody token in a class instance and assign it to a list
classify(current);
}
// the number of rows for the input matrices is the total
// number of "notes" played
// numRows = notes.size();
// create a printwriter for some output file, specified or not
if(args.length > 0) out = new PrintWriter (new FileWriter(args[0]));
else out = new PrintWriter (new FileWriter("output.txt"));
//Write out note info to file
out.write("_D: ");
for(int i = 0; i < notes.size(); i++) {
out.write(notes.get(i).pitchMatrix());
out.println();
}
out.println();
//Write out duration info to file
out.write("_D: ");
for(int i = 0; i < notes.size(); i++) {
out.write(notes.get(i).durationMatrix());
out.println();
}
out.println();
//Write out timbre info to file
out.write("_D: ");
for(int i = 0; i < timbres.size(); i++) {
out.write(timbres.get(i).timbreMatrix());
out.println();
}
out.println();
} finally {
if (s != null) {
s.close();
}
if (out != null) {
out.close();
}
}
}
/*
* Classify token as Note or Timbre and and if it is a note,
* add it and the current timbre to their respective lists.
*/
public static void classify (Token t) {
if(t.isTimbre()) {
currentTimbre = t.parseTimbre();
}else if(t.isNote()) {
notes.add(t.parseNote());
timbres.add(currentTimbre);
}else {
return;
}
}
}