Example #1
0
        private void OnEnable()
        {
            BackgroundStack = new Texture2DStack();

            WaveformIconStack = new Texture2DStack();
            WaveformIconStack.AddToStack(WaveformIconStackFunc);
            WaveformIconStack.RecalculateTextureStack();

            AudioPreviewStack = new Texture2DStack();
            AudioPreviewStack.AddToStack(WaveformStackFunc);
            AudioPreviewStack.AddToStack(TimeMarkerStackFunc);
            AudioPreviewStack.AddToStack(CursorLineStackFunc);
            AudioPreviewStack.AddToStack(TrimLineStackFunc);
            AudioPreviewStack.RecalculateTextureStack();

            OnWindowSizeUpdate();
        }
Example #2
0
        private void OnGUI()
        {
            if (Event.current.mousePosition != LastMousePosition)
            {
                LastMousePosition = Event.current.mousePosition;
            }


            if (ImagePreviews == null)
            {
                CreateStyles();
            }

            if (AudioPreviewStack == null)
            {
                AudioPreviewStack = new Texture2DStack();
            }

            if (previousScreenSize != new Vector2Int(Mathf.FloorToInt(position.width), Mathf.FloorToInt(position.height)))
            {
                previousScreenSize.x = Mathf.FloorToInt(position.width);
                previousScreenSize.y = Mathf.FloorToInt(position.height);
                OnWindowSizeUpdate();
            }

            GUI.Box(new Rect(0, 0, position.width, position.height), BackgroundStack.finalTexture2D);

            GUILayout.BeginHorizontal();
            GUILayout.Label("WaterKat Audio Editor", new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold
            });
            GUILayout.EndHorizontal();

            GUILayout.Space(10);

            sourceClip = EditorGUILayout.ObjectField("Source Audio", sourceClip, typeof(AudioClip), false) as AudioClip;
            if (sourceClip == null)
            {
                return;
            }

            GUILayout.Space(10);

            if (VisibilityCheck("Audio Playback", ref PlaybackPreviewVisible))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(timeFloatToString(0));
                GUILayout.Label(timeFloatToString(PlayBar.value), LabelCenterAligned);
                GUILayout.Label(timeFloatToString(PlayBar.maxLimit), LabelRightAligned);
                GUILayout.EndHorizontal();
                PlayBar.value = GUILayout.HorizontalSlider(PlayBar.value, PlayBar.minLimit, PlayBar.maxLimit);

                GUILayout.BeginHorizontal();
                GUILayout.Button("|◀");
                GUILayout.Button("▮▮");
                GUILayout.Button("▶");
                GUILayout.Button("|✖|", new GUIStyle(GUI.skin.button)
                {
                    fontStyle = FontStyle.Bold
                });
                GUILayout.Button("►|");
                GUILayout.EndHorizontal();

                GUILayout.Space(20);
            }



            if (VisibilityCheck("Zoom", ref ZoomPreviewVisisble))
            {
                GUILayout.Box(WaveformIconStack.finalTexture2D, ImagePreviews);

                float lastmin = ZoomSlider.minValue;
                float lastmax = ZoomSlider.maxValue;
                EditorGUILayout.MinMaxSlider(ref ZoomSlider.minValue, ref ZoomSlider.maxValue, ZoomSlider.minLimit, ZoomSlider.maxLimit);
                if ((lastmin != ZoomSlider.minValue) || (lastmax != ZoomSlider.maxValue))
                {
                    AudioPreviewStack.RecalculateTextureStackAtPoint(0);
                }

                GUILayout.Space(20);
            }



            if (VisibilityCheck("Audio Preview", ref AudioPreviewVisible))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(timeFloatToString(ZoomSlider.minValue));
                GUILayout.Label(timeFloatToString(ZoomSlider.maxValue), LabelRightAligned);
                GUILayout.EndHorizontal();

                GUILayout.Space(15);

                GUILayout.Box(AudioPreviewStack.finalTexture2D, ImagePreviews);

                AudioPreviewStack.RecalculateTextureStackAtPoint(2);
                Rect barRect = GUILayoutUtility.GetLastRect();

                int   marginOffset          = Mathf.FloorToInt((50 / 2) + ImagePreviews.margin.left);
                float relativeMousePosition = relativePosition(LastMousePosition.x, barRect.x, barRect.x + barRect.width);
                float relativeTime          = Mathf.Lerp(ZoomSlider.minValue, ZoomSlider.maxValue, relativeMousePosition);
                GUI.Label(new Rect(Mathf.Clamp(LastMousePosition.x, 0 + marginOffset, position.width - marginOffset) - 150, barRect.y - (ImageHeight * 3), 300, 100), timeFloatToString(relativeTime), LabelCenterAligned);
            }


            if (TrimPreviewVisible)
            {
                TrimSlider.minLimit = ZoomSlider.minValue;
                TrimSlider.maxLimit = ZoomSlider.maxValue;
                float lastMin = TrimSlider.minValue;
                float lastMax = TrimSlider.maxValue;
                EditorGUILayout.MinMaxSlider(ref TrimSlider.minValue, ref TrimSlider.maxValue, TrimSlider.minLimit, TrimSlider.maxLimit);
                if ((lastMin != TrimSlider.minValue) || (lastMax != TrimSlider.maxValue))
                {
                    AudioPreviewStack.RecalculateTextureStackAtPoint(4);
                }
            }
            VisibilityCheck("Trim Preview", ref TrimPreviewVisible);
            if (TrimPreviewVisible)
            {
                GUILayout.Space(10);
            }



            if (VisibilityCheck("Effects", ref EffectsVisible))
            {
                ((TrimEffect)TestTrimEffect).updateEffect(TrimSlider);
                ((TrimEffect)TestTrimEffect).DrawEffect();
                ((TrimEffect)TestTrimEffect).updateSlider(TrimSlider);
                GUILayout.Space(10);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.BeginVertical(GUILayout.MaxWidth(10), GUILayout.ExpandWidth(false));
                    {
                        if (GUILayout.Button("▲", ReorderButton))
                        {
                            testint++;
                        }
                        GUILayout.Label(testint.ToString(), LabelCenterAligned);
                        if (GUILayout.Button("▼", ReorderButton))
                        {
                            testint--;
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.BeginVertical();
                    {
                        ((AmplifyEffect)TestAmplifyEffect).DrawEffect();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(20);

                ((AmplifyEffect)TestAmplifyEffect).DrawEffect();
            }
        }