Skip to content

Commit

Permalink
feat: added feedback-streams to input-choice for multiviewer-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Sep 19, 2024
1 parent c669245 commit 9e68995
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 70 deletions.
3 changes: 2 additions & 1 deletion src/api/ateliereLive/pipelines/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export async function getPipelines(): Promise<
name: pipeline.name,
uuid: pipeline.uuid,
outputs: pipeline.outputs,
streams: pipeline.streams
streams: pipeline.streams,
feedback_streams: pipeline.feedback_streams
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toast from 'react-hot-toast';
import { MultiviewSettings } from '../../../interfaces/multiview';
import MultiviewSettingsConfig from './MultiviewSettings';
import PipelineSettingsConfig from './PipelineSettings';
import MultiviewLayoutSettings from './MultiviewLayoutSettings';
import MultiviewLayoutSettings from './MultiviewLayoutSettings/MultiviewLayoutSettings';
import { IconPlus, IconTrash } from '@tabler/icons-react';
import { Production } from '../../../interfaces/production';
import { usePutMultiviewPreset } from '../../../hooks/multiviewPreset';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { TList } from '../../../../hooks/useCreateInputArray';
import { MultiviewViewsWithId } from '../../../../hooks/useSetupMultiviewLayout';
import { MultiviewPreset } from '../../../../interfaces/preset';
import Options from '../Options';

