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.

Master.h 5.4KB

10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 <pthread.h>
  21. #include "../globals.h"
  22. #include "Microtonal.h"
  23. #include "Bank.h"
  24. #include "Recorder.h"
  25. #include "Dump.h"
  26. #include "XMLwrapper.h"
  27. #include "../Params/Controller.h"
  28. typedef enum {
  29. MUTEX_TRYLOCK, MUTEX_LOCK, MUTEX_UNLOCK
  30. } lockset;
  31. extern Dump dump;
  32. struct vuData {
  33. vuData(void);
  34. float outpeakl, outpeakr, maxoutpeakl, maxoutpeakr,
  35. rmspeakl, rmspeakr;
  36. int clipped;
  37. };
  38. /** It sends Midi Messages to Parts, receives samples from parts,
  39. * process them with system/insertion effects and mix them */
  40. class Master
  41. {
  42. public:
  43. /** Constructor TODO make private*/
  44. Master();
  45. /** Destructor*/
  46. ~Master();
  47. static Master &getInstance();
  48. static void deleteInstance();
  49. /**Saves all settings to a XML file
  50. * @return 0 for ok or <0 if there is an error*/
  51. int saveXML(const char *filename);
  52. /**This adds the parameters to the XML data*/
  53. void add2XML(XMLwrapper *xml);
  54. void defaults();
  55. /**loads all settings from a XML file
  56. * @return 0 for ok or -1 if there is an error*/
  57. int loadXML(const char *filename);
  58. void applyparameters(bool lockmutex = true);
  59. void getfromXML(XMLwrapper *xml);
  60. /**get all data to a newly allocated array (used for VST)
  61. * @return the datasize*/
  62. int getalldata(char **data);
  63. /**put all data from the *data array to zynaddsubfx parameters (used for VST)*/
  64. void putalldata(char *data, int size);
  65. //Mutex control
  66. /**Control the Master's mutex state.
  67. * @param lockset either trylock, lock, or unlock.
  68. * @return true when successful false otherwise.*/
  69. bool mutexLock(lockset request);
  70. //Midi IN
  71. void noteOn(char chan, char note, char velocity);
  72. void noteOff(char chan, char note);
  73. void polyphonicAftertouch(char chan, char note, char velocity);
  74. void setController(char chan, int type, int par);
  75. void setProgram(char chan, unsigned int pgm);
  76. //void NRPN...
  77. void ShutUp();
  78. int shutup;
  79. void vuUpdate(const float *outl, const float *outr);
  80. /**Audio Output*/
  81. void AudioOut(float *outl, float *outr);
  82. /**Audio Output (for callback mode). This allows the program to be controled by an external program*/
  83. void GetAudioOutSamples(size_t nsamples,
  84. unsigned samplerate,
  85. float *outl,
  86. float *outr);
  87. void partonoff(int npart, int what);
  88. /**parts \todo see if this can be made to be dynamic*/
  89. class Part * part[NUM_MIDI_PARTS];
  90. //parameters
  91. unsigned char Pvolume;
  92. unsigned char Pkeyshift;
  93. unsigned char Psysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  94. unsigned char Psysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  95. //parameters control
  96. void setPvolume(char Pvolume_);
  97. void setPkeyshift(char Pkeyshift_);
  98. void setPsysefxvol(int Ppart, int Pefx, char Pvol);
  99. void setPsysefxsend(int Pefxfrom, int Pefxto, char Pvol);
  100. //effects
  101. class EffectMgr * sysefx[NUM_SYS_EFX]; //system
  102. class EffectMgr * insefx[NUM_INS_EFX]; //insertion
  103. // void swapcopyeffects(int what,int type,int neff1,int neff2);
  104. //HDD recorder
  105. Recorder HDDRecorder;
  106. //part that's apply the insertion effect; -1 to disable
  107. short int Pinsparts[NUM_INS_EFX];
  108. //peaks for VU-meter
  109. void vuresetpeaks();
  110. //get VU-meter data
  111. vuData getVuData();
  112. //peaks for part VU-meters
  113. /**\todo synchronize this with a mutex*/
  114. float vuoutpeakpart[NUM_MIDI_PARTS];
  115. unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled
  116. Controller ctl;
  117. bool swaplr; //if L and R are swapped
  118. //other objects
  119. Microtonal microtonal;
  120. Bank bank;
  121. class FFTwrapper * fft;
  122. pthread_mutex_t mutex;
  123. pthread_mutex_t vumutex;
  124. private:
  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