Skip to content

Commit

Permalink
remove sound if no feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pierromond committed Apr 22, 2024
1 parent 67a5ced commit f668578
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FeatureDataTimeline } from "./FeatureDataTimeline";
import { EmotionFeatureScatterPlot } from "./EmotionFeatureScatterPlot";
import { AcousticFeatureCircles } from "./AcousticFeatureCircles";
import { useCurrentProject } from "../../../hooks/useCurrentProject";
import { SoundFeature } from "./SoundFeature";

export const FeatureDataPanel: FC<{
mapId: string;
Expand All @@ -19,10 +20,13 @@ export const FeatureDataPanel: FC<{
const mapVariable = project.maps[mapId].lassoVariable;

return (

<div className="map-point-data">
<SoundFeature feature={feature} mapId={mapId} currentTimeKey={project.maps[mapId].timeKey} />
<button className="btn-close" onClick={() => onClose()}></button>

<div className="map-point-data-content">

<AcousticFeatureCircles feature={feature} currentTimeKey={project.maps[mapId].timeKey} />

{/* Display emotion plot only if variables are available in the project */}
Expand Down
25 changes: 13 additions & 12 deletions packages/client/src/components/project/map/Selected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { config } from "../../../config";
import { getI18NText } from "../../../utils/i18n";
import { useCurrentProject } from "../../../hooks/useCurrentProject";
import { FeatureDataPanel } from "./FeatureDataPanel";
import { SoundFeature } from "./SoundFeature";


export const Selected: FC<{ mapId: "left" | "right" }> = ({ mapId }) => {
const locale = useLocale();
Expand Down Expand Up @@ -41,7 +41,7 @@ export const Selected: FC<{ mapId: "left" | "right" }> = ({ mapId }) => {
<>
{selected && (
<>
<SoundFeature feature={selected.feature} mapId={mapId} />

<FeatureDataPanel
mapId={mapId}
feature={selected.feature}
Expand All @@ -58,6 +58,16 @@ export const Selected: FC<{ mapId: "left" | "right" }> = ({ mapId }) => {
maxWidth={"50%"}
>
<div className="d-flex flex-column">
<div>
<img
className="img-fluid"
src={`${config.data_path}/${project.data.id}/assets/${images[imageIndex].path}`}
alt={getI18NText(locale, images[imageIndex].description)}
/>
{images[imageIndex].description && (
<p className="text-center mb-0">{getI18NText(locale, images[imageIndex].description)}</p>
)}
</div>
{images.length > 1 && (
<div className="d-flex justify-content-center mb-3">
<button
Expand Down Expand Up @@ -86,16 +96,7 @@ export const Selected: FC<{ mapId: "left" | "right" }> = ({ mapId }) => {
</button>
</div>
)}
<div>
<img
className="img-fluid"
src={`${config.data_path}/${project.data.id}/assets/${images[imageIndex].path}`}
alt={getI18NText(locale, images[imageIndex].description)}
/>
{images[imageIndex].description && (
<p className="text-center mb-0">{getI18NText(locale, images[imageIndex].description)}</p>
)}
</div>

</div>
</Popup>
)}
Expand Down
73 changes: 55 additions & 18 deletions packages/client/src/components/project/map/SoundFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,67 @@ import { Feature } from "geojson";

import { useCurrentProject } from "../../../hooks/useCurrentProject";

export const SoundFeature: FC<{ feature?: Feature; mapId: string }> = ({ mapId, feature }) => {
export const SoundFeature: FC<{ feature?: Feature; mapId: string; currentTimeKey?: string | null }> = ({
mapId,
feature,
currentTimeKey }) => {
const { project } = useCurrentProject();
const timeKey = useMemo(() => project.maps[mapId].timeKey, [project, mapId]);
const muted = useMemo(() => project.maps[mapId].muted, [project.maps, mapId]);
//const previousHowler = useRef<Howl | null>(null);

useEffect(() => {
// handle sound
let howler: Howl | null = null;
if (!muted && feature && feature.properties) {
const properties = timeKey && feature.properties[timeKey] ? feature.properties[timeKey] : feature.properties;
const noiseVariable = project.lassoVariables[`acoustic_soundlevel`];

if (properties.sound) {
const volume = feature.properties.acoustic_soundlevel
? feature.properties.acoustic_soundlevel / noiseVariable.maximumValue
: 1;
howler = new Howl({
src: [feature.properties.sound],
autoplay: true,
loop: true,
html5: true,
format: ["mp3"],
volume,
});

if (!muted && feature && feature.properties ) {


// if time is specified, we try to get it
if (currentTimeKey ) {

const properties = currentTimeKey && feature.properties[currentTimeKey] ? feature.properties[currentTimeKey] : feature.properties;
const noiseVariable = project.lassoVariables[`acoustic_soundlevel`];
if (properties.sound && feature.properties[currentTimeKey]) {

const volume = feature.properties[currentTimeKey].acoustic_soundlevel
? feature.properties[currentTimeKey].acoustic_soundlevel / noiseVariable.maximumValue
: 1;

howler = new Howl({
src: [feature.properties[currentTimeKey].sound],
autoplay: true,
loop: true,
html5: true,
format: ["mp3"],
volume,
});
}else{

}
} else {
if (timeKey ) {

}else{

const properties = timeKey && feature.properties[timeKey] ? feature.properties[timeKey] : feature.properties;
const noiseVariable = project.lassoVariables[`acoustic_soundlevel`];

if (properties.sound) {

const volume = feature.properties.acoustic_soundlevel
? feature.properties.acoustic_soundlevel / noiseVariable.maximumValue
: 1;
howler = new Howl({
src: [feature.properties.sound],
autoplay: true,
loop: true,
html5: true,
format: ["mp3"],
volume,
});
}
}
}
}

Expand All @@ -39,7 +76,7 @@ export const SoundFeature: FC<{ feature?: Feature; mapId: string }> = ({ mapId,
}, 200);
}
};
}, [feature, timeKey, project.lassoVariables, muted]);
}, [feature, currentTimeKey, project.lassoVariables, muted]);

Check warning on line 79 in packages/client/src/components/project/map/SoundFeature.tsx

View workflow job for this annotation

GitHub Actions / deploy

React Hook useEffect has a missing dependency: 'timeKey'. Either include it or remove the dependency array

Check warning on line 79 in packages/client/src/components/project/map/SoundFeature.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has a missing dependency: 'timeKey'. Either include it or remove the dependency array

Check warning on line 79 in packages/client/src/components/project/map/SoundFeature.tsx

View workflow job for this annotation

GitHub Actions / deploy

React Hook useEffect has a missing dependency: 'timeKey'. Either include it or remove the dependency array

return null;
};

0 comments on commit f668578

Please sign in to comment.