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.3KB

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