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.

202 lines
7.3KB

  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 "../Misc/Microtonal.h"
  23. #include <list> // For the monomemnotes list.
  24. class EffectMgr;
  25. class ADnoteParameters;
  26. class SUBnoteParameters;
  27. class PADnoteParameters;
  28. class SynthNote;
  29. class XMLWrapper;
  30. class FFTwrapper;
  31. /** Part implementation*/
  32. class Part
  33. {
  34. public:
  35. /**Constructor
  36. * @param microtonal_ Pointer to the microtonal object
  37. * @param fft_ Pointer to the FFTwrapper
  38. * @param mutex_ Pointer to the master pthread_mutex_t*/
  39. Part(Microtonal *microtonal_, FFTwrapper *fft_, pthread_mutex_t *mutex_);
  40. /**Destructor*/
  41. ~Part();
  42. // Midi commands implemented
  43. void NoteOn(unsigned char note,
  44. unsigned char velocity,
  45. int masterkeyshift);
  46. void NoteOff(unsigned char note);
  47. void PolyphonicAftertouch(unsigned char note,
  48. unsigned char velocity,
  49. int masterkeyshift);
  50. void AllNotesOff(); //panic
  51. void SetController(unsigned int type, int par);
  52. void RelaseSustainedKeys(); //this is called when the sustain pedal is relased
  53. void RelaseAllKeys(); //this is called on AllNotesOff controller
  54. /* The synthesizer part output */
  55. void ComputePartSmps(); //Part output
  56. //instrumentonly: 0 - save all, 1 - save only instrumnet, 2 - save only instrument without the name(used in bank)
  57. //saves the instrument settings to a XML file
  58. //returns 0 for ok or <0 if there is an error
  59. int saveXML(const char *filename);
  60. int loadXMLinstrument(const char *filename);
  61. void add2XML(XMLwrapper *xml);
  62. void add2XMLinstrument(XMLwrapper *xml);
  63. void defaults();
  64. void defaultsinstrument();
  65. void applyparameters(bool lockmutex = true);
  66. void getfromXML(XMLwrapper *xml);
  67. void getfromXMLinstrument(XMLwrapper *xml);
  68. void cleanup(bool final = false);
  69. //the part's kit
  70. struct {
  71. unsigned char Penabled, Pmuted, Pminkey, Pmaxkey;
  72. unsigned char *Pname;
  73. unsigned char Padenabled, Psubenabled, Ppadenabled;
  74. unsigned char Psendtoparteffect;
  75. ADnoteParameters *adpars;
  76. SUBnoteParameters *subpars;
  77. PADnoteParameters *padpars;
  78. } kit[NUM_KIT_ITEMS];
  79. //Part parameters
  80. void setkeylimit(unsigned char Pkeylimit);
  81. void setkititemstatus(int kititem, int Penabled_);
  82. unsigned char 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. unsigned char Pnoteon; //if the part receives NoteOn messages
  94. unsigned char Pkitmode; //if the kitmode is enabled
  95. unsigned char Pdrummode; //if all keys are mapped and the system is 12tET (used for drums)
  96. unsigned char Ppolymode; //Part mode - 0=monophonic , 1=polyphonic
  97. unsigned char Plegatomode; // 0=normal, 1=legato
  98. unsigned char Pkeylimit; //how many keys are alowed to be played same time (0=off), the older will be relased
  99. unsigned char *Pname; //name of the instrument
  100. struct { //instrument additional information
  101. unsigned char Ptype;
  102. unsigned char Pauthor[MAX_INFO_TEXT_SIZE + 1];
  103. unsigned char Pcomments[MAX_INFO_TEXT_SIZE + 1];
  104. } info;
  105. float *partoutl; //Left channel output of the part
  106. float *partoutr; //Right channel output of the part
  107. float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects;
  108. *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer
  109. enum NoteStatus {
  110. KEY_OFF, KEY_PLAYING, KEY_RELASED_AND_SUSTAINED, KEY_RELASED
  111. };
  112. float volume, oldvolumel, oldvolumer; //this is applied by Master
  113. float panning; //this is applied by Master, too
  114. Controller ctl; //Part controllers
  115. EffectMgr *partefx[NUM_PART_EFX]; //insertion part effects (they are part of the instrument)
  116. unsigned char Pefxroute[NUM_PART_EFX]; //how the effect's output is routed(to next effect/to out)
  117. bool Pefxbypass[NUM_PART_EFX]; //if the effects are bypassed
  118. pthread_mutex_t *mutex;
  119. pthread_mutex_t load_mutex;
  120. int lastnote;
  121. private:
  122. void RunNote(unsigned k);
  123. void KillNotePos(int pos);
  124. void RelaseNotePos(int pos);
  125. void MonoMemRenote(); // MonoMem stuff.
  126. int killallnotes; //is set to 1 if I want to kill all notes
  127. struct PartNotes {
  128. NoteStatus status;
  129. int note; //if there is no note playing, the "note"=-1
  130. int itemsplaying;
  131. struct {
  132. SynthNote *adnote,
  133. *subnote,
  134. *padnote;
  135. int sendtoparteffect;
  136. } kititem[NUM_KIT_ITEMS];
  137. int time;
  138. };
  139. int lastpos, lastposb; // To keep track of previously used pos and posb.
  140. bool lastlegatomodevalid; // To keep track of previous legatomodevalid.
  141. // MonoMem stuff
  142. std::list<unsigned char> monomemnotes; // A list to remember held notes.
  143. struct {
  144. unsigned char velocity;
  145. int mkeyshift; // I'm not sure masterkeyshift should be remembered.
  146. } monomem[256];
  147. /* 256 is to cover all possible note values.
  148. monomem[] is used in conjunction with the list to
  149. store the velocity and masterkeyshift values of a given note (the list only store note values).
  150. For example 'monomem[note].velocity' would be the velocity value of the note 'note'.*/
  151. PartNotes partnote[POLIPHONY];
  152. float oldfreq; //this is used for portamento
  153. Microtonal *microtonal;
  154. FFTwrapper *fft;
  155. };
  156. #endif