-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure-konduktiva.js
110 lines (100 loc) · 4.26 KB
/
configure-konduktiva.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
100
101
102
103
104
105
106
107
108
109
110
// --------------------------------------------------------------------------
// -- configure-konduktiva.js
// -- initial author: Renick Bell ([email protected])
// -- initial creation date: Fri Jul 7 10:56 AM CST 2023
// -- contributors: Yiler Huang ([email protected]); Steve Wang ([email protected])
// -- license: GPL 3.0
// --------------------------------------------------------------------------
//writen by Bell:
e.actions.yoshimiSequncedRhythm = ((p, b) => {
console.log(e.players[p])
add2Log(JSON.stringify(e.players[p]))
console.log(mask(p, e.maskMaps[e.players[p].maskMap], (e.currentBeat()), 1))
if ((mask(p, e.maskMaps[e.players[p].maskMap], (e.currentBeat()), 1)) != true) {
sortMidiInfo(e.players[p].beat.wrapLookup(b), e.players[p])
}
})
function setupPlayer(env, sequenceName) {
env.players[sequenceName] = new Player(sequenceName);
console.log('checkpoint 1')
env.players[sequenceName].maskMap = 'default'
console.log('checkpoint 2')
//env.players[playerName].samplePattern = playerName;
env.players[sequenceName].action = 'yoshimiSequncedRhythm';
console.log('checkpoint 3')
return sequenceName
}
function updateMidiOutputList(e) {
let easymidiOutputs = easymidi.getOutputs()
//The line below is specific To my Device:
if (e.outputs !== undefined) {
e.outputs.forEach(x => {
x.close()
})
}
e.outputs = easymidiOutputs.map(x => {
return new easymidi.Output(x)
})
}
//assignPlayerForMusicSynthesizerSession(1, generateMidiInfoData, twelveBars, 1)
function editSessionPlayer(session, midiInfo, beat, channel) {
console.log('chose to edit');
let name = 'musicSynthesizerSession' + JSON.stringify(session)
let sessionPlayer = e.players['musicSynthesizerSession' + session];
sessionPlayer.keyspan = midiInfo.total;
sessionPlayer.midiData = midiInfo;
sessionPlayer.beat = beat;
sessionPlayer.session = 1;
sessionPlayer.channel = channel;
let adjustedIoisAndBools = extendIoisAndBools(midiInfo.music, midiInfo.IoIs, midiInfo.bools)
let midiRhythm = new RhythmPattern(name, `midiRhythm${session}`, midiInfo.total, adjustedIoisAndBools.IoIs, adjustedIoisAndBools.bools)
midiRhythm.add(e)
e.outputs[session] = (new easymidi.Output(easymidi.getOutputs()[session]))
}
function checkIfSessionPlayerExist(session) {
return Object.keys(e.players).find(x => x === 'musicSynthesizerSession' + session);
}
function extendIoisAndBools(chords, iois, bools) {
let chordsLength = chords.length;
let newIois = [];
let newBools = [];
if (iois.length != bools.length) {
console.log("The length of IoIs and bools should be the same.")
}
while (newIois.length < chordsLength) {
iois.forEach(ioi => newIois.push(ioi));
bools.forEach(b => newBools.push(b));
}
return {
bools: newBools,
IoIs: newIois
}
}
function createSessionPlayer(session, midiInfo, beat, channel) {
let name = 'musicSynthesizerSession' + JSON.stringify(session)
setupPlayer(e, name);
let adjustedIoisAndBools = extendIoisAndBools(midiInfo.music, midiInfo.IoIs, midiInfo.bools)
let midiRhythm = new RhythmPattern(name, `midiRhythm${session}`, midiInfo.total, adjustedIoisAndBools.IoIs, adjustedIoisAndBools.bools)
midiRhythm.add(e)
let sessionPlayer = e.players['musicSynthesizerSession' + session]
sessionPlayer.midiData = midiInfo;
sessionPlayer.beat = beat;
sessionPlayer.session = 1; //changed for fitting my synth
sessionPlayer.channel = channel;
e.outputs.push(new easymidi.Output(easymidi.getOutputs()[session]))
}
function assignPlayerForMusicSynthesizerSession(session, midiInfo, keys, channel) {
midiInfo.IoIs = adjustArrayLength(midiInfo.music.length, midiInfo.IoIs)
midiInfo.bools = adjustArrayLength(midiInfo.music.length, midiInfo.bools)
let beat = new QuantizedMap(midiInfo.total, keys, buildArray(keys.length, (x) => {
return x
}))
if (checkIfSessionPlayerExist(session) != undefined) {
editSessionPlayer(session, midiInfo, beat, channel)
}
if (checkIfSessionPlayerExist(session) === undefined) {
createSessionPlayer(session, midiInfo, beat, channel)
} else {
editSessionPlayer(session, midiInfo, beat, channel)
}
}