-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess2MIDI.java
More file actions
96 lines (87 loc) · 2.09 KB
/
Copy pathchess2MIDI.java
File metadata and controls
96 lines (87 loc) · 2.09 KB
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
package chess_reading;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
public class ReadIn {
public static void main(String[] args) throws IOException {
File chess = new File("C:\\Users\\garry\\Washu\\Laptop Music\\chess midi\\chess.txt");
Scanner in = new Scanner(chess);
Path fileName = Path.of("C:\\Users\\garry\\Washu\\Laptop Music\\chess midi\\midi.txt");
int [][] position = new int [39][2];
//create an array to store the letter and number of each move
int i=0;
while (in.hasNextLine()) {
in.nextLine();
String currentLetter = in.nextLine();
//a the letter to the first column of the array
switch(currentLetter) {
case "a":
position[i][0]= 57;
break;
case "b":
position[i][0]= 59;
break;
case "c":
position[i][0]= 60;
break;
case "d":
position[i][0]= 62;
break;
case "e":
position[i][0]= 64;
break;
case "f":
position[i][0]= 65;
break;
case "g":
position[i][0]= 67;
break;
case "h":
position[i][0]= 69;
break;
}
String currentNum = in.nextLine();
switch(currentNum) {
case "1":
case "1 ":
position[i][1]= position[i][0]+2;
break;
case "2":
case "2 ":
position[i][1]= position[i][0]+3;
break;
case "3":
case "3 ":
position[i][1]= position[i][0]+5;
break;
case "4":
case "4 ":
position[i][1]= position[i][0]+7;
break;
case "5":
case "5 ":
position[i][1]= position[i][0]+8;
break;
case "6":
case "6 ":
position[i][1]= position[i][0]+10;
break;
case "7":
case "7 ":
position[i][1]= position[i][0]+12;
break;
}
i++;
}
arrayWrite(position,fileName);
}
public static void arrayWrite(int [][] array, Path fileName) throws IOException {
for (int i=0; i<=array.length-1;i++) {
Files.writeString(fileName, Integer.toString(array[i][1])+"\r\n",StandardOpenOption.APPEND);
System.out.println(array[i][1]);
}
}
}