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.

1234 lines
38KB

  1. #include "mscHack.hpp"
  2. //#include "mscHack_Controls.hpp"
  3. #include "dsp/digital.hpp"
  4. //#include "CLog.h"
  5. namespace rack_plugin_mscHack {
  6. #define GROUPS 4
  7. #define CH_PER_GROUP 4
  8. #define CHANNELS ( GROUPS * CH_PER_GROUP )
  9. #define nAUX 4
  10. #define GROUP_OFF_X 52
  11. #define CHANNEL_OFF_X 34
  12. #define FADE_MULT (0.0005f)
  13. #define L 0
  14. #define R 1
  15. #define MUTE_FADE_STATE_IDLE 0
  16. #define MUTE_FADE_STATE_INC 1
  17. #define MUTE_FADE_STATE_DEC 2
  18. //-----------------------------------------------------
  19. // Module Definition
  20. //
  21. //-----------------------------------------------------
  22. struct Mix_4x4_Stereo : Module
  23. {
  24. enum ParamIds
  25. {
  26. PARAM_MAIN_LEVEL,
  27. PARAM_LEVEL_IN,
  28. PARAM_PAN_IN = PARAM_LEVEL_IN + CHANNELS,
  29. PARAM_GROUP_LEVEL_IN = PARAM_PAN_IN + CHANNELS,
  30. PARAM_GROUP_PAN_IN = PARAM_GROUP_LEVEL_IN + GROUPS,
  31. PARAM_MUTE_BUTTON = PARAM_GROUP_PAN_IN + GROUPS,
  32. PARAM_SOLO_BUTTON = PARAM_MUTE_BUTTON + CHANNELS,
  33. PARAM_GROUP_MUTE = PARAM_SOLO_BUTTON + CHANNELS,
  34. PARAM_GROUP_SOLO = PARAM_GROUP_MUTE + GROUPS,
  35. PARAM_EQ_HI = PARAM_GROUP_SOLO + GROUPS,
  36. PARAM_EQ_MD = PARAM_EQ_HI + CHANNELS,
  37. PARAM_EQ_LO = PARAM_EQ_MD + CHANNELS,
  38. PARAM_AUX_KNOB = PARAM_EQ_LO + CHANNELS,
  39. PARAM_AUX_PREFADE = PARAM_AUX_KNOB + (GROUPS * nAUX),
  40. PARAM_AUX_OUT = PARAM_AUX_PREFADE + (GROUPS * nAUX),
  41. nPARAMS = PARAM_AUX_OUT + (nAUX)
  42. };
  43. enum InputIds
  44. {
  45. IN_LEFT,
  46. IN_RIGHT = IN_LEFT + CHANNELS,
  47. IN_LEVEL = IN_RIGHT + CHANNELS,
  48. IN_PAN = IN_LEVEL + CHANNELS,
  49. IN_GROUP_LEVEL = IN_PAN + CHANNELS,
  50. IN_GROUP_PAN = IN_GROUP_LEVEL + GROUPS,
  51. nINPUTS = IN_GROUP_PAN + GROUPS
  52. };
  53. enum OutputIds
  54. {
  55. OUT_MAINL,
  56. OUT_MAINR,
  57. OUT_AUXL,
  58. OUT_AUXR = OUT_AUXL + nAUX,
  59. nOUTPUTS = OUT_AUXR + nAUX
  60. };
  61. bool m_bInitialized = false;
  62. CLog lg;
  63. // mute buttons
  64. bool m_bMuteStates[ CHANNELS ] = {};
  65. float m_fMuteFade[ CHANNELS ] = {};
  66. int m_FadeState[ CHANNELS ] = {MUTE_FADE_STATE_IDLE};
  67. // solo buttons
  68. bool m_bSoloStates[ CHANNELS ] = {};
  69. // group mute buttons
  70. bool m_bGroupMuteStates[ GROUPS ] = {};
  71. float m_fGroupMuteFade[ GROUPS ] = {};
  72. int m_GroupFadeState[ GROUPS ] = {MUTE_FADE_STATE_IDLE};
  73. // group solo buttons
  74. bool m_bGroupSoloStates[ GROUPS ] = {};
  75. // processing
  76. bool m_bMono[ CHANNELS ];
  77. float m_fSubMix[ GROUPS ][ 3 ] = {};
  78. // aux
  79. bool m_bGroupPreFadeAuxStates[ GROUPS ][ nAUX ] = {};
  80. // LED Meters
  81. LEDMeterWidget *m_pLEDMeterChannel[ CHANNELS ][ 2 ] ={};
  82. LEDMeterWidget *m_pLEDMeterGroup[ GROUPS ][ 2 ] ={};
  83. LEDMeterWidget *m_pLEDMeterMain[ 2 ] ={};
  84. // EQ Rez
  85. float lp1[ CHANNELS ][ 2 ] = {}, bp1[ CHANNELS ][ 2 ] = {};
  86. float m_hpIn[ CHANNELS ];
  87. float m_lpIn[ CHANNELS ];
  88. float m_mpIn[ CHANNELS ];
  89. float m_rezIn[ CHANNELS ] = {0};
  90. float m_Freq;
  91. // buttons
  92. MyLEDButton *m_pButtonChannelMute[ CHANNELS ] = {};
  93. MyLEDButton *m_pButtonChannelSolo[ CHANNELS ] = {};
  94. MyLEDButton *m_pButtonGroupMute[ GROUPS ] = {};
  95. MyLEDButton *m_pButtonGroupSolo[ GROUPS ] = {};
  96. MyLEDButton *m_pButtonAuxPreFader[ GROUPS ][ nAUX ] = {};
  97. #define L 0
  98. #define R 1
  99. // Contructor
  100. Mix_4x4_Stereo() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){}
  101. //-----------------------------------------------------
  102. // MyEQHi_Knob
  103. //-----------------------------------------------------
  104. struct MyEQHi_Knob : Knob_Green1_15
  105. {
  106. Mix_4x4_Stereo *mymodule;
  107. int param;
  108. void onChange( EventChange &e ) override
  109. {
  110. mymodule = (Mix_4x4_Stereo*)module;
  111. if( mymodule )
  112. {
  113. param = paramId - Mix_4x4_Stereo::PARAM_EQ_HI;
  114. mymodule->m_hpIn[ param ] = value;
  115. }
  116. RoundKnob::onChange( e );
  117. }
  118. };
  119. //-----------------------------------------------------
  120. // MyEQHi_Knob
  121. //-----------------------------------------------------
  122. struct MyEQMid_Knob : Knob_Green1_15
  123. {
  124. Mix_4x4_Stereo *mymodule;
  125. int param;
  126. void onChange( EventChange &e ) override
  127. {
  128. mymodule = (Mix_4x4_Stereo*)module;
  129. if( mymodule )
  130. {
  131. param = paramId - Mix_4x4_Stereo::PARAM_EQ_MD;
  132. mymodule->m_mpIn[ param ] = value;
  133. }
  134. RoundKnob::onChange( e );
  135. }
  136. };
  137. //-----------------------------------------------------
  138. // MyEQHi_Knob
  139. //-----------------------------------------------------
  140. struct MyEQLo_Knob : Knob_Green1_15
  141. {
  142. Mix_4x4_Stereo *mymodule;
  143. int param;
  144. void onChange( EventChange &e ) override
  145. {
  146. mymodule = (Mix_4x4_Stereo*)module;
  147. if( mymodule )
  148. {
  149. param = paramId - Mix_4x4_Stereo::PARAM_EQ_LO;
  150. mymodule->m_lpIn[ param ] = value;
  151. }
  152. RoundKnob::onChange( e );
  153. }
  154. };
  155. // Overrides
  156. void step() override;
  157. json_t* toJson() override;
  158. void fromJson(json_t *rootJ) override;
  159. void onRandomize() override{}
  160. void onReset() override;
  161. void ProcessMuteSolo( int channel, bool bMute, bool bGroup );
  162. void ProcessEQ( int ch, float *pL, float *pR );
  163. };
  164. //-----------------------------------------------------
  165. // MyLEDButton_Aux
  166. //-----------------------------------------------------
  167. void Mix_4x4_Stereo_MyLEDButton_Aux( void *pClass, int id, bool bOn )
  168. {
  169. int ch, i;
  170. Mix_4x4_Stereo *mymodule;
  171. mymodule = (Mix_4x4_Stereo*)pClass;
  172. ch = id / nAUX;
  173. i = id - (nAUX * ch);
  174. mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] = !mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ];
  175. mymodule->m_pButtonAuxPreFader[ ch ][ i ]->Set( mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] );
  176. }
  177. //-----------------------------------------------------
  178. // MyLEDButton_ChMute
  179. //-----------------------------------------------------
  180. void Mix_4x4_Stereo_MyLEDButton_ChMute( void *pClass, int id, bool bOn )
  181. {
  182. Mix_4x4_Stereo *mymodule;
  183. mymodule = (Mix_4x4_Stereo*)pClass;
  184. mymodule->ProcessMuteSolo( id, true, false );
  185. }
  186. //-----------------------------------------------------
  187. // MyLEDButton_ChSolo
  188. //-----------------------------------------------------
  189. void Mix_4x4_Stereo_MyLEDButton_ChSolo( void *pClass, int id, bool bOn )
  190. {
  191. Mix_4x4_Stereo *mymodule;
  192. mymodule = (Mix_4x4_Stereo*)pClass;
  193. mymodule->ProcessMuteSolo( id, false, false );
  194. }
  195. //-----------------------------------------------------
  196. // MyLEDButton_GroupMute
  197. //-----------------------------------------------------
  198. void Mix_4x4_Stereo_MyLEDButton_GroupMute( void *pClass, int id, bool bOn )
  199. {
  200. Mix_4x4_Stereo *mymodule;
  201. mymodule = (Mix_4x4_Stereo*)pClass;
  202. mymodule->ProcessMuteSolo( id, true, true );
  203. }
  204. //-----------------------------------------------------
  205. // MyLEDButton_GroupSolo
  206. //-----------------------------------------------------
  207. void Mix_4x4_Stereo_MyLEDButton_GroupSolo( void *pClass, int id, bool bOn )
  208. {
  209. Mix_4x4_Stereo *mymodule;
  210. mymodule = (Mix_4x4_Stereo*)pClass;
  211. mymodule->ProcessMuteSolo( id, false, true );
  212. }
  213. #define CUTOFF (0.025f)
  214. //-----------------------------------------------------
  215. // Procedure: Widget
  216. //
  217. //-----------------------------------------------------
  218. struct Mix_4x4_Stereo_Widget : ModuleWidget {
  219. Mix_4x4_Stereo_Widget( Mix_4x4_Stereo *module );
  220. };
  221. Mix_4x4_Stereo_Widget::Mix_4x4_Stereo_Widget( Mix_4x4_Stereo *module ) : ModuleWidget(module)
  222. {
  223. float fx, fx2, fx3, fx5, fx7;
  224. int ch, x, y, i, ybase, x2, y2;
  225. box.size = Vec( 15*47, 380);
  226. {
  227. SVGPanel *panel = new SVGPanel();
  228. panel->box.size = box.size;
  229. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Mix_4x4_Stereo.svg")));
  230. addChild(panel);
  231. }
  232. //module->lg.Open("Mix_4x4_Stereo.txt");
  233. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  234. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  235. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  236. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  237. //----------------------------------------------------
  238. // Add mix sliders
  239. x = 23;
  240. y = 38;
  241. // main channel
  242. for ( ch = 0; ch < CHANNELS; ch++ )
  243. {
  244. // Left channel inputs
  245. addInput(Port::create<MyPortInSmall>( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_LEFT + ch ) );
  246. y += 25;
  247. // Right channel inputs
  248. addInput(Port::create<MyPortInSmall>( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_RIGHT + ch ) );
  249. y += 26;
  250. // Level knobs
  251. addParam(ParamWidget::create<Knob_Blue2_26>( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_LEVEL_IN + ch, 0.0, AMP_MAX, 0.0 ) );
  252. y += 31;
  253. // Level inputs
  254. addInput(Port::create<MyPortInSmall>( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_LEVEL + ch ) );
  255. y += 23;
  256. // pan knobs
  257. addParam(ParamWidget::create<Knob_Yellow2_26>( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_PAN_IN + ch, -1.0, 1.0, 0.0 ) );
  258. y += 31;
  259. // Pan inputs
  260. addInput(Port::create<MyPortInSmall>( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_PAN + ch ) );
  261. y += 22;
  262. // mute buttons
  263. module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x - 5, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_4x4_Stereo_MyLEDButton_ChMute );
  264. addChild( module->m_pButtonChannelMute[ ch ] );
  265. //y += 26;
  266. // solo buttons
  267. module->m_pButtonChannelSolo[ ch ] = new MyLEDButton( x + 11, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_4x4_Stereo_MyLEDButton_ChSolo );
  268. addChild( module->m_pButtonChannelSolo[ ch ] );
  269. y += 22;
  270. y2 = y;
  271. // eq and rez
  272. addParam(ParamWidget::create<Mix_4x4_Stereo::MyEQHi_Knob>( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_HI + ch, 0.0, 1.0, 0.5 ) );
  273. y += 19;
  274. addParam(ParamWidget::create<Mix_4x4_Stereo::MyEQMid_Knob>( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_MD + ch, 0.0, 1.0, 0.5 ) );
  275. y += 19;
  276. addParam(ParamWidget::create<Mix_4x4_Stereo::MyEQLo_Knob>( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_LO + ch, 0.0, 1.0, 0.5 ) );
  277. // LED Meters
  278. module->m_pLEDMeterChannel[ ch ][ 0 ] = new LEDMeterWidget( x + 13, y2 + 30, 4, 1, 1, true );
  279. addChild( module->m_pLEDMeterChannel[ ch ][ 0 ] );
  280. module->m_pLEDMeterChannel[ ch ][ 1 ] = new LEDMeterWidget( x + 18, y2 + 30, 4, 1, 1, true );
  281. addChild( module->m_pLEDMeterChannel[ ch ][ 1 ] );
  282. if( ( ch & 3 ) == 3 )
  283. {
  284. x += GROUP_OFF_X;
  285. }
  286. else
  287. {
  288. x += CHANNEL_OFF_X;
  289. }
  290. y = 38;
  291. }
  292. // group mixera
  293. ybase = 278;
  294. x = 12;
  295. for( i = 0; i < GROUPS; i++ )
  296. {
  297. // mute/solo buttons
  298. x2 = x + 81;
  299. y2 = ybase;
  300. module->m_pButtonGroupMute[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_4x4_Stereo_MyLEDButton_GroupMute );
  301. addChild( module->m_pButtonGroupMute[ i ] );
  302. x2 += 28;
  303. module->m_pButtonGroupSolo[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_4x4_Stereo_MyLEDButton_GroupSolo );
  304. addChild( module->m_pButtonGroupSolo[ i ] );
  305. // group level and pan inputs
  306. x2 = x + 79;
  307. y2 = ybase + 23;
  308. // group VU Meters
  309. module->m_pLEDMeterGroup[ i ][ 0 ] = new LEDMeterWidget( x2 + 2, y2 + 21, 5, 2, 1, true );
  310. addChild( module->m_pLEDMeterGroup[ i ][ 0 ] );
  311. module->m_pLEDMeterGroup[ i ][ 1 ] = new LEDMeterWidget( x2 + 9, y2 + 21, 5, 2, 1, true );
  312. addChild( module->m_pLEDMeterGroup[ i ][ 1 ] );
  313. // group level and pan knobs
  314. x2 = x + 105;
  315. y2 = ybase + 17;
  316. addParam(ParamWidget::create<Knob_Blue2_26>( Vec( x2, y2 + 3 ), module, Mix_4x4_Stereo::PARAM_GROUP_LEVEL_IN + i, 0.0, AMP_MAX, 0.0 ) );
  317. y2 += 32;
  318. addParam(ParamWidget::create<Knob_Yellow2_26>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_GROUP_PAN_IN + i, -1.0, 1.0, 0.0 ) );
  319. // aux 1/3
  320. #define AUX_H 29
  321. x2 = x + 6;
  322. y2 = ybase + 20;
  323. module->m_pButtonAuxPreFader[ i ][ 0 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 0, module, Mix_4x4_Stereo_MyLEDButton_Aux );
  324. addChild( module->m_pButtonAuxPreFader[ i ][ 0 ] );
  325. y2 += AUX_H;
  326. module->m_pButtonAuxPreFader[ i ][ 2 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 2, module, Mix_4x4_Stereo_MyLEDButton_Aux );
  327. addChild( module->m_pButtonAuxPreFader[ i ][ 2 ] );
  328. x2 = x + 20;
  329. y2 = ybase + 16;
  330. addParam(ParamWidget::create<Knob_Red1_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 0, 0.0, AMP_MAX, 0.0 ) );
  331. y2 += AUX_H;
  332. addParam(ParamWidget::create<Knob_Blue3_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 2, 0.0, AMP_MAX, 0.0 ) );
  333. // aux 2/4
  334. x2 = x + 38;
  335. y2 = ybase + 28;
  336. addParam(ParamWidget::create<Knob_Yellow3_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 1, 0.0, AMP_MAX, 0.0 ) );
  337. y2 += AUX_H;
  338. addParam(ParamWidget::create<Knob_Purp1_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 3, 0.0, AMP_MAX, 0.0 ) );
  339. x2 = x + 62;
  340. y2 = ybase + 32;
  341. module->m_pButtonAuxPreFader[ i ][ 1 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 1, module, Mix_4x4_Stereo_MyLEDButton_Aux );
  342. addChild( module->m_pButtonAuxPreFader[ i ][ 1 ] );
  343. y2 += AUX_H;
  344. module->m_pButtonAuxPreFader[ i ][ 3 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 3, module, Mix_4x4_Stereo_MyLEDButton_Aux );
  345. addChild( module->m_pButtonAuxPreFader[ i ][ 3 ] );
  346. // account for slight error in pixel conversion to svg area
  347. x += 155;
  348. }
  349. //for( int i = 0; i < 15; i++ )
  350. //module->lg.f("level %d = %.3f\n", i, module->m_pLEDMeterChannel[ 0 ][ 0 ]->flevels[ i ] );
  351. // main mixer knob
  352. addParam(ParamWidget::create<Knob_Blue2_56>( Vec( 626, 237 ), module, Mix_4x4_Stereo::PARAM_MAIN_LEVEL, 0.0, AMP_MAX, 0.0 ) );
  353. module->m_pLEDMeterMain[ 0 ] = new LEDMeterWidget( 684, 242, 5, 3, 2, true );
  354. addChild( module->m_pLEDMeterMain[ 0 ] );
  355. module->m_pLEDMeterMain[ 1 ] = new LEDMeterWidget( 691, 242, 5, 3, 2, true );
  356. addChild( module->m_pLEDMeterMain[ 1 ] );
  357. // outputs
  358. addOutput(Port::create<MyPortOutSmall>( Vec( 636, 305 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_MAINL ) );
  359. addOutput(Port::create<MyPortOutSmall>( Vec( 668, 335 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_MAINR ) );
  360. // AUX out
  361. #define AUX_OUT_H 42
  362. x2 = 649;
  363. y2 = 25;
  364. addParam(ParamWidget::create<Knob_Red1_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 0, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H;
  365. addParam(ParamWidget::create<Knob_Yellow3_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 1, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H;
  366. addParam(ParamWidget::create<Knob_Blue3_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 2, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H;
  367. addParam(ParamWidget::create<Knob_Purp1_20>( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 3, 0.0, AMP_MAX, 0.0 ) );
  368. x2 = 635;
  369. y2 = 45;
  370. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL ) ); y2 += AUX_OUT_H;
  371. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 1 ) ); y2 += AUX_OUT_H;
  372. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 2 ) ); y2 += AUX_OUT_H;
  373. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 3 ) );
  374. x2 = 664;
  375. y2 = 45;
  376. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR ) ); y2 += AUX_OUT_H;
  377. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 1 ) ); y2 += AUX_OUT_H;
  378. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 2 ) ); y2 += AUX_OUT_H;
  379. addOutput(Port::create<MyPortOutSmall>( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 3 ) );
  380. // calculate eq rez freq
  381. fx = 3.141592 * (CUTOFF * 0.026315789473684210526315789473684) * 2 * 3.141592;
  382. fx2 = fx*fx;
  383. fx3 = fx2*fx;
  384. fx5 = fx3*fx2;
  385. fx7 = fx5*fx2;
  386. module->m_Freq = 2.0 * (fx
  387. - (fx3 * 0.16666666666666666666666666666667)
  388. + (fx5 * 0.0083333333333333333333333333333333)
  389. - (fx7 * 0.0001984126984126984126984126984127));
  390. module->m_bInitialized = true;
  391. module->onReset();
  392. }
  393. //-----------------------------------------------------
  394. // Procedure: reset
  395. //
  396. //-----------------------------------------------------
  397. void Mix_4x4_Stereo::onReset()
  398. {
  399. int ch, i, aux;
  400. if( !m_bInitialized )
  401. return;
  402. for( ch = 0; ch < CHANNELS; ch++ )
  403. {
  404. m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE;
  405. m_pButtonChannelMute[ ch ]->Set( false );
  406. m_pButtonChannelSolo[ ch ]->Set( false );
  407. m_bMuteStates[ ch ] = false;
  408. m_bSoloStates[ ch ] = false;
  409. m_fMuteFade[ ch ] = 1.0;
  410. }
  411. for( i = 0; i < GROUPS; i++ )
  412. {
  413. for( aux = 0; aux < nAUX; aux++ )
  414. {
  415. m_bGroupPreFadeAuxStates[ i ][ aux ] = false;
  416. m_pButtonAuxPreFader[ i ][ aux ]->Set( false );
  417. }
  418. m_GroupFadeState[ i ] = MUTE_FADE_STATE_IDLE;
  419. m_pButtonGroupMute[ i ]->Set( false );
  420. m_pButtonGroupSolo[ i ]->Set( false );
  421. m_bGroupMuteStates[ i ] = false;
  422. m_fGroupMuteFade[ i ] = 1.0;
  423. }
  424. }
  425. //-----------------------------------------------------
  426. // Procedure:
  427. //
  428. //-----------------------------------------------------
  429. json_t *Mix_4x4_Stereo::toJson()
  430. {
  431. bool *pbool;
  432. json_t *gatesJ;
  433. json_t *rootJ = json_object();
  434. // channel mutes
  435. pbool = &m_bMuteStates[ 0 ];
  436. gatesJ = json_array();
  437. for (int i = 0; i < CHANNELS; i++)
  438. {
  439. json_t *gateJ = json_integer( (int) pbool[ i ] );
  440. json_array_append_new( gatesJ, gateJ );
  441. }
  442. json_object_set_new( rootJ, "channel mutes", gatesJ );
  443. // channel solos
  444. pbool = &m_bSoloStates[ 0 ];
  445. gatesJ = json_array();
  446. for (int i = 0; i < CHANNELS; i++)
  447. {
  448. json_t *gateJ = json_integer( (int) pbool[ i ] );
  449. json_array_append_new( gatesJ, gateJ );
  450. }
  451. json_object_set_new( rootJ, "channel solos", gatesJ );
  452. // group mutes
  453. pbool = &m_bGroupMuteStates[ 0 ];
  454. gatesJ = json_array();
  455. for (int i = 0; i < GROUPS; i++)
  456. {
  457. json_t *gateJ = json_integer( (int) pbool[ i ] );
  458. json_array_append_new( gatesJ, gateJ );
  459. }
  460. json_object_set_new( rootJ, "group mutes", gatesJ );
  461. // group solos
  462. pbool = &m_bGroupSoloStates[ 0 ];
  463. gatesJ = json_array();
  464. for (int i = 0; i < GROUPS; i++)
  465. {
  466. json_t *gateJ = json_integer( (int) pbool[ i ] );
  467. json_array_append_new( gatesJ, gateJ );
  468. }
  469. json_object_set_new( rootJ, "group solos", gatesJ );
  470. // AUX states
  471. pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ];
  472. gatesJ = json_array();
  473. for (int i = 0; i < GROUPS * nAUX; i++)
  474. {
  475. json_t *gateJ = json_integer( (int) pbool[ i ] );
  476. json_array_append_new( gatesJ, gateJ );
  477. }
  478. json_object_set_new( rootJ, "group AUX prefade states", gatesJ );
  479. return rootJ;
  480. }
  481. //-----------------------------------------------------
  482. // Procedure: fromJson
  483. //
  484. //-----------------------------------------------------
  485. void Mix_4x4_Stereo::fromJson(json_t *rootJ)
  486. {
  487. int ch, i, aux;
  488. bool *pbool;
  489. json_t *StepsJ;
  490. bool bSolo[ GROUPS ] = {0}, bGroupSolo = false;
  491. // channel mutes
  492. pbool = &m_bMuteStates[ 0 ];
  493. StepsJ = json_object_get( rootJ, "channel mutes" );
  494. if (StepsJ)
  495. {
  496. for ( i = 0; i < CHANNELS; i++)
  497. {
  498. json_t *gateJ = json_array_get(StepsJ, i);
  499. if (gateJ)
  500. pbool[ i ] = json_integer_value( gateJ );
  501. }
  502. }
  503. // channel solos
  504. pbool = &m_bSoloStates[ 0 ];
  505. StepsJ = json_object_get( rootJ, "channel solos" );
  506. if (StepsJ)
  507. {
  508. for ( i = 0; i < CHANNELS; i++)
  509. {
  510. json_t *gateJ = json_array_get(StepsJ, i);
  511. if (gateJ)
  512. pbool[ i ] = json_integer_value( gateJ );
  513. }
  514. }
  515. // group mutes
  516. pbool = &m_bGroupMuteStates[ 0 ];
  517. StepsJ = json_object_get( rootJ, "group mutes" );
  518. if (StepsJ)
  519. {
  520. for ( i = 0; i < GROUPS; i++)
  521. {
  522. json_t *gateJ = json_array_get(StepsJ, i);
  523. if (gateJ)
  524. pbool[ i ] = json_integer_value( gateJ );
  525. }
  526. }
  527. // group solos
  528. pbool = &m_bGroupSoloStates[ 0 ];
  529. StepsJ = json_object_get( rootJ, "group solos" );
  530. if (StepsJ)
  531. {
  532. for ( i = 0; i < GROUPS; i++)
  533. {
  534. json_t *gateJ = json_array_get(StepsJ, i);
  535. if (gateJ)
  536. pbool[ i ] = json_integer_value( gateJ );
  537. }
  538. }
  539. // AUX states
  540. pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ];
  541. StepsJ = json_object_get( rootJ, "group AUX prefade states" );
  542. if (StepsJ)
  543. {
  544. for ( i = 0; i < GROUPS * nAUX; i++)
  545. {
  546. json_t *gateJ = json_array_get(StepsJ, i);
  547. if (gateJ)
  548. pbool[ i ] = json_integer_value( gateJ );
  549. }
  550. }
  551. // anybody soloing?
  552. for( ch = 0; ch < CHANNELS; ch++ )
  553. {
  554. if( m_bSoloStates[ ch ] )
  555. {
  556. bSolo[ ch / CH_PER_GROUP ] = true;
  557. }
  558. }
  559. for( ch = 0; ch < CHANNELS; ch++ )
  560. {
  561. if( bSolo[ ch / CH_PER_GROUP ] )
  562. {
  563. // only open soloing channels
  564. if( m_bSoloStates[ ch ] )
  565. m_fMuteFade[ ch ] = 1.0;
  566. else
  567. m_fMuteFade[ ch ] = 0.0;
  568. }
  569. else
  570. {
  571. // nobody is soloing so just open the non muted channels
  572. m_fMuteFade[ ch ] = m_bMuteStates[ ch ] ? 0.0: 1.0;
  573. }
  574. m_pButtonChannelMute[ ch ]->Set( m_bMuteStates[ ch ] );
  575. m_pButtonChannelSolo[ ch ]->Set( m_bSoloStates[ ch ] );
  576. //lg.f("channel mute fade = %.3f\n", m_fMuteFade[ ch ] );
  577. }
  578. // anybody group soloing?
  579. for( i = 0; i < GROUPS; i++ )
  580. {
  581. if( m_bGroupSoloStates[ i ] )
  582. {
  583. bGroupSolo = true;
  584. break;
  585. }
  586. }
  587. for( i = 0; i < GROUPS; i++ )
  588. {
  589. for( aux = 0; aux < nAUX; aux++ )
  590. m_pButtonAuxPreFader[ i ][ aux ]->Set( m_bGroupPreFadeAuxStates[ i ][ aux ] );
  591. if( bGroupSolo )
  592. {
  593. // only open soloing channels
  594. if( m_bGroupSoloStates[ i ] )
  595. m_fGroupMuteFade[ i ] = 1.0;
  596. else
  597. m_fGroupMuteFade[ i ] = 0.0;
  598. }
  599. else
  600. {
  601. // nobody is soloing so just open the non muted channels
  602. m_fGroupMuteFade[ i ] = m_bGroupMuteStates[ i ] ? 0.0: 1.0;
  603. }
  604. m_pButtonGroupMute[ i ]->Set( m_bGroupMuteStates[ i ] );
  605. m_pButtonGroupSolo[ i ]->Set( m_bGroupSoloStates[ i ] );
  606. //lg.f("group mute fade = %.3f\n", m_fGroupMuteFade[ i ] );
  607. }
  608. }
  609. //-----------------------------------------------------
  610. // Procedure: ProcessMuteSolo
  611. //
  612. //-----------------------------------------------------
  613. void Mix_4x4_Stereo::ProcessMuteSolo( int index, bool bMute, bool bGroup )
  614. {
  615. int i, group, si, ei;
  616. bool bSoloEnabled = false, bSoloOff = false;
  617. if( bGroup )
  618. {
  619. if( bMute )
  620. {
  621. m_bGroupMuteStates[ index ] = !m_bGroupMuteStates[ index ];
  622. // turn solo off
  623. if( m_bGroupSoloStates[ index ] )
  624. {
  625. bSoloOff = true;
  626. m_bGroupSoloStates[ index ] = false;
  627. m_pButtonGroupSolo[ index ]->Set( false );
  628. }
  629. // if mute is off then set volume
  630. if( m_bGroupMuteStates[ index ] )
  631. {
  632. m_pButtonGroupMute[ index ]->Set( true );
  633. m_GroupFadeState[ index ] = MUTE_FADE_STATE_DEC;
  634. }
  635. else
  636. {
  637. m_pButtonGroupMute[ index ]->Set( false );
  638. m_GroupFadeState[ index ] = MUTE_FADE_STATE_INC;
  639. }
  640. }
  641. else
  642. {
  643. m_bGroupSoloStates[ index ] = !m_bGroupSoloStates[ index ];
  644. // turn mute off
  645. if( m_bGroupMuteStates[ index ] )
  646. {
  647. m_bGroupMuteStates[ index ] = false;
  648. m_pButtonGroupMute[ index ]->Set( false );
  649. }
  650. // shut down volume of all groups not in solo
  651. if( !m_bGroupSoloStates[ index ] )
  652. {
  653. bSoloOff = true;
  654. m_pButtonGroupSolo[ index ]->Set( false );
  655. }
  656. else
  657. {
  658. m_pButtonGroupSolo[ index ]->Set( true );
  659. }
  660. }
  661. // is a track soloing?
  662. for( i = 0; i < GROUPS; i++ )
  663. {
  664. if( m_bGroupSoloStates[ i ] )
  665. {
  666. bSoloEnabled = true;
  667. break;
  668. }
  669. }
  670. if( bSoloEnabled )
  671. {
  672. // process solo
  673. for( i = 0; i < GROUPS; i++ )
  674. {
  675. // shut down volume of all groups not in solo
  676. if( !m_bGroupSoloStates[ i ] )
  677. {
  678. m_GroupFadeState[ i ] = MUTE_FADE_STATE_DEC;
  679. }
  680. else
  681. {
  682. m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC;
  683. }
  684. }
  685. }
  686. // nobody soloing and just turned solo off then enable all channels that aren't muted
  687. else if( bSoloOff )
  688. {
  689. // process solo
  690. for( i = 0; i < GROUPS; i++ )
  691. {
  692. // bring back if not muted
  693. if( !m_bGroupMuteStates[ i ] )
  694. {
  695. m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC;
  696. }
  697. }
  698. }
  699. }
  700. // !bGroup
  701. else
  702. {
  703. group = index / CH_PER_GROUP;
  704. si = group * CH_PER_GROUP;
  705. ei = si + CH_PER_GROUP;
  706. if( bMute )
  707. {
  708. m_bMuteStates[ index ] = !m_bMuteStates[ index ];
  709. // turn solo off
  710. if( m_bSoloStates[ index ] )
  711. {
  712. bSoloOff = true;
  713. m_bSoloStates[ index ] = false;
  714. m_pButtonChannelSolo[ index ]->Set( false );
  715. }
  716. // if mute is off then set volume
  717. if( m_bMuteStates[ index ] )
  718. {
  719. m_pButtonChannelMute[ index ]->Set( true );
  720. m_FadeState[ index ] = MUTE_FADE_STATE_DEC;
  721. }
  722. else
  723. {
  724. m_pButtonChannelMute[ index ]->Set( false );
  725. m_FadeState[ index ] = MUTE_FADE_STATE_INC;
  726. }
  727. }
  728. else
  729. {
  730. m_bSoloStates[ index ] = !m_bSoloStates[ index ];
  731. // turn mute off
  732. if( m_bMuteStates[ index ] )
  733. {
  734. m_bMuteStates[ index ] = false;
  735. m_pButtonChannelMute[ index ]->Set( false );
  736. }
  737. // toggle solo
  738. if( !m_bSoloStates[ index ] )
  739. {
  740. bSoloOff = true;
  741. m_pButtonChannelSolo[ index ]->Set( false );
  742. }
  743. else
  744. {
  745. m_pButtonChannelSolo[ index ]->Set( true );
  746. }
  747. }
  748. // is a track soloing?
  749. for( i = si; i < ei; i++ )
  750. {
  751. if( m_bSoloStates[ i ] )
  752. {
  753. bSoloEnabled = true;
  754. break;
  755. }
  756. }
  757. if( bSoloEnabled )
  758. {
  759. // process solo
  760. for( i = si; i < ei; i++ )
  761. {
  762. // shut down volume of all not in solo
  763. if( !m_bSoloStates[ i ] )
  764. {
  765. m_FadeState[ i ] = MUTE_FADE_STATE_DEC;
  766. }
  767. else
  768. {
  769. m_FadeState[ i ] = MUTE_FADE_STATE_INC;
  770. }
  771. }
  772. }
  773. // nobody soloing and just turned solo off then enable all channels that aren't muted
  774. else if( bSoloOff )
  775. {
  776. // process solo
  777. for( i = si; i < ei; i++ )
  778. {
  779. // bring back if not muted
  780. if( !m_bMuteStates[ i ] )
  781. {
  782. m_FadeState[ i ] = MUTE_FADE_STATE_INC;
  783. }
  784. }
  785. }
  786. }
  787. }
  788. //-----------------------------------------------------
  789. // Procedure: ProcessEQ
  790. //
  791. //-----------------------------------------------------
  792. #define MULTI (0.33333333333333333333333333333333f)
  793. void Mix_4x4_Stereo::ProcessEQ( int ch, float *pL, float *pR )
  794. {
  795. float rez, hp1;
  796. float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass;
  797. input[ L ] = *pL / AUDIO_MAX;
  798. input[ R ] = *pR / AUDIO_MAX;
  799. rez = 1.00;
  800. // do left and right channels
  801. for( int i = 0; i < 2; i++ )
  802. {
  803. input[ i ] = input[ i ] + 0.000000001;
  804. lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ];
  805. hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ];
  806. bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ];
  807. lowpass = lp1[ ch ][ i ];
  808. highpass = hp1;
  809. bandpass = bp1[ ch ][ i ];
  810. lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ];
  811. hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ];
  812. bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ];
  813. lowpass = lowpass + lp1[ ch ][ i ];
  814. highpass = highpass + hp1;
  815. bandpass = bandpass + bp1[ ch ][ i ];
  816. input[ i ] = input[ i ] - 0.000000001;
  817. lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ];
  818. hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ];
  819. bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ];
  820. lowpass = (lowpass + lp1[ ch ][ i ]) * MULTI;
  821. highpass = (highpass + hp1) * MULTI;
  822. bandpass = (bandpass + bp1[ ch ][ i ]) * MULTI;
  823. out[ i ] = ( highpass * m_hpIn[ ch ] ) + ( lowpass * m_lpIn[ ch ] ) + ( bandpass * m_mpIn[ ch ] );
  824. }
  825. *pL = clamp( out[ L ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX );
  826. *pR = clamp( out[ R ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX );
  827. }
  828. //-----------------------------------------------------
  829. // Procedure: step
  830. //
  831. //-----------------------------------------------------
  832. void Mix_4x4_Stereo::step()
  833. {
  834. int ch, group, aux;
  835. float inL = 0.0, inR = 0.0, inLClean, inRClean, outL, outR, mainL = 0.0, mainR = 0.0;
  836. float inLvl, inPan;
  837. float auxL[ nAUX ] = {}, auxR[ nAUX ] = {};
  838. bool bGroupActive[ GROUPS ] = {0};
  839. if( !m_bInitialized )
  840. return;
  841. memset( m_fSubMix, 0, sizeof(m_fSubMix) );
  842. // channel mixers
  843. for ( ch = 0; ch < CHANNELS; ch++ )
  844. {
  845. group = ch / CH_PER_GROUP;
  846. inLClean = 0.0;
  847. inRClean = 0.0;
  848. inL = 0.0;
  849. inR = 0.0;
  850. if( inputs[ IN_RIGHT + ch ].active || inputs[ IN_LEFT + ch ].active )
  851. {
  852. inLvl = clamp( ( params[ PARAM_LEVEL_IN + ch ].value + ( inputs[ IN_LEVEL + ch ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX );
  853. bGroupActive[ group ] = true;
  854. // check right channel first for possible mono
  855. if( inputs[ IN_RIGHT + ch ].active )
  856. {
  857. inRClean = inputs[ IN_RIGHT + ch ].value;
  858. inR = inRClean * inLvl;
  859. m_bMono[ ch ] = false;
  860. }
  861. else
  862. m_bMono[ ch ] = true;
  863. // left channel
  864. if( inputs[ IN_LEFT + ch ].active )
  865. {
  866. inLClean = inputs[ IN_LEFT + ch ].value;
  867. inL = inLClean * inLvl;
  868. if( m_bMono[ ch ] )
  869. {
  870. inRClean = inLClean;
  871. inR = inL;
  872. }
  873. }
  874. // put output to aux if pre fader
  875. for ( aux = 0; aux < nAUX; aux++ )
  876. {
  877. if( m_bGroupPreFadeAuxStates[ group ][ aux ] )
  878. {
  879. auxL[ aux ] += inLClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value;
  880. auxR[ aux ] += inRClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value;
  881. }
  882. }
  883. if( m_FadeState[ ch ] == MUTE_FADE_STATE_DEC )
  884. {
  885. m_fMuteFade[ ch ] -= FADE_MULT;
  886. if( m_fMuteFade[ ch ] <= 0.0 )
  887. {
  888. m_fMuteFade[ ch ] = 0.0;
  889. m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE;
  890. }
  891. }
  892. else if( m_FadeState[ ch ] == MUTE_FADE_STATE_INC )
  893. {
  894. m_fMuteFade[ ch ] += FADE_MULT;
  895. if( m_fMuteFade[ ch ] >= 1.0 )
  896. {
  897. m_fMuteFade[ ch ] = 1.0;
  898. m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE;
  899. }
  900. }
  901. ProcessEQ( ch, &inL, &inR );
  902. inL *= m_fMuteFade[ ch ];
  903. inR *= m_fMuteFade[ ch ];
  904. // pan
  905. inPan = clamp( params[ PARAM_PAN_IN + ch ].value + ( inputs[ IN_PAN + ch ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f );
  906. //lg.f("pan = %.3f\n", inputs[ IN_PAN + ch ].value );
  907. if( inPan <= 0.0 )
  908. inR *= ( 1.0 + inPan );
  909. else
  910. inL *= ( 1.0 - inPan );
  911. // put output to aux if not pre fader
  912. for ( aux = 0; aux < nAUX; aux++ )
  913. {
  914. if( !m_bGroupPreFadeAuxStates[ group ][ aux ] )
  915. {
  916. auxL[ aux ] += inL * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value;
  917. auxR[ aux ] += inR * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value;
  918. }
  919. }
  920. }
  921. // this channel not active
  922. else
  923. {
  924. }
  925. m_fSubMix[ group ][ L ] += inL;
  926. m_fSubMix[ group ][ R ] += inR;
  927. if( m_pLEDMeterChannel[ ch ][ 0 ] )
  928. m_pLEDMeterChannel[ ch ][ 0 ]->Process( inL / AUDIO_MAX );
  929. if( m_pLEDMeterChannel[ ch ][ 1 ] )
  930. m_pLEDMeterChannel[ ch ][ 1 ]->Process( inR / AUDIO_MAX);
  931. }
  932. // group mixers
  933. for ( group = 0; group < GROUPS; group++ )
  934. {
  935. outL = 0.0;
  936. outR = 0.0;
  937. if( bGroupActive[ group ] )
  938. {
  939. inLvl = clamp( ( params[ PARAM_GROUP_LEVEL_IN + group ].value + ( inputs[ IN_GROUP_LEVEL + group ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX );
  940. outL = m_fSubMix[ group ][ L ] * inLvl;
  941. outR = m_fSubMix[ group ][ R ] * inLvl;
  942. // pan
  943. inPan = clamp( params[ PARAM_GROUP_PAN_IN + group ].value + ( inputs[ IN_GROUP_PAN + group ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f );
  944. if( inPan <= 0.0 )
  945. outR *= ( 1.0 + inPan );
  946. else
  947. outL *= ( 1.0 - inPan );
  948. if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_DEC )
  949. {
  950. m_fGroupMuteFade[ group ] -= FADE_MULT;
  951. if( m_fGroupMuteFade[ group ] <= 0.0 )
  952. {
  953. m_fGroupMuteFade[ group ] = 0.0;
  954. m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE;
  955. }
  956. }
  957. else if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_INC )
  958. {
  959. m_fGroupMuteFade[ group ] += FADE_MULT;
  960. if( m_fGroupMuteFade[ group ] >= 1.0 )
  961. {
  962. m_fGroupMuteFade[ group ] = 1.0;
  963. m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE;
  964. }
  965. }
  966. outL *= m_fGroupMuteFade[ group ];
  967. outR *= m_fGroupMuteFade[ group ];
  968. }
  969. if( m_pLEDMeterGroup[ group ][ 0 ] )
  970. m_pLEDMeterGroup[ group ][ 0 ]->Process( outL / AUDIO_MAX );
  971. if( m_pLEDMeterGroup[ group ][ 1 ] )
  972. m_pLEDMeterGroup[ group ][ 1 ]->Process( outR / AUDIO_MAX );
  973. mainL += outL;
  974. mainR += outR;
  975. }
  976. if( m_pLEDMeterMain[ 0 ] )
  977. m_pLEDMeterMain[ 0 ]->Process( ( mainL / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value );
  978. if( m_pLEDMeterMain[ 1 ] )
  979. m_pLEDMeterMain[ 1 ]->Process( ( mainR / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value );
  980. // put aux output
  981. for ( aux = 0; aux < nAUX; aux++ )
  982. {
  983. outputs[ OUT_AUXL + aux ].value = clamp( auxL[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX );
  984. outputs[ OUT_AUXR + aux ].value = clamp( auxR[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX );
  985. }
  986. outputs[ OUT_MAINL ].value = clamp( mainL * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX );
  987. outputs[ OUT_MAINR ].value = clamp( mainR * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX );
  988. }
  989. } // namespace rack_plugin_mscHack
  990. using namespace rack_plugin_mscHack;
  991. RACK_PLUGIN_MODEL_INIT(mscHack, Mix_4x4_Stereo) {
  992. Model *modelMix_4x4_Stereo = Model::create<Mix_4x4_Stereo, Mix_4x4_Stereo_Widget>( "mscHack", "Mix_4x4_Stereo(2)", "MIXER 4x4 Stereo/Mono", MIXER_TAG, EQUALIZER_TAG, QUAD_TAG, PANNING_TAG, AMPLIFIER_TAG, MULTIPLE_TAG );
  993. return modelMix_4x4_Stereo;
  994. }