Пример #1
0
    public void DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
    {
        r = AudioCurveRendering.BeginCurveFrame(r);

        if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            int     numsamples = (int)r.width;
            float[] imp1; plugin.GetFloatBuffer("Impulse0", out imp1, numsamples);
            float[] imp2; plugin.GetFloatBuffer("Impulse1", out imp2, numsamples);

            float wet; plugin.GetFloatParameter("Wet", out wet); wet    *= 0.01f;
            float gain; plugin.GetFloatParameter("Gain", out gain); gain = Mathf.Pow(10.0f, gain * 0.05f);
            float useSample; plugin.GetFloatParameter("Use Sample", out useSample);

            m_Impulse1Color.a = m_Impulse2Color.a = blend;

            var r2 = new Rect(r.x, r.y, r.width, r.height * 0.5f);
            DrawCurve(r2, imp1, 1.0f, m_Impulse1Color, 90, wet, gain);
            r2.y += r2.height;
            DrawCurve(r2, imp2, 1.0f, m_Impulse2Color, 150, wet, gain);

            string name = "Impulse: " + Marshal.PtrToStringAnsi(ConvolutionReverb_GetSampleName((int)useSample));
            GUIHelpers.DrawText(r2.x + 5, r2.y - 5, r2.width, name, Color.white);
        }
        AudioCurveRendering.EndCurveFrame();
    }
Пример #2
0
    public void DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
    {
        Event     evt       = Event.current;
        int       controlID = GUIUtility.GetControlID(FocusType.Passive);
        EventType evtType   = evt.GetTypeForControl(controlID);

        r = AudioCurveRendering.BeginCurveFrame(r);


        if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            int numsamples = (int)r.width;

            float port; plugin.GetFloatParameter(portName, out port);


            string name = "Port: " + port;
            GUIHelpers.DrawText(r.x + 5, r.y + 5, r.width, name, Color.white);
        }
        AudioCurveRendering.EndCurveFrame();
    }
