-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmimic-real-music.js
executable file
·99 lines (84 loc) · 3.06 KB
/
mimic-real-music.js
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
// --------------------------------------------------------------------------
// -- mimic-real-music.js
// --------------------------------------------------------------------------
let easymidi = require('easymidi')
function updateMidiOutputList (outputs){
let easymidiOutputs = easymidi.getOutputs()
//The line below is specific To my Device:
easymidiOutputs.shift()
if (outputs !== undefined){
outputs.forEach(x => {
x.close()
})
}
return easymidiOutputs.map(x => {
return new easymidi.Output(x)
})
}
let outputs = []
outputs = updateMidiOutputList(outputs)
function sendMidiData (velocity, noteSpan, output, note){
// add2Log(note)
//add2Log('--------------------------------------------------------------------------')
output.send('noteon', {
note: note,
velocity: velocity,
channel: 0,
});
setTimeout(() => {
output.send('noteoff', {
note: note,
velocity: velocity,
channel: 0,
});
}, noteSpan * 1000)
}
chords = [
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }], // C
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }], // C
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }], // C
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }], // C
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 10, octave: 2 }, { note: 2, octave: 3 }, { note: 5, octave: 3 }], // Am
[{ note: 10, octave: 2 }, { note: 2, octave: 3 }, { note: 5, octave: 3 }], // Am
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 2, octave: 3 }, { note: 5, octave: 3 }, { note: 9, octave: 3 }], // Dm
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }], // C
[{ note: 0, octave: 3 }, { note: 4, octave: 3 }, { note: 7, octave: 3 }] // C
]
tempo = 180
b = 0
/*
player = setInterval(() => {
playChord()
}, 333)
clearInterval(player)
*/
function playChord (){
chords[(b % (chords.length - 1))].forEach(x => {
sendMidiData(100, 333, outputs[0],(x.note + (x.octave * 12)))
})
b += 1
}
//tempo per minute
var keypress = require('keypress');
// make `process.stdin` begin emitting "keypress" events
keypress(process.stdin);
// listen for the "keypress" event
process.stdin.on('keypress', function (ch, key) {
console.log('got "keypress"', key, ch);
if (key && key.ctrl && key.name == 'c') {
process.stdin.pause()
return false
}
else{
// playChord()
}
});
process.stdin.setRawMode(true);
process.stdin.pause();