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.

208 lines
7.6KB

  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 <functional>
  23. /** Part implementation*/
  24. class Part
  25. {
  26. public:
  27. /**Constructor
  28. * @param microtonal_ Pointer to the microtonal object
  29. * @param fft_ Pointer to the FFTwrapper*/
  30. Part(Allocator &alloc, const SYNTH_T &synth,
  31. const int& gzip_compression, const int& interpolation,
  32. Microtonal *microtonal_, FFTwrapper *fft_);
  33. /**Destructor*/
  34. ~Part();
  35. // Copy misc parameters not stored in .xiz format
  36. void cloneTraits(Part &part) const REALTIME;
  37. // Midi commands implemented
  38. void NoteOn(unsigned char note,
  39. unsigned char velocity,
  40. int masterkeyshift) REALTIME;
  41. void NoteOff(unsigned char note) REALTIME;
  42. void PolyphonicAftertouch(unsigned char note,
  43. unsigned char velocity,
  44. int masterkeyshift) REALTIME;
  45. void AllNotesOff() REALTIME; //panic
  46. void SetController(unsigned int type, int par) REALTIME;
  47. void ReleaseSustainedKeys() REALTIME; //this is called when the sustain pedal is released
  48. void ReleaseAllKeys() REALTIME; //this is called on AllNotesOff controller
  49. /* The synthesizer part output */
  50. void ComputePartSmps() REALTIME; //Part output
  51. //saves the instrument settings to a XML file
  52. //returns 0 for ok or <0 if there is an error
  53. int saveXML(const char *filename);
  54. int loadXMLinstrument(const char *filename);
  55. void add2XML(XMLwrapper *xml);
  56. void add2XMLinstrument(XMLwrapper *xml);
  57. void defaults();
  58. void defaultsinstrument();
  59. void applyparameters(void) NONREALTIME;
  60. void applyparameters(std::function<bool()> do_abort) NONREALTIME;
  61. void initialize_rt(void) REALTIME;
  62. void kill_rt(void) REALTIME;
  63. void getfromXML(XMLwrapper *xml);
  64. void getfromXMLinstrument(XMLwrapper *xml);
  65. void cleanup(bool final = false);
  66. //the part's kit
  67. struct Kit {
  68. Part *parent;
  69. bool Penabled, Pmuted;
  70. unsigned char Pminkey, Pmaxkey;
  71. char *Pname;
  72. bool Padenabled, Psubenabled, Ppadenabled;
  73. unsigned char Psendtoparteffect;
  74. ADnoteParameters *adpars;
  75. SUBnoteParameters *subpars;
  76. PADnoteParameters *padpars;
  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. bool Pdrummode; //if all keys are mapped and the system is 12tET (used for drums)
  96. bool Ppolymode; //Part mode - 0=monophonic , 1=polyphonic
  97. bool 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 released
  99. char *Pname; //name of the instrument
  100. struct { //instrument additional information
  101. unsigned char Ptype;
  102. char Pauthor[MAX_INFO_TEXT_SIZE + 1];
  103. 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_RELEASED_AND_SUSTAINED, KEY_RELEASED
  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. int lastnote;
  119. const static rtosc::Ports &ports;
  120. private:
  121. void RunNote(unsigned k);
  122. void KillNotePos(int pos);
  123. void ReleaseNotePos(int pos);
  124. void MonoMemRenote(); // MonoMem stuff.
  125. int killallnotes; //is set to 1 if I want to kill all notes
  126. struct PartNotes {
  127. NoteStatus status;
  128. int note; //if there is no note playing, the "note"=-1
  129. int itemsplaying;
  130. struct {
  131. SynthNote *adnote, *subnote, *padnote;
  132. int sendtoparteffect;
  133. } kititem[NUM_KIT_ITEMS];
  134. int time;
  135. };
  136. int lastpos, lastposb; // To keep track of previously used pos and posb.
  137. bool lastlegatomodevalid; // To keep track of previous legatomodevalid.
  138. // MonoMem stuff
  139. void monomemPush(char note);
  140. void monomemPop(char note);
  141. char monomemBack(void) const;
  142. bool monomemEmpty(void) const;
  143. void monomemClear(void);
  144. short monomemnotes[256]; // A list to remember held notes.
  145. struct {
  146. unsigned char velocity;
  147. int mkeyshift; // I'm not sure masterkeyshift should be remembered.
  148. } monomem[256];
  149. /* 256 is to cover all possible note values.
  150. monomem[] is used in conjunction with the list to
  151. store the velocity and masterkeyshift values of a given note (the list only store note values).
  152. For example 'monomem[note].velocity' would be the velocity value of the note 'note'.*/
  153. PartNotes partnote[POLYPHONY];
  154. float oldfreq; //this is used for portamento
  155. Microtonal *microtonal;
  156. FFTwrapper *fft;
  157. Allocator &memory;
  158. const SYNTH_T &synth;
  159. const int &gzip_compression, &interpolation;
  160. };
  161. #endif