Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
7.5KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Part.h - Part implementation
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef PART_H
  12. #define PART_H
  13. #define MAX_INFO_TEXT_SIZE 1000
  14. #include "../globals.h"
  15. #include "../Params/Controller.h"
  16. #include "../Containers/NotePool.h"
  17. #include <functional>
  18. /** Part implementation*/
  19. class Part
  20. {
  21. public:
  22. /**Constructor
  23. * @param microtonal_ Pointer to the microtonal object
  24. * @param fft_ Pointer to the FFTwrapper*/
  25. Part(Allocator &alloc, const SYNTH_T &synth, const AbsTime &time,
  26. const int& gzip_compression, const int& interpolation,
  27. Microtonal *microtonal_, FFTwrapper *fft_, WatchManager *wm=0, const char *prefix=0);
  28. /**Destructor*/
  29. ~Part();
  30. // Copy misc parameters not stored in .xiz format
  31. void cloneTraits(Part &part) const REALTIME;
  32. // Midi commands implemented
  33. //returns true when note is successfully applied
  34. bool NoteOn(unsigned char note,
  35. unsigned char velocity,
  36. int masterkeyshift) REALTIME;
  37. void NoteOff(unsigned char note) REALTIME;
  38. void PolyphonicAftertouch(unsigned char note,
  39. unsigned char velocity,
  40. int masterkeyshift) REALTIME;
  41. void AllNotesOff() REALTIME; //panic
  42. void SetController(unsigned int type, int par) REALTIME;
  43. void ReleaseSustainedKeys() REALTIME; //this is called when the sustain pedal is released
  44. void ReleaseAllKeys() REALTIME; //this is called on AllNotesOff controller
  45. /* The synthesizer part output */
  46. void ComputePartSmps() REALTIME; //Part output
  47. //saves the instrument settings to a XML file
  48. //returns 0 for ok or <0 if there is an error
  49. int saveXML(const char *filename);
  50. int loadXMLinstrument(const char *filename);
  51. void add2XML(XMLwrapper& xml);
  52. void add2XMLinstrument(XMLwrapper& xml);
  53. void defaults();
  54. void defaultsinstrument();
  55. void applyparameters(void) NONREALTIME;
  56. void applyparameters(std::function<bool()> do_abort) NONREALTIME;
  57. void initialize_rt(void) REALTIME;
  58. void kill_rt(void) REALTIME;
  59. void getfromXML(XMLwrapper& xml);
  60. void getfromXMLinstrument(XMLwrapper& xml);
  61. void cleanup(bool final = false);
  62. //the part's kit
  63. struct Kit {
  64. Kit(void);
  65. Part *parent;
  66. bool Penabled, Pmuted;
  67. unsigned char Pminkey, Pmaxkey;
  68. char *Pname;
  69. bool Padenabled, Psubenabled, Ppadenabled;
  70. unsigned char Psendtoparteffect;
  71. ADnoteParameters *adpars;
  72. SUBnoteParameters *subpars;
  73. PADnoteParameters *padpars;
  74. bool active(void) const;
  75. uint8_t sendto(void) const;
  76. bool validNote(char note) const;
  77. const static rtosc::Ports &ports;
  78. } kit[NUM_KIT_ITEMS];
  79. //Part parameters
  80. void setkeylimit(unsigned char Pkeylimit);
  81. void setkititemstatus(unsigned kititem, bool Penabled_);
  82. bool Penabled; /**<if the part is enabled*/
  83. unsigned char Pvolume; /**<part volume*/
  84. unsigned char Pminkey; /**<the minimum key that the part receives noteon messages*/
  85. unsigned char Pmaxkey; //the maximum key that the part receives noteon messages
  86. void setPvolume(char Pvolume);
  87. unsigned char Pkeyshift; //Part keyshift
  88. unsigned char Prcvchn; //from what midi channel it receive commnads
  89. unsigned char Ppanning; //part panning
  90. void setPpanning(char Ppanning);
  91. unsigned char Pvelsns; //velocity sensing (amplitude velocity scale)
  92. unsigned char Pveloffs; //velocity offset
  93. bool Pnoteon; //if the part receives NoteOn messages
  94. int Pkitmode; //if the kitmode is enabled
  95. //XXX consider deprecating drum mode
  96. bool Pdrummode; //if all keys are mapped and the system is 12tET (used for drums)
  97. bool Ppolymode; //Part mode - 0=monophonic , 1=polyphonic
  98. bool Plegatomode; // 0=normal, 1=legato
  99. unsigned char Pkeylimit; //how many keys are alowed to be played same time (0=off), the older will be released
  100. char *Pname; //name of the instrument
  101. struct { //instrument additional information
  102. unsigned char Ptype;
  103. char Pauthor[MAX_INFO_TEXT_SIZE + 1];
  104. char Pcomments[MAX_INFO_TEXT_SIZE + 1];
  105. } info;
  106. float *partoutl; //Left channel output of the part
  107. float *partoutr; //Right channel output of the part
  108. float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects;
  109. *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer
  110. float volume, oldvolumel, oldvolumer; //this is applied by Master
  111. float panning; //this is applied by Master, too
  112. Controller ctl; //Part controllers
  113. EffectMgr *partefx[NUM_PART_EFX]; //insertion part effects (they are part of the instrument)
  114. unsigned char Pefxroute[NUM_PART_EFX]; //how the effect's output is routed(to next effect/to out)
  115. bool Pefxbypass[NUM_PART_EFX]; //if the effects are bypassed
  116. int lastnote;
  117. const static rtosc::Ports &ports;
  118. private:
  119. void MonoMemRenote(); // MonoMem stuff.
  120. float getBaseFreq(int note, int keyshift) const;
  121. float getVelocity(uint8_t velocity, uint8_t velocity_sense,
  122. uint8_t velocity_offset) const;
  123. void verifyKeyMode(void);
  124. bool isPolyMode(void) const {return Ppolymode;}
  125. bool isMonoMode(void) const {return !Ppolymode && !Plegatomode;};
  126. bool isLegatoMode(void) const {return Plegatomode && !Pdrummode;}
  127. bool isNonKit(void) const {return Pkitmode == 0;}
  128. bool isMultiKit(void) const {return Pkitmode == 1;}
  129. bool isSingleKit(void) const {return Pkitmode == 2;}
  130. bool killallnotes;
  131. NotePool notePool;
  132. bool lastlegatomodevalid; // To keep track of previous legatomodevalid.
  133. // MonoMem stuff
  134. void monomemPush(char note);
  135. void monomemPop(char note);
  136. char monomemBack(void) const;
  137. bool monomemEmpty(void) const;
  138. void monomemClear(void);
  139. short monomemnotes[256]; // A list to remember held notes.
  140. struct {
  141. unsigned char velocity;
  142. int mkeyshift; // I'm not sure masterkeyshift should be remembered.
  143. } monomem[256];
  144. /* 256 is to cover all possible note values.
  145. monomem[] is used in conjunction with the list to
  146. store the velocity and masterkeyshift values of a given note (the list only store note values).
  147. For example 'monomem[note].velocity' would be the velocity value of the note 'note'.*/
  148. float oldfreq; //this is used for portamento
  149. Microtonal *microtonal;
  150. FFTwrapper *fft;
  151. WatchManager *wm;
  152. char prefix[64];
  153. Allocator &memory;
  154. const SYNTH_T &synth;
  155. const AbsTime &time;
  156. const int &gzip_compression, &interpolation;
  157. };
  158. #endif