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.

210 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
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef PART_H
  12. #define PART_H
  13. #define MAX_INFO_TEXT_SIZE 1000
  14. #include "../globals.h"
  15. #include "../Params/Controller.h"
  16. #include "../Containers/NotePool.h"
  17. #include <functional>
  18. namespace zyncarla {
  19. /** Part implementation*/
  20. class Part
  21. {
  22. public:
  23. /**Constructor
  24. * @param microtonal_ Pointer to the microtonal object
  25. * @param fft_ Pointer to the FFTwrapper*/
  26. Part(Allocator &alloc, const SYNTH_T &synth, const AbsTime &time,
  27. const int& gzip_compression, const int& interpolation,
  28. Microtonal *microtonal_, FFTwrapper *fft_, WatchManager *wm=0, const char *prefix=0);
  29. /**Destructor*/
  30. ~Part();
  31. // Copy misc parameters not stored in .xiz format
  32. void cloneTraits(Part &part) const REALTIME;
  33. // Midi commands implemented
  34. //returns true when note is successfully applied
  35. bool NoteOn(unsigned char note,
  36. unsigned char velocity,
  37. int masterkeyshift) REALTIME;
  38. void NoteOff(unsigned char note) REALTIME;
  39. void PolyphonicAftertouch(unsigned char note,
  40. unsigned char velocity,
  41. int masterkeyshift) REALTIME;
  42. void AllNotesOff() REALTIME; //panic
  43. void SetController(unsigned int type, int par) REALTIME;
  44. void ReleaseSustainedKeys() REALTIME; //this is called when the sustain pedal is released
  45. void ReleaseAllKeys() REALTIME; //this is called on AllNotesOff controller
  46. /* The synthesizer part output */
  47. void ComputePartSmps() REALTIME; //Part output
  48. //saves the instrument settings to a XML file
  49. //returns 0 for ok or <0 if there is an error
  50. int saveXML(const char *filename);
  51. int loadXMLinstrument(const char *filename);
  52. void add2XML(XMLwrapper& xml);
  53. void add2XMLinstrument(XMLwrapper& xml);
  54. void defaults();
  55. void defaultsinstrument();
  56. void applyparameters(void) NONREALTIME;
  57. void applyparameters(std::function<bool()> do_abort) NONREALTIME;
  58. void initialize_rt(void) REALTIME;
  59. void kill_rt(void) REALTIME;
  60. void getfromXML(XMLwrapper& xml);
  61. void getfromXMLinstrument(XMLwrapper& xml);
  62. void cleanup(bool final = false);
  63. //the part's kit
  64. struct Kit {
  65. Kit(void);
  66. Part *parent;
  67. bool firstkit;
  68. bool Penabled, Pmuted;
  69. unsigned char Pminkey, Pmaxkey;
  70. char *Pname;
  71. bool Padenabled, Psubenabled, Ppadenabled;
  72. unsigned char Psendtoparteffect;
  73. ADnoteParameters *adpars;
  74. SUBnoteParameters *subpars;
  75. PADnoteParameters *padpars;
  76. bool active(void) const;
  77. uint8_t sendto(void) const;
  78. bool validNote(char note) const;
  79. const static rtosc::Ports &ports;
  80. } kit[NUM_KIT_ITEMS];
  81. //Part parameters
  82. void setkeylimit(unsigned char Pkeylimit);
  83. void setkititemstatus(unsigned kititem, bool Penabled_);
  84. unsigned char partno; /**<if it's the Master's first part*/
  85. bool Penabled; /**<if the part is enabled*/
  86. unsigned char Pvolume; /**<part volume*/
  87. unsigned char Pminkey; /**<the minimum key that the part receives noteon messages*/
  88. unsigned char Pmaxkey; //the maximum key that the part receives noteon messages
  89. void setPvolume(char Pvolume);
  90. unsigned char Pkeyshift; //Part keyshift
  91. unsigned char Prcvchn; //from what midi channel it receives commands
  92. unsigned char Ppanning; //part panning
  93. void setPpanning(char Ppanning);
  94. unsigned char Pvelsns; //velocity sensing (amplitude velocity scale)
  95. unsigned char Pveloffs; //velocity offset
  96. bool Pnoteon; //if the part receives NoteOn messages
  97. int Pkitmode; //if the kitmode is enabled
  98. //XXX consider deprecating drum mode
  99. bool Pdrummode; //if all keys are mapped and the system is 12tET (used for drums)
  100. bool Ppolymode; //Part mode - 0=monophonic , 1=polyphonic
  101. bool Plegatomode; // 0=normal, 1=legato
  102. unsigned char Pkeylimit; //how many keys are alowed to be played same time (0=off), the older will be released
  103. char *Pname; //name of the instrument
  104. struct { //instrument additional information
  105. unsigned char Ptype;
  106. char Pauthor[MAX_INFO_TEXT_SIZE + 1];
  107. char Pcomments[MAX_INFO_TEXT_SIZE + 1];
  108. } info;
  109. float *partoutl; //Left channel output of the part
  110. float *partoutr; //Right channel output of the part
  111. float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects;
  112. *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer
  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. int lastnote;
  120. const static rtosc::Ports &ports;
  121. private:
  122. void MonoMemRenote(); // MonoMem stuff.
  123. float getBaseFreq(int note, int keyshift) const;
  124. float getVelocity(uint8_t velocity, uint8_t velocity_sense,
  125. uint8_t velocity_offset) const;
  126. void verifyKeyMode(void);
  127. bool isPolyMode(void) const {return Ppolymode;}
  128. bool isMonoMode(void) const {return !Ppolymode && !Plegatomode;};
  129. bool isLegatoMode(void) const {return Plegatomode && !Pdrummode;}
  130. bool isNonKit(void) const {return Pkitmode == 0;}
  131. bool isMultiKit(void) const {return Pkitmode == 1;}
  132. bool isSingleKit(void) const {return Pkitmode == 2;}
  133. bool killallnotes;
  134. NotePool notePool;
  135. bool lastlegatomodevalid; // To keep track of previous legatomodevalid.
  136. // MonoMem stuff
  137. void monomemPush(char note);
  138. void monomemPop(char note);
  139. char monomemBack(void) const;
  140. bool monomemEmpty(void) const;
  141. void monomemClear(void);
  142. short monomemnotes[256]; // 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. float oldfreq; //this is used for portamento
  152. Microtonal *microtonal;
  153. FFTwrapper *fft;
  154. WatchManager *wm;
  155. char prefix[64];
  156. Allocator &memory;
  157. const SYNTH_T &synth;
  158. const AbsTime &time;
  159. const int &gzip_compression, &interpolation;
  160. };
  161. }
  162. #endif