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.

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