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.

Part.h 7.9KB

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