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 the guitarix Engine namespace ------- */
22 
23 #pragma once
24 
25 
26 namespace gx_jack { class GxJack; }
27 
28 namespace gx_engine {
29 
30 /****************************************************************
31  ** MonoMute, StereoMute, MaxLevel
32  */
33 
34 class MonoMute: public PluginDef {
35 private:
36     static void process(int count, float *input, float *output, PluginDef*);
37 public:
38     MonoMute();
39 };
40 
41 class StereoMute: public PluginDef {
42 private:
43     static void process(int count, float *input0, float *input1,
44 			float *output0, float *output1, PluginDef*);
45 public:
46     StereoMute();
47 };
48 
49 class MaxLevel: public PluginDef {
50 public:
51     static const unsigned int channelcount = 2;
52 private:
53     static float maxlevel[channelcount];
54     static void process(int count, float *input0, float *input1,
55 			float *output0, float *output1, PluginDef*);
56     static int activate(bool start, PluginDef *plugin);
57     static int regparam(const ParamReg& reg);
58 public:
get(unsigned int channel)59     static float get(unsigned int channel) {
60 	assert(channel < channelcount);
61 	float v = maxlevel[channel];
62 	maxlevel[channel] = 0;
63 	return v;
64     }
65     MaxLevel();
66 };
67 
68 
69 /****************************************************************
70  ** class TunerAdapter
71  */
72 
73 #include "faust/low_high_cut.h"
74 
75 class TunerAdapter: public ModuleSelector, private PluginDef, public sigc::trackable {
76 private:
77     static void feed_tuner(int count, float *input, float *output, PluginDef*);
78     static int regparam(const ParamReg& reg);
79     static int activate(bool start, PluginDef *plugin);
80     static void init(unsigned int samplingFreq, PluginDef *plugin);
81     low_high_cut::Dsp lhc;
82     PitchTracker pitch_tracker;
83     int state;
84     ModuleSequencer& engine;
85     enum { tuner_use = 0x01, switcher_use = 0x02, midi_use = 0x04 };
86     void set_and_check(int use, bool on);
87     Plugin* dep_plugin;
88 public:
89     Plugin plugin;
90     TunerAdapter(ModuleSequencer& engine);
used_for_switching(bool on)91     void used_for_switching(bool on) { set_and_check(switcher_use, on); }
used_for_display(bool on)92     void used_for_display(bool on) { set_and_check(tuner_use, on); }
used_for_display()93     bool used_for_display() { return state & tuner_use; }
used_by_midi(bool on)94     void used_by_midi(bool on) { set_and_check(midi_use, on); }
set_dep_module(Plugin * dep)95     void set_dep_module(Plugin* dep) { dep_plugin = dep; }
96     void set_module();
signal_freq_changed()97     Glib::Dispatcher& signal_freq_changed() { return pitch_tracker.new_freq; }
get_freq()98     float get_freq() { return pitch_tracker.get_estimated_freq(); }
get_note()99     float get_note() { return pitch_tracker.get_estimated_note(); }
100 };
101 
102 
103 /****************************************************************
104  ** class NoiseGate
105  */
106 
107 class NoiseGate {
108 private:
109     static PluginDef inputdef;
110     static float fnglevel;
111     static float ngate;
112     static bool off;
113     static int noisegate_register(const ParamReg& reg);
114     static void inputlevel_compute(int count, float *input0, float *output0, PluginDef*);
115     static void outputgate_compute(int count, float *input, float *output, PluginDef*);
116     static int outputgate_activate(bool start, PluginDef *pdef);
117 public:
118     static Plugin inputlevel;
119     static PluginDef outputgate;
120     NoiseGate();
121 };
122 
123 
124 /****************************************************************
125  ** class OscilloscopeAdapter
126  */
127 
128 class OscilloscopeInfo {
129 private:
130     gx_jack::GxJack *jack;
131     sigc::signal<void(unsigned int, float*)> size_change;
132     float *buffer;
133     unsigned int buffer_size;
134     friend class OscilloscopeAdapter;
135 public:
136     int load;
137     int frames;
138     bool is_rt;
139     jack_nframes_t bsize;
140 
141  public:
OscilloscopeInfo()142     OscilloscopeInfo():
143         jack(nullptr), size_change(), buffer(nullptr), buffer_size(0),
144         load(0), frames(0), is_rt(false), bsize(0) {}
145     void readJSON(gx_system::JsonParser& jp);
146     void writeJSON(gx_system::JsonWriter& w) const;
147     void update();
get_buffer()148     float *get_buffer() const { return buffer; }
get_buffer_size()149     unsigned int get_buffer_size() const { return buffer_size; }
signal_size_change()150     sigc::signal<void(unsigned int, float*)> signal_size_change() { return size_change; }
151 };
152 
153 template<>
154 class ParameterV<OscilloscopeInfo>: public Parameter {
155 private:
156     OscilloscopeInfo value_storage;
157     OscilloscopeInfo *value;
158     sigc::signal<void, const OscilloscopeInfo&> changed;
159     void trigger_changed() override;
160 public:
161     ParameterV(const string& id, OscilloscopeInfo *v);
162     ParameterV(gx_system::JsonParser& jp);
163     ~ParameterV();
164     virtual void serializeJSON(gx_system::JsonWriter& jw) override;
signal_changed()165     sigc::signal<void, const OscilloscopeInfo&>& signal_changed() { return changed; }
166     static ParameterV<OscilloscopeInfo> *insert_param(
167         ParamMap &pmap, const string& id, OscilloscopeInfo *v);
get_value()168     OscilloscopeInfo& get_value() const { return *value; }
169     virtual void stdJSON_value() override;
170     virtual bool on_off_value() override;
171     virtual void writeJSON(gx_system::JsonWriter& jw) const override;
172     virtual bool compareJSON_value() override;
173     virtual void setJSON_value() override;
174     virtual void readJSON_value(gx_system::JsonParser& jp) override;
175 };
176 
177 typedef ParameterV<OscilloscopeInfo> OscParameter;
178 
179 class OscilloscopeAdapter: PluginDef {
180 public:
181     OscilloscopeInfo info;
182 private:
183     ParamMap &pmap;
184     static void fill_buffer(int count, float *input0, float *output0, PluginDef*);
185     static int osc_register(const ParamReg& reg);
186     static int osc_load_ui(const UiBuilder& builder, int format);
187     void change_buffersize(unsigned int);
188     int mul_buffer;
189 public:
190     Plugin plugin;
191     void clear_buffer();
get_size()192     unsigned int get_size() const { return info.buffer_size; }
get_buffer()193     inline float *get_buffer() const { return info.buffer; }
get_mul_buffer()194     int get_mul_buffer() { return mul_buffer; }
set_mul_buffer(int a,unsigned int b)195     void set_mul_buffer(int a, unsigned int b) { mul_buffer = a; change_buffersize(b); }
196     OscilloscopeAdapter(ModuleSequencer& engine);
set_jack(gx_jack::GxJack & jack)197     void set_jack(gx_jack::GxJack& jack) { info.jack = &jack; }
198 };
199 
200 
201 /****************************************************************
202  ** class GxSeqSettings
203  */
204 
205 class GxSeqSettings {
206  private:
207 
208     std::vector<int>        seqline;
209     void read_seqline(gx_system::JsonParser& jp);
210     friend class SequencerAdapter;
211     friend class ParameterV<GxSeqSettings>;
212  public:
213     GxSeqSettings();
214     GxSeqSettings& operator=(GxSeqSettings const& seqset);
215     bool operator==(const GxSeqSettings& seqset) const;
216     // getters and setters
getseqline()217     inline const std::vector<int>& getseqline() const    { return seqline; }
218 
setseqline(const std::vector<int> & seq)219     inline void setseqline(const std::vector<int>& seq) { seqline    = seq; }
220 
221  public:
222     void readJSON(gx_system::JsonParser& jp);
223     void writeJSON(gx_system::JsonWriter& w) const;
224 };
225 
226 template<>
227 class ParameterV<GxSeqSettings>: public Parameter {
228 private:
229     GxSeqSettings json_value;
230     GxSeqSettings *value;
231     GxSeqSettings std_value;
232     GxSeqSettings value_storage;
233     sigc::signal<void, const GxSeqSettings*> changed;
234 public:
235     ParameterV(const string& id, GxSeqSettings *v);
236     ParameterV(gx_system::JsonParser& jp);
237     ~ParameterV();
238     virtual void serializeJSON(gx_system::JsonWriter& jw);
signal_changed()239     sigc::signal<void, const GxSeqSettings*>& signal_changed() { return changed; }
240     static ParameterV<GxSeqSettings> *insert_param(
241 	ParamMap &pmap, const string& id, GxSeqSettings *v);
242     bool set(const GxSeqSettings& val) const;
get_value()243     const GxSeqSettings& get_value() const { return *value; }
244     virtual void stdJSON_value();
245     virtual bool on_off_value();
246     virtual void writeJSON(gx_system::JsonWriter& jw) const;
247     virtual bool compareJSON_value();
248     virtual void setJSON_value();
249     virtual void readJSON_value(gx_system::JsonParser& jp);
250 };
251 
252 typedef ParameterV<GxSeqSettings> SeqParameter;
253 
254 /****************************************************************
255  ** class GxJConvSettings
256  */
257 
258 class GxJConvSettings {
259  private:
260     // main jconv setting
261     std::string     fIRFile;
262     std::string     fIRDir;
263 
264     float           fGain;       // jconv gain
265     guint           fOffset;     // offset in IR where to start comvolution
266     guint           fLength;     // length of the IR to use for convolution
267     guint           fDelay;      // delay when to apply reverb
268     Gainline        gainline;
269     bool            fGainCor;
270     void read_gainline(gx_system::JsonParser& jp);
setIRDir(string name)271     inline void setIRDir(string name)             { fIRDir = name; }
272     friend class ConvolverAdapter;
273     friend class ParameterV<GxJConvSettings>;
274  public:
275     GxJConvSettings();
276     GxJConvSettings& operator=(GxJConvSettings const& jcset);
277     bool operator==(const GxJConvSettings& jcset) const;
278     // getters and setters
getIRFile()279     inline const std::string& getIRFile() const   { return fIRFile; }
280     std::string getFullIRPath() const;
getGain()281     inline float           getGain() const        { return fGain; }
getOffset()282     inline guint           getOffset() const      { return fOffset; }
getLength()283     inline guint           getLength() const      { return fLength; }
getDelay()284     inline guint           getDelay() const       { return fDelay; }
getGainCor()285     inline bool            getGainCor() const     { return fGainCor; }
getGainline()286     inline const Gainline& getGainline() const    { return gainline; }
getIRDir()287     const std::string& getIRDir() const           { return fIRDir; }
288     void setFullIRPath(string name);
setIRFile(string name)289     inline void setIRFile(string name)            { fIRFile = name; }
setGain(float gain)290     inline void setGain(float gain)               { fGain       = gain; }
setGainCor(bool gain)291     inline void setGainCor(bool gain)             { fGainCor    = gain; }
setOffset(guint offs)292     inline void setOffset(guint offs)             { fOffset     = offs; }
setLength(guint leng)293     inline void setLength(guint leng)             { fLength     = leng; }
setDelay(guint del)294     inline void setDelay(guint del)               { fDelay      = del;  }
setGainline(const Gainline & gain)295     inline void setGainline(const Gainline& gain) { gainline    = gain; }
296 
297  public:
298     void readJSON(gx_system::JsonParser& jp);
299     void writeJSON(gx_system::JsonWriter& w) const;
300 };
301 
302 class ConvolverAdapter;
303 
304 template<>
305 class ParameterV<GxJConvSettings>: public Parameter {
306 private:
307     GxJConvSettings json_value;
308     GxJConvSettings *value;
309     GxJConvSettings std_value;
310     GxJConvSettings value_storage;
311     sigc::signal<void, const GxJConvSettings*> changed;
312 public:
313     ParameterV(const string& id, ConvolverAdapter &conv, GxJConvSettings *v);
314     ParameterV(gx_system::JsonParser& jp);
315     ~ParameterV();
316     virtual void serializeJSON(gx_system::JsonWriter& jw);
signal_changed()317     sigc::signal<void, const GxJConvSettings*>& signal_changed() { return changed; }
318     static ParameterV<GxJConvSettings> *insert_param(
319 	ParamMap &pmap, const string& id, ConvolverAdapter &conv, GxJConvSettings *v);
320     bool set(const GxJConvSettings& val) const;
get_value()321     const GxJConvSettings& get_value() const { return *value; }
322     virtual void stdJSON_value();
323     virtual bool on_off_value();
324     virtual void writeJSON(gx_system::JsonWriter& jw) const;
325     virtual bool compareJSON_value();
326     virtual void setJSON_value();
327     virtual void readJSON_value(gx_system::JsonParser& jp);
328 };
329 
330 typedef ParameterV<GxJConvSettings> JConvParameter;
331 
332 
333 /****************************************************************
334  ** class ConvolverAdapter
335  */
336 
337 class ConvolverAdapter: protected PluginDef, public sigc::trackable {
338 protected:
339     GxConvolver conv;
340     boost::mutex activate_mutex;
341     EngineControl& engine;
342     sigc::slot<void> sync;
343     bool activated;
344     // wrapper for the rack order function pointers
345     void change_buffersize(unsigned int size);
346     GxJConvSettings jcset;
347     JConvParameter *jcp;
348 public:
349     Plugin plugin;
350 public:
351     ConvolverAdapter(EngineControl& engine, sigc::slot<void> sync);
352     ~ConvolverAdapter();
353     void restart();
354     bool conv_start();
getIRFile()355     inline const std::string& getIRFile() const { return jcset.getIRFile(); }
set_sync(bool val)356     inline void set_sync(bool val) { conv.set_sync(val); }
getFullIRPath()357     inline std::string getFullIRPath() const { return jcset.getFullIRPath(); }
getIRDir()358     inline const std::string& getIRDir() const { return jcset.getIRDir(); }
set(const GxJConvSettings & jcset)359     bool set(const GxJConvSettings& jcset) const { return jcp->set(jcset); }
get_jcset()360     const GxJConvSettings& get_jcset() const { return jcset; }
get_parameter_map()361     ParamMap& get_parameter_map() const { return engine.get_param(); }
362 };
363 
364 
365 /****************************************************************
366  ** class ConvolverStereoAdapter
367  */
368 
369 #include "faust/jconv_post.h"
370 #include "faust/jconv_post_mono.h"
371 
372 class ConvolverStereoAdapter: public ConvolverAdapter {
373 private:
374     jconv_post::Dsp jc_post;
375     // wrapper for the rack order function pointers
376     static void convolver_init(unsigned int samplingFreq, PluginDef *pdef);
377     static int activate(bool start, PluginDef *pdef);
378     static void convolver(int count, float *input0, float *input1,
379 			  float *output0, float *output1, PluginDef*);
380     static int convolver_register(const ParamReg& reg);
381     static int jconv_load_ui(const UiBuilder& builder, int format);
382 public:
383     ConvolverStereoAdapter(EngineControl& engine, sigc::slot<void> sync);
384     ~ConvolverStereoAdapter();
385 };
386 
387 
388 /****************************************************************
389  ** class ConvolverMonoAdapter
390  */
391 
392 class ConvolverMonoAdapter: public ConvolverAdapter {
393 private:
394     jconv_post_mono::Dsp jc_post_mono;
395     // wrapper for the rack order function pointers
396     static void convolver_init(unsigned int samplingFreq, PluginDef *pdef);
397     static int activate(bool start, PluginDef *pdef);
398     static void convolver(int count, float *input, float *output, PluginDef*);
399     static int convolver_register(const ParamReg& reg);
400     static int jconv_load_ui(const UiBuilder& builder, int format);
401 public:
402     ConvolverMonoAdapter(EngineControl& engine, sigc::slot<void> sync);
403     ~ConvolverMonoAdapter();
404 };
405 
406 
407 /****************************************************************
408  ** class BaseConvolver
409  */
410 
411 
412 class BaseConvolver: protected PluginDef {
413 protected:
414     GxSimpleConvolver conv;
415     boost::mutex activate_mutex;
416     EngineControl& engine;
417     sigc::slot<void> sync;
418     bool activated;
419     sigc::connection update_conn;
420     static void init(unsigned int samplingFreq, PluginDef *p);
421     static int activate(bool start, PluginDef *pdef);
422     void change_buffersize(unsigned int);
423     int conv_start();
424     bool check_update_timeout();
425     virtual void check_update() = 0;
426     virtual bool start(bool force = false) = 0;
427 public:
428     Plugin plugin;
429 public:
430     BaseConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
431     virtual ~BaseConvolver();
set_sync(bool val)432     inline void set_sync(bool val) { conv.set_sync(val); }
433 };
434 
435 /****************************************************************
436  ** class FixedBaseConvolver
437  */
438 
439 
440 class FixedBaseConvolver: protected PluginDef {
441 protected:
442     GxSimpleConvolver conv;
443     boost::mutex activate_mutex;
444     EngineControl& engine;
445     sigc::slot<void> sync;
446     bool activated;
447     unsigned int SamplingFreq;
448     unsigned int buffersize;
449     unsigned int bz;
450     sigc::connection update_conn;
451     static void init(unsigned int samplingFreq, PluginDef *p);
getSamplingFreq()452     unsigned int getSamplingFreq() { return SamplingFreq;};
453     static int activate(bool start, PluginDef *pdef);
454     void change_buffersize(unsigned int);
455     int conv_start();
456     bool check_update_timeout();
457     virtual void check_update() = 0;
458     virtual bool start(bool force = false) = 0;
459 public:
460     Plugin plugin;
461 public:
462     FixedBaseConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
463     virtual ~FixedBaseConvolver();
set_sync(bool val)464     inline void set_sync(bool val) { conv.set_sync(val); }
465 };
466 
467 /****************************************************************
468  ** class CabinetConvolver
469  */
470 
471 #include "faust/cabinet_impulse_former.h"
472 
473 class CabinetConvolver: public FixedBaseConvolver {
474 private:
475     int current_cab;
476     float level;
477     int cabinet;
478     float bass;
479     float treble;
480     float sum;
481     value_pair *cab_names;
482     cabinet_impulse_former::Dsp impf;
483     gx_resample::FixedRateResampler smp;
484     static void run_cab_conf(int count, float *input, float *output, PluginDef*);
485     static int register_cab(const ParamReg& reg);
486     bool do_update();
487     virtual void check_update();
488     virtual bool start(bool force = false);
cabinet_changed()489     bool cabinet_changed() { return current_cab != cabinet; }
update_cabinet()490     void update_cabinet() { current_cab = cabinet; }
sum_changed()491     bool sum_changed() { return std::abs(sum - (level + bass + treble)) > 0.01; }
update_sum()492     void update_sum() { sum = level + bass + treble; }
493 public:
494     CabinetConvolver(EngineControl& engine, sigc::slot<void> sync,
495        gx_resample::BufferResampler& resamp);
496     ~CabinetConvolver();
497 };
498 
499 #include "faust/cabinet_impulse_former_st.h"
500 
501 class CabinetStereoConvolver: public FixedBaseConvolver {
502 private:
503     int current_cab;
504     float level;
505     int cabinet;
506     float bass;
507     float treble;
508     float sum;
509     value_pair *cab_names;
510     cabinet_impulse_former_st::Dsp impf;
511     gx_resample::FixedRateResampler smp;
512     gx_resample::FixedRateResampler smps;
513     static void run_cab_conf(int count, float *input, float *input1, float *output, float *output1, PluginDef*);
514     static int register_cab(const ParamReg& reg);
515     bool do_update();
516     virtual void check_update();
517     virtual bool start(bool force = false);
cabinet_changed()518     bool cabinet_changed() { return current_cab != cabinet; }
update_cabinet()519     void update_cabinet() { current_cab = cabinet; }
sum_changed()520     bool sum_changed() { return fabs(sum - (level + bass + treble)) > 0.01; }
update_sum()521     void update_sum() { sum = level + bass + treble; }
522 public:
523     CabinetStereoConvolver(EngineControl& engine, sigc::slot<void> sync,
524        gx_resample::BufferResampler& resamp);
525     ~CabinetStereoConvolver();
526 };
527 
528 
529 /****************************************************************
530  ** class PreampConvolver
531  */
532 
533 #include "faust/preamp_impulse_former.h"
534 
535 class PreampConvolver: public FixedBaseConvolver {
536 private:
537     int current_pre;
538     float level;
539     int preamp;
540     float bass;
541     float treble;
542     float sum;
543     value_pair *pre_names;
544     preamp_impulse_former::Dsp impf;
545     gx_resample::FixedRateResampler smp;
546     static void run_pre_conf(int count, float *input, float *output, PluginDef*);
547     static int register_pre(const ParamReg& reg);
548     bool do_update();
549     virtual void check_update();
550     virtual bool start(bool force = false);
preamp_changed()551     bool preamp_changed() { return current_pre != preamp; }
update_preamp()552     void update_preamp() { current_pre = preamp; }
sum_changed()553     bool sum_changed() { return std::abs(sum - (level + bass + treble)) > 0.01; }
update_sum()554     void update_sum() { sum = level + bass + treble; }
555 public:
556     PreampConvolver(EngineControl& engine, sigc::slot<void> sync,
557        gx_resample::BufferResampler& resamp);
558     ~PreampConvolver();
559 };
560 
561 #include "faust/preamp_impulse_former_st.h"
562 
563 class PreampStereoConvolver: public FixedBaseConvolver {
564 private:
565     int current_pre;
566     float level;
567     int preamp;
568     float bass;
569     float treble;
570     float sum;
571     value_pair *pre_names;
572     preamp_impulse_former_st::Dsp impf;
573     gx_resample::FixedRateResampler smp;
574     gx_resample::FixedRateResampler smps;
575     static void run_pre_conf(int count, float *input, float *input1, float *output, float *output1, PluginDef*);
576     static int register_pre(const ParamReg& reg);
577     bool do_update();
578     virtual void check_update();
579     virtual bool start(bool force = false);
preamp_changed()580     bool preamp_changed() { return current_pre != preamp; }
update_preamp()581     void update_preamp() { current_pre = preamp; }
sum_changed()582     bool sum_changed() { return fabs(sum - (level + bass + treble)) > 0.01; }
update_sum()583     void update_sum() { sum = level + bass + treble; }
584 public:
585     PreampStereoConvolver(EngineControl& engine, sigc::slot<void> sync,
586        gx_resample::BufferResampler& resamp);
587     ~PreampStereoConvolver();
588 };
589 
590 /****************************************************************
591  ** class ContrastConvolver
592  */
593 
594 #include "faust/presence_level.h"
595 
596 class ContrastConvolver: public FixedBaseConvolver {
597 private:
598     float level;
599     float sum;
600     presence_level::Dsp presl;
601     gx_resample::FixedRateResampler smp;
602     static void run_contrast(int count, float *input, float *output, PluginDef*);
603     static int register_con(const ParamReg& reg);
update_sum()604     inline void update_sum() { sum = level; }
605     virtual void check_update();
606     bool do_update();
sum_changed()607     inline bool sum_changed() { return std::abs(sum - level) > 0.01; }
608     virtual bool start(bool force = false);
609 public:
610     ContrastConvolver(EngineControl& engine, sigc::slot<void> sync,
611        gx_resample::BufferResampler& resamp);
612     ~ContrastConvolver();
613 };
614 
615 /****************************************************************
616  ** class LV2Features
617  */
618 
619 class LV2Features {
620 private:
621 
622     static LV2_Options_Option gx_options[2];
623     static LV2_Feature gx_options_feature;
624 
625     static LV2_URID lv2_urid_map(LV2_URID_Map_Handle, const char* const uri_);
626     static LV2_Feature gx_urid_map_feature;
627 
628 #pragma GCC diagnostic push
629 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
630     static uint32_t lv2_uri_to_id(LV2_URI_Map_Callback_Data handle, const char*, const char* uri);
631     static LV2_URI_Map_Feature gx_uri_map;
632     static LV2_Feature gx_uri_map_feature;
633 #pragma GCC diagnostic pop
634 
635     static const char* lv2_urid_unmap(LV2_URID_Unmap_Handle, const LV2_URID urid);
636     static LV2_Feature gx_urid_unmap_feature;
LV2Features()637     LV2Features() {};
638 
639 public:
getInstance()640     static LV2Features& getInstance()
641         {
642             static LV2Features  instance;
643             return instance;
644         }
645     static LV2_Feature* gx_features[];
646     static LV2_URID_Map gx_urid_map;
647     static LV2_URID_Unmap gx_urid_unmap;
648 
649     LV2Features(LV2Features const&)     = delete;
650     void operator=(LV2Features const&)  = delete;
651 
652 };
653 
654 /****************************************************************
655  ** class LadspaLoader
656  */
657 
658 enum widget_type { tp_scale, tp_scale_log, tp_toggle, tp_enum, tp_display, tp_display_toggle, tp_none, tp_int, tp_enabled, tp_atom };
659 
660 struct paradesc: boost::noncopyable {
661     int index;
662     std::string name;
663     float dflt;
664     float low;
665     float up;
666     float step;
667     widget_type tp;
668     bool newrow;
669     bool has_caption;
670     value_pair* values;
paradescparadesc671     paradesc(): index(), name(), dflt(), low(), up(), step(), tp(), newrow(), has_caption(true), values() {}
672     ~paradesc();
673     void set_valuelist(const std::vector<std::string>& v);
674     void readJSON(gx_system::JsonParser& jp);
675     void writeJSON(gx_system::JsonWriter& jw);
676 };
677 
678 enum quirkflag { need_activate = 1, no_cleanup = 2, is_lv2 = 4 };
679 
680 class plugdesc {
681 public:
682     std::string path;
683     unsigned int index;
684     unsigned long UniqueID;
685     Glib::ustring Label;
686     Glib::ustring shortname;
687     Glib::ustring category;
688     int quirks; // quirkflag bits
689     int add_wet_dry;
690     int stereo_to_mono;
691     int master_idx;
692     Glib::ustring master_label;
693     std::vector<paradesc*> names;
694     std::string id_str;
695 private:
plugdesc()696     plugdesc() {}
697     ~plugdesc();
698     friend class LadspaLoader;
699 public:
700     void readJSON(gx_system::JsonParser& jp);
701     void writeJSON(gx_system::JsonWriter& jw);
702 };
703 
704 class LadspaLoader {
705 public:
706     typedef std::vector<plugdesc*> pluginarray;
707 private:
708     const gx_system::CmdlineOptions& options;
709     pluginarray plugins;
710     LilvWorld* world;
711     ParamMap& param;
712     const LilvPlugins* lv2_plugins;
713     LilvNode* lv2_AudioPort;
714     LilvNode* lv2_ControlPort;
715     LilvNode* lv2_InputPort;
716     LilvNode* lv2_OutputPort;
717     LilvNode* lv2_AtomPort;
718 private:
719     void read_module_config(const std::string& filename, plugdesc *p);
720     void read_module_list(pluginarray& p);
721 public:
722     LadspaLoader(const gx_system::CmdlineOptions& options, ParamMap& param);
723     ~LadspaLoader();
724     bool load(pluginarray& p);
size()725     unsigned int size() { return plugins.size(); }
create(unsigned int idx)726     PluginDef *create(unsigned int idx) { return create(plugins[idx]); }
727     PluginDef *create(const plugdesc *p);
begin()728     pluginarray::iterator begin() { return plugins.begin(); }
end()729     pluginarray::iterator end() { return plugins.end(); }
730     pluginarray::iterator find(plugdesc* desc);
731     void clear_list();
732     void set_plugins(pluginarray& new_plugins);
733     void update_instance(PluginDef *pdef, plugdesc *pdesc);
get_ladspa_filename(unsigned long uid)734     static std::string get_ladspa_filename(unsigned long uid)
735 	{ return "ladspa"+gx_system::to_string(uid)+".js"; }
get_ladspa_filename(std::string uid_key)736     static std::string get_ladspa_filename(std::string uid_key)
737 	{ return "ladspa"+uid_key.substr(9)+".js"; }
get_parameter_map()738     ParamMap& get_parameter_map() const { return param; }
739     friend class Lv2Dsp;
740 };
741 
742 
743 /****************************************************************
744  ** class Directout
745  */
746 
747 class Directout: public PluginDef {
748 public:
749     float* outdata;
750 private:
751 	int fSamplingFreq;
752     int 	bsize;
753     bool fdfill;
754     EngineControl&  engine;
755     sigc::slot<void> sync;
756     void mem_alloc();
757     void mem_free();
758     void init(unsigned int samplingFreq);
759     void compute(int count,  float *input0, float *input1, float *output0, float *output1);
760     void change_buffersize(unsigned int size);
761 
762     static void init_static(unsigned int samplingFreq, PluginDef*);
763     static void compute_static(int count, float *input0, float *input1, float *output0, float *output1, PluginDef*);
764 public:
765     bool   mem_allocated;
get_buffer()766     float* get_buffer() {return outdata;};
767     void set_data(bool dfill);
768     Plugin plugin;
769     static Plugin directoutput;
770     Directout( EngineControl& engine, sigc::slot<void> sync);
771     ~Directout();
772 };
773 
774 
775 /****************************************************************
776  ** class LiveLooper
777  */
778 
779 class LiveLooper: public PluginDef {
780 
781 
782 class FileResampler {
783 private:
784     Resampler r_file;
785     int inputRate, outputRate;
786 public:
787     int setup(int _inputRate, int _outputRate);
788     int run(int count, float *input, float *output);
max_out_count(int in_count)789     int max_out_count(int in_count) {
790 	return static_cast<int>(ceil((in_count*static_cast<double>(outputRate))/inputRate)); }
791 };
792 
793 private:
794 	int fSamplingFreq;
795 	float 	gain;
796 	float 	fRec0[2];
797 	float 	gain_out;
798 	float 	fclip1;
799 	float 	fclip2;
800 	float 	fclip3;
801 	float 	fclip4;
802 	float 	fclips1;
803 	float 	fclips2;
804 	float 	fclips3;
805 	float 	fclips4;
806 	float 	fspeed1;
807 	float 	fspeed2;
808 	float 	fspeed3;
809 	float 	fspeed4;
810 	float 	rplay1;
811 	float 	rplay2;
812 	float 	rplay3;
813 	float 	rplay4;
814 	float 	od1;
815 	float 	od2;
816 	float 	od3;
817 	float 	od4;
818 	float 	fod1;
819 	float 	fod2;
820 	float 	fod3;
821 	float 	fod4;
822 	float 	record1;
823 	int 	iVec0[2];
824 	int 	IOTA1;
825 	int 	IOTA2;
826 	int 	IOTA3;
827 	int 	IOTA4;
828 	float 	IOTAR1;
829 	float 	IOTAR2;
830 	float 	IOTAR3;
831 	float 	IOTAR4;
832 	float *tape1;
833 	int 	tape1_size;
834 	float 	fConst0;
835 	float 	fConst1;
836 	float 	fConst2;
837 	float 	reset1;
838 	int 	RecSize1[2];
839 	float 	rectime0;
840 	float 	fRec1[2];
841 	float 	fRec2[2];
842 	int 	iRec3[2];
843 	int 	iRec4[2];
844 	float 	play1;
845 	float 	playh1;
846 	float 	gain1;
847 	float 	record2;
848 	int 	iVec2[2];
849 	float *tape2;
850 	int 	tape2_size;
851 	float 	reset2;
852 	int 	RecSize2[2];
853 	float 	rectime1;
854 	float 	fRec6[2];
855 	float 	fRec7[2];
856 	int 	iRec8[2];
857 	int 	iRec9[2];
858 	float 	play2;
859 	float 	playh2;
860 	float 	gain2;
861 	float 	record3;
862 	int 	iVec4[2];
863 	float *tape3;
864 	int 	tape3_size;
865 	float 	reset3;
866 	int 	RecSize3[2];
867 	float 	rectime2;
868 	float 	fRec11[2];
869 	float 	fRec12[2];
870 	int 	iRec13[2];
871 	int 	iRec14[2];
872 	float 	play3;
873 	float 	playh3;
874 	float 	gain3;
875 	float 	record4;
876 	int 	iVec6[2];
877 	float *tape4;
878 	int 	tape4_size;
879 	float 	reset4;
880 	int 	RecSize4[2];
881 	float 	rectime3;
882 	float 	fRec16[2];
883 	float 	fRec17[2];
884 	int 	iRec18[2];
885 	int 	iRec19[2];
886 	float 	play4;
887 	float 	playh4;
888 	float 	gain4;
889 	float 	play_all;
890     float 	dout;
891     float* outbuffer;
892 	bool save1;
893 	bool save2;
894 	bool save3;
895 	bool save4;
896 	bool first1;
897 	bool first2;
898 	bool first3;
899 	bool first4;
900 	bool RP1;
901 	bool RP2;
902 	bool RP3;
903 	bool RP4;
904     Glib::ustring preset_name;
905     Glib::ustring load_file1;
906     Glib::ustring load_file2;
907     Glib::ustring load_file3;
908     Glib::ustring load_file4;
909     Glib::ustring cur_name;
910     Glib::ustring loop_dir;
911     bool save_p;
912     ParamMap& param;
913 	bool mem_allocated;
914     sigc::slot<void> sync;
915 	volatile int ready;
916     FileResampler smp;
917     Directout* d;
918 
919     int do_resample(int inrate, int insize, float *input, int maxsize);
920     int do_mono(int c, int f, float *oIn, float *tape, int n);
921     void play_all_tapes();
922     void mem_alloc();
923 	void mem_free();
924 	void clear_state_f();
925 	int activate(bool start);
926 	int load_ui_f(const UiBuilder& b, int form);
927 	void init(unsigned int samplingFreq);
928 	void compute(int count, float *input0, float *output0);
929 	int register_par(const ParamReg& reg);
930     void save_array(std::string name);
931     void load_array(std::string name);
932     void save_to_wave(std::string fname, float *tape, float fSize, int tape_size);
933     int load_from_wave(std::string fname, float **tape, int tape_size);
934     void set_p_state();
935     void load_tape1();
936     void load_tape2();
937     void load_tape3();
938     void load_tape4();
939 
940 	static void clear_state_f_static(PluginDef*);
941 	static int activate_static(bool start, PluginDef*);
942 	static int load_ui_f_static(const UiBuilder& b, int form);
943 	static void init_static(unsigned int samplingFreq, PluginDef*);
944 	static void compute_static(int count, float *input0, float *output0, PluginDef*);
945 	static int register_params_static(const ParamReg& reg);
946 	static void del_instance(PluginDef *p);
947 public:
948     Plugin plugin;
949 	LiveLooper(ParamMap& param_, sigc::slot<void> sync, const string& loop_dir_);
950 	~LiveLooper();
951 };
952 
953 
954 /****************************************************************
955  ** class SCapture
956  */
957 
958 
959 class SCapture: public PluginDef {
960 private:
961     SNDFILE *       recfile;
962     EngineControl&  engine;
963     int             fSamplingFreq;
964     int             channel;
965     float           fcheckbox0;
966     float           fcheckbox1;
967     float           fslider0;
968     float           fbargraph0;
969     float           fRecC0[2];
970     float           fformat;
971     int             IOTA;
972     int             iA;
973     int             savesize;
974     int             filesize;
975     float           *fRec0;
976     float           *fRec1;
977     float           *tape;
978     sem_t           m_trig;
979     pthread_t       m_pthr;
980     volatile bool   keep_stream;
981     bool            mem_allocated;
982     bool            is_wav;
983     bool            err;
984     float           fConst0;
985     float           fRecb0[2];
986     int             iRecb1[2];
987     float           fRecb2[2];
988     void        mem_alloc();
989     void        mem_free();
990     void        clear_state_f();
991     int         activate(bool start);
992     int         load_ui_f(const UiBuilder& b, int form);
993     void        init(unsigned int samplingFreq);
994     void        compute(int count, float *input0, float *output0);
995     void        compute_st(int count, float *input0, float *input1, float *output0, float *output1);
996     int         register_par(const ParamReg& reg);
997     void        save_to_wave(SNDFILE * sf, float *tape, int lSize);
998     SNDFILE     *open_stream(std::string fname);
999     void        close_stream(SNDFILE **sf);
1000     void        stop_thread();
1001     void        start_thread();
1002     void        disc_stream();
1003     inline std::string get_ffilename();
1004 
1005     static void *run_thread(void* p);
1006     static void clear_state_f_static(PluginDef*);
1007     static int  activate_static(bool start, PluginDef*);
1008     static const char *glade_def;
1009     static const char *glade_def_st;
1010     static int  load_ui_f_static(const UiBuilder& b, int form);
1011     static void init_static(unsigned int samplingFreq, PluginDef*);
1012     static void compute_static(int count, float *input0, float *output0, PluginDef*);
1013     static void compute_static_st(int count, float *input0, float *input1, float *output0, float *output1, PluginDef*);
1014     static int  register_params_static(const ParamReg& reg);
1015     static void del_instance(PluginDef *p);
1016 public:
1017     Plugin plugin;
1018     SCapture(EngineControl& engine, int channel_);
1019     ~SCapture();
1020 };
1021 
1022 /****************************************************************
1023  ** class DrumSequencer
1024  */
1025 
1026 #include "faust/drumseq.h"
1027 
1028 class Drumout {
1029 private:
1030     static float* set;
1031     static bool mb;
1032     static float* data;
1033     static Plugin input_drum;
1034     static void outputdrum_compute(int count, float *input0, float *input1, float *output0, float *output1, PluginDef*);
1035 public:
1036     static void set_plugin(Plugin p);
1037     static void set_data(float* mode, bool ready, float* buf);
1038     static Plugin output_drum;
1039     static PluginDef outputdrum;
1040     Drumout();
1041 };
1042 
1043 
1044 class DrumSequencer: public PluginDef {
1045 private:
1046     int fSamplingFreq;
1047     FAUSTFLOAT 	position;
1048     FAUSTFLOAT 	ftact;
1049     FAUSTFLOAT 	fsec;
1050     FAUSTFLOAT 	fsliderbpm;
1051     FAUSTFLOAT 	fsliderhum;
1052     drumseq::Dsp drums;
1053 
1054     int 	counter;
1055     int 	seq_size;
1056     int 	bsize;
1057     FAUSTFLOAT 	step;
1058     FAUSTFLOAT 	step_orig;
1059     FAUSTFLOAT 	fSlow1;
1060     FAUSTFLOAT 	fSlow3;
1061     FAUSTFLOAT 	fSlow5;
1062     FAUSTFLOAT 	fSlow7;
1063     FAUSTFLOAT 	fSlow12;
1064     FAUSTFLOAT 	fSlow14;
1065     FAUSTFLOAT 	fSlow16;
1066     FAUSTFLOAT 	fSlow18;
1067     FAUSTFLOAT 	fSlow20;
1068     FAUSTFLOAT 	fSlow22;
1069     std::vector<int> Vectom;
1070     std::vector<int> Vectom1;
1071     std::vector<int> Vectom2;
1072     std::vector<int> Veckick;
1073     std::vector<int> Vecsnare;
1074     std::vector<int> Vechat;
1075 
1076     EngineControl&  engine;
1077     bool            mem_allocated;
1078     sigc::slot<void> sync;
1079     volatile bool ready;
1080     float *outdata;
1081     GxSeqSettings tomset;
1082     SeqParameter *tomp;
1083     GxSeqSettings tomset1;
1084     SeqParameter *tomp1;
1085     GxSeqSettings tomset2;
1086     SeqParameter *tomp2;
1087     GxSeqSettings snareset;
1088     SeqParameter *snarep;
1089     GxSeqSettings hatset;
1090     SeqParameter *hatp;
1091     GxSeqSettings kickset;
1092     SeqParameter *kickp;
1093 
1094     void mem_alloc();
1095     void mem_free();
1096     void init(unsigned int samplingFreq);
1097     void compute(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0);
1098     void change_buffersize(unsigned int size);
1099     int register_par(const ParamReg& reg);
1100 
1101     int min_seq_size();
1102     void reset_tom();
1103     void reset_tom1();
1104     void reset_tom2();
1105     void reset_kick();
1106     void reset_hat();
1107     void reset_snare();
1108 
1109     static void init_static(unsigned int samplingFreq, PluginDef*);
1110     static void compute_static(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0, PluginDef*);
1111     static int register_params_static(const ParamReg& reg);
1112     static void del_instance(PluginDef *p);
1113     static int drum_load_ui(const UiBuilder& builder, int format);
1114 public:
1115     Plugin plugin;
1116     DrumSequencer(EngineControl& engine, sigc::slot<void> sync);
1117     ~DrumSequencer();
1118 };
1119 
1120 /****************************************************************************
1121 *
1122 * NAME: smbPitchShift.cpp
1123 * VERSION: 1.2
1124 * HOME URL: http://www.dspdimension.com
1125 * KNOWN BUGS: none
1126 *
1127 *
1128 * COPYRIGHT 1999-2009 Stephan M. Bernsee <smb [AT] dspdimension [DOT] com>
1129 *
1130 * Modified for guitarix by Hermann Meyer 2014
1131 *
1132 * 						The Wide Open License (WOL)
1133 *
1134 * Permission to use, copy, modify, distribute and sell this software and its
1135 * documentation for any purpose is hereby granted without fee, provided that
1136 * the above copyright notice and this license appear in all source copies.
1137 * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF
1138 * ANY KIND. See http://www.dspguru.com/wol.htm for more information.
1139 *
1140 *****************************************************************************/
1141 
1142 
1143 #define M_PI 3.14159265358979323846
1144 #define MAX_FRAME_LENGTH 8096
1145 
1146 class smbPitchShift : public PluginDef {
1147 private:
1148     gx_resample::SimpleResampler resamp;
1149     EngineControl&  engine;
1150 	bool            mem_allocated;
1151     sigc::slot<void> sync;
1152 	volatile bool ready;
1153 	float gInFIFO[MAX_FRAME_LENGTH];
1154 	float gOutFIFO[MAX_FRAME_LENGTH];
1155     float *fpb;
1156     float *expect;
1157     float *hanning;
1158     float *hanningd;
1159     float *resampin;
1160     float *resampin2;
1161     float *resampout;
1162     float *indata2;
1163 	float gLastPhase[MAX_FRAME_LENGTH/2+1];
1164 	float gSumPhase[MAX_FRAME_LENGTH/2+1];
1165 	float gOutputAccum[2*MAX_FRAME_LENGTH];
1166 	float gAnaFreq[MAX_FRAME_LENGTH];
1167 	float gAnaMagn[MAX_FRAME_LENGTH];
1168 	float gSynFreq[MAX_FRAME_LENGTH];
1169 	float gSynMagn[MAX_FRAME_LENGTH];
1170 	float semitones;
1171 	float a,b,c,d,l;
1172 	float wet;
1173 	float dry;
1174     float mpi, mpi1;
1175     float tone;
1176 	int   octave, osamp, numSampsToResamp, numSampsToProcess, fftFrameSize, sampleRate ;
1177 	int latency;
1178     int ai;
1179     int aio;
1180     int ii;
1181 	long  gRover ;
1182 	double magn, phase, tmp, real, imag;
1183 	double freqPerBin, freqPerBin1, freqPerBin2, expct;
1184     double fftFrameSize3;
1185     double fftFrameSize4;
1186     double osamp1,osamp2;
1187 	long   i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;
1188 
1189     fftwf_complex fftw_in[MAX_FRAME_LENGTH], fftw_out[MAX_FRAME_LENGTH];
1190     fftwf_plan ftPlanForward, ftPlanInverse;
1191 
1192     inline int load_ui_f(const UiBuilder& b, int form);
1193 	int register_par(const ParamReg& reg);
1194     void change_latency();
1195 
1196     void mem_alloc();
1197 	void mem_free();
1198     void clear_state();
1199 	int activate(bool start);
1200 	bool setParameters( int sampleRate);
1201 	void PitchShift(int count, float *indata, float *outdata);
1202     void change_buffersize(unsigned int size);
1203     static int  activate_static(bool start, PluginDef*);
1204     static void del_instance(PluginDef *p);
1205     static int registerparam(const ParamReg& reg);
1206     static int load_ui_f_static(const UiBuilder& b, int form);
1207 	static void init(unsigned int sampleRate, PluginDef *plugin);
1208     static void compute_static(int count, float *input0, float *output0, PluginDef *p);
1209 
1210 public:
1211     Plugin plugin;
1212 	smbPitchShift(EngineControl& engine, sigc::slot<void> sync);
1213 	~smbPitchShift();
1214 };
1215 
1216 
1217 } // namespace gx_engine
1218