public WaveformPreview GetOrCreateWaveformPreview(TimelineClip clip, AudioClip audioClip, Rect rect, double startTime, double endTime)
        {
            if (QualitySettings.activeColorSpace != m_ColorSpace)
            {
                m_ColorSpace = QualitySettings.activeColorSpace;
                m_PersistentPreviews.Clear();
            }

            bool previewExists       = m_PersistentPreviews.TryGetValue(clip, out WaveformPreview preview);
            bool audioClipHasChanged = preview != null && audioClip != preview.presentedObject;

            if (!previewExists || audioClipHasChanged)
            {
                if (AssetDatabase.Contains(audioClip))
                {
                    preview = CreateWaveformPreview(audioClip, rect);
                }
                m_PersistentPreviews[clip] = preview;
            }

            if (preview == null)
            {
                return(null);
            }

            preview.looping = clip.SupportsLooping();
            preview.SetTimeInfo(startTime, endTime - startTime);
            preview.OptimizeForSize(rect.size);
            return(preview);
        }
        /// <inheritdoc/>
        public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
        {
            if (!TimelineWindow.instance.state.showAudioWaveform)
            {
                return;
            }

            var rect = region.position;

            if (rect.width <= 0)
            {
                return;
            }

            var audioClip = clip.asset as AudioClip;

            if (audioClip == null)
            {
                var audioPlayableAsset = clip.asset as AudioPlayableAsset;
                if (audioPlayableAsset != null)
                {
                    audioClip = audioPlayableAsset.clip;
                }
            }

            if (audioClip == null)
            {
                return;
            }

            var             quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height));
            WaveformPreview preview;

            if (QualitySettings.activeColorSpace != m_ColorSpace)
            {
                m_ColorSpace = QualitySettings.activeColorSpace;
                m_PersistentPreviews.Clear();
            }

            if (!m_PersistentPreviews.TryGetValue(clip, out preview) || audioClip != preview.presentedObject)
            {
                preview = m_PersistentPreviews[clip] = WaveformPreviewFactory.Create((int)quantizedRect.width, audioClip);
                Color waveColour  = GammaCorrect(DirectorStyles.Instance.customSkin.colorAudioWaveform);
                Color transparent = waveColour;
                transparent.a           = 0;
                preview.backgroundColor = transparent;
                preview.waveColor       = waveColour;
                preview.SetChannelMode(WaveformPreview.ChannelMode.MonoSum);
                preview.updated += () => TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
            }

            preview.looping = clip.SupportsLooping();
            preview.SetTimeInfo(region.startTime, region.endTime - region.startTime);
            preview.OptimizeForSize(quantizedRect.size);

            if (Event.current.type == EventType.Repaint)
            {
                preview.ApplyModifications();
                preview.Render(quantizedRect);
            }
        }