edo.js
Version:
A set of functions for manipulating musical pitches within a given EDO
282 lines (280 loc) • 11.7 kB
JavaScript
// // const EDO = require("../index.js").EDO
// // const Time = require("../index.js").Time
// import {EDO} from "../edo.js"
// //
// // const sorted = el=> el.map(c=>c.join(""))
// // .sort((a,b)=>a-b)
// //
// //
// //
// // const edo = new EDO(12)
// // const edo24 = new EDO(24)
// // let C = edo.scale([0,1,2,3,4,5,6,7,8,9,10,11])
// // let M = edo.scale([0,2,4,5,7,9,11])
// // let P = edo.scale([0,2,4,7,9])
// // let mm = edo.scale([0,2,3,5,7,9,11])
// // let hm = edo.scale([0,2,3,5,7,8,11])
// // let o = edo.scale([0,2,3,5,6,8,9,11])
// // let wt = edo.scale([0,2,4,6,8,10])
// // let pv = edo.scale([0,3,4,7,8,11])
// //
// // let AtharKurd = edo24.scale([0,2,6,12,14,16,22])
// // let JinsAtharKurd = [0,2,6,12,14]
// // let JinsHijazkar = [0,6,8,10,16,18]
// // let JinsHijaz = [0,2,8,10]
// // let JinsSikah = [0,3,7]
// // let Bayati = edo24.scale([0,4,7,10,14,18,20])
// // let JinsBayati = [0,3,6,10]
// // let JinsNahawand = [0,4,6,10,14]
// // let Hijaz = edo24.scale([0,2,8,10,14,16,20])
// // let Huzam = edo24.scale([0,4,7,10,14,16,22])
// // let Kurd = edo24.scale([0,4,6,10,14,18,20])
// // let Nikritz = edo24.scale([0,4,6,12,14,18,20])
// // let JinsNikriz = [0,4,6,12,14]
// // let Rast = edo24.scale([0,4,7,10,14,18,21])
// // let JinsRast = [0,4,7,10,14]
// // let JinsRast2 = [0,4,7]
// // let Sikah = edo24.scale([0,4,7,10,14,18,21])
// // let JinsUpperRast = [0,4,7,10]
// // let JinsKurd = [0,2,6,10]
//
// // let scales = edo24.get.scales(1,24,1,24,7,7)
// // // .map(e=>24/Math.pow(2,e.get.entropy(4)))
// // .map(e=>new Set(e.get.diagnostic_combinations(true)).size)
// // .reduce((ag,e)=>e+ag,0)/14421
// // console.log(scales)
//
// // let scales = edo24.get.scales(1,24,1,24,10,10)
// // .map(e=>({pitches:e.pitches.join(''),entropy: 24/Math.pow(2,e.get.entropy(5)),u:e.is.uniqueness()}))
// // .filter(e=>e.u==false)
// // .sort((a,b)=>a.entropy-b.entropy)
// // console.log(scales)
//
//
// // // console.log(new Set(M.get.diagnostic_combinations(true)).size)
// // console.log(12/Math.pow(2,hm.get.entropy(4)))
//
// // // let nk = edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],3).map(e=>edo.get.normal_order(e).join('')).sort((a,b)=>a-b)
// // // console.log(new Set(nk).size)
// // //
// // // console.log(nk.length,nk.filter(e=>e=='06').length)
// //
// //
// // console.log(-Math.log2(2/3))
// //
// //
// //
// //
// //
// //
// //
// // console.log(o.get.transposition(3).join(""))
//
// // console.log(M.get.position_of_quality([0,5,6]).length)
//
// // const e = pv.get.entropy(5)
// // console.log(Math.round(e*100)/100, Math.round(12/Math.pow(2,e)*10)/10)
//
// //
// // const nkM = edo.get.n_choose_k(M.pitches,6).map(e=>edo.get.normal_order(e).join("."))
// // const nkmm = edo.get.n_choose_k(mm.pitches,6).map(e=>edo.get.normal_order(e).join("."))
// // const nkhm = edo.get.n_choose_k(hm.pitches,6).map(e=>edo.get.normal_order(e).join("."))
// //
// // const allChords = [...nkM, ...nkmm, ...nkhm]
// // const unique = Array.from(new Set(allChords)).sort()
// // unique.forEach(u=>{
// // const nu = u.split('.').map(e=>parseInt(e))
// // const major = M.get.position_of_quality(nu).length
// // const HM = hm.get.position_of_quality(nu).length
// // const MM = mm.get.position_of_quality(nu).length
// // console.log(
// // `${u}:
// // ${Math.round(M.get.information(nu)*100)/100}
// // (${major}),
// // ${Math.round(mm.get.information(nu)*100)/100}
// // (${MM}),
// // ${Math.round(hm.get.information(nu)*100)/100}
// // (${HM}),
// // ${Math.round(((major+MM+HM)/allChords.length)*100)/100}`
// // )
// // })
//
// // console.log(M.get.position_of_quality([11,8,6,4,9,1]).length)
// // let scales = edo.get.scales(1,12,1,12,7,7)
// // let scales = [M,mm,hm,wt,o,P]
// // let catalog = []
// // for (let i = 1; i <7 ; i++) {
// // const chords = edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],i).map(e=>edo.get.normal_order(e)))
// // chords.forEach(chord=>{
// // let sum = 0
// // const entry ={chord:chord}
// // scales.forEach(scale=>{
// // const instances = scale.get.position_of_quality(chord).length
// // entry[scale.pitches.join('-')]=instances
// // sum+=(instances>0?1:0)
// // })
// // console.log(chord,sum)
// // })
// // }
// // catalog = catalog.filter(e=>e.major!=Infinity || e.mm!=Infinity || e.hm!=Infinity )
// // catalog = catalog.sort((a,b)=>b.chord.length-a.chord.length || b.major-a.major || b.mm-a.mm || b.hm-a.hm)
// // catalog = catalog.map(e=>{
// // e.major = 12/Math.pow(2,e.major)
// // e.mm = 12/Math.pow(2,e.mm)
// // e.hm = 12/Math.pow(2,e.hm)
// // return e
// // })
// // catalog.forEach(e=>console.log(e.chord))
// // //
// // import {createObjectCsvWriter} from "csv-writer";
// //
// // const csvWriter = createObjectCsvWriter({
// // path: 'out.csv',
// // header: Object.keys(catalog[0]).map(e=>({id:e,title:e}))
// // });
// //
// //
// // csvWriter
// // .writeRecords(catalog)
// // .then(()=> console.log('The CSV file was written successfully'));
//
//
// // console.log(edo.scale([0,3,5,6,8,10]).count.P5s())
//
// // let edo = new EDO(1200)
// //
// // let well = edo.scale([0,204,386,498,702,884,1088])
// // // let diatonic = edo.scale([0,200,400,500,700,900,1100])
// // // let equal = edo.scale([0,171, 343, 514, 686, 857, 1029])
// // let equalR = edo.scale([0,171, 343, 514, 686, 857, 1029].map(e=>e+Math.round((Math.random()*40)-20)))
// // console.log(well.normal().pitches)
// // console.log(equalR.normal().pitches)
//
// // const normalize = (actual,oldMin=50,oldMax=100,newMin=50,newMax=100) => {
// // const oldRange = oldMax-oldMin
// // const newRange = newMax-newMin
// // const convRatio = oldRange/newRange
// // const newVal = ((actual-oldMin)/convRatio)+newMin
// // return newVal
// //
// // }
// //
// // console.log(normalize(171.4,100,204,0,270))
// //
// // let edo = new EDO(14)
// //
// // // let diatonic = edo.scale([0,2,4,5,7,9,11])
// // // let trichords = diatonic.get.n_chords(6)
// // // trichords.forEach(t=>console.log(t.join(''),diatonic.get.position_of_quality(t)))
// // // console.log(edo.get.evenly_split(4))
// // // const diatonic = edo.scale([0,1,3,7])
// // // console.log(diatonic.get.symmetricalness())
// // const scales = edo.get.scales(1,14,1,14,4,4)
// // .sort((a,b)=>a.get.evenness_of_spread()-b.get.evenness_of_spread())
// // .forEach(scale=>console.log(scale.pitches, scale.get.name(),scale.get.evenness_of_spread()))
// // //
// //
// // // const scale = edo.scale([0,2,4,6,7])
// // // console.log(scale.get.mean(true))
// //
// // console.log(edo.convert.name_to_scale('14-585').get.modes())
//
// // const edo = new EDO()
// // console.log(edo.scale([0,2,3,6]).mode(0).get.scale_degree_roles())
// // console.log(edo.get.stacked([2,4,5,7,9,11,0],[3,4]))
// //
// // const edo = new EDO()
// // const stacked = (pitches,intervals,transposed_to_0=false) => {
// // const winners = []
// // const recur = (pitches, intervals,result=[]) => {
// // if(pitches.length==0) return winners.push(result)
// // const ed = 12
// // const pitch = result[result.length-1]%ed
// // // console.log("Working with",pitch)
// // for (let i = 0; i < pitches.length; i++) {
// // let kosher = true
// // if(!Number.isNaN(pitch)) {
// // const delta = edo.mod(pitches[i]-pitch,ed)
// // if(intervals.indexOf(delta)==-1) {
// // kosher=false
// // // console.log(`FAIL:
// // // the pitch ${pitches[i]} has a delta of ${delta} from ${pitch}.`)
// // }
// // }
// //
// // if(kosher) {
// // // console.log("current:", pitches,intervals,result)
// // const newPitches = [...pitches.slice(0,i),...pitches.slice(i+1)]
// // const newResult = [...result,pitches[i]]
// // // console.log("NP",newPitches,"NR",newResult,"P",pitches[i])
// // recur(newPitches,intervals,newResult)
// // }
// // }
// // }
// // recur(pitches,intervals)
// // if(transposed_to_0) winners.map(el=>this.get.transposition(el,el[0]*-1,false))
// // return winners
// // }
// // console.log(edo.get.stacked([0,2,4,6,8,9,11],[4,5]).map(e=>e.join(' ')))
//
//
// let edo = new EDO(12)
// //
// // const eAtC = (scale) => {
// // let sum = 0
// // let totalChords = 0
// // for (let n = 1; n <=scale.count.pitches() ; n++) {
// // const nk = scale.parent.get.n_choose_k(scale.pitches,n).map(e=>scale.parent.get.normal_order(e).join("."))
// // totalChords+=nk.length
// // }
// //
// // for (let n = 1; n <=scale.count.pitches() ; n++) {
// // const nk = scale.parent.get.n_choose_k(scale.pitches,n).map(e=>scale.parent.get.normal_order(e).join("."))
// // const unique = Array.from(new Set(nk))
// // .sort()
// // unique.forEach(c=>{
// // const p = nk.filter(e=>e==c).length/totalChords
// // const i = scale.get.information(c.split('.').map(e=>parseInt(e)))
// // sum+=p*i
// // })
// // }
// // return sum
// // }
// //
// //
// // const scales = edo.get.scales(1,12,1,12,8,8).map(scale=>{
// // const e = eAtC(scale)
// // const a = 12/Math.pow(2,e)
// // return {scale: scale.pitches.join(' '), ambiguity: Math.round(a*100)/100, u:scale.is.uniqueness()}
// // })
// // .sort((a,b)=>a.ambiguity-b.ambiguity)
// // .forEach(scale=>console.log(scale))
//
// const M = edo.scale([0,2,4,5,7,9,11])
// const mm = edo.scale([0,2,3,5,7,9,11])
// const hm = edo.scale([0,2,3,5,7,8,11])
// const wt = edo.scale([0,2,4,6,8,10])
// const o = edo.scale([0,2,3,5,6,8,9,11])
// const p = edo.scale([0,2,4,7,9])
// const a = edo.scale([0,3,4,7,8,11])
//
// const allCombos = []
// allCombos.push(...edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],2).map(combo=>edo.get.normal_order(combo))))
// allCombos.push(...edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],3).map(combo=>edo.get.normal_order(combo))))
// allCombos.push(...edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],4).map(combo=>edo.get.normal_order(combo))))
// allCombos.push(...edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],5).map(combo=>edo.get.normal_order(combo))))
// allCombos.push(...edo.get.unique_elements(edo.get.n_choose_k([0,1,2,3,4,5,6,7,8,9,10,11],6).map(combo=>edo.get.normal_order(combo))))
// allCombos.forEach(combo=>{
// console.log(
// [combo.join(' ')],
// `M: ${M.get.position_of_quality(combo).length}`,
// `mm: ${mm.get.position_of_quality(combo).length}`,
// `hm: ${hm.get.position_of_quality(combo).length}`,
// `wt: ${wt.get.position_of_quality(combo).length/(12/wt.count.transpositions())}`,
// `o: ${o.get.position_of_quality(combo).length/(12/o.count.transpositions())}`,
// `p: ${p.get.position_of_quality(combo).length}`,
// `a: ${a.get.position_of_quality(combo).length/(12/a.count.transpositions())}`,
//
// )
//
// })