logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
svetotehnik  
#1 Posted : Saturday, February 20, 2021 5:42:36 PM(UTC)
svetotehnik

Rank: Member

Groups: Registered
Joined: 11/6/2020(UTC)
Posts: 20
Russian Federation
Location: Saint-Petersburg

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
My goal is to write the volume value from XML and convert it from string to integer

but at this line interpreter returns error: "Input string was not in a correct format"
Code:
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)


replacing a period with a comma nor convert to a double does not help

Code:
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)

dim WhatISVolume as string = (x.SelectSingleNode("//input[@title='Music']/@volume").Value)

dim WhatISVolumeComma as string = ""

If WhatISVolume.Contains(".") Then
    WhatISVolumeComma = WhatISVolume.Replace(".", ",")
End If

dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)

for i as integer = 0 to WhatISVolumeInt
             API.Function("SetVolume",Input:="Music",Value:=WhatISVolumeInt)
             WhatISVolumeInt = WhatISVolumeInt-1
sleep(8)
next


and yes, I know about SetVolumeFade function =)
DWAM  
#2 Posted : Saturday, February 20, 2021 6:02:03 PM(UTC)
DWAM

Rank: Advanced Member

Groups: Registered
Joined: 3/20/2014(UTC)
Posts: 2,721
Man
France
Location: Bordeaux, France

Thanks: 243 times
Was thanked: 794 time(s) in 589 post(s)
In case this might help (not sure what you're trying to do)

Quote:
The Volume level in vMix is linked to amplitude and scales with the following formula:

Volume = 0 to 100 (used for UI volume bars)
Amplitude = 0 to 1 (used for API Meter and Volume values)
Decibels = 0 dB to -infinity

Volume = (Amplitude ^ 0.25) * 100
Amplitude = (Volume / 100) ^ 4

Example
VolumeBar = 50
Amplitude = 0.0625
MeterF = 0.0625
VolumeXML = 6.25

Martin
vMix

P.S meter values in XML are in Amplitude 0-1, while volume values in XML are in Amplitude 0-100
dmwkr  
#3 Posted : Saturday, February 20, 2021 6:35:44 PM(UTC)
dmwkr

Rank: Advanced Member

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 513

Thanks: 62 times
Was thanked: 119 time(s) in 108 post(s)
Originally Posted by: svetotehnik Go to Quoted Post


Code:


dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeInt)




Line 13 of your code contains the variable WhatISVolumeInt twice. Doesn't seem right.
svetotehnik  
#4 Posted : Saturday, February 20, 2021 6:39:14 PM(UTC)
svetotehnik

Rank: Member

Groups: Registered
Joined: 11/6/2020(UTC)
Posts: 20
Russian Federation
Location: Saint-Petersburg

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Amplitude is not available from API, MeterF is current level value, not Volume
svetotehnik  
#5 Posted : Saturday, February 20, 2021 6:43:43 PM(UTC)
svetotehnik

Rank: Member

Groups: Registered
Joined: 11/6/2020(UTC)
Posts: 20
Russian Federation
Location: Saint-Petersburg

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: dmwkr Go to Quoted Post
Originally Posted by: svetotehnik Go to Quoted Post


Code:


dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeInt)




Line 13 of your code contains the variable WhatISVolumeInt twice. Doesn't seem right.


typo, corrected

this way it does not works too
Code:
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)


doggy  
#6 Posted : Saturday, February 20, 2021 6:53:28 PM(UTC)
doggy

Rank: Advanced Member

Groups: Registered
Joined: 12/27/2012(UTC)
Posts: 5,085
Belgium
Location: Belgium

Thanks: 284 times
Was thanked: 920 time(s) in 759 post(s)
Not sure what you are getting at , seems you want the value before the period to return as a single integer ?

Code:
Dim IWant = Convert.ToInt32(WhatISVolume.Split("."c)(0))


or

Code:
Console.WriteLine(Math.Ceiling(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Floor(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Round(Convert.ToDecimal(WhatISVolume )))
thanks 1 user thanked doggy for this useful post.
svetotehnik on 2/20/2021(UTC)
svetotehnik  
#7 Posted : Saturday, February 20, 2021 7:10:39 PM(UTC)
svetotehnik

Rank: Member

Groups: Registered
Joined: 11/6/2020(UTC)
Posts: 20
Russian Federation
Location: Saint-Petersburg

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: doggy Go to Quoted Post
Not sure what you are getting at , seems you want the value before the period to return as a single integer ?

Code:
Dim IWant = Convert.ToInt32(WhatISVolume.Split("."c)(0))


or

Quote:
Console.WriteLine(Math.Ceiling(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Floor(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Round(Convert.ToDecimal(WhatISVolume )))


Yes, value before period was solution:

Code:
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)

dim WhatISVolume as string = (x.SelectSingleNode("//input[@title='Music']/@volume").Value)

Dim WhatISVolumeComma as string = WhatISVolume

If WhatISVolume.Contains(".") Then
   WhatISVolumeComma = WhatISVolume.Substring(0, WhatISVolume.IndexOf("."))
End If

dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)

for i as integer = 0 to WhatISVolumeInt
             API.Function("SetVolume",Input:="Music",Value:=WhatISVolumeInt)
             WhatISVolumeInt = WhatISVolumeInt-1
sleep(8)
next


Thank you!

matkeane  
#8 Posted : Saturday, February 20, 2021 9:37:03 PM(UTC)
matkeane

Rank: Advanced Member

Groups: Registered
Joined: 10/6/2020(UTC)
Posts: 98
France

Was thanked: 21 time(s) in 21 post(s)
Does VBscript have support for locales? I've written code in the past which assumed decimal values would include a period, which of course failed the first time it encountered input from a different locale where commas are used as the decimal separator. Just curious how VBscript deals with that.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.