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.

187 lines
5.4KB

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