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.

223 lines
6.7KB

  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
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. */
  12. #ifndef MASTER_H
  13. #define MASTER_H
  14. #include "../globals.h"
  15. #include "Microtonal.h"
  16. #include <rtosc/automations.h>
  17. #include <rtosc/ports.h>
  18. #include "Time.h"
  19. #include "Bank.h"
  20. #include "Recorder.h"
  21. #include "../Params/Controller.h"
  22. #include "../Synth/WatchPoint.h"
  23. namespace zyncarla {
  24. class Allocator;
  25. struct vuData {
  26. vuData(void);
  27. float outpeakl, outpeakr, maxoutpeakl, maxoutpeakr,
  28. rmspeakl, rmspeakr;
  29. int clipped;
  30. };
  31. /** It sends Midi Messages to Parts, receives samples from parts,
  32. * process them with system/insertion effects and mix them */
  33. class Master
  34. {
  35. public:
  36. /** Constructor TODO make private*/
  37. Master(const SYNTH_T &synth, class Config *config);
  38. /** Destructor*/
  39. ~Master();
  40. char last_xmz[XMZ_PATH_MAX];
  41. void applyOscEvent(const char *event);
  42. /**Saves all settings to a XML file
  43. * @return 0 for ok or <0 if there is an error*/
  44. int saveXML(const char *filename);
  45. /**This adds the parameters to the XML data*/
  46. void add2XML(XMLwrapper& xml);
  47. static void saveAutomation(XMLwrapper &xml, const rtosc::AutomationMgr &midi);
  48. static void loadAutomation(XMLwrapper &xml, rtosc::AutomationMgr &midi);
  49. void defaults();
  50. /**loads all settings from a XML file
  51. * @return 0 for ok or -1 if there is an error*/
  52. int loadXML(const char *filename);
  53. /**Save all settings to an OSC file (as specified by RT OSC)
  54. * @param filename File to save to or NULL (useful for testing)
  55. * @return 0 for ok or <0 if there is an error*/
  56. int saveOSC(const char *filename);
  57. /**loads all settings from an OSC file (as specified by RT OSC)
  58. * @return 0 for ok or <0 if there is an error*/
  59. int loadOSC(const char *filename);
  60. /**Regenerate PADsynth and other non-RT parameters
  61. * It is NOT SAFE to call this from a RT context*/
  62. void applyparameters(void) NONREALTIME;
  63. //This must be called prior-to/at-the-time-of RT insertion
  64. void initialize_rt(void) REALTIME;
  65. void getfromXML(XMLwrapper& xml);
  66. /**get all data to a newly allocated array (used for plugin)
  67. * @return the datasize*/
  68. int getalldata(char **data) NONREALTIME;
  69. /**put all data from the *data array to zynaddsubfx parameters (used for plugin)*/
  70. void putalldata(const char *data);
  71. //Midi IN
  72. void noteOn(char chan, char note, char velocity);
  73. void noteOff(char chan, char note);
  74. void polyphonicAftertouch(char chan, char note, char velocity);
  75. void setController(char chan, int type, int par);
  76. //void NRPN...
  77. void ShutUp();
  78. int shutup;
  79. void vuUpdate(const float *outl, const float *outr);
  80. //Process a set of OSC events in the bToU buffer
  81. bool runOSC(float *outl, float *outr, bool offline=false);
  82. /**Audio Output*/
  83. bool AudioOut(float *outl, float *outr) REALTIME;
  84. /**Audio Output (for callback mode).
  85. * This allows the program to be controled by an external program*/
  86. void GetAudioOutSamples(size_t nsamples,
  87. unsigned samplerate,
  88. float *outl,
  89. float *outr) REALTIME;
  90. void partonoff(int npart, int what);
  91. //Set callback to run when master changes
  92. void setMasterChangedCallback(void(*cb)(void*,Master*),void *ptr);
  93. /**parts \todo see if this can be made to be dynamic*/
  94. class Part * part[NUM_MIDI_PARTS];
  95. //parameters
  96. unsigned char Pvolume;
  97. unsigned char Pkeyshift;
  98. unsigned char Psysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  99. unsigned char Psysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  100. //parameters control
  101. void setPvolume(char Pvolume_);
  102. void setPkeyshift(char Pkeyshift_);
  103. void setPsysefxvol(int Ppart, int Pefx, char Pvol);
  104. void setPsysefxsend(int Pefxfrom, int Pefxto, char Pvol);
  105. //effects
  106. class EffectMgr * sysefx[NUM_SYS_EFX]; //system
  107. class EffectMgr * insefx[NUM_INS_EFX]; //insertion
  108. // void swapcopyeffects(int what,int type,int neff1,int neff2);
  109. //HDD recorder
  110. Recorder HDDRecorder;
  111. //part that's apply the insertion effect; -1 to disable
  112. short int Pinsparts[NUM_INS_EFX];
  113. //peaks for VU-meter
  114. void vuresetpeaks();
  115. //peaks for part VU-meters
  116. float vuoutpeakpart[NUM_MIDI_PARTS];
  117. unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled
  118. AbsTime time;
  119. Controller ctl;
  120. bool swaplr; //if L and R are swapped
  121. //other objects
  122. Microtonal microtonal;
  123. //Strictly Non-RT instrument bank object
  124. Bank bank;
  125. class FFTwrapper * fft;
  126. static const rtosc::Ports &ports;
  127. float volume;
  128. //Statistics on output levels
  129. vuData vu;
  130. //Display info on midi notes
  131. bool activeNotes[128];
  132. //Other watchers
  133. WatchManager watcher;
  134. //Midi Learn
  135. rtosc::AutomationMgr automate;
  136. bool frozenState;//read-only parameters for threadsafe actions
  137. Allocator *memory;
  138. rtosc::ThreadLink *bToU;
  139. rtosc::ThreadLink *uToB;
  140. bool pendingMemory;
  141. const SYNTH_T &synth;
  142. const int& gzip_compression; //!< value from config
  143. //Heartbeat for identifying plugin offline modes
  144. //in units of 10 ms (done s.t. overflow is in 497 days)
  145. uint32_t last_beat = 0;
  146. uint32_t last_ack = 0;
  147. private:
  148. float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
  149. float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
  150. int keyshift;
  151. //information relevent to generating plugin audio samples
  152. float *bufl;
  153. float *bufr;
  154. off_t off;
  155. size_t smps;
  156. //Callback When Master changes
  157. void(*mastercb)(void*,Master*);
  158. void* mastercb_ptr;
  159. //Return XML data as string. Must be freed.
  160. char* getXMLData();
  161. //Used by loadOSC and saveOSC
  162. int loadOSCFromStr(const char *filename);
  163. };
  164. }
  165. #endif