export default function MultiviewLayout({
multiviewPresetLayout,
inputList,
handleChange
}: {
multiviewPresetLayout: MultiviewPreset;
inputList: TList[] | undefined;
handleChange: (id: number | undefined, value: string) => void;
}) {
return (
<div
className={`border-4 border-p/50 relative p-2 m-2`}
style={{
width: `${multiviewPresetLayout.layout.output_width}rem`,
height: `${multiviewPresetLayout.layout.output_height}rem`
}}
>
{multiviewPresetLayout.layout.views.map(
(singleView: MultiviewViewsWithId) => {
const { x, y, width, height, label, id } = singleView;
const previewView = singleView.input_slot === 1002;
const programView = singleView.input_slot === 1001;

return (
<div
key={x + y}
className="flex items-center justify-center border-[1px] border-p/50 absolute w-full"
style={{
width: `${width}rem`,
height: `${height}rem`,
top: `${y}rem`,
left: `${x}rem`
}}
>
{inputList && (previewView || programView) && (
<p className="flex items-center">{label}</p>
)}
{inputList && !previewView && !programView && (
<Options
label={label}
options={inputList.map((singleSource) => singleSource.label)}
value={label ? label : ''}
update={(value) => handleChange(id, value)}
columnStyle
/>
)}
</div>
);
}
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useEffect, useState } from 'react';
import { useMultiviewPresets } from '../../../hooks/multiviewPreset';
import Options from './Options';
import { MultiviewPreset } from '../../../interfaces/preset';
import { useTranslate } from '../../../i18n/useTranslate';
import { useMultiviewPresets } from '../../../../hooks/multiviewPreset';
import Options from '../Options';
import { MultiviewPreset } from '../../../../interfaces/preset';
import { useTranslate } from '../../../../i18n/useTranslate';
import { useSetupMultiviewLayout } from '../../../../hooks/useSetupMultiviewLayout';
import { Production } from '../../../../interfaces/production';
import { useConfigureMultiviewLayout } from '../../../../hooks/useConfigureMultiviewLayout';
import Input from '../Input';
import MultiviewLayout from './MultiviewLayout';
import {
MultiviewViewsWithId,
useSetupMultiviewLayout
} from '../../../hooks/useSetupMultiviewLayout';
import { Production } from '../../../interfaces/production';
import { useConfigureMultiviewLayout } from '../../../hooks/useConfigureMultiviewLayout';
import { SourceReference } from '../../../interfaces/Source';
import Input from './Input';
TList,
useCreateInputArray
} from '../../../../hooks/useCreateInputArray';

type ChangeLayout = {
defaultLabel?: string;
source?: SourceReference;
source?: TList;
id: number;
};

Expand Down Expand Up @@ -44,6 +45,7 @@ export default function MultiviewLayoutSettings({
configMode,
newPresetName
);
const { inputList } = useCreateInputArray(production);
const t = useTranslate();

const multiviewPresetNames = multiviewPresets?.map((preset) => preset.name)
Expand Down Expand Up @@ -81,14 +83,14 @@ export default function MultiviewLayoutSettings({
};

const handleChange = (id: number | undefined, value: string) => {
if (production && id && multiviewPresets) {
if (inputList && id && multiviewPresets) {
// Remove 2 from id to remove id for Preview- and Program-view
// Add 1 to index to get the correct input_slot
const idFirstInputView = id - 2 + 1;
const defaultLabel = multiviewPresets[0].layout.views.find(
(item) => item.input_slot === idFirstInputView
)?.label;
production.sources.map((source) => {
inputList.map((source) => {
if (value === '') {
setChangedLayout({ defaultLabel, id });
}
Expand All @@ -99,59 +101,17 @@ export default function MultiviewLayoutSettings({
}
};

const renderPresetModel = () => {
if (multiviewPresetLayout) {
return (
<div
className={`border-4 border-p/50 relative p-2 m-2`}
style={{
width: `${multiviewPresetLayout.layout.output_width}rem`,
height: `${multiviewPresetLayout.layout.output_height}rem`
}}
>
{multiviewPresetLayout.layout.views.map(
(singleView: MultiviewViewsWithId) => {
const { x, y, width, height, label, id } = singleView;
const previewView = singleView.input_slot === 1002;
const programView = singleView.input_slot === 1001;

return (
<div
key={x + y}
className="flex items-center justify-center border-[1px] border-p/50 absolute w-full"
style={{
width: `${width}rem`,
height: `${height}rem`,
top: `${y}rem`,
left: `${x}rem`
}}
>
{production && (previewView || programView) && (
<p className="flex items-center">{label}</p>
)}
{production && !previewView && !programView && (
<Options
label={label}
options={production.sources.map(
(singleSource) => singleSource.label
)}
value={label ? label : ''}
update={(value) => handleChange(id, value)}
columnStyle
/>
)}
</div>
);
}
)}
</div>
);
}
};

return (
<div className="flex flex-col w-full h-full">
{renderPresetModel()}
{multiviewPresetLayout && (
<MultiviewLayout
multiviewPresetLayout={multiviewPresetLayout}
inputList={inputList}
handleChange={(id: number | undefined, value: string) =>
handleChange(id, value)
}
/>
)}
<div className="flex flex-col w-[50%] h-full">
<Options
label={t('preset.select_multiview_preset')}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useConfigureMultiviewLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { use, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { MultiviewPreset } from '../interfaces/preset';
import { SourceReference } from '../interfaces/Source';
import { MultiviewViewsWithId } from './useSetupMultiviewLayout';
import { TList } from './useCreateInputArray';

export function useConfigureMultiviewLayout(
preset: MultiviewPreset | null,
defaultLabel: string | undefined,
source: SourceReference | undefined,
source: TList | undefined,
id: number | undefined,
configMode: string,
name: string | null
Expand Down
44 changes: 44 additions & 0 deletions src/hooks/useCreateInputArray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useEffect, useState } from 'react';
import { usePipelines } from './pipelines';
import { Production } from '../interfaces/production';

export type TList = {
input_slot: number;
label: string;
};

export function useCreateInputArray(production: Production | undefined) {
const [inputList, setInputList] = useState<TList[] | undefined>();
const [pipelines] = usePipelines();

useEffect(() => {
if (production && pipelines) {
const list: TList[] = [];
production.sources.map((source) =>
list.push({
input_slot: source.input_slot,
label: source.label
})
);
pipelines.flatMap((pipeline) =>
pipeline.feedback_streams.flatMap((source) => {
if (source.input_slot > 1000) {
list.push({
input_slot: source.input_slot,
label: source.name
});
}
})
);
const uniqueList = list.filter(
(item, index, self) =>
index ===
self.findIndex(
(t) => t.input_slot === item.input_slot && t.label === item.label
)
);
return setInputList(uniqueList);
}
}, [production, pipelines]);
return { inputList };
}

0 comments on commit 9e68995

Please sign in to comment.