Guitarix
gx_internal_plugins.h
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 the guitarix Engine namespace ------- */
22 
23 #pragma once
24 
25 
26 #include <lilv/lilv.h>
27 #include "lv2/lv2plug.in/ns/ext/presets/presets.h"
28 #include "lv2/lv2plug.in/ns/ext/state/state.h"
29 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
30 
31 namespace gx_jack { class GxJack; }
32 
33 namespace gx_engine {
34 
35 /****************************************************************
36  ** MonoMute, StereoMute, MaxLevel, MidiAudioBuffer
37  */
38 
39 class MonoMute: public PluginDef {
40 private:
41  static void process(int count, float *input, float *output, PluginDef*);
42 public:
43  MonoMute();
44 };
45 
46 class StereoMute: public PluginDef {
47 private:
48  static void process(int count, float *input0, float *input1,
49  float *output0, float *output1, PluginDef*);
50 public:
51  StereoMute();
52 };
53 
54 class MaxLevel: public PluginDef {
55 public:
56  static const unsigned int channelcount = 2;
57 private:
58  static float maxlevel[channelcount];
59  static void process(int count, float *input0, float *input1,
60  float *output0, float *output1, PluginDef*);
61  static int activate(bool start, PluginDef *plugin);
62 public:
63  static float get(unsigned int channel) {
64  assert(channel < channelcount);
65  float v = maxlevel[channel];
66  maxlevel[channel] = 0;
67  return v;
68  }
69  MaxLevel();
70 };
71 
72 
73 /****************************************************************
74  ** class TunerAdapter
75  */
76 
77 class TunerAdapter: public ModuleSelector, private PluginDef, public sigc::trackable {
78 private:
79  static void feed_tuner(int count, float *input, float *output, PluginDef*);
80  static int regparam(const ParamReg& reg);
81  static int activate(bool start, PluginDef *plugin);
82  static void init(unsigned int samplingFreq, PluginDef *plugin);
83  PitchTracker pitch_tracker;
84  int state;
85  ModuleSequencer& engine;
86  enum { tuner_use = 0x01, switcher_use = 0x02, midi_use = 0x04 };
87  void set_and_check(int use, bool on);
88  Plugin* dep_plugin;
89 public:
92  void used_for_switching(bool on) { set_and_check(switcher_use, on); }
93  void used_for_display(bool on) { set_and_check(tuner_use, on); }
94  bool used_for_display() { return state & tuner_use; }
95  void used_by_midi(bool on) { set_and_check(midi_use, on); }
96  void set_dep_module(Plugin* dep) { dep_plugin = dep; }
97  void set_module();
98  Glib::Dispatcher& signal_freq_changed() { return pitch_tracker.new_freq; }
99  float get_freq() { return pitch_tracker.get_estimated_freq(); }
100  float get_note() { return pitch_tracker.get_estimated_note(); }
101 };
102 
103 
104 /****************************************************************
105  ** class MidiAudioBuffer
106  */
107 
109 private:
110  float fslider45;
111  float fslider38;
112  float fslider31;
113  float fslider27;
114  float fslider29;
115  float fslider30;
116  float fslider26;
117  float fslider33;
118  float fslider34;
119  float fslider35;
120  float fslider36;
121  float fslider42;
122  float fslider43;
123  float fslider40;
124  float fslider41;
125  float fslider44;
126  float fslider37;
127  float fslider39;
128  float fslider46;
129  float fslider47;
130  float fslider48;
131  float fConstlog;
132  float fConstlog2;
133  float beat0;
134  float midi_gain;
135  float fConstun0;
136  float fslider32;
137  float BeatFilter1;
138  float BeatFilter2;
139  float BeatFilterk;
140  bool fautogain;
141  bool fpitch;
142  bool fautogain1;
143  bool fpitch1;
144  bool fpitch2;
145  bool fautogain2;
146  bool midistat;
147  bool midistat1;
148  bool midistat2;
149  bool midistat3;
150 
151  int weg;
152  int program;
153  int program2;
154  int volume2;
155  int Beat_is;
156  int send;
157  int volume;
158  int noten;
159  int program1;
160  int send1;
161  int noten1;
162  int volume1;
163  int send2;
164  int noten2;
165 
166  bool fcheckbox10;
167  bool fcheckbox11;
168 
169  unsigned char* midi_send;
170  unsigned char* midi_send1;
171  unsigned char* midi_send2;
172 
173 public:
174  void register_parameter(const ParamReg& reg);
175  void init(int samplingFreq);
176  void process_midi(int len, float *audiodata, void *midi_port_buf, float jcpu_load,
177  float fConsta4, float fConsta1t);
178  bool get_midistat() { return midistat; }
179 };
180 
181 
183 public:
184  enum Load { load_off = -1, load_low = 0, load_high = 1, load_over = 2 };
185 private:
186  MidiVariables midi;
188  gx_jack::GxJack* jack;
189  Load jack_overload;
190  Glib::Dispatcher overload_change;
191  static void fill_buffer(int count, float *input0, float *output0, PluginDef*);
192  static int regparam(const ParamReg& reg);
193  static void init(unsigned int samplingFreq, PluginDef *plugin);
194  static int activate(bool start, PluginDef *plugin);
195 public:
198  void set_jack(gx_jack::GxJack* jack_) { jack = jack_; }
199  bool get_midistat() { return midi.get_midistat(); }
200  Load jack_load_status() { return jack_overload; }
201  Glib::Dispatcher& signal_jack_load_change() { return overload_change; }
202 };
203 
204 
205 /****************************************************************
206  ** class NoiseGate
207  */
208 
209 class NoiseGate {
210 private:
211  static PluginDef inputdef;
212  static float fnglevel;
213  static float ngate;
214  static bool off;
215  static int noisegate_register(const ParamReg& reg);
216  static void inputlevel_compute(int count, float *input0, float *output0, PluginDef*);
217  static void outputgate_compute(int count, float *input, float *output, PluginDef*);
218  static int outputgate_activate(bool start, PluginDef *pdef);
219 public:
222  NoiseGate();
223 };
224 
225 
226 /****************************************************************
227  ** class OscilloscopeAdapter
228  */
229 
231 private:
232  static float* buffer;
233  static unsigned int size;
234  static void fill_buffer(int count, float *input0, float *output0, PluginDef*);
235  static int osc_register(const ParamReg& reg);
236  static int activate(bool start, PluginDef *p);
237  void change_buffersize(unsigned int);
238  int mul_buffer;
239 public:
241  sigc::signal<int, bool> activation;
242  sigc::signal<void, unsigned int> size_change;
243  void clear_buffer();
244  unsigned int get_size() { return size; }
245  inline float *get_buffer() { return buffer; }
246  int get_mul_buffer() { return mul_buffer; }
247  void set_mul_buffer(int a, unsigned int b) { mul_buffer = a; change_buffersize(b); }
249 };
250 
251 
252 /****************************************************************
253  ** class GxJConvSettings
254  */
255 
257  private:
258  // main jconv setting
259  std::string fIRFile;
260  std::string fIRDir;
261 
262  float fGain; // jconv gain
263  guint fOffset; // offset in IR where to start comvolution
264  guint fLength; // length of the IR to use for convolution
265  guint fDelay; // delay when to apply reverb
266  Gainline gainline;
267  bool fGainCor;
268  void read_gainline(gx_system::JsonParser& jp);
269  inline void setIRDir(string name) { fIRDir = name; }
270  friend class ConvolverAdapter;
272  public:
273  GxJConvSettings();
274  GxJConvSettings& operator=(GxJConvSettings const& jcset);
275  bool operator==(const GxJConvSettings& jcset) const;
276  // getters and setters
277  inline const std::string& getIRFile() const { return fIRFile; }
278  std::string getFullIRPath() const;
279  inline float getGain() const { return fGain; }
280  inline guint getOffset() const { return fOffset; }
281  inline guint getLength() const { return fLength; }
282  inline guint getDelay() const { return fDelay; }
283  inline bool getGainCor() const { return fGainCor; }
284  inline const Gainline& getGainline() const { return gainline; }
285  const std::string& getIRDir() const { return fIRDir; }
286  void setFullIRPath(string name);
287  inline void setIRFile(string name) { fIRFile = name; }
288  inline void setGain(float gain) { fGain = gain; }
289  inline void setGainCor(bool gain) { fGainCor = gain; }
290  inline void setOffset(guint offs) { fOffset = offs; }
291  inline void setLength(guint leng) { fLength = leng; }
292  inline void setDelay(guint del) { fDelay = del; }
293  inline void setGainline(const Gainline& gain) { gainline = gain; }
294 
295  public:
296  void readJSON(gx_system::JsonParser& jp);
297  void writeJSON(gx_system::JsonWriter& w) const;
298 };
299 
300 class ConvolverAdapter;
301 
302 template<>
304 private:
305  const gx_system::PathList *searchpath;
306  const gx_system::PrefixConverter* pfx_conv;
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);
315  ~ParameterV();
316  virtual void serializeJSON(gx_system::JsonWriter& jw);
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;
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 
331 
332 
333 /****************************************************************
334  ** class ConvolverAdapter
335  */
336 
337 class ConvolverAdapter: protected PluginDef, public sigc::trackable {
338 protected:
340  boost::mutex activate_mutex;
342  sigc::slot<void> sync;
344  bool activated;
345  // wrapper for the rack order function pointers
346  void change_buffersize(unsigned int size);
348  JConvParameter *jcp;
349 public:
351 public:
352  ConvolverAdapter(EngineControl& engine, sigc::slot<void> sync, ParamMap& param);
353  ~ConvolverAdapter();
354  void restart();
355  bool conv_start();
356  inline const std::string& getIRFile() const { return jcset.getIRFile(); }
357  inline void set_sync(bool val) { conv.set_sync(val); }
358  inline std::string getFullIRPath() const { return jcset.getFullIRPath(); }
359  inline const std::string& getIRDir() const { return jcset.getIRDir(); }
360  bool set(const GxJConvSettings& jcset) const { return jcp->set(jcset); }
361  const GxJConvSettings& get_jcset() const { return jcset; }
362  ParamMap& get_parameter_map() const { return param; }
363 };
364 
365 
366 /****************************************************************
367  ** class ConvolverStereoAdapter
368  */
369 
370 #include "faust/jconv_post.h"
371 #include "faust/jconv_post_mono.h"
372 
374 private:
375  jconv_post::Dsp jc_post;
376  // wrapper for the rack order function pointers
377  static void convolver_init(unsigned int samplingFreq, PluginDef *pdef);
378  static int activate(bool start, PluginDef *pdef);
379  static void convolver(int count, float *input0, float *input1,
380  float *output0, float *output1, PluginDef*);
381  static int convolver_register(const ParamReg& reg);
382 public:
383  ConvolverStereoAdapter(EngineControl& engine, sigc::slot<void> sync, ParamMap& param);
385 };
386 
387 
388 /****************************************************************
389  ** class ConvolverMonoAdapter
390  */
391 
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 public:
401  ConvolverMonoAdapter(EngineControl& engine, sigc::slot<void> sync, ParamMap& param);
403 };
404 
405 
406 /****************************************************************
407  ** class BaseConvolver
408  */
409 
410 
411 class BaseConvolver: protected PluginDef {
412 protected:
414  boost::mutex activate_mutex;
416  sigc::slot<void> sync;
417  bool activated;
418  sigc::connection update_conn;
419  static void init(unsigned int samplingFreq, PluginDef *p);
420  static int activate(bool start, PluginDef *pdef);
421  void change_buffersize(unsigned int);
422  int conv_start();
423  bool check_update_timeout();
424  virtual void check_update() = 0;
425  virtual bool start(bool force = false) = 0;
426 public:
428 public:
429  BaseConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
430  virtual ~BaseConvolver();
431  inline void set_sync(bool val) { conv.set_sync(val); }
432 };
433 
434 /****************************************************************
435  ** class CabinetConvolver
436  */
437 
438 #include "faust/cabinet_impulse_former.h"
439 
441 private:
442  int current_cab;
443  float level;
444  int cabinet;
445  float bass;
446  float treble;
447  float sum;
448  value_pair *cab_names;
449  cabinet_impulse_former::Dsp impf;
450  static void run_cab_conf(int count, float *input, float *output, PluginDef*);
451  static int register_cab(const ParamReg& reg);
452  bool do_update();
453  virtual void check_update();
454  virtual bool start(bool force = false);
455  bool cabinet_changed() { return current_cab != cabinet; }
456  void update_cabinet() { current_cab = cabinet; }
457  bool sum_changed() { return abs(sum - (level + bass + treble)) > 0.01; }
458  void update_sum() { sum = level + bass + treble; }
459 public:
460  CabinetConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
461  ~CabinetConvolver();
462 };
463 
464 
465 /****************************************************************
466  ** class PreampConvolver
467  */
468 
469 #include "faust/preamp_impulse_former.h"
470 
472 private:
473  int current_pre;
474  float level;
475  int preamp;
476  float bass;
477  float treble;
478  float sum;
479  value_pair *pre_names;
480  preamp_impulse_former::Dsp impf;
481  static void run_pre_conf(int count, float *input, float *output, PluginDef*);
482  static int register_pre(const ParamReg& reg);
483  bool do_update();
484  virtual void check_update();
485  virtual bool start(bool force = false);
486  bool preamp_changed() { return current_pre != preamp; }
487  void update_preamp() { current_pre = preamp; }
488  bool sum_changed() { return abs(sum - (level + bass + treble)) > 0.01; }
489  void update_sum() { sum = level + bass + treble; }
490 public:
491  PreampConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
492  ~PreampConvolver();
493 };
494 
495 /****************************************************************
496  ** class ContrastConvolver
497  */
498 
499 #include "faust/presence_level.h"
500 
502 private:
503  float level;
504  float sum;
505  presence_level::Dsp presl;
506  static void run_contrast(int count, float *input, float *output, PluginDef*);
507  static int register_con(const ParamReg& reg);
508  inline void update_sum() { sum = level; }
509  virtual void check_update();
510  bool do_update();
511  inline bool sum_changed() { return abs(sum - level) > 0.01; }
512  virtual bool start(bool force = false);
513 public:
514  ContrastConvolver(EngineControl& engine, sigc::slot<void> sync, gx_resample::BufferResampler& resamp);
516 };
517 
518 
519 /****************************************************************
520  ** class LadspaLoader
521  */
522 
524 
525 struct paradesc: boost::noncopyable {
526  int index;
527  std::string name;
528  float dflt;
529  float low;
530  float up;
531  float step;
533  bool newrow;
536  paradesc(): index(), name(), dflt(), low(), up(), step(), tp(), newrow(), has_caption(true), values() {}
537  ~paradesc();
538  void set_valuelist(const std::vector<std::string>& v);
539  void readJSON(gx_system::JsonParser& jp);
540  void writeJSON(gx_system::JsonWriter& jw);
541 };
542 
543 enum quirkflag { need_activate = 1, no_cleanup = 2, is_lv2 = 4 };
544 
545 class plugdesc {
546 public:
547  std::string path;
548  unsigned int index;
549  unsigned long UniqueID;
550  Glib::ustring Label;
551  Glib::ustring shortname;
552  Glib::ustring category;
553  int quirks; // quirkflag bits
556  Glib::ustring master_label;
557  std::vector<paradesc*> names;
558  std::string id_str;
559 private:
560  plugdesc() {}
561  ~plugdesc();
562  friend class LadspaLoader;
563 public:
564  void readJSON(gx_system::JsonParser& jp);
565  void writeJSON(gx_system::JsonWriter& jw);
566 };
567 
569 public:
570  typedef std::vector<plugdesc*> pluginarray;
571 private:
572  const gx_system::CmdlineOptions& options;
573  pluginarray plugins;
574  LilvWorld* world;
575  const LilvPlugins* lv2_plugins;
576  LilvNode* lv2_AudioPort;
577  LilvNode* lv2_ControlPort;
578  LilvNode* lv2_InputPort;
579  LilvNode* lv2_OutputPort;
580 private:
581  void read_module_config(const std::string& filename, plugdesc *p);
582  void read_module_list(pluginarray& p);
583 public:
584  LadspaLoader(const gx_system::CmdlineOptions& options);
585  ~LadspaLoader();
586  bool load(pluginarray& p);
587  unsigned int size() { return plugins.size(); }
588  PluginDef *create(unsigned int idx) { return create(plugins[idx]); }
589  PluginDef *create(const plugdesc *p);
590  pluginarray::iterator begin() { return plugins.begin(); }
591  pluginarray::iterator end() { return plugins.end(); }
592  pluginarray::iterator find(plugdesc* desc);
593  void set_plugins(pluginarray& new_plugins);
594  void change_plugins(pluginarray& new_plugins);
595  void update_instance(PluginDef *pdef, plugdesc *pdesc);
596  static std::string get_ladspa_filename(unsigned long uid)
597  { return "ladspa"+gx_system::to_string(uid)+".js"; }
598  static std::string get_ladspa_filename(std::string uid_key)
599  { return "ladspa"+uid_key.substr(9)+".js"; }
600  friend class Lv2Dsp;
601 };
602 
603 
604 /****************************************************************
605  ** class LiveLooper
606  */
607 
608 
609 class LiveLooper: public PluginDef {
610 
611 
612 class FileResampler {
613 private:
614  Resampler r_file;
615  int inputRate, outputRate;
616  int last_in_count;
617 public:
618  int setup(int _inputRate, int _outputRate);
619  int run(int count, float *input, float *output);
620  int max_out_count(int in_count) {
621  return static_cast<int>(ceil((in_count*static_cast<double>(outputRate))/inputRate)); }
622 };
623 
624 private:
625  int fSamplingFreq;
626  float gain;
627  float fRec0[2];
628  float gain_out;
629  float fclip1;
630  float fclip2;
631  float fclip3;
632  float fclip4;
633  float fclips1;
634  float fclips2;
635  float fclips3;
636  float fclips4;
637  float fspeed1;
638  float fspeed2;
639  float fspeed3;
640  float fspeed4;
641  float rplay1;
642  float rplay2;
643  float rplay3;
644  float rplay4;
645  float load1;
646  float load2;
647  float load3;
648  float load4;
649  float record1;
650  int iVec0[2];
651  int IOTA1;
652  int IOTA2;
653  int IOTA3;
654  int IOTA4;
655  float IOTAR1;
656  float IOTAR2;
657  float IOTAR3;
658  float IOTAR4;
659  float *tape1;
660  int tape1_size;
661  float fConst0;
662  float fConst1;
663  float fConst2;
664  float reset1;
665  int RecSize1[2];
666  float rectime0;
667  float fRec1[2];
668  float fRec2[2];
669  int iRec3[2];
670  int iRec4[2];
671  float play1;
672  float playh1;
673  float gain1;
674  float record2;
675  int iVec2[2];
676  float *tape2;
677  int tape2_size;
678  float reset2;
679  int RecSize2[2];
680  float rectime1;
681  float fRec6[2];
682  float fRec7[2];
683  int iRec8[2];
684  int iRec9[2];
685  float play2;
686  float playh2;
687  float gain2;
688  float record3;
689  int iVec4[2];
690  float *tape3;
691  int tape3_size;
692  float reset3;
693  int RecSize3[2];
694  float rectime2;
695  float fRec11[2];
696  float fRec12[2];
697  int iRec13[2];
698  int iRec14[2];
699  float play3;
700  float playh3;
701  float gain3;
702  float record4;
703  int iVec6[2];
704  float *tape4;
705  int tape4_size;
706  float reset4;
707  int RecSize4[2];
708  float rectime3;
709  float fRec16[2];
710  float fRec17[2];
711  int iRec18[2];
712  int iRec19[2];
713  float play4;
714  float playh4;
715  float gain4;
716  float play_all;
717  bool save1;
718  bool save2;
719  bool save3;
720  bool save4;
721  bool RP1;
722  bool RP2;
723  bool RP3;
724  bool RP4;
725  Glib::ustring preset_name;
726  Glib::ustring load_file1;
727  Glib::ustring load_file2;
728  Glib::ustring load_file3;
729  Glib::ustring load_file4;
730  Glib::ustring cur_name;
731  Glib::ustring loop_dir;
732  bool save_p;
733  ParamMap& param;
734  bool mem_allocated;
735  sigc::slot<void> sync;
736  volatile int ready;
737  FileResampler smp;
738 
739  int do_resample(int inrate, int insize, float *input, int maxsize);
740  int do_mono(int c, int f, float *oIn, float *tape, int n);
741  void play_all_tapes();
742  void mem_alloc();
743  void mem_free();
744  void clear_state_f();
745  int activate(bool start);
746  int load_ui_f(const UiBuilder& b, int form);
747  void init(unsigned int samplingFreq);
748  void compute(int count, float *input0, float *output0);
749  int register_par(const ParamReg& reg);
750  void save_array(std::string name);
751  void load_array(std::string name);
752  void save_to_wave(std::string fname, float *tape, float fSize, int tape_size);
753  int load_from_wave(std::string fname, float **tape, int tape_size);
754  void set_p_state();
755  void load_tape1();
756  void load_tape2();
757  void load_tape3();
758  void load_tape4();
759 
760  static void clear_state_f_static(PluginDef*);
761  static int activate_static(bool start, PluginDef*);
762  static int load_ui_f_static(const UiBuilder& b, int form);
763  static void init_static(unsigned int samplingFreq, PluginDef*);
764  static void compute_static(int count, float *input0, float *output0, PluginDef*);
765  static int register_params_static(const ParamReg& reg);
766  static void del_instance(PluginDef *p);
767 public:
769  LiveLooper(ParamMap& param_, sigc::slot<void> sync, const string& loop_dir_);
770  ~LiveLooper();
771 };
772 
773 
774 /****************************************************************
775  ** class SCapture
776  */
777 
778 
779 class SCapture: public PluginDef {
780 private:
781  SNDFILE * recfile;
782  EngineControl& engine;
783  int fSamplingFreq;
784  int channel;
785  float fcheckbox0;
786  float fcheckbox1;
787  float fslider0;
788  float fbargraph0;
789  float fRecC0[2];
790  float fformat;
791  int IOTA;
792  int iA;
793  int savesize;
794  int filesize;
795  float *fRec0;
796  float *fRec1;
797  float *tape;
798  sem_t m_trig;
799  pthread_t m_pthr;
800  volatile bool keep_stream;
801  bool mem_allocated;
802  bool is_wav;
803  bool err;
804  float fConst0;
805  float fRecb0[2];
806  int iRecb1[2];
807  float fRecb2[2];
808  void mem_alloc();
809  void mem_free();
810  void clear_state_f();
811  int activate(bool start);
812  int load_ui_f(const UiBuilder& b, int form);
813  void init(unsigned int samplingFreq);
814  void compute(int count, float *input0, float *output0);
815  void compute_st(int count, float *input0, float *input1, float *output0, float *output1);
816  int register_par(const ParamReg& reg);
817  void save_to_wave(SNDFILE * sf, float *tape, int lSize);
818  SNDFILE *open_stream(std::string fname);
819  void close_stream(SNDFILE **sf);
820  void stop_thread();
821  void start_thread();
822  void disc_stream();
823  inline std::string get_ffilename();
824 
825  static void *run_thread(void* p);
826  static void clear_state_f_static(PluginDef*);
827  static int activate_static(bool start, PluginDef*);
828  static const char *glade_def;
829  static const char *glade_def_st;
830  static int load_ui_f_static(const UiBuilder& b, int form);
831  static void init_static(unsigned int samplingFreq, PluginDef*);
832  static void compute_static(int count, float *input0, float *output0, PluginDef*);
833  static void compute_static_st(int count, float *input0, float *input1, float *output0, float *output1, PluginDef*);
834  static int register_params_static(const ParamReg& reg);
835  static void del_instance(PluginDef *p);
836 public:
838  SCapture(EngineControl& engine, int channel_);
839  ~SCapture();
840 };
841 
842 
843 /****************************************************************************
844 *
845 * NAME: smbPitchShift.cpp
846 * VERSION: 1.2
847 * HOME URL: http://www.dspdimension.com
848 * KNOWN BUGS: none
849 *
850 *
851 * COPYRIGHT 1999-2009 Stephan M. Bernsee <smb [AT] dspdimension [DOT] com>
852 *
853 * Modified for guitarix by Hermann Meyer 2014
854 *
855 * The Wide Open License (WOL)
856 *
857 * Permission to use, copy, modify, distribute and sell this software and its
858 * documentation for any purpose is hereby granted without fee, provided that
859 * the above copyright notice and this license appear in all source copies.
860 * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF
861 * ANY KIND. See http://www.dspguru.com/wol.htm for more information.
862 *
863 *****************************************************************************/
864 
865 
866 #define M_PI 3.14159265358979323846
867 #define MAX_FRAME_LENGTH 8096
868 
869 class smbPitchShift : public PluginDef {
870 private:
872  EngineControl& engine;
873  bool mem_allocated;
874  sigc::slot<void> sync;
875  volatile bool ready;
876  ParamMap& param;
877  float gInFIFO[MAX_FRAME_LENGTH];
878  float gOutFIFO[MAX_FRAME_LENGTH];
879  float *fpb;
880  float *expect;
881  float *hanning;
882  float *hanningd;
883  float *resampin;
884  float *resampin2;
885  float *resampout;
886  float *indata2;
887  float gLastPhase[MAX_FRAME_LENGTH/2+1];
888  float gSumPhase[MAX_FRAME_LENGTH/2+1];
889  float gOutputAccum[2*MAX_FRAME_LENGTH];
890  float gAnaFreq[MAX_FRAME_LENGTH];
891  float gAnaMagn[MAX_FRAME_LENGTH];
892  float gSynFreq[MAX_FRAME_LENGTH];
893  float gSynMagn[MAX_FRAME_LENGTH];
894  float semitones;
895  float a,b,c,d,l;
896  float wet;
897  float dry;
898  float mpi, mpi1;
899  float tone;
900  int octave, osamp, numSampsToResamp, numSampsToProcess, fftFrameSize, sampleRate ;
901  int latency;
902  int ai;
903  int aio;
904  int ii;
905  long gRover , gInit ;
906  double magn, phase, tmp, window, real, imag;
907  double freqPerBin, freqPerBin1, freqPerBin2, expct;
908  double fftFrameSize3;
909  double fftFrameSize4;
910  double osamp1,osamp2;
911  long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;
912 
913  fftwf_complex fftw_in[MAX_FRAME_LENGTH], fftw_out[MAX_FRAME_LENGTH];
914  fftwf_plan ftPlanForward, ftPlanInverse;
915 
916  inline int load_ui_f(const UiBuilder& b, int form);
917  int register_par(const ParamReg& reg);
918  void change_latency();
919 
920  void mem_alloc();
921  void mem_free();
922  void clear_state();
923  int activate(bool start);
924  bool setParameters( int sampleRate);
925  void PitchShift(int count, float *indata, float *outdata);
926  void change_buffersize(unsigned int size);
927  static int activate_static(bool start, PluginDef*);
928  static void del_instance(PluginDef *p);
929  static int registerparam(const ParamReg& reg);
930  static int load_ui_f_static(const UiBuilder& b, int form);
931  static void init(unsigned int sampleRate, PluginDef *plugin);
932  static void compute_static(int count, float *input0, float *output0, PluginDef *p);
933 
934 public:
936  smbPitchShift(ParamMap& param_, EngineControl& engine, sigc::slot<void> sync);
937  ~smbPitchShift();
938 };
939 
940 
941 } // namespace gx_engine
CmdConnection::msg_type start
Definition: jsonrpc.cpp:255
std::string getFullIRPath() const
Glib::Dispatcher & signal_jack_load_change()
pluginarray::iterator end()
bool set(const GxJConvSettings &val) const
ParameterV< GxJConvSettings > JConvParameter
void init(int samplingFreq)
ParamMap & get_parameter_map() const
void set_jack(gx_jack::GxJack *jack_)
static std::string get_ladspa_filename(std::string uid_key)
std::vector< plugdesc * > pluginarray
const std::string & getIRFile() const
sigc::signal< void, const GxJConvSettings * > & signal_changed()
sigc::signal< int, bool > activation
std::string getFullIRPath() const
PluginDef * create(unsigned int idx)
const std::string & getIRFile() const
static PluginDef outputgate
void compute(int count, float *input0, float *output0)
std::string to_string(const T &t)
Definition: gx_system.h:523
const Gainline & getGainline() const
#define MAX_FRAME_LENGTH
sigc::signal< void, unsigned int > size_change
std::vector< paradesc * > names
const GxJConvSettings & get_value() const
const std::string & getIRDir() const
pluginarray::iterator begin()
void setGainline(const Gainline &gain)
const std::string & getIRDir() const
void set_dep_module(Plugin *dep)
Glib::Dispatcher & signal_freq_changed()
static std::string get_ladspa_filename(unsigned long uid)
std::string fformat(float value, float step)
const GxJConvSettings & get_jcset() const
Glib::Dispatcher new_freq
void set_mul_buffer(int a, unsigned int b)