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.

183 lines
5.4KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Master.h - It sends Midi Messages to Parts, receives samples from parts,
  4. process them with system/insertion effects and mix them
  5. Copyright (C) 2002-2005 Nasca Octavian Paul
  6. Author: Nasca Octavian Paul
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License
  9. as published by the Free Software Foundation.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License (version 2 or later) for more details.
  14. You should have received a copy of the GNU General Public License (version 2)
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef MASTER_H
  19. #define MASTER_H
  20. #include "../globals.h"
  21. #include "Microtonal.h"
  22. #include "Bank.h"
  23. #include "Recorder.h"
  24. #include "Dump.h"
  25. #include "XMLwrapper.h"
  26. #include "../Params/Controller.h"
  27. typedef enum {
  28. MUTEX_TRYLOCK, MUTEX_LOCK, MUTEX_UNLOCK
  29. } lockset;
  30. extern Dump dump;
  31. struct vuData {
  32. vuData(void);
  33. float outpeakl, outpeakr, maxoutpeakl, maxoutpeakr,
  34. rmspeakl, rmspeakr;
  35. int clipped;
  36. };
  37. /** It sends Midi Messages to Parts, receives samples from parts,
  38. * process them with system/insertion effects and mix them */
  39. class Master
  40. {
  41. public:
  42. /** Constructor TODO make private*/
  43. Master();
  44. /** Destructor*/
  45. ~Master();
  46. static Master &getInstance();
  47. static void deleteInstance();
  48. /**Saves all settings to a XML file
  49. * @return 0 for ok or <0 if there is an error*/
  50. int saveXML(const char *filename);
  51. /**This adds the parameters to the XML data*/
  52. void add2XML(XMLwrapper *xml);
  53. void defaults();
  54. /**loads all settings from a XML file
  55. * @return 0 for ok or -1 if there is an error*/
  56. int loadXML(const char *filename);
  57. void applyparameters(bool lockmutex = true);
  58. void getfromXML(XMLwrapper *xml);
  59. /**get all data to a newly allocated array (used for VST)
  60. * @return the datasize*/
  61. int getalldata(char **data);
  62. /**put all data from the *data array to zynaddsubfx parameters (used for VST)*/
  63. void putalldata(char *data, int size);
  64. //Mutex control
  65. /**Control the Master's mutex state.
  66. * @param lockset either trylock, lock, or unlock.
  67. * @return true when successful false otherwise.*/
  68. bool mutexLock(lockset request);
  69. //Midi IN
  70. void noteOn(char chan, char note, char velocity);
  71. void noteOff(char chan, char note);
  72. void polyphonicAftertouch(char chan, char note, char velocity);
  73. void setController(char chan, int type, int par);
  74. void setProgram(char chan, unsigned int pgm);
  75. //void NRPN...
  76. void ShutUp();
  77. int shutup;
  78. void vuUpdate(const float *outl, const float *outr);
  79. /**Audio Output*/
  80. void AudioOut(float *outl, float *outr);
  81. /**Audio Output (for callback mode). This allows the program to be controled by an external program*/
  82. void GetAudioOutSamples(size_t nsamples,
  83. unsigned samplerate,
  84. float *outl,
  85. float *outr);
  86. void partonoff(int npart, int what);
  87. /**parts \todo see if this can be made to be dynamic*/
  88. class Part * part[NUM_MIDI_PARTS];
  89. //parameters
  90. unsigned char Pvolume;
  91. unsigned char Pkeyshift;
  92. unsigned char Psysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  93. unsigned char Psysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  94. //parameters control
  95. void setPvolume(char Pvolume_);
  96. void setPkeyshift(char Pkeyshift_);
  97. void setPsysefxvol(int Ppart, int Pefx, char Pvol);
  98. void setPsysefxsend(int Pefxfrom, int Pefxto, char Pvol);
  99. //effects
  100. class EffectMgr * sysefx[NUM_SYS_EFX]; //system
  101. class EffectMgr * insefx[NUM_INS_EFX]; //insertion
  102. // void swapcopyeffects(int what,int type,int neff1,int neff2);
  103. //HDD recorder
  104. Recorder HDDRecorder;
  105. //part that's apply the insertion effect; -1 to disable
  106. short int Pinsparts[NUM_INS_EFX];
  107. //peaks for VU-meter
  108. void vuresetpeaks();
  109. //get VU-meter data
  110. vuData getVuData();
  111. //peaks for part VU-meters
  112. /**\todo synchronize this with a mutex*/
  113. float vuoutpeakpart[NUM_MIDI_PARTS];
  114. unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled
  115. Controller ctl;
  116. bool swaplr; //if L and R are swapped
  117. //other objects
  118. Microtonal microtonal;
  119. Bank bank;
  120. class FFTwrapper * fft;
  121. pthread_mutex_t mutex;
  122. pthread_mutex_t vumutex;
  123. private:
  124. bool nullRun;
  125. vuData vu;
  126. float volume;
  127. float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  128. float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  129. int keyshift;
  130. //information relevent to generating plugin audio samples
  131. float *bufl;
  132. float *bufr;
  133. off_t off;
  134. size_t smps;
  135. };
  136. #endif