fix atom chain.
This commit is contained in:
		| @@ -30,25 +30,22 @@ export const CurrentPatternAtom = atomWithRefresh<Pattern | null>(async (get) => | |||||||
|   } |   } | ||||||
|   return null; |   return null; | ||||||
| }); | }); | ||||||
| export const PulsesInCurrentPatternAtom = atomWithRefresh( |  | ||||||
|   (get) => get(CurrentPatternAtom)?.pulses ?? [], |  | ||||||
| ); |  | ||||||
| export const CurrentPatternDuration = atom((get) => { | export const CurrentPatternDuration = atom((get) => { | ||||||
|   const currentPattern = get(CurrentPatternAtom); |   const currentPattern = get(CurrentPatternAtom); | ||||||
|   if (!currentPattern) return 0; |   if (!currentPattern) return 0; | ||||||
|   return totalDuration(currentPattern); |   return totalDuration(currentPattern); | ||||||
| }); | }); | ||||||
| export const SelectedPulseIdAtom = atom<string | null>(null); | export const SelectedPulseIdAtom = atom<string | null>(null); | ||||||
| export const SelectedPulseAtom = atom<Pulse | null>((get) => { | export const SelectedPulseAtom = atom<Pulse | null>(async (get) => { | ||||||
|   const pulses = get(PulsesInCurrentPatternAtom); |   const pattern = await get(CurrentPatternAtom); | ||||||
|   const selectedPulseId = get(SelectedPulseIdAtom); |   const selectedPulseId = get(SelectedPulseIdAtom); | ||||||
|   return pulses.find((pulse) => pulse.id === selectedPulseId) ?? null; |   console.debug('[refresh selected pulse]', selectedPulseId, pattern); | ||||||
|  |   return pattern?.pulses?.find((pulse) => pulse.id === selectedPulseId) ?? null; | ||||||
| }); | }); | ||||||
|  |  | ||||||
| export function useSavePattern() { | export function useSavePattern() { | ||||||
|   const refreshPatterns = useSetAtom(PatternsAtom); |   const refreshPatterns = useSetAtom(PatternsAtom); | ||||||
|   const selectedPatternId = useAtomValue(SelectedPatternIdAtom); |   const selectedPatternId = useAtomValue(SelectedPatternIdAtom); | ||||||
|   const refreshSelectedPattern = useSetAtom(CurrentPatternAtom); |  | ||||||
|   const { showToast } = useNotification(); |   const { showToast } = useNotification(); | ||||||
|  |  | ||||||
|   const savePattern = useCallback( |   const savePattern = useCallback( | ||||||
| @@ -56,9 +53,6 @@ export function useSavePattern() { | |||||||
|       try { |       try { | ||||||
|         await invoke('save_pattern', { pattern }); |         await invoke('save_pattern', { pattern }); | ||||||
|         refreshPatterns(); |         refreshPatterns(); | ||||||
|         if (pattern.id === selectedPatternId) { |  | ||||||
|           refreshSelectedPattern(); |  | ||||||
|         } |  | ||||||
|         return true; |         return true; | ||||||
|       } catch (error) { |       } catch (error) { | ||||||
|         console.error('[save pattern]', error); |         console.error('[save pattern]', error); | ||||||
|   | |||||||
| @@ -6,39 +6,39 @@ export enum FrequencyShifting { | |||||||
|   /** |   /** | ||||||
|    * Change frequency undergoes a linear transformation from previous pulse to current one. |    * Change frequency undergoes a linear transformation from previous pulse to current one. | ||||||
|    */ |    */ | ||||||
|   Linear, |   Linear = 0, | ||||||
|   /** |   /** | ||||||
|    * Change frequency undergoes a quadratic transformation from previous pulse to current one. |    * Change frequency undergoes a quadratic transformation from previous pulse to current one. | ||||||
|    */ |    */ | ||||||
|   Quadratic, |   Quadratic = 1, | ||||||
|   /** |   /** | ||||||
|    * Change frequency undergoes a cubic transformation from previous pulse to current one. |    * Change frequency undergoes a cubic transformation from previous pulse to current one. | ||||||
|    */ |    */ | ||||||
|   Cubic, |   Cubic = 2, | ||||||
|   /** |   /** | ||||||
|    * Change frequency with quick fade in and fade out. |    * Change frequency with quick fade in and fade out. | ||||||
|    */ |    */ | ||||||
|   Ease, |   Ease = 3, | ||||||
|   /** |   /** | ||||||
|    * Change frequency with spiking within range from previous pulse and current one. |    * Change frequency with spiking within range from previous pulse and current one. | ||||||
|    */ |    */ | ||||||
|   Pulsating, |   Pulsating = 4, | ||||||
|   /** |   /** | ||||||
|    * Based on frequency of previous pulse, take the twice of frequency of current pulse as the peak frequency. Follow the maximum frequency limitation. |    * Based on frequency of previous pulse, take the twice of frequency of current pulse as the peak frequency. Follow the maximum frequency limitation. | ||||||
|    */ |    */ | ||||||
|   Spiking, |   Spiking = 5, | ||||||
|   /** |   /** | ||||||
|    * Randomize frequency within range from previous frequency and current one. |    * Randomize frequency within range from previous frequency and current one. | ||||||
|    */ |    */ | ||||||
|   Randomize, |   Randomize = 6, | ||||||
|   /** |   /** | ||||||
|    * Randomize frequency within minium and maximum frequency. |    * Randomize frequency within minium and maximum frequency. | ||||||
|    */ |    */ | ||||||
|   Maniac, |   Maniac = 7, | ||||||
|   /** |   /** | ||||||
|    * Synchronize changes of frequency with pulse width changes. |    * Synchronize changes of frequency with pulse width changes. | ||||||
|    */ |    */ | ||||||
|   Synchronized, |   Synchronized = 8, | ||||||
| } | } | ||||||
|  |  | ||||||
| export interface ControlPoint { | export interface ControlPoint { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user