Skip to content

Commit

Permalink
Set up some pieces to support global limiter
Browse files Browse the repository at this point in the history
 * scaffolding for global limiter AWP
 * placeholder small view for destination node
  • Loading branch information
Ameobea committed Dec 13, 2024
1 parent e092831 commit 832ee6c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
35 changes: 35 additions & 0 deletions src/globalLimiter/GlobalLimiterAWP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class GlobalLimiterAWP extends AudioWorkletProcessor {
constructor() {
super();

this.isShutdown = false;

this.port.onmessage = evt => this.handleMessage(evt.data);
}

handleMessage(data) {
switch (data.type) {
default: {
console.error('Unhandled message type in global limiter AWP: ', evt.data.type);
}
}
}

process(inputs, outputs, _params) {
if (this.isShutdown) {
return false;
}

const input = inputs[0]?.[0];
const output = outputs[0]?.[0];
if (!input || !output) {
return true;
}

// TODO

return true;
}
}

registerProcessor('global-limiter-awp', GlobalLimiterAWP);
5 changes: 1 addition & 4 deletions src/graphEditor/GraphEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,7 @@ const GraphEditor: React.FC<{ stateKey: string }> = ({ stateKey }) => {

<div style={{ display: 'flex', width: 400, flex: 1, flexDirection: 'column' }}>
{selectedNodeVCID ? (
<FlatButton
style={{ marginBottom: 4 }}
onClick={() => getEngine()!.switch_view_context(selectedNodeVCID)}
>
<FlatButton onClick={() => getEngine()!.switch_view_context(selectedNodeVCID)}>
Show Full UI
</FlatButton>
) : null}
Expand Down
25 changes: 12 additions & 13 deletions src/graphEditor/nodes/CustomAudio/CustomAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { LGAudioConnectables } from '../AudioConnectablesNode';
import { FMSynthFxNode } from './FMSynthFx/FMSynthFxNode';
import { SubgraphPortalNode } from 'src/graphEditor/nodes/CustomAudio/Subgraph/SubgraphPortalNode';
import { BPMNode } from 'src/graphEditor/nodes/CustomAudio/BPM/BPMNode';
import { DestinationNodeSmallViewShim } from 'src/graphEditor/nodes/CustomAudio/Destination/DestinationNodeSmallView';

const ctx = new AudioContext();

Expand Down Expand Up @@ -335,26 +336,26 @@ const CustomBiquadFilterNode = enhanceAudioNode({
),
});

export class CustomAudioDestinationNode extends GainNode {
constructor(ctx: AudioContext) {
super(ctx);
return (ctx as any).globalVolume as GainNode;
}
}

const CustomDestinationNode = enhanceAudioNode({
AudioNodeClass: class CustomAudioDestinationNode {
constructor(ctx: AudioContext) {
return (ctx as any).globalVolume as GainNode;
}
},
AudioNodeClass: CustomAudioDestinationNode,
nodeType: 'customAudio/destination',
name: 'Destination',
buildConnectables: (
foreignNode: ForeignNode<GainNode> & {
node: GainNode;
}
) => ({
buildConnectables: (foreignNode: ForeignNode<GainNode> & { node: GainNode }) => ({
inputs: Map<string, ConnectableInput>().set('input', {
node: foreignNode.node,
type: 'customAudio',
}),
outputs: Map<string, ConnectableOutput>(),
node: foreignNode,
}),
SmallViewRenderer: DestinationNodeSmallViewShim,
getOverridableParams: () => [],
paramKeys: [],
});
Expand All @@ -364,9 +365,7 @@ const NativeCompressorNode = enhanceAudioNode({
nodeType: 'customAudio/nativeCompressor',
name: 'Native Compressor',
buildConnectables: (
foreignNode: ForeignNode<DynamicsCompressorNode> & {
node: DynamicsCompressorNode;
}
foreignNode: ForeignNode<DynamicsCompressorNode> & { node: DynamicsCompressorNode }
) => ({
inputs: Map<string, ConnectableInput>(
Object.entries({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts" context="module">
const buildSettings = (): ControlPanelSetting[] => [
{ type: 'checkbox', label: 'enable safety limiter' },
];
</script>

<script lang="ts">
import SvelteControlPanel, {
type ControlPanelSetting,
} from 'src/controls/SvelteControlPanel/SvelteControlPanel.svelte';
import type { CustomAudioDestinationNode } from 'src/graphEditor/nodes/CustomAudio/CustomAudio';
export let node: CustomAudioDestinationNode;
$: settings = buildSettings();
</script>

<div class="root">
<SvelteControlPanel title="destination settings" {settings} width={500} />
</div>

<style lang="css">
.root {
display: flex;
flex-direction: column;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { CustomAudioDestinationNode, ForeignNode } from 'src/graphEditor/nodes/CustomAudio';
import { mkSvelteComponentShim } from 'src/svelteUtils';
import DestinationNodeSmallView from './DestinationNodeSmallView.svelte';

interface DestinationNodeSmallViewProps {
node: ForeignNode<CustomAudioDestinationNode>;
}

export const DestinationNodeSmallViewShim = mkSvelteComponentShim(
DestinationNodeSmallView as any
) as unknown as React.FC<DestinationNodeSmallViewProps>;

0 comments on commit 832ee6c

Please sign in to comment.