コード例 #1
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);
    }
コード例 #2
0
    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);
    }
コード例 #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);

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

        if (evtType == EventType.MouseDown && r.Contains(evt.mousePosition) && evt.button == 0)
        {
            float lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width;
            float mf = (float)GUIHelpers.MapNormalizedFrequency(midFreq, samplerate, useLogScale, false) * r.width;
            float hf = (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width;
            float ld = Mathf.Abs(x - lf);
            float md = Mathf.Abs(x - mf);
            float hd = Mathf.Abs(x - hf);
            float 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)
        {
            float 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)
            {
                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, 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);
    }
コード例 #4
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);

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

        if (evtType == EventType.MouseDown && r.Contains(evt.mousePosition) && evt.button == 0)
        {
            float lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width;
            float 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)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            // Mark bands (low, medium and high bands)
            Color lowColor  = new Color(0.0f, 0.0f, 0.0f, blend);
            Color midColor  = new Color(0.5f, 0.5f, 0.5f, blend);
            Color 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)
            {
                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, 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);
    }