Skip to content

Commit

Permalink
input + ref tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Dec 14, 2024
1 parent 8bf9587 commit f97c9c4
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 124 deletions.
23 changes: 19 additions & 4 deletions packages/core-rewrite/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function defineInputType<
}

abstract class SourceType<TKind extends string> {
constructor(public kind: TKind) {}
constructor(public id: TKind) {}

abstract settings(): SourceType<TKind>;
}
Expand Down Expand Up @@ -46,7 +46,7 @@ export class InputType<

async getDefaultSettings(obs: OBS) {
const res = await obs.ws.call("GetInputDefaultSettings", {
inputKind: this.kind,
inputKind: this.id,
});

return res.defaultInputSettings as TSettings;
Expand All @@ -56,13 +56,14 @@ export class InputType<
type DefineFilterArgs<TSettings> = {
name: string;
enabled?: boolean;
index?: number;
settings?: Partial<TSettings>;
};

export type FilterTypeSettings<TType extends FilterType<any, any>> =
TType extends FilterType<any, infer TSettings> ? TSettings : never;

class FilterType<
export class FilterType<
TKind extends string = string,
TSettings extends Record<string, any> = any
> extends SourceType<TKind> {
Expand Down Expand Up @@ -202,6 +203,20 @@ export class Input<
value: i.itemValue as InputTypeSettings<TType>[K],
}));
}

async getFilters(obs: OBS) {
const { filters } = await obs.ws.call("GetSourceFilterList", {
sourceName: this.args.name,
});

return filters.map((f) => ({
enabled: f.filterEnabled as boolean,
index: f.filterIndex as number,
kind: f.filterKind as string,
name: f.filterName as string,
settings: f.filterSettings as any,
}));
}
}

export type InputFilters<T extends Input<any, any>> = T extends Input<
Expand All @@ -219,7 +234,7 @@ export type FilterSettings<TInput extends Filter<any>> = TInput extends Filter<

export class Filter<TType extends FilterType<any, any>> {
constructor(
public type: TType,
public kind: TType,
public args: DefineFilterArgs<FilterTypeSettings<TType>>
) {}

Expand Down
6 changes: 2 additions & 4 deletions packages/core-rewrite/src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ export const noiseGateFilter = defineFilterType("noise_gate_filter").settings<{
}>();

export const noiseSuppressFilter = defineFilterType(
"noise_suppress_filter"
).settings<{
method: "speex" | "rnnoise" | "nvafx";
}>();
"noise_suppress_filter_v2"
).settings<{ method: "speex" | "rnnoise" | "nvafx" }>();

export const renderDelayFilter = defineFilterType("gpu_delay").settings<{
delay_ms: number;
Expand Down
8 changes: 6 additions & 2 deletions packages/core-rewrite/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ declare module "obs-websocket-js" {
SetSourcePrivateSettings: {
sourceName: string;
sourceSettings: {
SCENEIFY?: SceneifyPrivateSettings;
SCENEIFY?: SceneifyPrivateSettings & {
filters?: Array<{ name: string }>;
};
};
};
GetSourcePrivateSettings: {
Expand All @@ -33,7 +35,9 @@ declare module "obs-websocket-js" {
SetSourcePrivateSettings: void;
GetSourcePrivateSettings: {
sourceSettings: {
SCENEIFY?: SceneifyPrivateSettings;
SCENEIFY?: SceneifyPrivateSettings & {
filters?: Array<{ name: string }>;
};
};
};
SetSceneItemPrivateSettings: {};
Expand Down
51 changes: 17 additions & 34 deletions packages/core-rewrite/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { defineScene } from "./definition.ts";
import {
gainFilter,
noiseGateFilter,
noiseSuppressFilter,
sharpenFilter,
// streamfxBlurFilter,
} from "./filters.ts";
import {
browserSource,
colorSource,
coreAudioInputCapture,
macOSScreenCapture,
videoCaptureSource,
} from "./inputs.ts";
import { OBS } from "./obs.ts";
import { syncScene as syncScene } from "./runtime.ts";
import { alignmentToOBS } from "./sceneItem.ts";
import { FilterDefsOfInputDef, syncScene as syncScene } from "./runtime.ts";

export const GAP = 20;

Expand All @@ -39,6 +38,20 @@ const micInput = coreAudioInputCapture.defineInput({
"AppleUSBAudioEngine:Burr-Brown from TI :USB Audio CODEC :130000:2",
enable_downmix: true,
},
filters: {
gain: gainFilter.defineFilter({
index: 0,
enabled: true,
name: "Gain",
settings: { db: 2.5 },
}),
noiseSuppression: noiseSuppressFilter.defineFilter({
index: 1,
enabled: true,
name: "Noise Suppression",
settings: { method: "speex" },
}),
},
});

const OUTPUT_WIDTH = 1920;
Expand Down Expand Up @@ -90,11 +103,6 @@ export const mainScene = defineScene({
index: 4,
input: micInput,
},

// mic: {
// index: 4,
// input: aud
// }
// guest: {
// input: browserSource.defineInput({
// name: "Guest",
Expand Down Expand Up @@ -125,27 +133,6 @@ export const mainScene = defineScene({
// },
// }),
// },
// display: {
// index: 0,
// input: display,
// positionX: 0,
// positionY: 0,
// },
// micAudio: {
// input: micInput,
// },
// systemAudio: {
// input: coreAudioInputCapture.defineInput({
// name: "System Audio",
// settings: {
// device_id: "BlackHole16ch_UID",
// },
// // TODO
// // volume: {
// // db: -8
// // }
// }),
// },
},
});

Expand Down Expand Up @@ -178,11 +165,7 @@ async function main() {
const main = await syncScene(obs, mainScene);
const camera = await syncScene(obs, cameraScene);

obs.setCurrentScene(camera);

setTimeout(() => {
obs.setCurrentScene(main);
}, 1000);
await obs.setCurrentScene(main);
}

main();
5 changes: 4 additions & 1 deletion packages/core-rewrite/src/obs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import OBSWebsocket from "obs-websocket-js";
import { Scene } from "./runtime.ts";
import { Scene, Input } from "./runtime.ts";

export type LogLevel = "none" | "info" | "error";

export class OBS {
ws: OBSWebsocket;
logging: LogLevel;

/** @internal */
syncedInputs = new Map<string, Input<any>>();

constructor() {
this.ws = new OBSWebsocket();
this.logging = "info";
Expand Down
Loading

0 comments on commit f97c9c4

Please sign in to comment.