Made Some Changes Trying Techno
This commit is contained in:
parent
2af51efe0d
commit
a60aa223a5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -11,8 +11,9 @@ import javax.sound.midi.Track;
|
||||||
public class BeatMaker {
|
public class BeatMaker {
|
||||||
Sequence s;
|
Sequence s;
|
||||||
Track t;
|
Track t;
|
||||||
|
private int drum = 13;
|
||||||
|
|
||||||
public BeatMaker(Sequence s) throws InvalidMidiDataException {
|
public BeatMaker(Sequence s, int speed) throws InvalidMidiDataException {
|
||||||
this.s = s;
|
this.s = s;
|
||||||
t = s.createTrack();
|
t = s.createTrack();
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ public class BeatMaker {
|
||||||
|
|
||||||
// **** set tempo (meta event) ****
|
// **** set tempo (meta event) ****
|
||||||
MetaMessage mt = new MetaMessage();
|
MetaMessage mt = new MetaMessage();
|
||||||
byte[] bt = { 0x10, (byte) 0x00, 0x00 };
|
byte[] bt = { (byte) speed, (byte) 0x00, 0x00 };
|
||||||
mt.setMessage(0x51, bt, 3);
|
mt.setMessage(0x51, bt, 3);
|
||||||
me = new MidiEvent(mt, (long) 0);
|
me = new MidiEvent(mt, (long) 0);
|
||||||
t.add(me);
|
t.add(me);
|
||||||
|
|
@ -54,13 +55,15 @@ public class BeatMaker {
|
||||||
|
|
||||||
private void generateDrums() throws InvalidMidiDataException {
|
private void generateDrums() throws InvalidMidiDataException {
|
||||||
|
|
||||||
int b1 = (int) (Math.random() * 3);
|
// int b1 = (int) (Math.random() * 3);
|
||||||
int b2 = (int) (Math.random() * 3);
|
// int b2 = (int) (Math.random() * 3);
|
||||||
|
int b1 = 0;
|
||||||
|
int b2 = 2;
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
// **** set instrument to Piano ****
|
// **** set instrument to Piano ****
|
||||||
ShortMessage mm = new ShortMessage();
|
ShortMessage mm = new ShortMessage();
|
||||||
mm.setMessage(ShortMessage.PROGRAM_CHANGE, 1, 118, 0x00);
|
mm.setMessage(ShortMessage.PROGRAM_CHANGE, 1, drum , 0x00);
|
||||||
MidiEvent me = new MidiEvent(mm, (long) 0);
|
MidiEvent me = new MidiEvent(mm, (long) 0);
|
||||||
t.add(me);
|
t.add(me);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ package technomaker;
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new TechnoMaker().save("test1.mid");
|
new TechnoMaker(8).save("test1.mid");
|
||||||
try {
|
try {
|
||||||
Process p = Runtime.getRuntime().exec("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" D:\\spigotworkspace\\TenchnoMaker\\test1.mid");
|
// Process p = Runtime.getRuntime().exec("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" D:\\spigotworkspace\\TenchnoMaker\\test1.mid");
|
||||||
Thread.sleep(41*1000);
|
// Thread.sleep(120*1000);
|
||||||
p = Runtime.getRuntime().exec("taskkill /IM \"vlc.exe\" /F");
|
// p = Runtime.getRuntime().exec("taskkill /IM \"vlc.exe\" /F");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package technomaker;
|
package technomaker;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.sound.midi.InvalidMidiDataException;
|
import javax.sound.midi.InvalidMidiDataException;
|
||||||
import javax.sound.midi.MetaMessage;
|
import javax.sound.midi.MetaMessage;
|
||||||
import javax.sound.midi.MidiEvent;
|
import javax.sound.midi.MidiEvent;
|
||||||
|
|
@ -12,8 +14,11 @@ public class MelodyMaker {
|
||||||
|
|
||||||
Sequence s;
|
Sequence s;
|
||||||
Track t;
|
Track t;
|
||||||
|
int instrument = 80 + (int) (Math.random() * 7);
|
||||||
|
int instrumentR = 80 + (int) (Math.random() * 7);
|
||||||
|
private int ton = 60;
|
||||||
|
|
||||||
public MelodyMaker(Sequence s) throws Exception {
|
public MelodyMaker(Sequence s, int speed) throws Exception {
|
||||||
this.s = s;
|
this.s = s;
|
||||||
t = s.createTrack();
|
t = s.createTrack();
|
||||||
|
|
||||||
|
|
@ -26,7 +31,7 @@ public class MelodyMaker {
|
||||||
|
|
||||||
// **** set tempo (meta event) ****
|
// **** set tempo (meta event) ****
|
||||||
MetaMessage mt = new MetaMessage();
|
MetaMessage mt = new MetaMessage();
|
||||||
byte[] bt = { 0x10, (byte) 0x00, 0x00 };
|
byte[] bt = { (byte) speed, (byte) 0x00, 0x00 };
|
||||||
mt.setMessage(0x51, bt, 3);
|
mt.setMessage(0x51, bt, 3);
|
||||||
me = new MidiEvent(mt, (long) 0);
|
me = new MidiEvent(mt, (long) 0);
|
||||||
t.add(me);
|
t.add(me);
|
||||||
|
|
@ -54,24 +59,36 @@ public class MelodyMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateMelody() throws Exception {
|
private void generateMelody() throws Exception {
|
||||||
for (int i = 0; i < 10; i++)
|
generateRefrain();
|
||||||
addStrophe(40 * i);
|
addStrophe(40 * 0);
|
||||||
|
addRefrain(40 * 1);
|
||||||
|
addStrophe(40 * 2);
|
||||||
|
addStrophe(40 * 3);
|
||||||
|
addRefrain(40 * 4);
|
||||||
|
addStrophe(40 * 5);
|
||||||
|
addRefrain(40 * 6);
|
||||||
|
addStrophe(40 * 7);
|
||||||
|
// for (int i = 0; i < 8; i++)
|
||||||
|
// addRefrain(40 * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStrophe(int offset) throws Exception {
|
private void addStrophe(int offset) throws Exception {
|
||||||
|
|
||||||
int variation = 1 + (int) (Math.random() * 6);
|
int variation = 1 + (int) (Math.random() * 3);
|
||||||
|
|
||||||
int ton = 60;
|
|
||||||
for (int i = 0; i < 40;) {
|
for (int i = 0; i < 40;) {
|
||||||
|
|
||||||
i += 1 + Math.pow(Math.random() * 3, 2) * 0.3;
|
i += 1 + Math.pow(Math.random() * 3, 2) * 0.3;
|
||||||
|
|
||||||
ton += (int) (Math.random() * (variation * 2 + 1)) - variation;
|
ton += new Random().nextInt(variation * 2 + 1) - variation;
|
||||||
|
if (ton <= 0)
|
||||||
|
ton = 0;
|
||||||
|
if (ton >= 128)
|
||||||
|
ton = 127;
|
||||||
|
|
||||||
// **** set instrument to Piano ****
|
// **** set instrument to Piano ****
|
||||||
ShortMessage mm = new ShortMessage();
|
ShortMessage mm = new ShortMessage();
|
||||||
mm.setMessage(ShortMessage.PROGRAM_CHANGE, (int) (Math.random()*100), 0x00);
|
mm.setMessage(ShortMessage.PROGRAM_CHANGE, instrument, 0x00);
|
||||||
MidiEvent me = new MidiEvent(mm, (long) 0 + offset);
|
MidiEvent me = new MidiEvent(mm, (long) 0 + offset);
|
||||||
t.add(me);
|
t.add(me);
|
||||||
|
|
||||||
|
|
@ -89,4 +106,56 @@ public class MelodyMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShortMessage[] refrainOn = new ShortMessage[40];
|
||||||
|
ShortMessage[] refrainOff = new ShortMessage[40];
|
||||||
|
int[] tonLänge = new int[40];
|
||||||
|
|
||||||
|
private void generateRefrain() throws InvalidMidiDataException {
|
||||||
|
int variation = 1 + (int) (Math.random() * 3);
|
||||||
|
|
||||||
|
for (int i = 0; i < 39;) {
|
||||||
|
i += 1 + Math.random() * 2;
|
||||||
|
|
||||||
|
ton += new Random().nextInt(variation * 2 + 1) - variation;
|
||||||
|
if (ton <= 0)
|
||||||
|
ton = 0;
|
||||||
|
if (ton >= 128)
|
||||||
|
ton = 127;
|
||||||
|
ShortMessage mm = new ShortMessage();
|
||||||
|
mm.setMessage(ShortMessage.NOTE_ON, ton, 127);
|
||||||
|
ShortMessage mm2 = new ShortMessage();
|
||||||
|
mm2.setMessage(ShortMessage.NOTE_OFF, ton, 127);
|
||||||
|
if (i >= 40)
|
||||||
|
i = 39;
|
||||||
|
refrainOn[i] = mm;
|
||||||
|
refrainOff[i] = mm2;
|
||||||
|
tonLänge[i] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRefrain(int offset) throws Exception {
|
||||||
|
|
||||||
|
for (int i = 0; i < 40; i++) {
|
||||||
|
|
||||||
|
// **** set instrument to Piano ****
|
||||||
|
ShortMessage mm = new ShortMessage();
|
||||||
|
mm.setMessage(ShortMessage.PROGRAM_CHANGE, instrumentR, 0x00);
|
||||||
|
MidiEvent me = new MidiEvent(mm, (long) 0 + offset);
|
||||||
|
t.add(me);
|
||||||
|
|
||||||
|
if (refrainOn[i] == null) {
|
||||||
|
System.out.println("exit"+i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// **** note on - middle C ****
|
||||||
|
me = new MidiEvent(refrainOn[i], (long) i + offset);
|
||||||
|
t.add(me);
|
||||||
|
// **** note off - middle C - 120 ticks later ****
|
||||||
|
me = new MidiEvent(refrainOff[i], (long) tonLänge[i] + offset);
|
||||||
|
t.add(me);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ public class TechnoMaker {
|
||||||
Sequence s;
|
Sequence s;
|
||||||
BeatMaker bm;
|
BeatMaker bm;
|
||||||
MelodyMaker mm;
|
MelodyMaker mm;
|
||||||
|
int speed;
|
||||||
|
|
||||||
public TechnoMaker() {
|
public TechnoMaker(int speed) {
|
||||||
|
this.speed = speed;
|
||||||
try {
|
try {
|
||||||
s = new Sequence(Sequence.PPQ, 4);
|
s = new Sequence(Sequence.PPQ, 4);
|
||||||
Track t = s.createTrack();
|
Track t = s.createTrack();
|
||||||
mm = new MelodyMaker(s);
|
mm = new MelodyMaker(s,this.speed);
|
||||||
bm = new BeatMaker(s);
|
bm = new BeatMaker(s,this.speed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue