Skip to content

Commit

Permalink
Merge pull request #161 from GeheimagentNr1/disabled_hardware
Browse files Browse the repository at this point in the history
Add No_Hardware as HardwareType to disable radio audio effects
  • Loading branch information
pierr3 authored Sep 10, 2024
2 parents a4a3839 + b379c3d commit fe98a69
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
31 changes: 31 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <absl/strings/ascii.h>
#include <absl/strings/match.h>
#include <atomic>
#include <cctype>
#include <chrono>
#include <cstddef>
#include <httplib.h>
Expand Down Expand Up @@ -258,6 +259,33 @@ void SetCid(const Napi::CallbackInfo& info)
UserSession::cid = cid;
}

void SetRadioEffects(const Napi::CallbackInfo& info)
{
auto radioEffects = info[0].As<Napi::String>().Utf8Value();
radioEffects = absl::AsciiStrToLower(radioEffects);
bool enableInputFilters;
bool enableOutputEffects;

if (radioEffects == "on") {
enableInputFilters = true;
enableOutputEffects = true;
} else if (radioEffects == "input") {
enableInputFilters = true;
enableOutputEffects = false;
} else if (radioEffects == "output") {
enableInputFilters = false;
enableOutputEffects = true;
} else if (radioEffects == "off") {
enableInputFilters = false;
enableOutputEffects = false;
} else {
TRACK_LOG_WARNING("Invalid radioEffects value: {}", radioEffects);
return;
}
mClient->SetEnableInputFilters(enableInputFilters);
mClient->SetEnableOutputEffects(enableOutputEffects);
}

void SetHardwareType(const Napi::CallbackInfo& info)
{
auto hardwareTypeIndex = info[0].As<Napi::Number>().Int32Value();
Expand Down Expand Up @@ -764,6 +792,9 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)

exports.Set(Napi::String::New(env, "SetRadioGain"), Napi::Function::New(env, SetRadioGain));

exports.Set(
Napi::String::New(env, "SetRadioEffects"), Napi::Function::New(env, SetRadioEffects));

exports.Set(
Napi::String::New(env, "SetHardwareType"), Napi::Function::New(env, SetHardwareType));