Пример #3
0
    public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
    {
        Event     evt       = Event.current;
        int       controlID = GUIUtility.GetControlID(FocusType.Passive);
        EventType evtType   = evt.GetTypeForControl(controlID);

        r = AudioCurveRendering.BeginCurveFrame(r);


        if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            const float dbRange  = 40.0f;
            const float magScale = 1.0f / dbRange;

            float showSpectrum;
            plugin.GetFloatParameter("ShowSpectrum", out showSpectrum);
            if (showSpectrum >= 0.5f)
            {
                blend *= 0.5f;
            }

            bool useLogScale = false;

            float numModes = 0;
            if (plugin.GetFloatParameter("Num modes", out numModes) && numModes > 0 && numModes < 1000)
            {
                float[] coeffs;
                if (plugin.GetFloatBuffer("Coeffs", out coeffs, (int)numModes * 3) && coeffs != null)
                {
                    // Draw filled curve
                    DrawFilterCurve(
                        r,
                        coeffs,
                        ScaleAlpha(AudioCurveRendering.kAudioOrange, blend),
                        (int)numModes,
                        useLogScale,
                        false,
                        samplerate,
                        magScale);

                    GUIHelpers.DrawFrequencyTickMarks(r, samplerate, useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend));
                }
            }

            if (showSpectrum >= 0.5f)
            {
                float spectrumOffset;
                plugin.GetFloatParameter("SpectrumOffset", out spectrumOffset);

                int     specLen = (int)r.width;
                float[] spec;

                plugin.GetFloatBuffer("InputSpec", out spec, specLen);
                DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 0.3f, 1.0f, 0.3f, 0.5f * blend, spectrumOffset);

                plugin.GetFloatBuffer("OutputSpec", out spec, specLen);
                DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 1.0f, 0.3f, 0.3f, 0.5f * blend, spectrumOffset);
            }
        }

        AudioCurveRendering.EndCurveFrame();
        return(false);
    }
        public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
        {
            var evt       = Event.current;
            var controlID = GUIUtility.GetControlID(FocusType.Passive);
            var evtType   = evt.GetTypeForControl(controlID);

            r = AudioCurveRendering.BeginCurveFrame(r);

            var thr     = 4.0f;
            var changed = false;
            var x       = evt.mousePosition.x - r.x;

            if ((evtType == EventType.MouseDown) && r.Contains(evt.mousePosition) && (evt.button == 0))
            {
                var lf = (float)GUIHelpers.MapNormalizedFrequency(_lowFreq, samplerate, _useLogScale, false) * r.width;
                var mf = (float)GUIHelpers.MapNormalizedFrequency(_midFreq, samplerate, _useLogScale, false) * r.width;
                var hf = (float)GUIHelpers.MapNormalizedFrequency(_highFreq, samplerate, _useLogScale, false) * r.width;
                var ld = Mathf.Abs(x - lf);
                var md = Mathf.Abs(x - mf);
                var hd = Mathf.Abs(x - hf);
                var d  = ld;
                dragOperation = DragOperation.Low;
                if (md < d)
                {
                    d             = md;
                    dragOperation = DragOperation.Mid;
                }

                if (hd < d)
                {
                    d             = hd;
                    dragOperation = DragOperation.High;
                }

                GUIUtility.hotControl = controlID;
                EditorGUIUtility.SetWantsMouseJumping(1);
                evt.Use();
            }
            else if ((evtType == EventType.MouseDrag) && (GUIUtility.hotControl == controlID))
            {
                switch (dragOperation)
                {
                case DragOperation.Low:
                    _lowFreq = Mathf.Clamp(
                        (float)GUIHelpers.MapNormalizedFrequency(
                            GUIHelpers.MapNormalizedFrequency(_lowFreq, samplerate, _useLogScale, false) +
                            (evt.delta.x / r.width),
                            samplerate,
                            _useLogScale,
                            true
                            ),
                        10.0f,
                        samplerate * 0.5f
                        );
                    if (evt.shift)
                    {
                        _lowQ = Mathf.Clamp(_lowQ - (evt.delta.y * 0.05f), 0.01f, 10.0f);
                    }
                    else
                    {
                        _lowGain = Mathf.Clamp(_lowGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                    }

                    break;

                case DragOperation.Mid:
                    _midFreq = Mathf.Clamp(
                        (float)GUIHelpers.MapNormalizedFrequency(
                            GUIHelpers.MapNormalizedFrequency(_midFreq, samplerate, _useLogScale, false) +
                            (evt.delta.x / r.width),
                            samplerate,
                            _useLogScale,
                            true
                            ),
                        10.0f,
                        samplerate * 0.5f
                        );
                    if (evt.shift)
                    {
                        _midQ = Mathf.Clamp(_midQ - (evt.delta.y * 0.05f), 0.01f, 10.0f);
                    }
                    else
                    {
                        _midGain = Mathf.Clamp(_midGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                    }

                    break;

                case DragOperation.High:
                    _highFreq = Mathf.Clamp(
                        (float)GUIHelpers.MapNormalizedFrequency(
                            GUIHelpers.MapNormalizedFrequency(_highFreq, samplerate, _useLogScale, false) +
                            (evt.delta.x / r.width),
                            samplerate,
                            _useLogScale,
                            true
                            ),
                        10.0f,
                        samplerate * 0.5f
                        );
                    if (evt.shift)
                    {
                        _highQ = Mathf.Clamp(_highQ - (evt.delta.y * 0.05f), 0.01f, 10.0f);
                    }
                    else
                    {
                        _highGain = Mathf.Clamp(_highGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                    }

                    break;
                }

                changed = true;
                evt.Use();
            }
            else if ((evtType == EventType.MouseUp) && (evt.button == 0) && (GUIUtility.hotControl == controlID))
            {
                GUIUtility.hotControl = 0;
                EditorGUIUtility.SetWantsMouseJumping(0);
                evt.Use();
            }

            if (Event.current.type == EventType.Repaint)
            {
                var blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

                // Mark bands (low, medium and high bands)
                DrawBandSplitMarker(
                    plugin,
                    r,
                    (float)GUIHelpers.MapNormalizedFrequency(_lowFreq, samplerate, _useLogScale, false) * r.width,
                    thr,
                    (GUIUtility.hotControl == controlID) && (dragOperation == DragOperation.Low),
                    new Color(0, 0, 0, blend)
                    );
                DrawBandSplitMarker(
                    plugin,
                    r,
                    (float)GUIHelpers.MapNormalizedFrequency(_midFreq, samplerate, _useLogScale, false) * r.width,
                    thr,
                    (GUIUtility.hotControl == controlID) && (dragOperation == DragOperation.Mid),
                    new Color(0.5f, 0.5f, 0.5f, blend)
                    );
                DrawBandSplitMarker(
                    plugin,
                    r,
                    (float)GUIHelpers.MapNormalizedFrequency(_highFreq, samplerate, _useLogScale, false) * r.width,
                    thr,
                    (GUIUtility.hotControl == controlID) && (dragOperation == DragOperation.High),
                    new Color(1.0f, 1.0f, 1.0f, blend)
                    );

                const float dbRange  = 40.0f;
                const float magScale = 1.0f / dbRange;

                float[] coeffs;
                plugin.GetFloatBuffer("Coeffs", out coeffs, 15);

                // Draw filled curve
                DrawFilterCurve(
                    r,
                    coeffs,
                    true,
                    true,
                    true,
                    ScaleAlpha(AudioCurveRendering.kAudioOrange, blend),
                    _useLogScale,
                    false,
                    _masterGain,
                    samplerate,
                    magScale
                    );

                if (GUIUtility.hotControl == controlID)
                {
                    DrawFilterCurve(
                        r,
                        coeffs,
                        dragOperation == DragOperation.Low,
                        dragOperation == DragOperation.Mid,
                        dragOperation == DragOperation.High,
                        new Color(1.0f, 1.0f, 1.0f, 0.2f * blend),
                        _useLogScale,
                        true,
                        _masterGain,
                        samplerate,
                        magScale
                        );
                }

                if (_showSpectrum)
                {
                    var     specLen = (int)r.width;
                    float[] spec;

                    plugin.GetFloatBuffer("InputSpec", out spec, specLen);
                    DrawSpectrum(r, _useLogScale, spec, dbRange, samplerate, 0.3f, 1.0f, 0.3f, 0.5f * blend, 0.0f);

                    plugin.GetFloatBuffer("OutputSpec", out spec, specLen);
                    DrawSpectrum(r, _useLogScale, spec, dbRange, samplerate, 1.0f, 0.3f, 0.3f, 0.5f * blend, 0.0f);
                }

                GUIHelpers.DrawFrequencyTickMarks(r, samplerate, _useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend));
            }

            AudioCurveRendering.EndCurveFrame();
            return(changed);
        }
    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);
    }
        public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
        {
            r = AudioCurveRendering.BeginCurveFrame(r);

            if (Event.current.type == EventType.Repaint)
            {
                var blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

                float window;
                plugin.GetFloatParameter("Window", out window);
                window *= samplerate;
                if (window > samplerate)
                {
                    window = samplerate;
                }

                float[] corr;
                var     numsamples = (int)window;
                plugin.GetFloatBuffer("Correlation", out corr, 2 * numsamples);
                numsamples = corr.Length;

                var cx = r.x + (r.width * 0.5f);
                var cy = r.y + (r.height * 0.5f);

                coord1[0].Set(r.x, r.y + (r.height * 0.5f), 0);
                coord1[1].Set(r.x + r.width, r.y + (r.height * 0.5f), 0);
                coord2[0].Set(r.x + (r.width * 0.5f), r.y, 0);
                coord2[1].Set(r.x + (r.width * 0.5f), r.y + r.height, 0);

                var w  = (2.0f * 3.1415926f) / (circle.Length - 1);
                var cr = r.height * 0.4f;
                for (var n = 0; n < circle.Length; n++)
                {
                    circle[n].Set(cx + (cr * Mathf.Cos(n * w)), cy + (cr * Mathf.Sin(n * w)), 0);
                }

                float scale;
                plugin.GetFloatParameter("Scale", out scale);
                scale *= cr;

                var lineTint = 0.5f;
                UnityEditor.Handles.color = new Color(lineTint, lineTint, lineTint, 0.75f);
                UnityEditor.Handles.DrawAAPolyLine(2.0f, coord1.Length, coord1);
                UnityEditor.Handles.DrawAAPolyLine(2.0f, coord2.Length, coord2);
                UnityEditor.Handles.DrawAAPolyLine(2.0f, circle.Length, circle);

                HandleUtilityWrapper.handleWireMaterial.SetPass(0);
                GL.Begin(GL.LINES);
                var col1 = AudioCurveRendering.kAudioOrange;
                var col2 = Color.yellow;
                col1.a = blend;
                col2.a = 0.0f;
                var cs = 1.0f / ((numsamples / 2) - 1);
                for (var n = 0; n < (numsamples / 2); n++)
                {
                    var px = cx + (scale * corr[n * 2]);
                    var py = cy - (scale * corr[(n * 2) + 1]);
                    if ((px >= r.x) && (py >= r.y) && (px < (r.x + r.width)) && (py < (r.y + r.height)))
                    {
                        GL.Color(Color.Lerp(col1, col2, n * cs));
                        GL.Vertex3(px, py - 1.0f, 0.0f);
                        GL.Vertex3(px, py, 0.0f);
                    }
                }

                GL.End();
            }

            AudioCurveRendering.EndCurveFrame();
            return(false);
        }
    public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate, int channel)
    {
        r = AudioCurveRendering.BeginCurveFrame(r);

        if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            float window, scale, mode;
            plugin.GetFloatParameter("Window", out window);
            plugin.GetFloatParameter("Scale", out scale);
            plugin.GetFloatParameter("Mode", out mode);

            float[] buffer;
            int     numsamples = (mode >= 1.0f) ? maxspeclen : (int)(window * samplerate);
            plugin.GetFloatBuffer("Channel" + channel.ToString(), out buffer, numsamples);
            numsamples = buffer.Length;

            if (mode < 2.0f)
            {
                Color lineColor = new Color(1.0f, 0.5f, 0.2f, blend);
                if (mode >= 1.0f)
                {
                    scale *= 0.1f;
                    AudioCurveRendering.DrawFilledCurve(r, delegate(float x)
                    {
                        float f  = Mathf.Clamp(x * (numsamples - 2) * window * 0.5f, 0, numsamples - 2);
                        int i    = (int)Mathf.Floor(f);
                        float s1 = 20.0f * Mathf.Log10(buffer[i] + 0.0001f);
                        float s2 = 20.0f * Mathf.Log10(buffer[i + 1] + 0.0001f);
                        return((s1 + (s2 - s1) * (f - i)) * scale);
                    }, lineColor);
                    GUIHelpers.DrawFrequencyTickMarks(r, samplerate * window * 0.5f, false, Color.red);
                    GUIHelpers.DrawDbTickMarks(r, 1.0f / scale, scale, Color.red, new Color(1.0f, 0.0f, 0.0f, 0.25f));
                }
                else
                {
                    AudioCurveRendering.DrawCurve(r, delegate(float x) { return(scale * buffer[(int)Mathf.Floor(x * (numsamples - 2))]); }, lineColor);
                    GUIHelpers.DrawTimeTickMarks(r, window, Color.red, new Color(1.0f, 0.0f, 0.0f, 0.25f));
                }
            }
            else
            {
                scale *= 0.1f;

                for (int i = 0; i < maxspeclen; i++)
                {
                    float v = 20.0f * Mathf.Log10(buffer[i] + 0.0001f) * scale;
                    spec[i] = new Color(
                        Mathf.Clamp(v * 4.0f - 1.0f, 0.0f, 1.0f),
                        Mathf.Clamp(v * 4.0f - 2.0f, 0.0f, 1.0f),
                        1.0f - Mathf.Clamp(Mathf.Abs(v * 4.0f - 1.0f), 0.0f, 1.0f) * Mathf.Clamp(4.0f - 4.0f * v, 0.0f, 1.0f),
                        1.0f);
                }

                if (spectex[channel] == null)
                {
                    spectex[channel] = new Texture2D(maxspeclen, scopeheight);
                }

                specpos[channel] = (specpos[channel] + 1) % scopeheight;
                spectex[channel].SetPixels(0, specpos[channel], maxspeclen, 1, spec);
                spectex[channel].Apply();

                Color oldColor = GUI.color;
                GUI.color = new Color(1.0f, 1.0f, 1.0f, blend);

                Rect r2 = new Rect(r.x, r.y + specpos[channel], r.width / (window * 0.5f), scopeheight);
                GUI.DrawTexture(r2, spectex[channel], ScaleMode.StretchToFill, false, 1.0f);

                r2.y -= scopeheight;
                GUI.DrawTexture(r2, spectex[channel], ScaleMode.StretchToFill, false, 1.0f);

                GUI.color = oldColor;

                GUIHelpers.DrawFrequencyTickMarks(r, samplerate * window * 0.5f, false, Color.red);
            }
        }
        AudioCurveRendering.EndCurveFrame();
        return(false);
    }
