public void 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); 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); var x = r.x + (r.width * (ofs - rofs)); var mindist = Mathf.Abs(x - evt.mousePosition.x); dragOperation = DragOperation.RandomOffset; x = r.x; for (var i = DragOperation.Offset; i <= DragOperation.RandomWindowLen; i++) { float value; plugin.GetFloatParameter(DragParams[(int)i], out value); x += r.width * value; var 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) { var blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f; var 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 ); var x1 = r.x + (r.width * (ofs - rofs)); var x2 = r.x + (r.width * ofs); var x3 = x2 + (r.width * wlen); var 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); var name = "Sample: " + Marshal.PtrToStringAnsi(Granulator_GetSampleName((int)useSample)); GUIHelpers.DrawText(r2.x + 5, r2.y - 5, r2.width, name, Color.white); } AudioCurveRendering.EndCurveFrame(); }
public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate) { var evt = Event.current; var 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); var 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: { var yscaleDraw = yscale * 0.05f; // Background grid and values var lineColor = new Color(0, 0, 0, 0.2f); var 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 var 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, int channel) { r = AudioCurveRendering.BeginCurveFrame(r); if (Event.current.type == EventType.Repaint) { var 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; var numsamples = mode >= 1.0f ? maxspeclen : (int)(window * samplerate); plugin.GetFloatBuffer("Channel" + channel, out buffer, numsamples); numsamples = buffer.Length; if (mode < 2.0f) { var lineColor = new Color(1.0f, 0.5f, 0.2f, blend); if (mode >= 1.0f) { scale *= 0.1f; AudioCurveRendering.DrawFilledCurve( r, delegate(float x) { var f = Mathf.Clamp(x * (numsamples - 2) * window * 0.5f, 0, numsamples - 2); var i = (int)Mathf.Floor(f); var s1 = 20.0f * Mathf.Log10(buffer[i] + 0.0001f); var 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 (var i = 0; i < maxspeclen; i++) { var 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(); var oldColor = GUI.color; GUI.color = new Color(1.0f, 1.0f, 1.0f, blend); var 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); }