-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities-music.js
55 lines (49 loc) · 1.79 KB
/
utilities-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
// --------------------------------------------------------------------------
// -- utilities-music.js
// -- initial author: Renick Bell ([email protected])
// -- initial creation date: Wed Jun 28 10:08:48 AM CST 2023
// -- contributors: Yiler Huang ([email protected]); Steve Wang ([email protected])
// -- license: GPL 3.0
// --------------------------------------------------------------------------
//Next step, play chrods with new system
let easymidi = await import('easymidi')
let notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
const {
Chord,
Interval,
Note,
Scale,
Key,
Progression,
Midi,
RomanNumeral,
Mode
} = require("tonal")
/**
* Converts bars(music) to beats(music)
* @param {numbers} beatsPerBar - Sets the beats per bar which the conversion uses.
* @param {array} inputBars - Barsr to convert
* @example console.log(barsToBeats(4, [0, 1, 2, 3])) //[ 0, 4, 8, 12 ]
*/
function barsToBeats(beatsPerBar, inputBars) {
return inputBars.map(e => e *= beatsPerBar)
}
// function melodyFromChordProgression (noteValues, iois){
// let notesToPlay = iois[1] - iois[0]
// notesToPlay += notesToPlay / 2
// return {notes: noteValues.map(x => {
// let chosenNotes = []
// for (let i = 0; i < x.length; i++) {
// chosenNotes.push(A.pick(x))
// }
// return chosenNotes
// }).flat(), iois: A.buildArray(iois.length, x => x * notesToPlay)}
// }
function melodyFromChordProgression (noteValues, iois){
let notesToPlay = iois[1] - iois[0]
notesToPlay += notesToPlay / 2
return {notes: noteValues.map(x => {
let chosenNotes = x.map(n => {return A.pick(x)})
return chosenNotes
}).flat(), iois: A.buildArray(iois.length, x => x * notesToPlay)}
}