From c7a42b508b33307091b3e790a7e6b824e81cc8cc Mon Sep 17 00:00:00 2001 From: SkechyWolf <37350695+SkechyWolf@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:47:14 -0800 Subject: [PATCH] Add some more Voicemod stuff --- packages/packages/src/voicemod/ctx.ts | 29 +++- packages/packages/src/voicemod/index.ts | 196 ++++++++++++++++++++++-- 2 files changed, 210 insertions(+), 15 deletions(-) diff --git a/packages/packages/src/voicemod/ctx.ts b/packages/packages/src/voicemod/ctx.ts index 88d47aa9..e567eac4 100644 --- a/packages/packages/src/voicemod/ctx.ts +++ b/packages/packages/src/voicemod/ctx.ts @@ -12,6 +12,8 @@ export function createCtx() { const [voices, setVoices] = createSignal>(new Map()); const [voiceChanger, setVoiceChanger] = createSignal(false); const [hearVoice, setHearVoice] = createSignal(false); + const [backgroundEffects, setBackgroundEffects] = createSignal(false); + const [micMute, setMicMute] = createSignal(false); type Voice = { bitmapChecksum: string; @@ -82,6 +84,24 @@ export function createCtx() { }), ); }, 2000); + setTimeout(() => { + ws.send( + JSON.stringify({ + action: "getBackgroundEffectStatus", + id: "doesntMatter", + payload: {}, + }), + ); + }, 2000); + setTimeout(() => { + ws.send( + JSON.stringify({ + action: "getMuteMicStatus", + id: "doesntMatter", + payload: {}, + }), + ); + }, 2000); ws.addEventListener("close", (event) => { console.log(`Port: ${port} Closed.`); setState(None); @@ -109,8 +129,13 @@ export function createCtx() { if (data.actionType === "toggleHearMyVoice") { setHearVoice(data.actionObject.value); } + if(data.actionType === "toggleBackground") { + setBackgroundEffects(data.actionObject.value); + } + if(data.actionType === "toggleMuteMic") { + setMicMute(data.actionObject.value); + } - console.log(voices()); }); }); } @@ -124,5 +149,5 @@ export function createCtx() { connect(); - return { state, setState, voices, setVoices, voiceChanger, hearVoice }; + return { state, setState, voices, setVoices, voiceChanger, hearVoice, backgroundEffects, micMute }; } diff --git a/packages/packages/src/voicemod/index.ts b/packages/packages/src/voicemod/index.ts index 7f91c69d..ae6d7aae 100644 --- a/packages/packages/src/voicemod/index.ts +++ b/packages/packages/src/voicemod/index.ts @@ -2,6 +2,7 @@ import { Package } from "@macrograph/runtime"; import { createCtx } from "./ctx"; import { t } from "@macrograph/typesystem"; +import { ReactiveMap } from "@solid-primitives/map"; export type Pkg = ReturnType; @@ -14,16 +15,21 @@ export function pkg() { SettingsUI: () => import("./settings"), }); - pkg.createSchema({ - name: "Set voice", + pkg.createSchema({ + name: "Select Random Voice", type: "exec", createIO({ io }) { return { - voice: io.dataInput({ - id: "voice", - name: "Voice", + option: io.dataInput({ + id: "option", + name: "option", type: t.string(), - fetchSuggestions: async () => Array.from(context.voices().keys()), + fetchSuggestions: async () => [ + "FreeVoices", + "AllVoices", + "FavoriteVoices", + "CustomVoices" + ], }), }; }, @@ -31,10 +37,10 @@ export function pkg() { const ws = context.state(); const request = { - action: "loadVoice", + action: "selectRandomVoice", id: "ThisDoesntMatter", payload: { - voiceID: context.voices().get(ctx.getInput(io.voice)), + mode: ctx.getInput(io.option), }, }; @@ -44,8 +50,9 @@ export function pkg() { }, }); - pkg.createSchema({ - name: "Set Voice Changer State", + + pkg.createSchema({ + name: "Set Background Effects State", type: "exec", createIO({ io }) { return { @@ -59,18 +66,18 @@ export function pkg() { const ws = context.state(); const request = { - action: "toggleVoiceChanger", + action: "toggleBackground", id: "ThisDoesntMatter", payload: {}, }; - if (ws.isSome() && context.voiceChanger() !== ctx.getInput(io.state)) { + if (ws.isSome() && context.backgroundEffects() !== ctx.getInput(io.state)) { ws.unwrap().send(JSON.stringify(request)); } }, }); - pkg.createSchema({ + pkg.createSchema({ name: "Set Hear Self State", type: "exec", createIO({ io }) { @@ -96,5 +103,168 @@ export function pkg() { }, }); + pkg.createSchema({ + name: "Set Mic Mute State", + type: "exec", + createIO({ io }) { + return { + state: io.dataInput({ + id: "state", + type: t.bool(), + }), + }; + }, + async run({ ctx, io }) { + const ws = context.state(); + + const request = { + action: "toggleMuteMic", + id: "ThisDoesntMatter", + payload: {}, + }; + + if (ws.isSome() && context.micMute() !== ctx.getInput(io.state)) { + ws.unwrap().send(JSON.stringify(request)); + } + }, + }); + + pkg.createSchema({ + name: "Set Voice", + type: "exec", + createIO({ io }) { + return { + voice: io.dataInput({ + id: "voice", + name: "Voice", + type: t.string(), + fetchSuggestions: async () => Array.from(context.voices().keys()), + }), + }; + }, + async run({ ctx, io }) { + const ws = context.state(); + + const request = { + action: "loadVoice", + id: "ThisDoesntMatter", + payload: { + voiceID: context.voices().get(ctx.getInput(io.voice)), + }, + }; + + if (ws.isSome()) { + ws.unwrap().send(JSON.stringify(request)); + } + }, + }); + + pkg.createSchema({ + name: "Set Voice Changer State", + type: "exec", + createIO({ io }) { + return { + state: io.dataInput({ + id: "state", + type: t.bool(), + }), + }; + }, + async run({ ctx, io }) { + const ws = context.state(); + + const request = { + action: "toggleVoiceChanger", + id: "ThisDoesntMatter", + payload: {}, + }; + + if (ws.isSome() && context.voiceChanger() !== ctx.getInput(io.state)) { + ws.unwrap().send(JSON.stringify(request)); + } + }, + }); + + pkg.createSchema({ + name: "Get Background Effects State", + type: "pure", + createIO({ io }) { + return { + status: io.dataOutput({ + id: "status", + type: t.bool(), + }), + }; + }, + run({ ctx, io }) { + ctx.setOutput(io.status, context.backgroundEffects()); + }, + }); + + pkg.createSchema({ + name: "Get Hear Self State", + type: "pure", + createIO({ io }) { + return { + status: io.dataOutput({ + id: "status", + type: t.bool(), + }), + }; + }, + run({ ctx, io }) { + ctx.setOutput(io.status, context.hearVoice()); + }, + }); + + pkg.createSchema({ + name: "Get Mic Mute State", + type: "pure", + createIO({ io }) { + return { + status: io.dataOutput({ + id: "status", + type: t.bool(), + }), + }; + }, + run({ ctx, io }) { + ctx.setOutput(io.status, context.micMute()); + }, + }); + + pkg.createSchema({ + name: "Get Voices", + type: "pure", + createIO({ io }) { + return { + status: io.dataOutput({ + id: "voices", + type: t.map(t.string()), + }), + }; + }, + run({ ctx, io }) { + console.log(context.voices()) + ctx.setOutput(io.status, new ReactiveMap(context.voices())); + }, + }); + + pkg.createSchema({ + name: "Get Voice Changer State", + type: "pure", + createIO({ io }) { + return { + status: io.dataOutput({ + id: "status", + type: t.bool(), + }), + }; + }, + run({ ctx, io }) { + ctx.setOutput(io.status, context.voiceChanger()); + }, + }); + return pkg; }