Custom peak meter doesn't work in a DAW
-
Please excuse my amatuerish code 🥲
Content.makeFrontInterface(332, 550); Engine.loadFontAs("{PROJECT_FOLDER}Fonts/Px437_Portfolio_6x8.ttf", "Portfolio_6x8"); const var PeakIn = Synth.getEffect("PeakIn"); const var PeakOut = Synth.getEffect("PeakOut"); const var Gate = Synth.getEffect("Gate"); const var HPF = Synth.getEffect("HPF"); const var Dynamics = Synth.getEffect("Dynamics"); const var inputPanel = Content.addPanel("pnlInput", 130, 111); const var outputPanel = Content.addPanel("pnlOutput", 275, 111); const var MAX_PEAK_HOLD_FRAMES = 45; const var MAX_PEAK_DECAY_RATE = 0.5; Content.setPropertiesFromJSON("pnlInput", { "width": 15, "height": 333, "opaque": false }); Content.setPropertiesFromJSON("pnlOutput", { "width": 15, "height": 333, "opaque": false }); inputPanel.data.currentLevel = -60.0; inputPanel.data.maxPeakdB = -60.0; inputPanel.data.holdCounter = 0; outputPanel.data.currentLevel = -60.0; outputPanel.data.maxPeakdB = -60.0; outputPanel.data.holdCounter = 0; inline function dbToY(db, panelHeight) { local clamped = Math.range(db, -60.0, 6.0); local percent = (clamped - (-60.0)) / (6.0 - (-60.0)); return panelHeight - (percent * panelHeight); }; inputPanel.setPaintRoutine(function(g) { local w = this.getWidth(); local h = this.getHeight(); local floor = Content.getComponent("knbFloor").getValue(); local slack = Content.getComponent("knbSlack").getValue(); local fade = Content.getComponent("knbFade").getValue(); local slackLevel = floor + slack; local fadeInLevel = floor + fade * 9; local fadeOutLevel = slackLevel - fade * 9; local rawLevel = PeakIn.getCurrentLevel(1); local LeveldB = (rawLevel > 0) ? Engine.getDecibelsForGainFactor(rawLevel) : -60.0; local peak = dbToY(LeveldB, h); local maxPeakY = dbToY(this.data.maxPeakdB, h); local floorY = dbToY(floor, h); local slackY = dbToY(slackLevel, h); local fadeInY = dbToY(fadeInLevel, h); local fadeOutY = dbToY(fadeOutLevel, h); g.setColour(0xFF433151); g.fillRect([3, maxPeakY - 1, 9, 2]); g.setColour(0xFFE5007F); g.fillRect([3, peak, 9, h - peak]); g.setColour(Colours.withAlpha(Colours.green, 0.2)); g.fillRect([0, floorY, w, slackY - floorY]); g.setColour(Colours.withAlpha(Colours.whitesmoke, 0.5)); g.fillRect([0, fadeInY - 1, w, 2]); g.setColour(Colours.withAlpha(Colours.whitesmoke, 0.5)); g.fillRect([0, fadeOutY - 1, w, 2]); g.setColour(Colours.withAlpha(Colours.red, 1)); g.fillRect([0, slackY - 1, w, 2]); g.setColour(Colours.withAlpha(Colours.green, 1)); g.fillRect([0, floorY - 1, w, 2]); }); outputPanel.setPaintRoutine(function(g) { local w = this.getWidth(); local h = this.getHeight(); local rawLevel = PeakOut.getCurrentLevel(1); local LeveldB = (rawLevel > 0) ? Engine.getDecibelsForGainFactor(rawLevel) : -60.0; local peak = dbToY(LeveldB, h); local maxPeakY = dbToY(this.data.maxPeakdB, h); g.setColour(0xFFE5007F); g.fillRect([3, maxPeakY - 1, 9, 2]); g.setColour(0xFF433151); g.fillRect([3, peak, 9, h - peak]); }); inputPanel.setTimerCallback(function() { local rawLevel = PeakIn.getCurrentLevel(1); local leveldB = (rawLevel > 0) ? Engine.getDecibelsForGainFactor(rawLevel) : -60.0; if (leveldB > this.data.maxPeakdB) { this.data.maxPeakdB = leveldB; this.data.holdCounter = 0; } else { this.data.holdCounter += 1; if (this.data.holdCounter > MAX_PEAK_HOLD_FRAMES) this.data.maxPeakdB = Math.max(leveldB, this.data.maxPeakdB - MAX_PEAK_DECAY_RATE); } this.repaint(); }); outputPanel.setTimerCallback(function() { local rawLevel = PeakOut.getCurrentLevel(1); local leveldB = (rawLevel > 0) ? Engine.getDecibelsForGainFactor(rawLevel) : -60.0; if (leveldB > this.data.maxPeakdB) { this.data.maxPeakdB = leveldB; this.data.holdCounter = 0; } else { this.data.holdCounter += 1; if (this.data.holdCounter > MAX_PEAK_HOLD_FRAMES) this.data.maxPeakdB = Math.max(leveldB, this.data.maxPeakdB - MAX_PEAK_DECAY_RATE); } this.repaint(); }); inputPanel.startTimer(30); outputPanel.startTimer(30);I honestly have no frickin idea how to even fix this, also why is it louder in my DAW? AudioLooper is already at 0dB
-
@Kalliopei In the video there is warnings about using locals inside paint routines, you should use var instead, maybe that could be the reason?
-
@Kalliopei I changed all locals inside the paint routines to vars and compiled your code stripped down, added ENABLE_ALL_PEAK_METERS=1 in the project and it works inside Logic