Expand Down
2 changes: 2 additions & 0 deletions backend/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ declare namespace TrackAudioAfv {
export function SetRadioGain(gain: number): void;
export function SetPtt(activate: boolean): void;

export function SetRadioEffects(type: string): void;

export function SetHardwareType(type: number): void;

export function StartMicTest(): void;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/main/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { dialog } from 'electron';
import Store from 'electron-store';

export type RadioEffects = 'on' | 'input' | 'output' | 'off';

export type AlwaysOnTopMode = 'never' | 'always' | 'inMiniMode';

// Used to check for older settings that need upgrading. This should get
Expand All @@ -18,6 +20,7 @@ export const defaultConfiguration = {
cid: '',
password: '',
callsign: '',
radioEffects: 'on' as RadioEffects,
hardwareType: 0,
radioGain: 0,
alwaysOnTop: 'never' as AlwaysOnTopMode
Expand All @@ -35,6 +38,7 @@ export interface Configuration {
password: string;
callsign: string;

radioEffects: RadioEffects;
hardwareType: number;
radioGain: number;

Expand Down
8 changes: 7 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Store from 'electron-store';
import { join } from 'path';
import { AfvEventTypes, TrackAudioAfv } from 'trackaudio-afv';
import icon from '../../resources/AppIcon/icon.png?asset';
import configManager, { AlwaysOnTopMode } from './config';
import configManager, {AlwaysOnTopMode, RadioEffects} from './config';

type WindowMode = 'mini' | 'maxi';

Expand Down Expand Up @@ -55,6 +55,7 @@ const setAudioSettings = () => {
configManager.config.headsetOutputDeviceId,
configManager.config.speakerOutputDeviceId
);
TrackAudioAfv.SetRadioEffects(configManager.config.radioEffects);
TrackAudioAfv.SetHardwareType(configManager.config.hardwareType);
};

Expand Down Expand Up @@ -432,6 +433,11 @@ ipcMain.handle('set-radio-gain', (_, radioGain: number) => {
TrackAudioAfv.SetRadioGain(radioGain);
});

ipcMain.handle('set-radio-effects', (_, radioEffects: RadioEffects) => {
configManager.updateConfig({ radioEffects });
TrackAudioAfv.SetRadioEffects(radioEffects);
});

ipcMain.handle('set-hardware-type', (_, hardwareType: number) => {
configManager.updateConfig({ hardwareType });
TrackAudioAfv.SetHardwareType(hardwareType);
Expand Down
4 changes: 3 additions & 1 deletion src/preload/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer, IpcRendererEvent } from 'electron';
import { AlwaysOnTopMode } from '../main/config';
import {AlwaysOnTopMode, RadioEffects} from '../main/config';

export const api = {
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -67,6 +67,8 @@ export const api = {

SetRadioGain: (gain: number) => ipcRenderer.invoke('set-radio-gain', gain),

SetRadioEffects: (type: RadioEffects) => ipcRenderer.invoke('set-radio-effects', type),

SetHardwareType: (type: number) => ipcRenderer.invoke('set-hardware-type', type),

getVersion: () => ipcRenderer.invoke('get-version'),
Expand Down
29 changes: 22 additions & 7 deletions src/renderer/src/components/settings-modal/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
import { AudioApi, AudioDevice } from 'trackaudio-afv';
import { useDebouncedCallback } from 'use-debounce';
import { AlwaysOnTopMode, Configuration } from '../../../../../src/main/config';
import {AlwaysOnTopMode, Configuration, RadioEffects} from '../../../../../src/main/config';
import useRadioState from '../../store/radioStore';
import useUtilStore from '../../store/utilStore';
import AudioApis from './audio-apis';
Expand All @@ -24,6 +24,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
const [audioApis, setAudioApis] = useState(Array<AudioApi>);
const [audioOutputDevices, setAudioOutputDevices] = useState(Array<AudioDevice>);
const [audioInputDevices, setAudioInputDevices] = useState(Array<AudioDevice>);
const [radioEffects, setRadioEffects] = useState<RadioEffects>("on");
const [hardwareType, setHardwareType] = useState(0);
const [config, setConfig] = useState({} as Configuration);
const [alwaysOnTop, setAlwaysOnTop] = useState<AlwaysOnTopMode>('never');
Expand Down Expand Up @@ -63,6 +64,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
setConfig(config);
setCid(config.cid);
setPassword(config.password);
setRadioEffects(config.radioEffects);
setHardwareType(config.hardwareType);
setAlwaysOnTop(config.alwaysOnTop as AlwaysOnTopMode); // Type assertion since the config will never be a boolean at this point
})
Expand Down Expand Up @@ -191,6 +193,15 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
void window.api.StartMicTest();
};

const handleRadioEffectsChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
setChangesSaved(SaveStatus.Saving);
const radioEffects = e.target.value as RadioEffects;
void window.api.SetRadioEffects(radioEffects);
setRadioEffects(radioEffects);
setConfig({ ...config, radioEffects: radioEffects});
setChangesSaved(SaveStatus.Saved);
};

const handleHardwareTypeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
setChangesSaved(SaveStatus.Saving);
const hardwareType = parseInt(e.target.value);
Expand Down Expand Up @@ -241,13 +252,17 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
onChange={(e) => debouncedPassword(e.target.value)}
></input>

{/* <label className="mt-1">Radio Effects</label>
<select id="" className="form-control mt-1" disabled>
<label className="mt-1">Radio Effects</label>
<select id=""
className="form-control mt-1"
value={radioEffects}
onChange={handleRadioEffectsChange}>
<option value="on">On</option>
<option value="saab">Input only</option>
<option value="mercedes">Output only</option>
<option value="audi">Off</option>
</select> */}
<option value="input">Input only</option>
<option value="output">Output only</option>
<option value="off">Off</option>
</select>

<label className="mt-2">Radio Hardware</label>
<select
id=""
Expand Down

0 comments on commit fe98a69

Please sign in to comment.