-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
141 lines (119 loc) · 3.55 KB
/
Application.cpp
File metadata and controls
141 lines (119 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "IPlug_include_in_plug_src.h"
#include "IControls.h"
#include "config.h"
#include "Core/OSMPEngine.hpp"
#include "Graphic/OSMPGui.hpp"
using namespace iplug;
using namespace igraphics;
class OpenSampler final : public Plugin
{
public:
OpenSampler(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
{
mEngine = std::make_unique<OpenSampler::OSMPEngine>();
GetParam(kParamGain)->InitDouble("Gain", 0.8, 0.0, 1.0, 0.01, "%");
GetParam(kParamAttack)->InitDouble("Attack", 0.01, 0.001, 2.0, 0.001, "s");
GetParam(kParamDecay)->InitDouble("Decay", 0.1, 0.001, 2.0, 0.001, "s");
GetParam(kParamSustain)->InitDouble("Sustain", 0.7, 0.0, 1.0, 0.01, "%");
GetParam(kParamRelease)->InitDouble("Release", 0.2, 0.001, 5.0, 0.001, "s");
#if IPLUG_EDITOR
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_DARK_GRAY);
pGraphics->LoadFont("Inter-Regular", INTER_REGULAR_FN);
pGraphics->LoadFont("Inter-Bold", INTER_BOLD_FN);
pGraphics->LoadFont("Inter-SemiBold", INTER_SEMIBOLD_FN);
pGraphics->LoadFont("Inter-Medium", INTER_MEDIUM_FN);
pGraphics->LoadFont("Inter-Light", INTER_LIGHT_FN);
const IRECT b = pGraphics->GetBounds();
mGui = std::make_unique<OpenSampler::OSMPGui>(pGraphics, mEngine.get());
mGui->CreateControls();
};
#endif
}
#if IPLUG_DSP
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override
{
const int nChans = NOutChansConnected();
if (mEngine) {
mEngine->ProcessBlock(outputs, nFrames, nChans);
}
}
void OnReset() override
{
if (mEngine) {
mEngine->Init(GetSampleRate(), GetBlockSize());
}
}
void ProcessMidiMsg(const IMidiMsg& msg) override
{
TRACE;
if (!mEngine) return;
switch (msg.StatusMsg())
{
case IMidiMsg::kNoteOn:
if (msg.Velocity() > 0) {
mEngine->NoteOn(msg.NoteNumber(), msg.Velocity());
} else {
mEngine->NoteOff(msg.NoteNumber());
}
break;
case IMidiMsg::kNoteOff:
mEngine->NoteOff(msg.NoteNumber());
break;
case IMidiMsg::kControlChange:
if (msg.ControlChangeIdx() == IMidiMsg::kAllNotesOff) {
mEngine->AllNotesOff();
}
break;
default:
break;
}
SendMidiMsg(msg);
}
void OnParamChange(int paramIdx) override
{
if (!mEngine) return;
switch (paramIdx)
{
case kParamGain:
mEngine->SetMasterVolume(GetParam(kParamGain)->Value());
break;
case kParamAttack:
mEngine->SetAttack(GetParam(kParamAttack)->Value());
break;
case kParamDecay:
mEngine->SetDecay(GetParam(kParamDecay)->Value());
break;
case kParamSustain:
mEngine->SetSustain(GetParam(kParamSustain)->Value());
break;
case kParamRelease:
mEngine->SetRelease(GetParam(kParamRelease)->Value());
break;
default:
break;
}
}
#endif
private:
enum EParams
{
kParamGain = 0,
kParamAttack,
kParamDecay,
kParamSustain,
kParamRelease,
kNumParams
};
enum EPresets
{
kNumPresets = 1
};
std::unique_ptr<OpenSampler::OSMPEngine> mEngine;
std::unique_ptr<OpenSampler::OSMPGui> mGui;
};