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.

196 lines
5.9KB

  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 <rtosc/miditable.h>
  23. #include <rtosc/ports.h>
  24. #include "Time.h"
  25. #include "Bank.h"
  26. #include "Recorder.h"
  27. #include "../Params/Controller.h"
  28. class Allocator;
  29. struct vuData {
  30. vuData(void);
  31. float outpeakl, outpeakr, maxoutpeakl, maxoutpeakr,
  32. rmspeakl, rmspeakr;
  33. int clipped;
  34. };
  35. /** It sends Midi Messages to Parts, receives samples from parts,
  36. * process them with system/insertion effects and mix them */
  37. class Master
  38. {
  39. public:
  40. /** Constructor TODO make private*/
  41. Master(const SYNTH_T &synth, class Config *config);
  42. /** Destructor*/
  43. ~Master();
  44. char last_xmz[XMZ_PATH_MAX];
  45. void applyOscEvent(const char *event);
  46. /**Saves all settings to a XML file
  47. * @return 0 for ok or <0 if there is an error*/
  48. int saveXML(const char *filename);
  49. /**This adds the parameters to the XML data*/
  50. void add2XML(XMLwrapper& xml);
  51. void defaults();
  52. /**loads all settings from a XML file
  53. * @return 0 for ok or -1 if there is an error*/
  54. int loadXML(const char *filename);
  55. /**Regenerate PADsynth and other non-RT parameters
  56. * It is NOT SAFE to call this from a RT context*/
  57. void applyparameters(void) NONREALTIME;
  58. //This must be called prior-to/at-the-time-of RT insertion
  59. void initialize_rt(void) REALTIME;
  60. void getfromXML(XMLwrapper& xml);
  61. /**get all data to a newly allocated array (used for plugin)
  62. * @return the datasize*/
  63. int getalldata(char **data) NONREALTIME;
  64. /**put all data from the *data array to zynaddsubfx parameters (used for plugin)*/
  65. void putalldata(const char *data);
  66. //Midi IN
  67. void noteOn(char chan, char note, char velocity);
  68. void noteOff(char chan, char note);
  69. void polyphonicAftertouch(char chan, char note, char velocity);
  70. void setController(char chan, int type, int par);
  71. //void NRPN...
  72. void ShutUp();
  73. int shutup;
  74. void vuUpdate(const float *outl, const float *outr);
  75. /**Audio Output*/
  76. void AudioOut(float *outl, float *outr) REALTIME;
  77. /**Audio Output (for callback mode).
  78. * This allows the program to be controled by an external program*/
  79. void GetAudioOutSamples(size_t nsamples,
  80. unsigned samplerate,
  81. float *outl,
  82. float *outr) REALTIME;
  83. void partonoff(int npart, int what);
  84. //Set callback to run when master changes
  85. void setMasterChangedCallback(void(*cb)(void*,Master*),void *ptr);
  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. //peaks for part VU-meters
  109. float vuoutpeakpart[NUM_MIDI_PARTS];
  110. unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled
  111. AbsTime time;
  112. Controller ctl;
  113. bool swaplr; //if L and R are swapped
  114. //other objects
  115. Microtonal microtonal;
  116. //Strictly Non-RT instrument bank object
  117. Bank bank;
  118. class FFTwrapper * fft;
  119. static const rtosc::Ports &ports;
  120. float volume;
  121. //Statistics on output levels
  122. vuData vu;
  123. rtosc::MidiMapperRT midi;
  124. bool frozenState;//read-only parameters for threadsafe actions
  125. Allocator *memory;
  126. rtosc::ThreadLink *bToU;
  127. rtosc::ThreadLink *uToB;
  128. bool pendingMemory;
  129. const SYNTH_T &synth;
  130. const int& gzip_compression; //!< value from config
  131. private:
  132. float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  133. float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  134. int keyshift;
  135. //information relevent to generating plugin audio samples
  136. float *bufl;
  137. float *bufr;
  138. off_t off;
  139. size_t smps;
  140. //Callback When Master changes
  141. void(*mastercb)(void*,Master*);
  142. void* mastercb_ptr;
  143. };
  144. #endif