It is currently March 28th, 2024, 10:36 am

AudioLevel

Share and get help with Plugins and Addons
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AudioLevel

Post by jsmorley »

I suppose that in a perfect world the numeric value of a child measure with Type=DeviceList could be the count.

[MeterDeviceInfo]
Meter=String
FontColor=255,255,255
FontSize=11
AntiAlias=1
Text=Total Devices: [MeasureDeviceList:]#CRLF#[MeasureDeviceList]
DynamicVariables=1
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: AudioLevel

Post by StArL0rd84 »

Code: Select all

[MeasureDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=DeviceList

[DeviceNumberInfo]
Meter=String
Text=Total Devices: [MeasureDeviceList:]#CRLF#[MeasureDeviceList]
FontColor=255,255,255
StringAlign=Center
FontFace=GeForce Regular
FontSize=20
AntiAlias=1
X=300r
Y=r
Image
Nope
I've got 4 active devices
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AudioLevel

Post by jsmorley »

StArL0rd84 wrote: Nope
I've got 4 active devices
Did I say it WAS a perfect world? ;-)

I was actually just suggesting that feature to dgrace...
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AudioLevel

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasureAudio]
Measure=Plugin
Plugin=AudioLevel
Port=Output

[DeviceList]
Measure=Plugin
Plugin=AudioLevel
Type=DeviceList
OnChangeAction=[!UpdateMeasure DeviceCount]

[DeviceCount]
Measure=Script
ScriptFile=DeviceCount.lua
UpdateDivider=-1

[DeviceNumberInfo]
Meter=String
MeasureName=DeviceList
FontColor=255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=11
AntiAlias=1
DynamicVariables=1
Text=Total Devices: [DeviceCount]#CRLF#Device List:#CRLF#[DeviceList]
DeviceCount.Lua:

Code: Select all

function Initialize()

	deviceList = SKIN:GetMeasure('DeviceList')

end
	
function Update()

	dummyValue, deviceCount = string.gsub(deviceList:GetStringValue(), '\n', '')
	return (deviceCount + 1)
		
end
1.png
What we are doing here is taking advantage of a useful feature of the string.gsub function in Lua. It stands for "global substitute", and it does pretty much what it sounds like. It takes a string value as input, and two parms. The string to replace, and the string to replace it with.

The clever bit is that it returns two values. First, the new string with the replacements done, which we actually don't need at all, and second, the number of "instances" that it was able to replace.

So we replace all occurrences of '\n' (a newline) with '' (an empty string) in the value of the [DeviceList] measure from the skin. That gives me 3 newlines in my system. But wait, there isn't a newline at the end of the last entry, so we need to add 1 to the value to get the real count.

So we return deviceCount + 1 to the skin and use it in our meter.


P.S. Don't forget the DynamicVariables=1 on the meter when you use [SectionVariables], like you did a minute ago...
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: AudioLevel

Post by StArL0rd84 »

jsmorley wrote:Did I say it WAS a perfect world? ;-)

I was actually just suggesting that feature to dgrace...
Oh i am sorry, i misunderstood you.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AudioLevel

Post by jsmorley »

StArL0rd84 wrote:Oh i am sorry, i misunderstood you.
Not a problem. Be sure to check the Lua solution I posted above. It's really quite simple.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: AudioLevel

Post by StArL0rd84 »

jsmorley wrote:Not a problem. Be sure to check the Lua solution I posted above. It's really quite simple.
Thank so much for the Lua solution jsmorley, it totally works.
I disabled all the greyed out devices and it returned the correct number of devices.
Some day i will learn Lua, i hope, because it is so powerful.
I delved into it a bit but i guess for me the learning curve is a bit high.
I really don't like to log on here and just get the answers for free without much work on my part.
But at the same time i really appreciate you guys helpfulness.
A big thank you to all yall is in order.
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: AudioLevel

Post by killall-q »

Whoops, I posted a solution, but didn't realize one was already provided on the last page.

Lua is really easy to learn, it's like Python, or simplified C++, and so much more elegant than building Rube Goldberg machines out of measures in Rainmeter.

http://luatut.com/crash_course.html
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: AudioLevel

Post by StArL0rd84 »

So sorry to bother you guys again :oops:
but would it be possible to convert the windows string DeviceID to a number value?

Image

Code: Select all

[MeasureCurrentDevice]
Measure=Plugin
Plugin=AudioLevel
Type=DeviceID

[CurrentDeviceInfo]
Meter=String
MeasureName=MeasureCurrentDevice
FontColor=255,255,255
FontSize=11
AntiAlias=1
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AudioLevel

Post by jsmorley »

StArL0rd84 wrote:So sorry to bother you guys again :oops:
but would it be possible to convert the windows string DeviceID to a number value?
Sure, but need a slightly different approach than simply counting newlines. More like something killall-q posted a bit ago and then deleted...

Skin:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasureAudio]
Measure=Plugin
Plugin=AudioLevel
Port=Output

[Variables]
CurrentDeviceNum=""

[MeasureDeviceList]
Measure=Plugin
Plugin=AudioLevel
Type=DeviceList

[MeasureCurrentDevice]
Measure=Plugin
Plugin=AudioLevel
Type=DeviceID
OnChangeAction=[!UpdateMeasure MeasureDeviceInfo]

[MeasureCurrentDeviceName]
Measure=Plugin
Plugin=AudioLevel
Type=DeviceName

[MeasureDeviceInfo]
Measure=Script
ScriptFile=DeviceInfo.lua
UpdateDivider=-1

[MeterDeviceInfo]
Meter=String
FontColor=255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=11
AntiAlias=1
DynamicVariables=1
Text=Current Device Number: #CurrentDeviceNum##CRLF#Current Device ID: [MeasureCurrentDevice]#CRLF#Current Device Name: [MeasureCurrentDeviceName]#CRLF##CRLF#Total Devices: [MeasureDeviceInfo]#CRLF#Device List:#CRLF#[MeasureDeviceList]
DeviceInfo.lua:

Code: Select all

function Initialize()

	deviceList = SKIN:GetMeasure('MeasureDeviceList')
	currentDevice = SKIN:GetMeasure('MeasureCurrentDevice')
	
end
   
function Update()

	local currentNum = 0
	
	local stringList = deviceList:GetStringValue()
	local matchDevice = currentDevice:GetStringValue()
	
	for listEntry in string.gmatch(stringList, '{.-}%.{.-}') do

		currentNum = currentNum + 1	
		if listEntry == matchDevice then
			SKIN:Bang('!SetVariable', 'CurrentDeviceNum', currentNum)
		end

	end	 
	
	return (currentNum)
      
end
1.png
Post Reply