@@ -41,77 +41,6 @@ export interface TrackState {
4141 pan : number ;
4242}
4343
44- export interface WaveformPlaylistContextValue {
45- // State
46- isPlaying : boolean ;
47- currentTime : number ;
48- duration : number ;
49- audioBuffers : AudioBuffer [ ] ;
50- peaksDataArray : TrackClipPeaks [ ] ; // Array of tracks, each containing array of clip peaks
51- trackStates : TrackState [ ] ;
52- annotations : AnnotationData [ ] ;
53- activeAnnotationId : string | null ;
54- selectionStart : number ;
55- selectionEnd : number ;
56- isAutomaticScroll : boolean ;
57- continuousPlay : boolean ;
58- linkEndpoints : boolean ;
59- annotationsEditable : boolean ;
60-
61- // Playback controls
62- play : ( startTime ?: number , playDuration ?: number ) => Promise < void > ;
63- pause : ( ) => void ;
64- stop : ( ) => void ;
65- setCurrentTime : ( time : number ) => void ;
66-
67- // Track controls
68- setTrackMute : ( trackIndex : number , muted : boolean ) => void ;
69- setTrackSolo : ( trackIndex : number , soloed : boolean ) => void ;
70- setTrackVolume : ( trackIndex : number , volume : number ) => void ;
71- setTrackPan : ( trackIndex : number , pan : number ) => void ;
72-
73- // Selection
74- setSelection : ( start : number , end : number ) => void ;
75-
76- // Time format
77- timeFormat : TimeFormat ;
78- setTimeFormat : ( format : TimeFormat ) => void ;
79- formatTime : ( seconds : number ) => string ;
80-
81- // Zoom
82- samplesPerPixel : number ;
83- zoomIn : ( ) => void ;
84- zoomOut : ( ) => void ;
85- canZoomIn : boolean ;
86- canZoomOut : boolean ;
87-
88- // Master volume
89- masterVolume : number ;
90- setMasterVolume : ( volume : number ) => void ;
91-
92- // Automatic scroll
93- setAutomaticScroll : ( enabled : boolean ) => void ;
94- setScrollContainer : ( element : HTMLDivElement | null ) => void ;
95-
96- // Annotation controls
97- setContinuousPlay : ( enabled : boolean ) => void ;
98- setLinkEndpoints : ( enabled : boolean ) => void ;
99- setAnnotationsEditable : ( enabled : boolean ) => void ;
100- setAnnotations : React . Dispatch < React . SetStateAction < AnnotationData [ ] > > ;
101- setActiveAnnotationId : ( id : string | null ) => void ;
102-
103- // Refs
104- playoutRef : React . RefObject < TonePlayout | null > ;
105- currentTimeRef : React . RefObject < number > ;
106-
107- // Playlist info
108- sampleRate : number ;
109- waveHeight : number ;
110- timeScaleHeight : number ;
111- minimumPlaylistHeight : number ;
112- controls : { show : boolean ; width : number } ;
113- }
114-
11544// Split contexts for performance optimization
11645// High-frequency updates (currentTime) are isolated from low-frequency state changes
11746
@@ -222,9 +151,6 @@ const PlaylistStateContext = createContext<PlaylistStateContextValue | null>(nul
222151const PlaylistControlsContext = createContext < PlaylistControlsContextValue | null > ( null ) ;
223152const PlaylistDataContext = createContext < PlaylistDataContextValue | null > ( null ) ;
224153
225- // Keep the original context for backwards compatibility
226- const WaveformPlaylistContext = createContext < WaveformPlaylistContextValue | null > ( null ) ;
227-
228154export interface WaveformPlaylistProviderProps {
229155 tracks : ClipTrack [ ] ; // Updated to use clip-based model
230156 timescale ?: boolean ;
@@ -1071,15 +997,15 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
1071997 // Split context values for performance optimization
1072998 // High-frequency updates (currentTime) isolated from other state
1073999
1074- const animationValue : PlaybackAnimationContextValue = {
1000+ const animationValue : PlaybackAnimationContextValue = useMemo ( ( ) => ( {
10751001 isPlaying,
10761002 currentTime,
10771003 currentTimeRef,
10781004 playbackStartTimeRef,
10791005 audioStartPositionRef,
1080- } ;
1006+ } ) , [ isPlaying , currentTime , currentTimeRef , playbackStartTimeRef , audioStartPositionRef ] ) ;
10811007
1082- const stateValue : PlaylistStateContextValue = {
1008+ const stateValue : PlaylistStateContextValue = useMemo ( ( ) => ( {
10831009 continuousPlay,
10841010 linkEndpoints,
10851011 annotationsEditable,
@@ -1092,18 +1018,24 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
10921018 selectedTrackId,
10931019 loopStart,
10941020 loopEnd,
1095- } ;
1021+ } ) , [ continuousPlay , linkEndpoints , annotationsEditable , isAutomaticScroll , isLoopEnabled , annotations , activeAnnotationId , selectionStart , selectionEnd , selectedTrackId , loopStart , loopEnd ] ) ;
10961022
1097- const controlsValue : PlaylistControlsContextValue = {
1023+ const setCurrentTimeControl = useCallback ( ( time : number ) => {
1024+ currentTimeRef . current = time ;
1025+ setCurrentTime ( time ) ;
1026+ } , [ currentTimeRef ] ) ;
1027+
1028+ const setAutomaticScrollControl = useCallback ( ( enabled : boolean ) => {
1029+ setIsAutomaticScroll ( enabled ) ;
1030+ } , [ ] ) ;
1031+
1032+ const controlsValue : PlaylistControlsContextValue = useMemo ( ( ) => ( {
10981033 // Playback controls
10991034 play,
11001035 pause,
11011036 stop,
11021037 seekTo,
1103- setCurrentTime : ( time : number ) => {
1104- currentTimeRef . current = time ;
1105- setCurrentTime ( time ) ;
1106- } ,
1038+ setCurrentTime : setCurrentTimeControl ,
11071039
11081040 // Track controls
11091041 setTrackMute,
@@ -1127,9 +1059,7 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
11271059 setMasterVolume,
11281060
11291061 // Automatic scroll
1130- setAutomaticScroll : ( enabled : boolean ) => {
1131- setIsAutomaticScroll ( enabled ) ;
1132- } ,
1062+ setAutomaticScroll : setAutomaticScrollControl ,
11331063 setScrollContainer,
11341064 scrollContainerRef,
11351065
@@ -1146,9 +1076,9 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
11461076 setLoopRegionFromSelection,
11471077 clearLoopRegion,
11481078
1149- } ;
1079+ } ) , [ play , pause , stop , seekTo , setCurrentTimeControl , setTrackMute , setTrackSolo , setTrackVolume , setTrackPan , setSelection , setSelectedTrackId , setTimeFormat , formatTime , zoom . zoomIn , zoom . zoomOut , setMasterVolume , setAutomaticScrollControl , setScrollContainer , scrollContainerRef , setContinuousPlay , setLinkEndpoints , setAnnotationsEditable , setAnnotations , setActiveAnnotationId , setLoopEnabled , setLoopRegion , setLoopRegionFromSelection , clearLoopRegion ] ) ;
11501080
1151- const dataValue : PlaylistDataContextValue = {
1081+ const dataValue : PlaylistDataContextValue = useMemo ( ( ) => ( {
11521082 duration,
11531083 audioBuffers,
11541084 peaksDataArray,
@@ -1170,15 +1100,7 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
11701100 progressBarWidth,
11711101 isReady,
11721102 mono,
1173- } ;
1174-
1175- // Combined value for backwards compatibility
1176- const value : WaveformPlaylistContextValue = {
1177- ...animationValue ,
1178- ...stateValue ,
1179- ...controlsValue ,
1180- ...dataValue ,
1181- } ;
1103+ } ) , [ duration , audioBuffers , peaksDataArray , trackStates , tracks , sampleRate , waveHeight , timeScaleHeight , minimumPlaylistHeight , controls , playoutRef , samplesPerPixel , timeFormat , masterVolume , zoom . canZoomIn , zoom . canZoomOut , barWidth , barGap , progressBarWidth , isReady , mono ] ) ;
11821104
11831105 // Merge user theme with default theme
11841106 const mergedTheme = { ...defaultTheme , ...userTheme } ;
@@ -1189,9 +1111,7 @@ export const WaveformPlaylistProvider: React.FC<WaveformPlaylistProviderProps> =
11891111 < PlaylistStateContext . Provider value = { stateValue } >
11901112 < PlaylistControlsContext . Provider value = { controlsValue } >
11911113 < PlaylistDataContext . Provider value = { dataValue } >
1192- < WaveformPlaylistContext . Provider value = { value } >
11931114 { children }
1194- </ WaveformPlaylistContext . Provider >
11951115 </ PlaylistDataContext . Provider >
11961116 </ PlaylistControlsContext . Provider >
11971117 </ PlaylistStateContext . Provider >
@@ -1235,12 +1155,3 @@ export const usePlaylistData = () => {
12351155 return context ;
12361156} ;
12371157
1238- // Main hook that combines all contexts - use this for backwards compatibility
1239- // or when you need access to multiple contexts
1240- export const useWaveformPlaylist = ( ) => {
1241- const context = useContext ( WaveformPlaylistContext ) ;
1242- if ( ! context ) {
1243- throw new Error ( 'useWaveformPlaylist must be used within WaveformPlaylistProvider' ) ;
1244- }
1245- return context ;
1246- } ;
0 commit comments