{
   "code" : "({\r\n\t// Code to add in the synth to monitor\r\n\t/*\r\n\tvar grBefore, grAfter;\r\n\t//// Some code\r\n\tgrBefore = __signal_to_measure__; // Gain reduction measurement\r\n\t//// UGen to measure\r\n\tgrAfter = __signal_to_measure__; // Gain reduction measurement\r\n\tSendReply.kr(Impulse.kr(10), '/level', [Amplitude.kr(grAfter - grBefore).lag(0, 1)]); // Gain Reduction measurement\r\n\t//// Some more code\r\n\t*/\r\n\t// Parameters\r\n\tvar maxReduc = -6; // Maximum gain reduction indicated\r\n\tvar nIntervals = 10; // Number of ticks (except the zero)\r\n\tvar width = 40; // Width of the indicator in px\r\n\tvar height = 300; // Height of the indicator in px\r\n\tvar winName = \"Gain Reduction\"; // Name of the window\r\n\tvar window, indicator, layout, oscFn;\r\n\t// Window creation\r\n\twindow = Window(\"Gain reduction\").front;\r\n\twindow.setInnerExtent(width, height);\r\n\t// Level indicator setup\r\n\tindicator = LevelIndicator().fixedWidth_(width).fixedHeight_(height);\r\n\tindicator.numTicks = nIntervals + 1;\r\n\tindicator.numMajorTicks = 3;\r\n\tindicator.warning = 0.dbamp;\r\n\tindicator.critical = 0.dbamp;\r\n\tindicator.background = Color.new255(246, 184, 0);\r\n\tindicator.meterColor = Color.black;\r\n\t// Layout of the window\r\n\tlayout = HLayout();\r\n\tlayout.add(nil);\r\n\tlayout.add(VLayout(indicator));\r\n\tlayout.add(VLayout(StaticText().string_(\"0.0dB\"), nil, StaticText().string_((maxReduc/2.0).asString ++ \"dB\"), nil, StaticText().string_((1.0*maxReduc).asString ++ \"dB\")\r\n\t));\r\n\tlayout.add(nil);\r\n\twindow.layout = layout;\r\n\twindow.onClose_({oscFn.free;});\r\n\t// Level indicator update\r\n\toscFn = OSCFunc({arg msg;\r\n\t\t{\r\n\t\t\tindicator.value = (1-msg[3]).ampdb.linlin(maxReduc, 0, 0, 1);\r\n\r\n\t\t}.defer;\r\n\t}, '/level', s.addr);\r\n}.fork(AppClock);\r\n) \r\n\r\n// Try it with this simple example\r\n(\r\n\r\n// something to meter\r\nb = Buffer.read(s, Platform.resourceDir +/+ \"sounds/a11wlk01.wav\");\r\n\r\nx = {\r\n\tvar colum, noise, imp, delimp, mul = 1, before, after;\r\n\tdelimp = Delay1.kr(imp);\r\n\tcolum = PlayBuf.ar(1, b, BufRateScale.kr(b), loop: 1)!2 * mul;\r\n\r\n\tbefore = colum; // Gain reduction measurement\r\n\tcolum = Compander.ar(colum, colum,\r\n\t\tthresh: MouseX.kr(0.01, 1),\r\n\t\tslopeBelow: 1,\r\n\t\tslopeAbove: 0.5,\r\n\t\tclampTime:  0.01,\r\n\t\trelaxTime:  0.01\r\n\t);\r\n\tafter = colum; // Gain reduction measurement\r\n\tSendReply.kr(Impulse.kr(10), '/level', [Amplitude.kr(after - before).lag(0, 1)]); // Gain Reduction measurement\r\n\tcolum\r\n}.play;\r\n\r\nCmdPeriod.doOnce({x.free; b.free});\r\n)",
   "is_private" : null,
   "id" : "1-5cW",
   "labels" : [
      "gui",
      "compression",
      "gain reduction",
      "visual osc"
   ],
   "ancestor_list" : [],
   "description" : "Simple visualisation of the gain reduction for effects like compression. It can be run in its own editor window and requires only minimal modification of the original code. Uses OSC messages like in the example of LevelIndicator.\r\n\r\nThere's an implementation exemple at the bottom of the code.\r\n\r\nThe main trick is that the meter actually shows (1 - gain_reduction) but the colours are switched between the background and the meter to give the illusion of an inverted meter.",
   "name" : "Visual gain reduction meter",
   "author" : "jpdrecourt"
}
