Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/packages/src/voicemod/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export function createCtx() {
const [voices, setVoices] = createSignal<Map<string, string>>(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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
});
});
}
Expand All @@ -124,5 +149,5 @@ export function createCtx() {

connect();

return { state, setState, voices, setVoices, voiceChanger, hearVoice };
return { state, setState, voices, setVoices, voiceChanger, hearVoice, backgroundEffects, micMute };
}
196 changes: 183 additions & 13 deletions packages/packages/src/voicemod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof pkg>;

Expand All @@ -14,27 +15,32 @@ 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"
],
}),
};
},
async run({ ctx, io }) {
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),
},
};

Expand All @@ -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 {
Expand All @@ -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 }) {
Expand All @@ -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;
}