diff --git a/src/app.module.ts b/src/app.module.ts index 3700ae0..1613475 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -2,11 +2,11 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { StripController } from './strip/strip.controller'; -import { Bus } from './bus/bus.controller'; +import { BusController } from './bus/bus.controller'; @Module({ imports: [], - controllers: [AppController, StripController], - providers: [AppService, Bus], + controllers: [AppController, StripController, BusController], + providers: [AppService], }) export class AppModule {} diff --git a/src/app.service.ts b/src/app.service.ts index aacc9e2..81eeb51 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -6,7 +6,7 @@ import { Query, } from '@nestjs/common'; import * as config from '../config.js'; -import { Control, Strip } from 'voicemeeter-remote-library/dist'; +import { Bus, Control, Strip } from 'voicemeeter-remote-library/dist'; import { VoicemeeterType } from 'voicemeeter-remote-library/dist/VMR/Control'; export enum IOType { @@ -18,13 +18,16 @@ export enum IOType { export class AppService implements OnModuleInit { private control = new Control(config.dllPath, config.headerPath); private strips: Strip[]; - // private buses: Bus[]; + private buses: Bus[]; async onModuleInit() { await this.control.initialize(); this.control.login(); this.strips = [...Array(this.getAvailableIOs().strips.total).keys()].map( (id) => new Strip(this.control, id), ); + this.buses = [...Array(this.getAvailableIOs().buses.total).keys()].map( + (id) => new Bus(this.control, id), + ); } getType() { @@ -40,19 +43,35 @@ export class AppService implements OnModuleInit { }; } - getGain(IOType: IOType, id: number) { - return this.strips[id].Gain; + getGain(ioType: IOType, id: number) { + if (ioType === IOType.BUS) { + return this.buses[id].Gain; + } else if (ioType === IOType.STRIP) { + return this.strips[id].Gain; + } } - setGain(IOType: IOType, id: number, gain: number) { - return (this.strips[id].Gain = gain); + setGain(ioType: IOType, id: number, gain: number) { + if (ioType === IOType.BUS) { + return (this.buses[id].Gain = gain); + } else if (ioType === IOType.STRIP) { + return (this.strips[id].Gain = gain); + } } - getMuteState(IOType: IOType, id: number) { - return this.strips[id].Mute; + getMuteState(ioType: IOType, id: number) { + if (ioType === IOType.BUS) { + return this.buses[id].Mute; + } else if (ioType === IOType.STRIP) { + return this.strips[id].Mute; + } } - setMuteState(IOType: IOType, id: number, state: boolean) { - return (this.strips[id].Mute = state); + setMuteState(ioType: IOType, id: number, state: boolean) { + if (ioType === IOType.BUS) { + return (this.buses[id].Mute = state); + } else if (ioType === IOType.STRIP) { + return (this.strips[id].Mute = state); + } } } diff --git a/src/bus/bus.controller.ts b/src/bus/bus.controller.ts index 2871058..5dae4c5 100644 --- a/src/bus/bus.controller.ts +++ b/src/bus/bus.controller.ts @@ -10,7 +10,7 @@ import { import { AppService, IOType } from 'src/app.service'; @Controller('/bus/:busId') -export class Bus { +export class BusController { constructor(private readonly appService: AppService) {} @Get('/gain') diff --git a/src/main.ts b/src/main.ts index 4c1b409..2a758cb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableShutdownHooks(); - await app.listen(3000); + app.enableCors({origin: "*"}) + await app.listen(3001); } bootstrap();