Guitarix
gx_internal_ui_plugins.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  *
20  *
21  * This is part of the Guitarix Audio Engine
22  *
23  *
24  *
25  * --------------------------------------------------------------------------
26  */
27 
28 #include "engine.h"
29 
30 namespace gx_engine {
31 
32 /****************************************************************
33  ** MonoMute, StereoMute, MaxLevel
34  */
35 
37  : PluginDef() {
39  id = "monomute";
40  name = "?monomute";
41  mono_audio = process;
42 }
43 
44 void MonoMute::process(int count, float *input, float *output, PluginDef*) {
45  (void)memset(output, 0, count*sizeof(float));
46 }
47 
49  : PluginDef() {
51  id = "stereomute";
52  name = "?stereomute";
53  stereo_audio = process;
54 }
55 
56 void StereoMute::process(int count, float *input0, float *input1,
57  float *output0, float *output1, PluginDef*) {
58  (void)memset(output0, 0, count*sizeof(float));
59  (void)memset(output1, 0, count*sizeof(float));
60 }
61 
63  : PluginDef() {
65  flags = PGN_SNOOP;
66  id = "maxlevel";
67  name = "?maxlevel";
68  stereo_audio = process;
69  activate_plugin = activate;
70 }
71 
72 float MaxLevel::maxlevel[channelcount] = {0};
73 
74 void MaxLevel::process(int count, float *input1, float *input2, float*, float*, PluginDef*) {
75  const float *data[channelcount] = {input1, input2};
76  assert(channelcount == 2);
77  for (unsigned int c = 0; c < channelcount; c++) {
78  float level = 0;
79  for (int i = 0; i < count; i++) {
80  float t = abs(data[c][i]);
81  if (level < t) {
82  level = t;
83  }
84  }
85  maxlevel[c] = max(maxlevel[c], level);
86  }
87 }
88 
89 int MaxLevel::activate(bool start, PluginDef *plugin) {
90  if (!start) {
91  for (unsigned int c = 0; c < channelcount; c++) {
92  maxlevel[c] = 0;
93  }
94  }
95  return 0;
96 }
97 
98 
99 /****************************************************************
100  ** class TunerAdapter
101  */
102 
104  : ModuleSelector(engine_),
105  PluginDef(),
106  trackable(),
107  pitch_tracker(),
108  state(),
109  engine(engine_),
110  dep_plugin(),
111  plugin() {
113  flags = PGN_SNOOP;
114  id = "tuner";
115  name = "Rack Tuner";
116  mono_audio = feed_tuner;
117  set_samplerate = init;
118  activate_plugin = activate;
119  register_params = regparam;
120  plugin.set_pdef(this);
121 }
122 
123 void TunerAdapter::init(unsigned int samplingFreq, PluginDef *plugin) {
124  TunerAdapter& self = *static_cast<TunerAdapter*>(plugin);
125  int priority, policy;
126  // zita-convoler uses 5 levels, so substract 6
127  self.engine.get_sched_priority(policy, priority, 6);
128  self.pitch_tracker.init(policy, priority, samplingFreq);
129 }
130 
131 void TunerAdapter::set_and_check(int use, bool on) {
132  if (on) {
133  state |= use;
134  } else {
135  state &= ~use;
136  }
137  if (plugin.get_on_off() != bool(state)) {
138  plugin.set_on_off(bool(state));
139  engine.set_rack_changed();
140  }
141  if (use == switcher_use) {
142  pitch_tracker.set_fast_note_detection(on);
143  }
144 }
145 
146 int TunerAdapter::activate(bool start, PluginDef *plugin) {
147  if (!start) {
148  static_cast<TunerAdapter*>(plugin)->pitch_tracker.reset();
149  }
150  return 0;
151 }
152 
153 void TunerAdapter::feed_tuner(int count, float* input, float*, PluginDef* plugin) {
154  static_cast<TunerAdapter*>(plugin)->pitch_tracker.add(count, input);
155 }
156 
157 int TunerAdapter::regparam(const ParamReg& reg) {
158  TunerAdapter* a = static_cast<TunerAdapter*>(reg.plugin);
159  a->plugin.set_on_off(false);
160  return 0;
161 }
162 
164  if (dep_plugin) {
165  used_by_midi(dep_plugin->get_on_off());
166  }
167 }
168 
169 
170 /****************************************************************
171  ** class OscilloscopeAdapter
172  */
173 
175  : PluginDef(),
176  mul_buffer(1),
177  plugin(),
178  activation(),
179  size_change()
180 {
181  assert(buffer == 0);
184  id = "oscilloscope";
185  name = N_("Oscilloscope");
186  category = N_("Misc");
187  mono_audio = fill_buffer;
188  activate_plugin = activate;
189  plugin.set_pdef(this);
190  engine.signal_buffersize_change().connect(
191  sigc::mem_fun(*this, &OscilloscopeAdapter::change_buffersize));
192 }
193 
194 int OscilloscopeAdapter::osc_register(const ParamReg& reg) {
195 
196  return 0;
197 }
198 
199 void OscilloscopeAdapter::change_buffersize(unsigned int size_) {
200  //FIXME waveview display needs mutex
201  size_change(0);
202  float *b = buffer;
203  unsigned int d = mul_buffer;
204  if (size_ > 1023) d = 1;
205  buffer = new float[size_ * d];
206  size = size_* d;
207  clear_buffer();
208  size_change(size_* d);
209  delete b;
210 }
211 
212 float* OscilloscopeAdapter::buffer = 0;
213 unsigned int OscilloscopeAdapter::size = 0;
214 
215 // rt process function
216 void OscilloscopeAdapter::fill_buffer(int count, float *input0, float *output0, PluginDef *p) {
217  OscilloscopeAdapter& self = *static_cast<OscilloscopeAdapter*>(p);
218  if (count*self.mul_buffer != static_cast<int>(size)) {
219  return;
220  }
221  if (self.mul_buffer > 1) {
222  (void)memmove(buffer, &buffer[count], sizeof(float)*count*(self.mul_buffer-1));
223  }
224  (void)memcpy(&buffer[count*(self.mul_buffer-1)], output0, sizeof(float)*count);
225 }
226 
227 int OscilloscopeAdapter::activate(bool start, PluginDef *plugin) {
228  return static_cast<OscilloscopeAdapter*>(plugin)->activation(start);
229 }
230 
232  memset(buffer, 0, size*sizeof(float));
233 }
234 
235 } // namespace gx_engine
CmdConnection::msg_type start
Definition: jsonrpc.cpp:255
OscilloscopeAdapter(ModuleSequencer &engine)
void get_sched_priority(int &policy, int &priority, int prio_dim=0)
PluginDef * plugin
Definition: gx_plugin.h:123
#define N_(String)
const char * name
Definition: gx_plugin.h:186
static const unsigned int channelcount
void set_fast_note_detection(bool v)
void set_on_off(bool v) const
TunerAdapter(ModuleSequencer &engine)
const char * category
Definition: gx_plugin.h:190
sigc::signal< int, bool > activation
#define PLUGINDEF_VERSION
Definition: gx_plugin.h:179
registerfunc register_params
Definition: gx_plugin.h:200
#define max(x, y)
int flags
Definition: gx_plugin.h:183
sigc::signal< void, unsigned int > size_change
activatefunc activate_plugin
Definition: gx_plugin.h:199
process_stereo_audio stereo_audio
Definition: gx_plugin.h:196
void add(int count, float *input)
inifunc set_samplerate
Definition: gx_plugin.h:198
process_mono_audio mono_audio
Definition: gx_plugin.h:195
bool get_on_off() const
int version
Definition: gx_plugin.h:182
sigc::signal< void, unsigned int > & signal_buffersize_change()