Skip to content

Commit

Permalink
Format Examples/Test src
Browse files Browse the repository at this point in the history
  • Loading branch information
olilarkin committed Mar 26, 2023
1 parent b9208ae commit 3e6e052
Show file tree
Hide file tree
Showing 59 changed files with 1,175 additions and 1,655 deletions.
58 changes: 27 additions & 31 deletions Examples/IPlugChunks/IPlugChunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ IPlugChunks::IPlugChunks(const InstanceInfo& info)
GetParam(kParamGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%");

#if IPLUG_EDITOR // http://bit.ly/2S64BDd
mMakeGraphicsFunc = [&]() {
return MakeGraphics(*this, PLUG_WIDTH, PLUG_HEIGHT, PLUG_FPS, GetScaleForScreen(PLUG_WIDTH, PLUG_HEIGHT));
};

mMakeGraphicsFunc = [&]() { return MakeGraphics(*this, PLUG_WIDTH, PLUG_HEIGHT, PLUG_FPS, GetScaleForScreen(PLUG_WIDTH, PLUG_HEIGHT)); };

mLayoutFunc = [&](IGraphics* pGraphics) {
pGraphics->AttachCornerResizer(EUIResizerMode::Scale, false);
pGraphics->AttachPanelBackground(COLOR_GRAY);
Expand All @@ -21,10 +19,10 @@ IPlugChunks::IPlugChunks(const InstanceInfo& info)
const IVStyle style = DEFAULT_STYLE.WithDrawShadows(false);
pGraphics->AttachControl(new IVBakedPresetManagerControl(b.ReduceFromTop(30.f), style));
pGraphics->AttachControl(new IVMultiSliderControl<kNumSteps>(b, "", style), kCtrlMultiSlider)->SetActionFunction([pGraphics](IControl* pCaller) {

double vals[kNumSteps];

for (int i = 0; i < kNumSteps; i++) {
for (int i = 0; i < kNumSteps; i++)
{
vals[i] = pCaller->GetValue(i);
}
pGraphics->GetDelegate()->SendArbitraryMsgFromUI(kMsgTagSliderChanged, kCtrlMultiSlider, sizeof(vals), &vals);
Expand All @@ -33,81 +31,79 @@ IPlugChunks::IPlugChunks(const InstanceInfo& info)
#endif
}

bool IPlugChunks::SerializeState(IByteChunk &chunk) const
bool IPlugChunks::SerializeState(IByteChunk& chunk) const
{
// serialize the multislider state state before serializing the regular params
for (int i = 0; i< kNumSteps; i++)
for (int i = 0; i < kNumSteps; i++)
{
chunk.Put(&mSteps[i]);
}

return SerializeParams(chunk); // must remember to call SerializeParams at the end
}

// this over-ridden method is called when the host is trying to load the plug-in state and you need to unpack the data into your algorithm
int IPlugChunks::UnserializeState(const IByteChunk &chunk, int startPos)
int IPlugChunks::UnserializeState(const IByteChunk& chunk, int startPos)
{
double v = 0.;

// unserialize the steps state before unserializing the regular params
for (int i = 0; i< kNumSteps; i++)
for (int i = 0; i < kNumSteps; i++)
{
startPos = chunk.Get(&v, startPos);
mSteps[i] = v;
}

// If UI exists
if(GetUI())
if (GetUI())
UpdateUIControls();

// must remember to call UnserializeParams at the end
return UnserializeParams(chunk, startPos);
}

#if IPLUG_DSP
void IPlugChunks::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
int samplesPerBeat = (int) GetSamplesPerBeat();
int samplePos = (int) GetSamplePos();
int samplesPerBeat = (int)GetSamplesPerBeat();
int samplePos = (int)GetSamplePos();

for (int s = 0; s < nFrames; s++)
{
int mod = (samplePos + s) % (samplesPerBeat * kBeatDiv);

mStepPos = mod / (samplesPerBeat / kBeatDiv);

if (mStepPos >= kNumSteps)
{
mStepPos = 0;
}

for (int c = 0; c < 2; c++) {

for (int c = 0; c < 2; c++)
{
outputs[c][s] = inputs[c][s];
}
}
}
#endif

void IPlugChunks::OnUIOpen()
{
UpdateUIControls();
}
void IPlugChunks::OnUIOpen() { UpdateUIControls(); }

void IPlugChunks::UpdateUIControls()
{
auto* pMultiSlider = GetUI()->GetControlWithTag(kCtrlMultiSlider);
for (int i = 0; i< kNumSteps; i++)

for (int i = 0; i < kNumSteps; i++)
{
pMultiSlider->SetValue(mSteps[i], i);
}

GetUI()->SetAllControlsDirty();
}

bool IPlugChunks::OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData)
{
if(msgTag == kMsgTagSliderChanged)
if (msgTag == kMsgTagSliderChanged)
{
auto* pVals = reinterpret_cast<const double*>(pData);
memcpy(mSteps, pVals, kNumSteps * sizeof(double));
Expand All @@ -118,7 +114,7 @@ bool IPlugChunks::OnMessage(int msgTag, int ctrlTag, int dataSize, const void* p

void IPlugChunks::OnIdle()
{
if(mStepPos != mPrevPos)
if (mStepPos != mPrevPos)
{
mPrevPos = mStepPos;
SendControlMsgFromDelegate(kCtrlMultiSlider, IVMultiSliderControl<>::kMsgTagSetHighlight, sizeof(int), &mPrevPos);
Expand Down
12 changes: 6 additions & 6 deletions Examples/IPlugChunks/IPlugChunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ class IPlugChunks final : public Plugin
public:
IPlugChunks(const InstanceInfo& info);

bool SerializeState(IByteChunk &chunk) const override;
int UnserializeState(const IByteChunk &chunk, int startPos) override;
// bool CompareState(const uint8_t* pIncomingState, int startPos) const override;
bool SerializeState(IByteChunk& chunk) const override;
int UnserializeState(const IByteChunk& chunk, int startPos) override;
// bool CompareState(const uint8_t* pIncomingState, int startPos) const override;

void OnIdle() override;
void OnUIOpen() override;
bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) override;

#if IPLUG_DSP // http://bit.ly/2S64BDd
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
#endif

private:
void UpdateUIControls();

std::atomic<int> mStepPos;
int mPrevPos = -1;
double mSteps[kNumSteps] = {};
Expand Down
4 changes: 2 additions & 2 deletions Examples/IPlugChunks/resources/AUv3Framework.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <TargetConditionals.h>
#if TARGET_OS_IOS == 1
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#import <Cocoa/Cocoa.h>
#endif

//! Project version number for AUv3Framework.
Expand Down
4 changes: 2 additions & 2 deletions Examples/IPlugCocoaUI/IPlugCocoaUI-Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const NSInteger kNumPresets = 3;
const NSInteger kParamGain = 0;
const NSInteger kNumParams = 1;

//tags in interface builder default to 0, so avoid using that control tag
// tags in interface builder default to 0, so avoid using that control tag
const NSInteger kCtrlTagVolumeSlider = 1;
const NSInteger kCtrlTagButton = 2;
const NSInteger kCtrlTagVUMeter = 3;
Expand All @@ -15,7 +15,7 @@ const NSInteger kUpdateMessage = 0;
const NSInteger kMsgTagHello = 1;
const NSInteger kMsgTagRestorePreset = 2;

const NSInteger kDataPacketSize = 1024; //floats
const NSInteger kDataPacketSize = 1024; // floats


#endif
7 changes: 3 additions & 4 deletions Examples/IPlugCocoaUI/IPlugCocoaUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ class IPlugCocoaUI final : public Plugin
public:
IPlugCocoaUI(const InstanceInfo& info);
~IPlugCocoaUI();

void* OpenWindow(void* pParent) override;

void OnParentWindowResize(int width, int height) override;
bool OnHostRequestingSupportedViewConfiguration(int width, int height) override;
bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) override;
void OnParamChange(int paramIdx) override;
void OnIdle() override;
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;

private:

IPeakSender<> mSender;
};
4 changes: 2 additions & 2 deletions Examples/IPlugCocoaUI/resources/AUv3Framework.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <TargetConditionals.h>
#if TARGET_OS_IOS == 1
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#import <Cocoa/Cocoa.h>
#endif

#import <AUv3Framework/IPlugCocoaViewController.h>
Expand Down

0 comments on commit 3e6e052

Please sign in to comment.