Пример #1
0
    public override bool OnGUI(IAudioEffectPlugin plugin)
    {
        // port int field
        plugin.GetFloatParameter(portName, out float port);
        plugin.GetFloatParameterInfo(portName, out float minVal, out float maxVal, out float defVal);

        portInt = (int)port;
        portInt = Mathf.Clamp(EditorGUILayout.IntField("Port number:", portInt), (int)minVal, (int)maxVal);
        plugin.SetFloatParameter(portName, portInt);

        // box
        // GUILayout.Space(5f);
        // Rect r = GUILayoutUtility.GetRect(200, 100, GUILayout.ExpandWidth(true));
        // DrawControl(plugin, r, plugin.GetSampleRate());
        // GUILayout.Space(5f);

        // show/hide default sliders
        return(false);
    }
    public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
    {
        Event evt = Event.current;

        int dragControlID = GUIUtility.GetControlID(FocusType.Passive);

        r = AudioCurveRendering.BeginCurveFrame(r);

        float windowMin, windowMax, windowDef; plugin.GetFloatParameterInfo("Window", out windowMin, out windowMax, out windowDef);
        float yscaleMin, yscaleMax, yscaleDef; plugin.GetFloatParameterInfo("YScale", out yscaleMin, out yscaleMax, out yscaleDef);
        float yoffsetMin, yoffsetMax, yoffsetDef; plugin.GetFloatParameterInfo("YOffset", out yoffsetMin, out yoffsetMax, out yoffsetDef);

        float window; plugin.GetFloatParameter("Window", out window);
        float yscale; plugin.GetFloatParameter("YScale", out yscale);
        float yoffset; plugin.GetFloatParameter("YOffset", out yoffset);

        float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

        switch (evt.GetTypeForControl(dragControlID))
        {
        case EventType.MouseDown:
            if (evt.button == 0 && r.Contains(evt.mousePosition) && GUIUtility.hotControl == 0)
            {
                GUIUtility.hotControl = dragControlID;
                evt.Use();
            }
            break;

        case EventType.MouseUp:
            if (evt.button == 0 && GUIUtility.hotControl == dragControlID)
            {
                GUIUtility.hotControl = 0;
                evt.Use();
            }
            break;

        case EventType.MouseDrag:
            if (GUIUtility.hotControl == dragControlID)
            {
                window = Mathf.Clamp(window + evt.delta.x * 0.1f, windowMin, windowMax);
                if (evt.shift)
                {
                    yoffset = Mathf.Clamp(yoffset - (0.5f * evt.delta.y / yscale), yoffsetMin, yoffsetMax);
                }
                else
                {
                    yscale = Mathf.Clamp(yscale - evt.delta.y * 0.01f, yscaleMin, yscaleMax);
                }
                plugin.SetFloatParameter("Window", window);
                plugin.SetFloatParameter("YScale", yscale);
                plugin.SetFloatParameter("YOffset", yoffset);
                evt.Use();
            }
            break;

        case EventType.ScrollWheel:
            if (r.Contains(evt.mousePosition))
            {
                window  = Mathf.Clamp(window + evt.delta.x * 0.1f, windowMin, windowMax);
                yoffset = Mathf.Clamp(yoffset - (0.5f * evt.delta.y / yscale), yoffsetMin, yoffsetMax);
                plugin.SetFloatParameter("Window", window);
                plugin.SetFloatParameter("YScale", yscale);
                plugin.SetFloatParameter("YOffset", yoffset);
                evt.Use();
            }
            break;

        case EventType.Repaint:
        {
            float yscaleDraw = yscale * 0.05f;

            // Background grid and values
            Color lineColor = new Color(0, 0, 0, 0.2f);
            Color textColor = new Color(1.0f, 1.0f, 1.0f, 0.3f * blend);
            GUIHelpers.DrawDbTickMarks(r, yoffset, yscaleDraw, textColor, lineColor);
            GUIHelpers.DrawTimeTickMarks(r, window, textColor, lineColor);

            // Curves
            int     numsamples = (int)r.width;
            float[] mcurve; plugin.GetFloatBuffer("MomentaryRMS", out mcurve, numsamples);
            float[] scurve; plugin.GetFloatBuffer("ShortTermRMS", out scurve, numsamples);
            float[] icurve; plugin.GetFloatBuffer("IntegratedRMS", out icurve, numsamples);

            DrawCurve(r, mcurve, yoffset, yscaleDraw, new Color(1.0f, 0.0f, 0.0f, blend * 0.5f), 90);
            DrawCurve(r, scurve, yoffset, yscaleDraw, new Color(0.0f, 1.0f, 0.0f, blend * 0.3f), 150);
            DrawCurve(r, icurve, yoffset, yscaleDraw, new Color(0.0f, 0.0f, 1.0f, blend * 0.3f), 210);
        }
        break;
        }

        AudioCurveRendering.EndCurveFrame();
        return(false);
    }