Пример #8
0
        public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
        {
            var evt       = Event.current;
            var controlID = GUIUtility.GetControlID(FocusType.Passive);
            var evtType   = evt.GetTypeForControl(controlID);

            r = AudioCurveRendering.BeginCurveFrame(r);

            var thr     = 4.0f;
            var changed = false;
            var x       = evt.mousePosition.x - r.x;

            if ((evtType == EventType.MouseDown) && r.Contains(evt.mousePosition) && (evt.button == 0))
            {
                var lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width;
                var hf = (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width;
                dragOperation = DragOperation.Mid;
                if (x < (lf + thr))
                {
                    dragOperation = DragOperation.Low;
                }
                else if (x > (hf - thr))
                {
                    dragOperation = DragOperation.High;
                }

                GUIUtility.hotControl = controlID;
                EditorGUIUtility.SetWantsMouseJumping(1);
                evt.Use();
            }
            else if ((evtType == EventType.MouseDrag) && (GUIUtility.hotControl == controlID))
            {
                if ((dragOperation == DragOperation.Low) || (dragOperation == DragOperation.Mid))
                {
                    lowFreq = Mathf.Clamp(
                        (float)GUIHelpers.MapNormalizedFrequency(
                            GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) +
                            (evt.delta.x / r.width),
                            samplerate,
                            useLogScale,
                            true
                            ),
                        10.0f,
                        highFreq
                        );
                }

                if (dragOperation == DragOperation.Low)
                {
                    lowGain = Mathf.Clamp(lowGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                }

                if (dragOperation == DragOperation.Mid)
                {
                    midGain = Mathf.Clamp(midGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                }

                if ((dragOperation == DragOperation.Mid) || (dragOperation == DragOperation.High))
                {
                    highFreq = Mathf.Clamp(
                        (float)GUIHelpers.MapNormalizedFrequency(
                            GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) +
                            (evt.delta.x / r.width),
                            samplerate,
                            useLogScale,
                            true
                            ),
                        lowFreq,
                        samplerate * 0.5f
                        );
                }

                if (dragOperation == DragOperation.High)
                {
                    highGain = Mathf.Clamp(highGain - (evt.delta.y * 0.5f), -100.0f, 100.0f);
                }

                changed = true;
                evt.Use();
            }
            else if ((evtType == EventType.MouseUp) && (evt.button == 0) && (GUIUtility.hotControl == controlID))
            {
                GUIUtility.hotControl = 0;
                EditorGUIUtility.SetWantsMouseJumping(0);
                evt.Use();
            }

            if (Event.current.type == EventType.Repaint)
            {
                var blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

                // Mark bands (low, medium and high bands)
                var lowColor  = new Color(0.0f, 0.0f, 0.0f, blend);
                var midColor  = new Color(0.5f, 0.5f, 0.5f, blend);
                var highColor = new Color(1.0f, 1.0f, 1.0f, blend);
                DrawBandSplitMarker(
                    plugin,
                    r,
                    (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width,
                    thr,
                    (GUIUtility.hotControl == controlID) &&
                    ((dragOperation == DragOperation.Low) || (dragOperation == DragOperation.Mid)),
                    lowColor
                    );
                DrawBandSplitMarker(
                    plugin,
                    r,
                    (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width,
                    thr,
                    (GUIUtility.hotControl == controlID) &&
                    ((dragOperation == DragOperation.High) || (dragOperation == DragOperation.Mid)),
                    highColor
                    );

                const float dbRange  = 40.0f;
                const float magScale = 1.0f / dbRange;

                float[] liveData;
                plugin.GetFloatBuffer("LiveData", out liveData, 6);

                float[] coeffs;
                plugin.GetFloatBuffer("Coeffs", out coeffs, 20);

                if (GUIUtility.hotControl == controlID)
                {
                    DrawFilterCurve(
                        r,
                        coeffs,
                        dragOperation == DragOperation.Low ? Mathf.Pow(10.0f, 0.05f * lowGain) : 0.0f,
                        dragOperation == DragOperation.Mid ? Mathf.Pow(10.0f, 0.05f * midGain) : 0.0f,
                        dragOperation == DragOperation.High ? Mathf.Pow(10.0f, 0.05f * highGain) : 0.0f,
                        new Color(1.0f, 1.0f, 1.0f, 0.2f * blend),
                        true,
                        samplerate,
                        magScale
                        );
                }

                DrawFilterCurve(
                    r,
                    coeffs,
                    Mathf.Pow(10.0f, 0.05f * lowGain) * liveData[0],
                    0.0f,
                    0.0f,
                    lowColor,
                    false,
                    samplerate,
                    magScale
                    );
                DrawFilterCurve(
                    r,
                    coeffs,
                    0.0f,
                    Mathf.Pow(10.0f, 0.05f * midGain) * liveData[1],
                    0.0f,
                    midColor,
                    false,
                    samplerate,
                    magScale
                    );
                DrawFilterCurve(
                    r,
                    coeffs,
                    0.0f,
                    0.0f,
                    Mathf.Pow(10.0f, 0.05f * highGain) * liveData[2],
                    highColor,
                    false,
                    samplerate,
                    magScale
                    );

                DrawFilterCurve(
                    r,
                    coeffs,
                    Mathf.Pow(10.0f, 0.05f * lowGain) * liveData[0],
                    Mathf.Pow(10.0f, 0.05f * midGain) * liveData[1],
                    Mathf.Pow(10.0f, 0.05f * highGain) * liveData[2],
                    ScaleAlpha(AudioCurveRendering.kAudioOrange, 0.5f),
                    false,
                    samplerate,
                    magScale
                    );

                DrawFilterCurve(
                    r,
                    coeffs,
                    Mathf.Pow(10.0f, 0.05f * lowGain),
                    Mathf.Pow(10.0f, 0.05f * midGain),
                    Mathf.Pow(10.0f, 0.05f * highGain),
                    AudioCurveRendering.kAudioOrange,
                    false,
                    samplerate,
                    magScale
                    );

                if (showSpectrum)
                {
                    var     specLen = (int)r.width;
                    float[] spec;

                    plugin.GetFloatBuffer("InputSpec", out spec, specLen);
                    DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 0.3f, 1.0f, 0.3f, 0.5f * blend, 0.0f);

                    plugin.GetFloatBuffer("OutputSpec", out spec, specLen);
                    DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 1.0f, 0.3f, 0.3f, 0.5f * blend, 0.0f);
                }

                GUIHelpers.DrawFrequencyTickMarks(r, samplerate, useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend));
            }

            AudioCurveRendering.EndCurveFrame();
            return(changed);
        }
