LMMS
Loading...
Searching...
No Matches
DistrhoPluginPingPongPan.cpp
Go to the documentation of this file.
1/*
2 * DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
3 * Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
4 * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For a full copy of the license see the LICENSE file.
16 */
17
18#include "DistrhoPluginPingPongPan.hpp"
19
20#include <cmath>
21
22static const float k2PI = 6.283185307f;
23
25
26// -----------------------------------------------------------------------
27
28DistrhoPluginPingPongPan::DistrhoPluginPingPongPan()
29 : Plugin(paramCount, 1, 0) // 1 program, 0 states
30{
31 // set default values
32 loadProgram(0);
33
34 // reset
35 deactivate();
36}
37
38// -----------------------------------------------------------------------
39// Init
40
41void DistrhoPluginPingPongPan::initParameter(uint32_t index, Parameter& parameter)
42{
43 switch (index)
44 {
45 case paramFreq:
46 parameter.hints = kParameterIsAutomatable;
47 parameter.name = "Frequency";
48 parameter.symbol = "freq";
49 parameter.ranges.def = 50.0f;
50 parameter.ranges.min = 0.0f;
51 parameter.ranges.max = 100.0f;
52 break;
53
54 case paramWidth:
55 parameter.hints = kParameterIsAutomatable;
56 parameter.name = "Width";
57 parameter.symbol = "width";
58 parameter.unit = "%";
59 parameter.ranges.def = 75.0f;
60 parameter.ranges.min = 0.0f;
61 parameter.ranges.max = 100.0f;
62 break;
63 }
64}
65
66void DistrhoPluginPingPongPan::initProgramName(uint32_t index, String& programName)
67{
68 if (index != 0)
69 return;
70
71 programName = "Default";
72}
73
74// -----------------------------------------------------------------------
75// Internal data
76
77float DistrhoPluginPingPongPan::getParameterValue(uint32_t index) const
78{
79 switch (index)
80 {
81 case paramFreq:
82 return fFreq;
83 case paramWidth:
84 return fWidth;
85 default:
86 return 0.0f;
87 }
88}
89
90void DistrhoPluginPingPongPan::setParameterValue(uint32_t index, float value)
91{
92 if (getSampleRate() <= 0.0)
93 return;
94
95 switch (index)
96 {
97 case paramFreq:
98 fFreq = value;
99 waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
100 break;
101 case paramWidth:
102 fWidth = value;
103 break;
104 }
105}
106
107void DistrhoPluginPingPongPan::loadProgram(uint32_t index)
108{
109 if (index != 0)
110 return;
111
112 // Default values
113 fFreq = 50.0f;
114 fWidth = 75.0f;
115
116 // reset filter values
117 activate();
118}
119
120// -----------------------------------------------------------------------
121// Process
122
123void DistrhoPluginPingPongPan::activate()
124{
125 waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
126}
127
128void DistrhoPluginPingPongPan::deactivate()
129{
130 wavePos = 0.0f;
131}
132
133void DistrhoPluginPingPongPan::run(const float** inputs, float** outputs, uint32_t frames)
134{
135 const float* in1 = inputs[0];
136 const float* in2 = inputs[1];
137 float* out1 = outputs[0];
138 float* out2 = outputs[1];
139
140 for (uint32_t i=0; i < frames; ++i)
141 {
142 pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f);
143
144 if ((wavePos += waveSpeed) >= k2PI)
145 wavePos -= k2PI;
146
147 out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f);
148 out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f);
149 }
150}
151
152// -----------------------------------------------------------------------
153
155{
156 return new DistrhoPluginPingPongPan();
157}
158
159// -----------------------------------------------------------------------
160
#define END_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:191
#define START_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:190
Plugin * createPlugin()
Definition DistrhoPluginPingPongPan.cpp:154
static const float k2PI
Definition DistrhoPluginPingPongPan.cpp:22
static void deactivate(LV2_Handle instance)
Definition bindings_test_plugin.c:128
Definition basics.h:174
Definition String.h:48
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate)=0
unsigned int uint32_t
Definition mid.cpp:100