iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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
23BEGIN_IPLUG_NAMESPACE
24BEGIN_IGRAPHICS_NAMESPACE
25
28template <int MAXNC = 1, int MAXBUF = 128>
30 , public IVectorBase
31{
32public:
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 for (int c=0; c<mBuf.nChans; c++)
61 {
62 // drawdata expects normalized values and buffer contains unnormalized, so draw in the top half
63 g.DrawData(GetColor(kFG), r.FracRectVertical(0.5, true), mBuf.vals[c].data(), mBufferSize, nullptr, &mBlend, mTrackSize);
64 }
65 }
66
67 void OnResize() override
68 {
70 SetDirty(false);
71 }
72
73 void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override
74 {
75 if (!IsDisabled() && msgTag == ISender<>::kUpdateMessage)
76 {
77 IByteStream stream(pData, dataSize);
78
79 int pos = 0;
80 pos = stream.Get(&mBuf, pos);
81
82 SetDirty(false);
83 }
84 }
85
86 void SetBufferSize(int bufferSize)
87 {
88 assert(bufferSize > 0);
89 assert(bufferSize <= MAXBUF);
90 mBufferSize = bufferSize;
91 }
92
93private:
95 float mPadding = 2.f;
96 int mBufferSize = MAXBUF;
97};
98
99END_IGRAPHICS_NAMESPACE
100END_IPLUG_NAMESPACE
101
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:268
int Get(T *pDst, int startPos) const
Get arbitary typed data from the stream.
Definition: IPlugStructs.h:289
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
bool IsDisabled() const
Definition: IControl.h:362
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control.
Definition: IControl.h:323
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2497
virtual void DrawData(const IColor &color, const IRECT &bounds, float *normYPoints, int nPoints, float *normXPoints=nullptr, const IBlend *pBlend=0, float thickness=1.f, const IColor *pFillColor=nullptr)
Draw a line between a collection of normalized points.
Definition: IGraphics.cpp:2450
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:794
ISender is a utility class which can be used to defer data from the realtime audio processing and sen...
Definition: ISender.h:65
Vectorial multi-channel capable oscilloscope control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
IVScopeControl(const IRECT &bounds, const char *label="", const IVStyle &style=DEFAULT_STYLE)
Constructs an IVScopeControl.
void OnMsgFromDelegate(int msgTag, int dataSize, const void *pData) override
Implement to receive messages sent to the control, see IEditorDelegate:SendControlMsgFromDelegate()
void DrawWidget(IGraphics &g) override
Draw the IVControl main widget (override)
A base interface to be combined with IControl for vectorial controls "IVControls",...
Definition: IControl.h:757
IRECT MakeRects(const IRECT &parent, bool hasHandle=false)
Calculate the rectangles for the various areas, depending on the style.
Definition: IControl.h:1158
virtual void DrawBackground(IGraphics &g, const IRECT &rect)
Draw the IVControl background (usually transparent)
Definition: IControl.h:876
void AttachIControl(IControl *pControl, const char *label)
Call in the constructor of your IVControl to link the IVectorBase and IControl.
Definition: IControl.h:775
virtual void DrawLabel(IGraphics &g)
Draw the IVControl label text.
Definition: IControl.h:889
const IColor & GetColor(EVColor color) const
Get value of a specific EVColor in the IVControl.
Definition: IControl.h:801
Used to manage a rectangular area, independent of draw class/platform.
IRECT FracRectVertical(float frac, bool fromTop=false) const
Returns a new IRECT with a height that is multiplied by frac.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
ISenderData is used to represent a typed data packet, that may contain values for multiple channels.
Definition: ISender.h:34
A struct encapsulating a set of properties used to configure IVControls.