1 /*
2  * DISTRHO glBars Plugin based on XMMS/XBMC "GL Bars"
3  * Copyright (C) 1998-2000  Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
4  * Copyright (C) 2000 Christian Zander <phoenix@minion.de>
5  * Copyright (C) 2015 Nedko Arnaudov
6  * Copyright (C) 2016 Filipe Coelho <falktx@falktx.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * For a full copy of the license see the LICENSE file.
19  */
20 
21 #include "DistrhoPluginGLBars.hpp"
22 
23 #include "glBars.hpp"
24 
25 START_NAMESPACE_DISTRHO
26 
27 // -----------------------------------------------------------------------
28 
DistrhoPluginGLBars()29 DistrhoPluginGLBars::DistrhoPluginGLBars()
30     : Plugin(kParameterCount, 0, 0),
31       fState(nullptr)
32 {
33     fParameters[kParameterScale] = 1.f / log(256.f);
34     fParameters[kParameterSpeed] = 0.025f;
35     fParameters[kParameterX]     = 0.0f;
36     fParameters[kParameterY]     = 0.5f;
37     fParameters[kParameterZ]     = 0.0f;
38 }
39 
~DistrhoPluginGLBars()40 DistrhoPluginGLBars::~DistrhoPluginGLBars()
41 {
42     DISTRHO_SAFE_ASSERT(fState == nullptr);
43 }
44 
45 // -----------------------------------------------------------------------
46 // Init
47 
initParameter(uint32_t index,Parameter & parameter)48 void DistrhoPluginGLBars::initParameter(uint32_t index, Parameter& parameter)
49 {
50     switch (index)
51     {
52     case kParameterScale:
53         parameter.hints      = kParameterIsAutomable|kParameterIsLogarithmic;
54         parameter.name       = "Scale";
55         parameter.symbol     = "scale";
56         parameter.unit       = "";
57         parameter.ranges.def = 1.0f / log(256.f);
58         parameter.ranges.min = 0.5f / log(256.f);
59         parameter.ranges.max = 3.0f / log(256.f);
60         break;
61 
62     case kParameterSpeed:
63         parameter.hints      = kParameterIsAutomable|kParameterIsLogarithmic;
64         parameter.name       = "Speed";
65         parameter.symbol     = "speed";
66         parameter.unit       = "";
67         parameter.ranges.def = 0.025f;
68         parameter.ranges.min = 0.0125f;
69         parameter.ranges.max = 0.1f;
70         break;
71 
72     case kParameterX:
73         parameter.hints      = kParameterIsAutomable;
74         parameter.name       = "X";
75         parameter.symbol     = "x";
76         parameter.unit       = "";
77         parameter.ranges.def = -4.0f;
78         parameter.ranges.min = 0.0f;
79         parameter.ranges.max = 4.0f;
80         break;
81 
82     case kParameterY:
83         parameter.hints      = kParameterIsAutomable;
84         parameter.name       = "Y";
85         parameter.symbol     = "y";
86         parameter.unit       = "";
87         parameter.ranges.def = 0.5f;
88         parameter.ranges.min = -4.0f;
89         parameter.ranges.max = 4.0f;
90         break;
91 
92     case kParameterZ:
93         parameter.hints      = kParameterIsAutomable;
94         parameter.name       = "Z";
95         parameter.symbol     = "z";
96         parameter.unit       = "";
97         parameter.ranges.def = 0.0f;
98         parameter.ranges.min = -4.0f;
99         parameter.ranges.max = 4.0f;
100         break;
101     }
102 }
103 
104 // -----------------------------------------------------------------------
105 // Internal data
106 
getParameterValue(uint32_t index) const107 float DistrhoPluginGLBars::getParameterValue(uint32_t index) const
108 {
109     if (index >= kParameterCount)
110         return 0.0f;
111 
112     return fParameters[index];
113 }
114 
setParameterValue(uint32_t index,float value)115 void DistrhoPluginGLBars::setParameterValue(uint32_t index, float value)
116 {
117     if (index >= kParameterCount)
118         return;
119 
120     fParameters[index] = value;
121 }
122 
123 // -----------------------------------------------------------------------
124 // Process
125 
run(const float ** inputs,float ** outputs,uint32_t frames)126 void DistrhoPluginGLBars::run(const float** inputs, float** outputs, uint32_t frames)
127 {
128     const float* in  = inputs[0];
129     float*       out = outputs[0];
130 
131     if (out != in)
132         std::memcpy(out, in, sizeof(float)*frames);
133 
134     const MutexLocker csm(fMutex);
135 
136     if (fState != nullptr)
137         fState->AudioData(in, frames);
138 }
139 
140 // -----------------------------------------------------------------------
141 
createPlugin()142 Plugin* createPlugin()
143 {
144     return new DistrhoPluginGLBars();
145 }
146 
147 // -----------------------------------------------------------------------
148 
149 END_NAMESPACE_DISTRHO
150