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.

204 lines
7.4KB

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