diff --git a/front/.expo-shared/assets.json b/front/.expo-shared/assets.json deleted file mode 100644 index 1e6decf..0000000 --- a/front/.expo-shared/assets.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, - "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true -} diff --git a/front/components/Play/PartitionMagic.tsx b/front/components/Play/PartitionMagic.tsx index cef984c..2c7add3 100644 --- a/front/components/Play/PartitionMagic.tsx +++ b/front/components/Play/PartitionMagic.tsx @@ -72,20 +72,27 @@ const PartitionMagic = ({ React.useEffect(() => { if (!pianoSounds.current) { Promise.all( - Object.entries(PianoNotes).map(([midiNumber, noteResource]) => - Audio.Sound.createAsync(noteResource, { - volume: 1, - progressUpdateIntervalMillis: 100, - }).then((sound) => [midiNumber, sound.sound] as const) - ) - ).then((res) => { - pianoSounds.current = res.reduce( - (prev, curr) => ({ ...prev, [curr[0]]: curr[1] }), - {} - ); - console.log('sound loaded'); + Object.entries(PianoNotes).map(async ([midiNumber, noteResource]) => { + const { sound: s } = await Audio.Sound.createAsync(noteResource, { + progressUpdateIntervalMillis: 500, + }); + // const truc = await s.setProgressUpdateIntervalAsync(50); + // console.warn(truc); + return [midiNumber, s] as const; + }) + ).then((sounds) => { + pianoSounds.current = Object.fromEntries(sounds); + console.log('piano sounds loaded'); }); } + const freeSounds = () => { + if (pianoSounds.current) { + Object.values(pianoSounds.current).forEach((s) => { + s.unloadAsync(); + }); + } + }; + return freeSounds; }, []); const partitionDims = React.useMemo<[number, number]>(() => { return [data?.pageWidth ?? 0, data?.pageHeight ?? 1]; @@ -122,7 +129,13 @@ const PartitionMagic = ({ cursor.notes.forEach(({ note, duration }) => { try { const sound = pianoSounds.current![note]!; - sound.playAsync().catch(console.error); + sound + .playAsync() + .then((t) => { + console.log('ts', timestamp, 'dur', duration, 'infos', note, t); + }) + .catch(console.error); + console.log('playing note', note); setTimeout(() => { sound.stopAsync(); }, duration - 10);