Skip to content

Commit

Permalink
fix: restructure fairlight eq state to be more logical (for users)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed May 30, 2021
1 parent a311824 commit 8bd5c28
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 50 deletions.
18 changes: 10 additions & 8 deletions src/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ export function createEmptyState(cmd?: IDeserializedCommand): AtemState {
state.fairlight = {
inputs: {},
master: {
equalizerBands: [undefined, undefined, undefined, undefined, undefined],
equalizerGain: 0,
equalizerEnabled: false,
makeUpGain: 0,
faderGain: 0,
followFadeToBlack: false,
equalizer: {
enabled: false,
gain: 0,
bands: [undefined, undefined, undefined, undefined, undefined],
},
},
}

Expand All @@ -86,8 +85,11 @@ export function createEmptyState(cmd?: IDeserializedCommand): AtemState {

if ('source' in cmdAny && typeof cmdAny.source === 'bigint') {
input.sources[cmdAny.source.toString()] = {
// properties: {
// }
equalizer: {
enabled: false,
gain: 0,
bands: [undefined, undefined, undefined, undefined, undefined],
},
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/atem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { RecordingStateProperties } from './state/recording'
import { OmitReadonly } from './lib/types'
import { StreamingServiceProperties } from './state/streaming'
import {
FairlightAudioMasterChannel,
FairlightAudioMonitorChannel,
FairlightAudioCompressorState,
FairlightAudioLimiterState,
Expand Down Expand Up @@ -701,7 +700,9 @@ export class Atem extends BasicAtem {
return this.sendCommand(command)
}

public setFairlightAudioMixerMasterProps(props: Partial<OmitReadonly<FairlightAudioMasterChannel>>): Promise<void> {
public setFairlightAudioMixerMasterProps(
props: Partial<Commands.FairlightMixerMasterCommandProperties>
): Promise<void> {
const command = new Commands.FairlightMixerMasterCommand()
command.updateProps(props)
return this.sendCommand(command)
Expand Down
34 changes: 24 additions & 10 deletions src/commands/Fairlight/FairlightMixerMasterCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { FairlightAudioMasterChannel } from '../../state/fairlight'
import { FairlightAudioMasterChannelPropertiesState } from '../../state/fairlight'
import { AtemState, InvalidIdError } from '../../state'
import { DeserializedCommand, WritableCommand } from '../CommandBase'
import { OmitReadonly } from '../../lib/types'
import * as Util from '../../lib/atemUtil'

export class FairlightMixerMasterCommand extends WritableCommand<OmitReadonly<FairlightAudioMasterChannel>> {
export interface FairlightMixerMasterCommandProperties extends FairlightAudioMasterChannelPropertiesState {
equalizerEnabled: boolean
equalizerGain: number

makeUpGain: number
}

export class FairlightMixerMasterCommand extends WritableCommand<FairlightMixerMasterCommandProperties> {
public static MaskFlags = {
equalizerEnabled: 1 << 0,
equalizerGain: 1 << 1,
Expand All @@ -29,7 +34,7 @@ export class FairlightMixerMasterCommand extends WritableCommand<OmitReadonly<Fa
}

export class FairlightMixerMasterUpdateCommand extends DeserializedCommand<
Omit<FairlightAudioMasterChannel, 'equalizerBands'> & { bandCount: number }
FairlightMixerMasterCommandProperties & { bandCount: number }
> {
public static readonly rawName = 'FAMP'

Expand All @@ -52,11 +57,20 @@ export class FairlightMixerMasterUpdateCommand extends DeserializedCommand<
}

state.fairlight.master = {
// default bands to empty
equalizerBands: new Array(this.properties.bandCount).fill(undefined),
// preserve old bands
...state.fairlight.master,
...Util.omit(this.properties, 'bandCount'),
properties: {
faderGain: this.properties.faderGain,
followFadeToBlack: this.properties.followFadeToBlack,
},
dynamics: {
...state.fairlight.master?.dynamics,
makeUpGain: this.properties.makeUpGain,
},
equalizer: {
...state.fairlight.master?.equalizer,
enabled: this.properties.equalizerEnabled,
gain: this.properties.equalizerGain,
bands: state.fairlight.master?.equalizer?.bands ?? new Array(this.properties.bandCount).fill(undefined), // Assume bands number doesnt change
},
}

return `fairlight.master`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ export class FairlightMixerMasterEqualizerBandUpdateCommand extends Deserialized
if (!state.fairlight.master) {
throw new InvalidIdError('Fairlight.Master')
}
if (this.band >= state.fairlight.master.equalizerBands.length) {
if (!state.fairlight.master.equalizer) {
throw new InvalidIdError('Fairlight.Master.Equalizer')
}
if (this.band >= state.fairlight.master.equalizer.bands.length) {
throw new InvalidIdError('Fairlight.Master.Equalizer', this.band)
}

state.fairlight.master.equalizerBands[this.band] = this.properties
state.fairlight.master.equalizer.bands[this.band] = this.properties

return `fairlight.master.equalizerBands.${this.band}`
return `fairlight.master.equalizer.bands.${this.band}`
}
}
36 changes: 31 additions & 5 deletions src/commands/Fairlight/FairlightMixerSourceCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FairlightAudioInput, FairlightAudioSourceProperties } from '../../state/fairlight'
import { FairlightAudioInput, FairlightAudioSourcePropertiesState } from '../../state/fairlight'
import { AtemState, InvalidIdError } from '../../state'
import * as Util from '../../lib/atemUtil'
import { DeserializedCommand, WritableCommand } from '../CommandBase'
Expand Down Expand Up @@ -37,7 +37,14 @@ export class FairlightMixerSourceDeleteCommand extends DeserializedCommand<Recor
}
}

export class FairlightMixerSourceCommand extends WritableCommand<OmitReadonly<FairlightAudioSourceProperties>> {
export interface FairlightMixerSourceCommandProperties extends FairlightAudioSourcePropertiesState {
equalizerEnabled: boolean
equalizerGain: number

makeUpGain: number
}

export class FairlightMixerSourceCommand extends WritableCommand<OmitReadonly<FairlightMixerSourceCommandProperties>> {
public static MaskFlags = {
framesDelay: 1 << 0,
gain: 1 << 1,
Expand Down Expand Up @@ -83,7 +90,7 @@ export class FairlightMixerSourceCommand extends WritableCommand<OmitReadonly<Fa
}

export class FairlightMixerSourceUpdateCommand extends DeserializedCommand<
Omit<FairlightAudioSourceProperties, 'equalizerBands'> & { bandCount: number }
FairlightMixerSourceCommandProperties & { bandCount: number }
> {
public static readonly rawName = 'FASP'

Expand Down Expand Up @@ -137,14 +144,33 @@ export class FairlightMixerSourceUpdateCommand extends DeserializedCommand<

input.sources[sourceIdStr] = {
...oldSource,
equalizer: {
...oldSource?.equalizer,
enabled: this.properties.equalizerEnabled,
gain: this.properties.equalizerGain,
bands: oldSource?.equalizer?.bands ?? new Array(this.properties.bandCount).fill(undefined),
},
dynamics: {
...oldSource?.dynamics,
makeUpGain: this.properties.makeUpGain,
},
properties: {
equalizerBands: new Array(this.properties.bandCount).fill(undefined),
// preserve old props
...(oldSource ? oldSource.properties : {}),
...Util.omit(this.properties, 'bandCount'),
...Util.omit(this.properties, 'bandCount', 'equalizerEnabled', 'equalizerGain', 'makeUpGain'),
},
}

// input.sources[sourceIdStr] = {
// ...oldSource,
// properties: {
// equalizerBands: new Array(this.properties.bandCount).fill(undefined),
// // preserve old props
// ...(oldSource ? oldSource.properties : {}),
// ...Util.omit(this.properties, 'bandCount'),
// },
// }

return `fairlight.inputs.${this.index}.sources.${sourceIdStr}.properties`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ export class FairlightMixerSourceEqualizerBandUpdateCommand extends Deserialized
const source = input.sources[sourceIdStr] || {}
input.sources[sourceIdStr] = source

if (!source.properties) {
throw new InvalidIdError('Fairlight.Inputs.Source', this.index, sourceIdStr)
if (!source.equalizer) {
throw new InvalidIdError('Fairlight.Inputs.Source.Equalizer', this.index, sourceIdStr)
}

if (this.band >= source.properties.equalizerBands.length) {
if (this.band >= source.equalizer.bands.length) {
throw new InvalidIdError('Fairlight.Master.Equalizer', this.band)
}

source.properties.equalizerBands[this.band] = this.properties
source.equalizer.bands[this.band] = this.properties

return `fairlight.inputs.${this.index}.sources.${sourceIdStr}.properties.equalizerBands.${this.band}`
return `fairlight.inputs.${this.index}.sources.${sourceIdStr}.equalizer.bands.${this.band}`
}
}
30 changes: 14 additions & 16 deletions src/state/fairlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../enums'

export interface FairlightAudioDynamicsState {
// makeUpGain: number
makeUpGain?: number

limiter?: FairlightAudioLimiterState
compressor?: FairlightAudioCompressorState
Expand Down Expand Up @@ -58,16 +58,15 @@ export interface FairlightAudioEqualizerBandState {
qFactor: number
}

export interface FairlightAudioMasterChannel {
equalizerEnabled: boolean
equalizerGain: number
readonly equalizerBands: Array<FairlightAudioEqualizerBandState | undefined>

makeUpGain: number
export interface FairlightAudioMasterChannelPropertiesState {
/** Gain in decibel, -Infinity to +6dB */
faderGain: number
followFadeToBlack: boolean
}
export interface FairlightAudioMasterChannel {
properties?: FairlightAudioMasterChannelPropertiesState

equalizer?: FairlightAudioEqualizerState
dynamics?: Omit<FairlightAudioDynamicsState, 'expander'>
}

Expand All @@ -79,11 +78,16 @@ export interface FairlightAudioMonitorChannel {
}

export interface FairlightAudioSource {
properties?: FairlightAudioSourceProperties

properties?: FairlightAudioSourcePropertiesState
equalizer?: FairlightAudioEqualizerState
dynamics?: FairlightAudioDynamicsState
}
export interface FairlightAudioSourceProperties {
export interface FairlightAudioEqualizerState {
enabled: boolean
gain: number
readonly bands: Array<FairlightAudioEqualizerBandState | undefined>
}
export interface FairlightAudioSourcePropertiesState {
readonly sourceType: FairlightAudioSourceType

readonly maxFramesDelay: number
Expand All @@ -96,12 +100,6 @@ export interface FairlightAudioSourceProperties {
balance: number
faderGain: number

equalizerEnabled: boolean
equalizerGain: number
readonly equalizerBands: Array<FairlightAudioEqualizerBandState | undefined>

makeUpGain: number

readonly supportedMixOptions: FairlightAudioMixOption[]
mixOption: FairlightAudioMixOption
}
Expand Down

0 comments on commit 8bd5c28

Please sign in to comment.