Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide invisible audio sources from the audio mixer #5144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 23 additions & 5 deletions app/components-react/editor/elements/Mixer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,31 @@ import { Services } from 'components-react/service-provider';
import { Menu } from 'util/menus/Menu';
import { $t } from 'services/i18n';
import { useRealmObject } from 'components-react/hooks/realm';
import { getDefined } from 'util/properties-type-guards';

const mins = { x: 150, y: 120 };

export function getVisibleAudioSourcesIds() {
const { ScenesService, AudioService } = Services;
const activeScene = getDefined(ScenesService.views.activeScene);

// Get sources ids for visible scene items
// using the Set to avoid duplicates and improve performance
const visibleSourcesIds = new Set(
activeScene.items.filter(item => item.visible).map(item => item.sourceId),
);

return AudioService.views.sourcesForCurrentScene
.filter(source => {
return (
!source.mixerHidden &&
source.isControlledViaObs &&
(visibleSourcesIds.has(source.sourceId) || source.isGlobal())
);
})
.map(source => source.sourceId);
}

export function Mixer() {
const { EditorCommandsService, AudioService, CustomizationService } = Services;

Expand All @@ -26,11 +48,7 @@ export function Mixer() {
}, []);

const performanceMode = useRealmObject(CustomizationService.state).performanceMode;
const { audioSourceIds } = useVuex(() => ({
audioSourceIds: AudioService.views.sourcesForCurrentScene
.filter(source => !source.mixerHidden && source.isControlledViaObs)
.map(source => source.sourceId),
}));
const audioSourceIds = useVuex(getVisibleAudioSourcesIds);

function showAdvancedSettings() {
AudioService.actions.showAdvancedSettings();
Expand Down
8 changes: 5 additions & 3 deletions app/components-react/editor/elements/mixer/GLVolmeters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import vShaderSrc from 'util/webgl/shaders/volmeter.vert';
import fShaderSrc from 'util/webgl/shaders/volmeter.frag';
import { Services } from 'components-react/service-provider';
import { assertIsDefined, getDefined } from 'util/properties-type-guards';
import { getVisibleAudioSourcesIds } from '../Mixer';

// Configuration
const CHANNEL_HEIGHT = 3;
Expand Down Expand Up @@ -133,9 +134,10 @@ class GLVolmetersController {

// TODO: refactor into a single source of truth between Mixer and Volmeters
get audioSources() {
return this.audioService.views.sourcesForCurrentScene.filter(source => {
return !source.mixerHidden && source.isControlledViaObs;
});
const vidibleSourceIds = getVisibleAudioSourcesIds();
return this.audioService.views.sourcesForCurrentScene.filter(source =>
vidibleSourceIds.includes(source.sourceId),
);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/services/audio/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ export class AudioSource implements IAudioSourceApi {
return { ...this.source.state, ...this.audioSourceState };
}

isGlobal() {
return this.source.channel !== void 0;
}

get monitoringOptions() {
return [
{ value: obs.EMonitoringType.None, label: $t('Monitor Off') },
Expand Down
Loading