migrate EQ+ to Revamp
This commit is contained in:
@@ -1,65 +1,71 @@
|
|||||||
import {EqBandType, EqualizerSchema, ParameterDecoder} from "@opendaw/lib-dawproject"
|
import {BandSchema, EqBandType, EqualizerSchema, ParameterDecoder} from "@opendaw/lib-dawproject"
|
||||||
import {RevampDeviceBox} from "@opendaw/studio-boxes"
|
import {RevampDeviceBox, RevampPass, RevampShelf} from "@opendaw/studio-boxes"
|
||||||
import {BoxGraph, Field} from "@opendaw/lib-box"
|
import {BoxGraph, Field} from "@opendaw/lib-box"
|
||||||
import {clamp, ifDefined, int, UUID} from "@opendaw/lib-std"
|
import {ifDefined, int, UUID} from "@opendaw/lib-std"
|
||||||
import {Pointers} from "@opendaw/studio-enums"
|
import {Pointers} from "@opendaw/studio-enums"
|
||||||
import {semitoneToHz} from "@opendaw/lib-dsp"
|
import {semitoneToHz} from "@opendaw/lib-dsp"
|
||||||
|
|
||||||
export namespace BuiltinDevices {
|
export namespace BuiltinDevices {
|
||||||
const mapQ = (Qbw: number) => clamp(20 * Math.log10(Qbw), 0.01, 10)
|
|
||||||
|
|
||||||
export const equalizer = (boxGraph: BoxGraph,
|
export const equalizer = (boxGraph: BoxGraph,
|
||||||
equalizer: EqualizerSchema,
|
equalizer: EqualizerSchema,
|
||||||
field: Field<Pointers.MidiEffectHost> | Field<Pointers.AudioEffectHost>,
|
field: Field<Pointers.MidiEffectHost> | Field<Pointers.AudioEffectHost>,
|
||||||
index: int): RevampDeviceBox => {
|
index: int): RevampDeviceBox => {
|
||||||
|
const mapOrder = (order?: int) => {
|
||||||
|
switch (order) {
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
return 0
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
return 1
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
return 2
|
||||||
|
default:
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const readPass = (schema: BandSchema, pass: RevampPass) => {
|
||||||
|
const {order, frequency, q, enabled} = pass
|
||||||
|
order.setValue(mapOrder(schema.order))
|
||||||
|
frequency.setValue(semitoneToHz(schema.freq.value))
|
||||||
|
ifDefined(schema.Q?.value, value => q.setValue(value))
|
||||||
|
ifDefined(schema.enabled?.value, value => enabled.setValue(value))
|
||||||
|
}
|
||||||
|
const readShelf = (schema: BandSchema, pass: RevampShelf) => {
|
||||||
|
const {frequency, gain, enabled} = pass
|
||||||
|
frequency.setValue(ParameterDecoder.readValue(schema.freq))
|
||||||
|
ifDefined(schema.gain?.value, value => gain.setValue(value))
|
||||||
|
ifDefined(schema.enabled?.value, value => enabled.setValue(value))
|
||||||
|
}
|
||||||
return RevampDeviceBox.create(boxGraph, UUID.generate(), box => {
|
return RevampDeviceBox.create(boxGraph, UUID.generate(), box => {
|
||||||
box.host.refer(field)
|
box.host.refer(field)
|
||||||
box.index.setValue(index)
|
box.index.setValue(index)
|
||||||
box.label.setValue(equalizer.deviceName ?? "Revamp")
|
box.label.setValue(equalizer.deviceName ?? "Revamp")
|
||||||
|
let bellIndex: int = 0
|
||||||
equalizer.bands.forEach((band) => {
|
equalizer.bands.forEach((band) => {
|
||||||
switch (band.type) {
|
switch (band.type) {
|
||||||
case EqBandType.HIGH_PASS: {
|
case EqBandType.HIGH_PASS:
|
||||||
const {order, frequency, q, enabled} = box.highPass
|
return readPass(band, box.highPass)
|
||||||
// TODO order.setValue((band.order ?? 1) - 1)
|
case EqBandType.LOW_PASS:
|
||||||
frequency.setValue(semitoneToHz(band.freq.value))
|
return readPass(band, box.lowPass)
|
||||||
ifDefined(band.Q?.value, value => q.setValue(mapQ(value)))
|
case EqBandType.HIGH_SHELF:
|
||||||
ifDefined(band.enabled?.value === true, value => enabled.setValue(value))
|
return readShelf(band, box.highShelf)
|
||||||
return
|
case EqBandType.LOW_SHELF:
|
||||||
}
|
return readShelf(band, box.lowShelf)
|
||||||
case EqBandType.LOW_PASS: {
|
|
||||||
const {order, frequency, q, enabled} = box.lowPass
|
|
||||||
// TODO order.setValue((band.order ?? 1) - 1)
|
|
||||||
frequency.setValue(ParameterDecoder.readValue(band.freq))
|
|
||||||
ifDefined(band.Q?.value, value => q.setValue(mapQ(value)))
|
|
||||||
ifDefined(band.enabled?.value === true, value => enabled.setValue(value))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case EqBandType.HIGH_SHELF: {
|
|
||||||
const {frequency, gain, enabled} = box.highShelf
|
|
||||||
frequency.setValue(ParameterDecoder.readValue(band.freq))
|
|
||||||
ifDefined(band.gain?.value, value => gain.setValue(value))
|
|
||||||
ifDefined(band.enabled?.value === true, value => enabled.setValue(value))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case EqBandType.LOW_SHELF: {
|
|
||||||
const {frequency, gain, enabled} = box.lowShelf
|
|
||||||
frequency.setValue(ParameterDecoder.readValue(band.freq))
|
|
||||||
ifDefined(band.gain?.value, value => gain.setValue(value))
|
|
||||||
ifDefined(band.enabled?.value === true, value => enabled.setValue(value))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case EqBandType.BELL: {
|
case EqBandType.BELL: {
|
||||||
const {frequency, gain, q, enabled} = box.lowBell // TODO use all 3 for each new node
|
if (bellIndex === 3) {return}
|
||||||
|
const bell = [box.lowBell, box.midBell, box.highBell][bellIndex++]
|
||||||
|
const {frequency, gain, q, enabled} = bell
|
||||||
frequency.setValue(ParameterDecoder.readValue(band.freq))
|
frequency.setValue(ParameterDecoder.readValue(band.freq))
|
||||||
ifDefined(band.Q?.value, value => {
|
ifDefined(band.Q?.value, value => q.setValue(value))
|
||||||
const mapped = mapQ(value)
|
|
||||||
console.debug(value, mapped)
|
|
||||||
q.setValue(mapped)
|
|
||||||
})
|
|
||||||
ifDefined(band.gain?.value, value => gain.setValue(value))
|
ifDefined(band.gain?.value, value => gain.setValue(value))
|
||||||
ifDefined(band.enabled?.value === true, value => enabled.setValue(value))
|
ifDefined(band.enabled?.value, value => enabled.setValue(value))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
console.warn(`Cannot map band type: ${band.type} to Revamp`)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user