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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. //returns true when note is successfully applied
  40. bool NoteOn(unsigned char note,
  41. unsigned char velocity,
  42. int masterkeyshift) REALTIME;
  43. void NoteOff(unsigned char note) REALTIME;
  44. void PolyphonicAftertouch(unsigned char note,
  45. unsigned char velocity,
  46. int masterkeyshift) REALTIME;
  47. void AllNotesOff() REALTIME; //panic
  48. void SetController(unsigned int type, int par) REALTIME;
  49. void ReleaseSustainedKeys() REALTIME; //this is called when the sustain pedal is released
  50. void ReleaseAllKeys() REALTIME; //this is called on AllNotesOff controller
  51. /* The synthesizer part output */
  52. void ComputePartSmps() REALTIME; //Part output
  53. //saves the instrument settings to a XML file
  54. //returns 0 for ok or <0 if there is an error
  55. int saveXML(const char *filename);
  56. int loadXMLinstrument(const char *filename);
  57. void add2XML(XMLwrapper& xml);
  58. void add2XMLinstrument(XMLwrapper& xml);
  59. void defaults();
  60. void defaultsinstrument();
  61. void applyparameters(void) NONREALTIME;
  62. void applyparameters(std::function<bool()> do_abort) NONREALTIME;
  63. void initialize_rt(void) REALTIME;
  64. void kill_rt(void) REALTIME;
  65. void getfromXML(XMLwrapper& xml);
  66. void getfromXMLinstrument(XMLwrapper& xml);
  67. void cleanup(bool final = false);
  68. //the part's kit
  69. struct Kit {
  70. Part *parent;
  71. bool Penabled, Pmuted;
  72. unsigned char Pminkey, Pmaxkey;
  73. char *Pname;
  74. bool Padenabled, Psubenabled, Ppadenabled;
  75. unsigned char Psendtoparteffect;
  76. ADnoteParameters *adpars;
  77. SUBnoteParameters *subpars;
  78. PADnoteParameters *padpars;
  79. bool active(void) const;
  80. uint8_t sendto(void) const;
  81. bool validNote(char note) const;
  82. const static rtosc::Ports &ports;
  83. } kit[NUM_KIT_ITEMS];
  84. //Part parameters
  85. void setkeylimit(unsigned char Pkeylimit);
  86. void setkititemstatus(unsigned kititem, bool Penabled_);
  87. bool Penabled; /**<if the part is enabled*/
  88. unsigned char Pvolume; /**<part volume*/
  89. unsigned char Pminkey; /**<the minimum key that the part receives noteon messages*/
  90. unsigned char Pmaxkey; //the maximum key that the part receives noteon messages
  91. void setPvolume(char Pvolume);
  92. unsigned char Pkeyshift; //Part keyshift
  93. unsigned char Prcvchn; //from what midi channel it receive commnads
  94. unsigned char Ppanning; //part panning
  95. void setPpanning(char Ppanning);
  96. unsigned char Pvelsns; //velocity sensing (amplitude velocity scale)
  97. unsigned char Pveloffs; //velocity offset
  98. bool Pnoteon; //if the part receives NoteOn messages
  99. int Pkitmode; //if the kitmode is enabled
  100. //XXX consider deprecating drum mode
  101. bool Pdrummode; //if all keys are mapped and the system is 12tET (used for drums)
  102. bool Ppolymode; //Part mode - 0=monophonic , 1=polyphonic
  103. bool Plegatomode; // 0=normal, 1=legato
  104. unsigned char Pkeylimit; //how many keys are alowed to be played same time (0=off), the older will be released
  105. char *Pname; //name of the instrument
  106. struct { //instrument additional information
  107. unsigned char Ptype;
  108. char Pauthor[MAX_INFO_TEXT_SIZE + 1];
  109. char Pcomments[MAX_INFO_TEXT_SIZE + 1];
  110. } info;
  111. float *partoutl; //Left channel output of the part
  112. float *partoutr; //Right channel output of the part
  113. float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects;
  114. *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer
  115. enum NoteStatus {
  116. KEY_OFF, KEY_PLAYING, KEY_RELEASED_AND_SUSTAINED, KEY_RELEASED
  117. };
  118. float volume, oldvolumel, oldvolumer; //this is applied by Master
  119. float panning; //this is applied by Master, too
  120. Controller ctl; //Part controllers
  121. EffectMgr *partefx[NUM_PART_EFX]; //insertion part effects (they are part of the instrument)
  122. unsigned char Pefxroute[NUM_PART_EFX]; //how the effect's output is routed(to next effect/to out)
  123. bool Pefxbypass[NUM_PART_EFX]; //if the effects are bypassed
  124. int lastnote;
  125. const static rtosc::Ports &ports;
  126. private:
  127. void MonoMemRenote(); // MonoMem stuff.
  128. float getBaseFreq(int note, int keyshift) const;
  129. float getVelocity(uint8_t velocity, uint8_t velocity_sense,
  130. uint8_t velocity_offset) const;
  131. void verifyKeyMode(void);
  132. bool isPolyMode(void) const {return Ppolymode;}
  133. bool isMonoMode(void) const {return !Ppolymode && !Plegatomode;};
  134. bool isLegatoMode(void) const {return Plegatomode && !Pdrummode;}
  135. bool isNonKit(void) const {return Pkitmode == 0;}
  136. bool isMultiKit(void) const {return Pkitmode == 1;}
  137. bool isSingleKit(void) const {return Pkitmode == 2;}
  138. bool killallnotes;
  139. NotePool notePool;
  140. bool lastlegatomodevalid; // To keep track of previous legatomodevalid.
  141. // MonoMem stuff
  142. void monomemPush(char note);
  143. void monomemPop(char note);
  144. char monomemBack(void) const;
  145. bool monomemEmpty(void) const;
  146. void monomemClear(void);
  147. short monomemnotes[256]; // A list to remember held notes.
  148. struct {
  149. unsigned char velocity;
  150. int mkeyshift; // I'm not sure masterkeyshift should be remembered.
  151. } monomem[256];
  152. /* 256 is to cover all possible note values.
  153. monomem[] is used in conjunction with the list to
  154. store the velocity and masterkeyshift values of a given note (the list only store note values).
  155. For example 'monomem[note].velocity' would be the velocity value of the note 'note'.*/
  156. float oldfreq; //this is used for portamento
  157. Microtonal *microtonal;
  158. FFTwrapper *fft;
  159. Allocator &memory;
  160. const SYNTH_T &synth;
  161. const AbsTime &time;
  162. const int &gzip_compression, &interpolation;
  163. };
  164. #endif