iPlug2 - C++ Audio Plug-in Framework
IVScopeControl.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5 
6  See LICENSE.txt for more info.
7 
8  ==============================================================================
9 */
10 
11 #pragma once
12 
19 #include "IControl.h"
20 #include "ISender.h"
21 #include "IPlugStructs.h"
22 
23 BEGIN_IPLUG_NAMESPACE
24 BEGIN_IGRAPHICS_NAMESPACE
25 
28 template <int MAXNC = 1, int MAXBUF = 128>
29 class IVScopeControl : public IControl
30  , public IVectorBase
31 {
32 public:
37  IVScopeControl(const IRECT& bounds, const char* label = "", const IVStyle& style = DEFAULT_STYLE)
38  : IControl(bounds)
39  , IVectorBase(style)
40  {
41  AttachIControl(this, label);
42  }
43 
44  void Draw(IGraphics& g) override
45  {
46  DrawBackground(g, mRECT);
47  DrawWidget(g);
48  DrawLabel(g);
49 
50  if(mStyle.drawFrame)
51  g.DrawRect(GetColor(kFR), mWidgetBounds, &mBlend, mStyle.frameThickness);
52  }
53 
54  void DrawWidget(IGraphics& g) override
55  {
56  g.DrawHorizontalLine(GetColor(kSH), mWidgetBounds, 0.5, &mBlend, mStyle.frameThickness);
57 
58  IRECT r = mWidgetBounds.GetPadded(-mPadding);
59 
60  const float maxY = (r.H() / 2.f); // y +/- centre
61 
62  float xPerData = r.W() / (float) MAXBUF;
63 
64  for (int c = 0; c < mBuf.nChans; c++)
65  {
66  float xHi = 0.f;
67  float yHi = mBuf.vals[c][0] * maxY;
68  yHi = Clip(yHi, -maxY, maxY);
69 
70  g.PathMoveTo(r.L + xHi, r.MH() - yHi);
71  for (int s = 1; s < MAXBUF; s++)
72  {
73  xHi = ((float) s * xPerData);
74  yHi = mBuf.vals[c][s] * maxY;
75  yHi = Clip(yHi, -maxY, maxY);
76  g.PathLineTo(r.L + xHi, r.MH() - yHi);
77  }
78 
79  g.PathStroke(GetColor(kFG), mTrackSize, IStrokeOptions(), &mBlend);
80  }
81  }
82 
83  void OnResize() override
84  {
85  SetTargetRECT(MakeRects(mRECT));
86  SetDirty(false);
87  }
88 
89  void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override
90  {
91  if (!IsDisabled() && msgTag == ISender<>::kUpdateMessage)
92  {
93  IByteStream stream(pData, dataSize);
94 
95  int pos = 0;
96  pos = stream.Get(&mBuf, pos);
97 
98  SetDirty(false);
99  }
100  }
101 
102 private:
104  float mPadding = 2.f;
105 };
106 
107 END_IGRAPHICS_NAMESPACE
108 END_IPLUG_NAMESPACE
109 
int Get(T *pDst, int startPos) const
Get arbitary typed data from the stream.
Definition: IPlugStructs.h:289
virtual void PathMoveTo(float x, float y)=0
Move the current point in the current path.
float MH() const
void OnMsgFromDelegate(int msgTag, int dataSize, const void *pData) override
Implement to receive messages sent to the control, see IEditorDelegate:SendControlMsgFromDelegate() ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
IVScopeControl(const IRECT &bounds, const char *label="", const IVStyle &style=DEFAULT_STYLE)
Constructs an IVScopeControl.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2475
virtual void DrawBackground(IGraphics &g, const IRECT &rect)
Draw the IVControl background (usually transparent)
Definition: IControl.h:733
virtual void PathLineTo(float x, float y)=0
Add a line to the current path from the current point to the specified location.
virtual void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options=IStrokeOptions(), const IBlend *pBlend=0)=0
Stroke the current current path.
Used to manage stroke behaviour for path based drawing back ends.
ISender is a utility class which can be used to defer data from the realtime audio processing and sen...
void AttachIControl(IControl *pControl, const char *label)
Call in the constructor of your IVControl to link the IVectorBase and IControl.
Definition: IControl.h:641
This file contains the base IControl implementation, along with some base classes for specific types ...
Manages a non-owned block of memory, for receiving arbitrary message byte streams.
Definition: IPlugStructs.h:267
bool IsDisabled() const
Definition: IControl.h:356
ISenderData is used to represent a typed data packet, that may contain values for multiple channels...
Definition: ISender.h:30
IRECT MakeRects(const IRECT &parent, bool hasHandle=false)
Calculate the rectangles for the various areas, depending on the style.
Definition: IControl.h:1014
float H() const
void Draw(IGraphics &g) override
Draw the control to the graphics context.
float W() const
const IColor & GetColor(EVColor color) const
Get value of a specific EVColor in the IVControl.
Definition: IControl.h:664
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void DrawWidget(IGraphics &g) override
Draw the IVControl main widget (override)
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void DrawLabel(IGraphics &g)
Draw the IVControl label text.
Definition: IControl.h:746
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
void DrawHorizontalLine(const IColor &color, const IRECT &bounds, float y, const IBlend *pBlend=0, float thickness=1.f)
Draw a horizontal line, within a rectangular region of the graphics context.
Definition: IGraphics.cpp:747
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control...
Definition: IControl.h:317
float L
Left side of the rectangle (X)
ISender is a utility class which can be used to defer data from the realtime audio processing and sen...
Definition: ISender.h:57
Vectorial multi-channel capable oscilloscope control.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
A base interface to be combined with IControl for vectorial controls "IVControls", in order for them to share a common style If you need more flexibility, you&#39;re on your own!
Definition: IControl.h:624
A struct encapsulating a set of properties used to configure IVControls.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196