<commit_before>import frequencyToPitch from '../../../audioHelpers/frequencyToPitch'
import pitchToFrequency from '../../../audioHelpers/pitchToFrequency'

const lfoNode = ({frequency, gain, type}) => ({
  0: ['gain', 'output', {gain}],
  1: ['oscillator', 0, {frequency, type}],
})

const osc = ({detune, frequency, gain, pan, pitch, startTime, stopTime, type}) => ({
  0: ['gain', 'output', {gain}],
  1: ['stereoPanner', 0, {pan}],
  2: ['oscillator', 1, {
    detune,
    frequency: pitchToFrequency(frequencyToPitch(frequency) + pitch),
    startTime,
    stopTime,
    type,
  }],
})

export default ({filter, lfo, master, oscillators}, notes) =>
  notes.reduce((acc, {frequency, gain, id, startTime, stopTime}) => {
    const noteGainId = `noteGain-${id}`
    acc[noteGainId] = ['gain', 'filter', {gain}]
    oscillators.forEach((oscParams, i) => {
      acc[`osc${i}${id}`] = [osc, noteGainId, {...oscParams, frequency, startTime, stopTime}]
    })
    return acc
  }, {
    lfo: [lfoNode, {key: 'filter', destination: 'frequency'}, lfo],
    masterGain: ['gain', 'output', {gain: master.gain}],
    masterPan: ['stereoPanner', 'masterGain', {pan: master.pan}],
    filter: ['biquadFilter', 'masterPan', filter],
  })
<commit_msg>refactor(prometheus) factor out array method forEach for faster loop version<commit_after>import frequencyToPitch from '../../../audioHelpers/frequencyToPitch'
import pitchToFrequency from '../../../audioHelpers/pitchToFrequency'

const forEachIndexed = (f, xs) => {
  for (let i = 0; i < xs.length; i++) f(xs[i], i)
}

const lfoNode = ({frequency, gain, type}) => ({
  0: ['gain', 'output', {gain}],
  1: ['oscillator', 0, {frequency, type}],
})

const osc = ({detune, frequency, gain, pan, pitch, startTime, stopTime, type}) => ({
  0: ['gain', 'output', {gain}],
  1: ['stereoPanner', 0, {pan}],
  2: ['oscillator', 1, {
    detune,
    frequency: pitchToFrequency(frequencyToPitch(frequency) + pitch),
    startTime,
    stopTime,
    type,
  }],
})

export default ({filter, lfo, master, oscillators}, notes) =>
  notes.reduce((acc, {frequency, gain, id, startTime, stopTime}) => {
    const noteGainId = `noteGain-${id}`
    acc[noteGainId] = ['gain', 'filter', {gain}]
    forEachIndexed((oscParams, i) => {
      acc[`osc${i}${id}`] = [osc, noteGainId, {...oscParams, frequency, startTime, stopTime}]
    }, oscillators)
    return acc
  }, {
    lfo: [lfoNode, {key: 'filter', destination: 'frequency'}, lfo],
    masterGain: ['gain', 'output', {gain: master.gain}],
    masterPan: ['stereoPanner', 'masterGain', {pan: master.pan}],
    filter: ['biquadFilter', 'masterPan', filter],
  })

{'fraction_non_alphanumeric': 0.20561456752655538, 'fraction_numerical': 0.006449165402124431, 'mean_word_length': 4.221782178217822, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4115575', 'n_tokens_mistral': 931, 'n_tokens_neox': 922, 'n_words': 227}