horizontal level meter



  • Hi
    I'm looking at the Music Box example tutorial. thereis a nice vertical Level meter. But I couldn't do a horizontal level meter with modifying that code.

    Anyone can help with that, how can I make a horizontal level meter?



  • The dumbest solution would be putting this at the beginning of the paint routine (didn't test, it but might work)

    g.rotate(Math.PI / 2.0, [0, 0]);
    


  • @Christoph-Hart This code is from music box example. I put g.rotate at the begining of the paint routine. but it doesn't work.

    
    namespace VuMeter
    {
    
    	inline function createVuMeter(name, x, y)
    	{
    		local widget = Content.addPanel(name, x, y);
        
    		Content.setPropertiesFromJSON(name, {
    		"width": 16,
    		"height": 40,
    		"itemColour": 0xFFffe467,     
    		"itemColour2": 4279505940,
    		"bgColour": 4279505940,
    		"textColour": 4283782485,
    		"saveInPreset": false,
    		"opaque": 1
    		});
        	
    		widget.setPaintRoutine(function(g)
    		{
                            g.rotate(Math.PI / 2.0, [0, 0]);
    
    			g.fillAll(this.get("bgColour"));
    			
    			g.setColour(this.get("itemColour"));
        	
    			var lsize = parseInt(this.data.lvalue * (this.getHeight()-4));
    			var rsize = parseInt(this.data.rvalue * (this.getHeight()-4));
        	
    			g.fillRect([2, this.getHeight() - lsize - 2, (this.getWidth()-4)/2-1, lsize]);
    			g.fillRect([2 + this.getWidth() / 2 - 1, this.getHeight() - rsize - 2, (this.getWidth()-4)/2-1, rsize]);
        	
    			g.setColour(this.get("itemColour2"));
        	
    			for(i = 1; i < this.getHeight()-1; i = i + 3)
    			{
    				g.fillRect([1, i, this.getWidth()-2, 1]);
    			}
    		});
        
    		widget.setTimerCallback(function()
    		{
    			var lvalue;
    			var rvalue;
    			
    			if(this.data.fx)
    			{
    				lvalue = getNormalizedPeakValue(this.data.fx.getCurrentLevel(0));
    				rvalue = getNormalizedPeakValue(this.data.fx.getCurrentLevel(1));
    			}
    			else
    			{
    				lvalue = getNormalizedPeakValue(Engine.getMasterPeakLevel(0));
    				rvalue = getNormalizedPeakValue(Engine.getMasterPeakLevel(1));
    			}
    			
    			
        	
    			this.data.lvalue = Math.max(lvalue, this.data.lvalue - 0.04);
    			this.data.rvalue = Math.max(rvalue, this.data.rvalue - 0.04);
        	
    			this.repaintImmediately();
    		});
        
    		widget.startTimer(30);
    		return widget;
    	};
    
    	inline function setModule(vuMeter, module)
    	{
    		vuMeter.data.fx = module;
    	}
    	
    	inline function getNormalizedPeakValue(gain)
    	{
    		return 0.01 * (100.0 + Engine.getDecibelsForGainFactor(gain));
    	}
    }
    


  • Try this

    g.rotate(Math.PI / 2.0, [this.getWidth()/2, this.getHeight()/2]);
    


  • @d-healey Thanks!


Log in to reply
 

10
Online

474
Users

1.6k
Topics

12.1k
Posts