Пример #9
0
    public void DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate)
    {
        Event     evt       = Event.current;
        int       controlID = GUIUtility.GetControlID(FocusType.Passive);
        EventType evtType   = evt.GetTypeForControl(controlID);

        r = AudioCurveRendering.BeginCurveFrame(r);

        if (evtType == EventType.MouseDown && r.Contains(evt.mousePosition) && evt.button == 0)
        {
            float ofs, rofs;
            plugin.GetFloatParameter(DragParams[(int)DragOperation.Offset], out ofs);
            plugin.GetFloatParameter(DragParams[(int)DragOperation.RandomOffset], out rofs);
            float x       = r.x + r.width * (ofs - rofs);
            float mindist = Mathf.Abs(x - evt.mousePosition.x);
            dragOperation = DragOperation.RandomOffset;
            x             = r.x;
            for (DragOperation i = DragOperation.Offset; i <= DragOperation.RandomWindowLen; i++)
            {
                float value;
                plugin.GetFloatParameter(DragParams[(int)i], out value);
                x += r.width * value;
                float dx = Mathf.Abs(x - evt.mousePosition.x);
                if (dx < mindist)
                {
                    mindist       = dx;
                    dragOperation = i;
                }
            }
            GUIUtility.hotControl = controlID;
            EditorGUIUtility.SetWantsMouseJumping(1);
            evt.Use();
        }
        if (evtType == EventType.MouseDrag && GUIUtility.hotControl == controlID)
        {
            if (dragOperation != DragOperation.None)
            {
                float value;
                plugin.GetFloatParameter(DragParams[(int)dragOperation], out value);
                value = Mathf.Clamp(value + ((dragOperation == DragOperation.RandomOffset) ? -evt.delta.x : evt.delta.x) * 0.001f, 0.0f, 1.0f);
                plugin.SetFloatParameter(DragParams[(int)dragOperation], value);
                evt.Use();
            }
        }
        else if (evtType == EventType.MouseUp && GUIUtility.hotControl == controlID)
        {
            dragOperation         = DragOperation.None;
            GUIUtility.hotControl = 0;
            EditorGUIUtility.SetWantsMouseJumping(0);
            evt.Use();
        }
        else if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            int     numsamples = (int)r.width;
            float[] wave1; plugin.GetFloatBuffer("Waveform0", out wave1, numsamples);
            float[] wave2; plugin.GetFloatBuffer("Waveform1", out wave2, numsamples);

            float ofs; plugin.GetFloatParameter(DragParams[(int)DragOperation.Offset], out ofs);
            float rofs; plugin.GetFloatParameter(DragParams[(int)DragOperation.RandomOffset], out rofs);
            float wlen; plugin.GetFloatParameter(DragParams[(int)DragOperation.WindowLen], out wlen);
            float rwlen; plugin.GetFloatParameter(DragParams[(int)DragOperation.RandomWindowLen], out rwlen);
            float shape; plugin.GetFloatParameter("Shape", out shape);
            float useSample; plugin.GetFloatParameter("Use Sample", out useSample);

            m_Wave1Color.a = blend;
            m_Wave2Color.a = blend;
            m_Wave3Color.a = blend;
            m_Wave4Color.a = blend;

            var r2 = new Rect(r.x, r.y, r.width, r.height * 0.5f);
            DrawCurve(r2, wave1, 1.0f, m_Wave1Color, m_Wave2Color, m_Wave3Color, m_Wave4Color, 90, rofs, ofs, wlen, rwlen, shape);
            r2.y += r2.height;
            DrawCurve(r2, wave2, 1.0f, m_Wave1Color, m_Wave2Color, m_Wave3Color, m_Wave4Color, 150, rofs, ofs, wlen, rwlen, shape);

            float x1 = r.x + r.width * (ofs - rofs);
            float x2 = r.x + r.width * ofs;
            float x3 = x2 + r.width * wlen;
            float x4 = x3 + r.width * rwlen;
            GUIHelpers.DrawLine(x1, r.y, x1, r.y + r.height, m_Wave1Color);
            GUIHelpers.DrawLine(x2, r.y, x2, r.y + r.height, m_Wave2Color);
            GUIHelpers.DrawLine(x3, r.y, x3, r.y + r.height, m_Wave3Color);
            GUIHelpers.DrawLine(x4, r.y, x4, r.y + r.height, m_Wave4Color);

            string name = "Sample: " + Marshal.PtrToStringAnsi(Granulator_GetSampleName((int)useSample));
            GUIHelpers.DrawText(r2.x + 5, r2.y - 5, r2.width, name, Color.white);
        }
        AudioCurveRendering.EndCurveFrame();
    }