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.

176 lines
5.2KB

  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. /**Saves all settings to a XML file
  48. * @return 0 for ok or <0 if there is an error*/
  49. int saveXML(const char *filename);
  50. /**This adds the parameters to the XML data*/
  51. void add2XML(XMLwrapper *xml);
  52. void defaults();
  53. /**loads all settings from a XML file
  54. * @return 0 for ok or -1 if there is an error*/
  55. int loadXML(const char *filename);
  56. void applyparameters(bool lockmutex = true);
  57. void getfromXML(XMLwrapper *xml);
  58. /**get all data to a newly allocated array (used for VST)
  59. * @return the datasize*/
  60. int getalldata(char **data);
  61. /**put all data from the *data array to zynaddsubfx parameters (used for VST)*/
  62. void putalldata(char *data, int size);
  63. //Mutex control
  64. /**Control the Master's mutex state.
  65. * @param lockset either trylock, lock, or unlock.
  66. * @return true when successful false otherwise.*/
  67. bool mutexLock(lockset request);
  68. //Midi IN
  69. void noteOn(char chan, char note, char velocity);
  70. void noteOff(char chan, char note);
  71. void polyphonicAftertouch(char chan, char note, char velocity);
  72. void setController(char chan, int type, int par);
  73. void setProgram(char chan, unsigned int pgm);
  74. //void NRPN...
  75. void ShutUp();
  76. int shutup;
  77. void vuUpdate(const float *outl, const float *outr);
  78. /**Audio Output*/
  79. void AudioOut(float *outl, float *outr);
  80. /**Audio Output (for callback mode). This allows the program to be controled by an external program*/
  81. void GetAudioOutSamples(size_t nsamples,
  82. unsigned samplerate,
  83. float *outl,
  84. float *outr);
  85. void partonoff(int npart, int what);
  86. /**parts \todo see if this can be made to be dynamic*/
  87. class Part * part[NUM_MIDI_PARTS];
  88. //parameters
  89. unsigned char Pvolume;
  90. unsigned char Pkeyshift;
  91. unsigned char Psysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  92. unsigned char Psysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  93. //parameters control
  94. void setPvolume(char Pvolume_);
  95. void setPkeyshift(char Pkeyshift_);
  96. void setPsysefxvol(int Ppart, int Pefx, char Pvol);
  97. void setPsysefxsend(int Pefxfrom, int Pefxto, char Pvol);
  98. //effects
  99. class EffectMgr * sysefx[NUM_SYS_EFX]; //system
  100. class EffectMgr * insefx[NUM_INS_EFX]; //insertion
  101. // void swapcopyeffects(int what,int type,int neff1,int neff2);
  102. //HDD recorder
  103. Recorder HDDRecorder;
  104. //part that's apply the insertion effect; -1 to disable
  105. short int Pinsparts[NUM_INS_EFX];
  106. //peaks for VU-meter
  107. void vuresetpeaks();
  108. //get VU-meter data
  109. vuData getVuData();
  110. //peaks for part VU-meters
  111. /**\todo synchronize this with a mutex*/
  112. float vuoutpeakpart[NUM_MIDI_PARTS];
  113. unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled
  114. Controller ctl;
  115. bool swaplr; //if L and R are swapped
  116. //other objects
  117. Microtonal microtonal;
  118. Bank bank;
  119. class FFTwrapper * fft;
  120. pthread_mutex_t mutex;
  121. pthread_mutex_t vumutex;
  122. private:
  123. bool nullRun;
  124. vuData vu;
  125. float volume;
  126. float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  127. float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  128. int keyshift;
  129. };
  130. #endif