Skip to content

Commit

Permalink
Merge branch 'feature/no-audio' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
x37v committed Jun 14, 2024
2 parents b879edf + cece294 commit 9492e76
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
12 changes: 10 additions & 2 deletions src/components/page/statusWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionComponent, PropsWithChildren, ReactNode, memo } from "react";
import { IconDefinition } from "@fortawesome/free-solid-svg-icons";
import { faCircleNotch, faPlugCircleXmark } from "@fortawesome/free-solid-svg-icons";
import { faCircleNotch, faPlugCircleXmark, faVolumeXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useAppSelector } from "../../hooks/useAppDispatch";
import { RootStateType } from "../../lib/store";
Expand Down Expand Up @@ -32,7 +32,6 @@ const AppStatusWrapper: FunctionComponent<PropsWithChildren> = memo(function Wra
title = "Initializing State";
icon = faCircleNotch;
break;

case AppStatus.Reconnecting:
title = "Reconnecting";
icon = faCircleNotch;
Expand All @@ -45,6 +44,15 @@ const AppStatusWrapper: FunctionComponent<PropsWithChildren> = memo(function Wra
title = "Connection Lost";
icon = faPlugCircleXmark;
break;
case AppStatus.AudioOff:
title = "Audio is Off";
icon = faVolumeXmark;
helpText = (
<>
Go to Settings to update audio configuration.
</>
);
break;
case AppStatus.Error:
title = "Failed to establish Connection";
icon = faPlugCircleXmark;
Expand Down
58 changes: 48 additions & 10 deletions src/controller/oscqueryBridgeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class RunnerCmd {

export class OSCQueryBridgeControllerPrivate {

private _hasIsActive: boolean = false;

private static instanceExists(index: number): boolean {
return !!getPatcherNodeByIndex(store.getState(), index);
}
Expand Down Expand Up @@ -176,15 +178,27 @@ export class OSCQueryBridgeControllerPrivate {
return files;
}

private async _initAudio(state: OSCQueryRNBOState) {
// Init Transport
dispatch(initTransport(state.CONTENTS.jack?.CONTENTS?.transport));

// Initialize RNBO Graph Nodes
dispatch(initNodes(state.CONTENTS.jack?.CONTENTS.info.CONTENTS.ports, state.CONTENTS.inst));

// Fetch Connections Info
await this._initConnections();

// Set Init App Status
dispatch(setAppStatus(AppStatus.Ready));
}

private async _init() {

const state = await this._requestState<OSCQueryRNBOState>("/rnbo");

// Init Config
dispatch(initRunnerConfig(state));

// Init Transport
dispatch(initTransport(state.CONTENTS.jack.CONTENTS?.transport));

// Init Patcher Info
dispatch(initPatchers(state.CONTENTS.patchers));
Expand All @@ -195,21 +209,22 @@ export class OSCQueryBridgeControllerPrivate {
dispatch(initSetPresets(state.CONTENTS.inst?.CONTENTS?.control?.CONTENTS?.sets?.CONTENTS?.presets?.CONTENTS?.load?.RANGE?.[0]?.VALS || []));
dispatch(setGraphSetPresetLatest(state.CONTENTS.inst?.CONTENTS?.control?.CONTENTS?.sets?.CONTENTS?.presets?.CONTENTS?.loaded?.VALUE || ""));

// Initialize RNBO Graph Nodes
dispatch(initNodes(state.CONTENTS.jack.CONTENTS.info.CONTENTS.ports, state.CONTENTS.inst));

// Fetch Connections Info
await this._initConnections();

// TODO could take a bit?
try {
dispatch(initDataFiles(await this._getDataFileList()));
} catch(e) {
console.error("error getting datafiles", { e });
}

// Set Init App Status
dispatch(setAppStatus(AppStatus.Ready));
this._hasIsActive = state.CONTENTS.jack?.CONTENTS?.info?.CONTENTS?.is_active !== undefined;

// don't init audio if jack isn't active
if ((!this._hasIsActive && state.CONTENTS.jack?.CONTENTS?.active?.TYPE === "T") || state.CONTENTS.jack?.CONTENTS?.info?.CONTENTS?.is_active?.TYPE === "T") {
await this._initAudio(state);
} else {
dispatch(setAppStatus(AppStatus.AudioOff));
}

}

private _onClose = (evt: ErrorEvent) => {
Expand Down Expand Up @@ -398,12 +413,35 @@ export class OSCQueryBridgeControllerPrivate {
}
}

private async _handleActive(active: boolean, delay: boolean) {
if (active) {
if (delay) {
await sleep(500);
}
const state = await this._requestState<OSCQueryRNBOState>("/rnbo");
await this._initAudio(state);
} else {
dispatch(setAppStatus(AppStatus.AudioOff));
}
}

private async _processOSCMessage(packet: OSCMessage): Promise<void> {

if (packet.address === "/rnbo/jack/restart") {
return void dispatch(showNotification({ title: "Restarting Jack", message: "Please wait while the Jack server is being restarted with the updated audio configuration settings.", level: NotificationLevel.info }));
}

if (packet.address === "/rnbo/jack/info/is_active") {
this._hasIsActive = true;
await this._handleActive((packet.args as unknown as [boolean])?.[0], false);
return;
}

if (!this._hasIsActive && packet.address === "/rnbo/jack/active") {
await this._handleActive((packet.args as unknown as [boolean])?.[0], true);
return;
}

// Transport Control Control
if (packet.address === "/rnbo/jack/transport/bpm") {
if (packet.args?.length) return void dispatch(updateTransportStatus({ bpm: (packet.args as unknown as [number])?.[0] }));
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum AppStatus {
Ready,
Reconnecting,
ResyncingState,
AudioOff,
Closed,
Error
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,18 @@ export type OSCQueryRNBOJackTransport = OSCQueryBaseNode & {
export type OSCQueryRNBOJackState = OSCQueryBaseNode & {
CONTENTS: {
active: OSCQueryBooleanValue;
connections: OSCQueryRNBOJackConnections,
info: OSCQueryBaseNode & {
connections?: OSCQueryRNBOJackConnections,
info?: OSCQueryBaseNode & {
CONTENTS: {
is_realtime: OSCQueryBooleanValue;
owns_server: OSCQueryBooleanValue;
ports: OSCQueryRNBOJackPortInfo;
is_active?: OSCQueryBooleanValue;
};
};
config: OSCQueryRNBOJackConfig;
control: any;
transport: OSCQueryRNBOJackTransport;
transport?: OSCQueryRNBOJackTransport;
};
};

Expand Down

0 comments on commit 9492e76

Please sign in to comment.