diff --git a/lib/vban.ps1 b/lib/vban.ps1 index ed6fb55..c91373b 100644 --- a/lib/vban.ps1 +++ b/lib/vban.ps1 @@ -3,48 +3,21 @@ class Vban : IRemote { Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote) { $this.direction = $direction + + AddBoolMembers -PARAMS @('on') + AddStringMembers -PARAMS @('name', 'ip') } [string] identifier () { return 'vban.' + $this.direction + 'stream[' + $this.index + ']' } - hidden $_on = $($this | Add-Member ScriptProperty 'on' ` - { - $this.Getter('on') - } ` - { - param([bool]$arg) - $this._on = $this.Setter('on', $arg) - } - ) - - hidden $_name = $($this | Add-Member ScriptProperty 'name' ` - { - $this.Getter_String('name') - } ` - { - param([string]$arg) - $this._name = $this.Setter('name', $arg) - } - ) - - hidden $_ip = $($this | Add-Member ScriptProperty 'ip' ` - { - $this.Getter_String('ip') - } ` - { - param([string]$arg) - $this._ip = $this.Setter('ip', $arg) - } - ) - hidden $_port = $($this | Add-Member ScriptProperty 'port' ` { - $this.Getter('port') + [int]$this.Getter('port') } ` { - param([string]$arg) + param([int]$arg) if ($arg -ge 1024 -and $arg -le 65535) { $this._port = $this.Setter('port', $arg) } @@ -56,7 +29,7 @@ class Vban : IRemote { hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` { - $this.Getter('sr') + [int]$this.Getter('sr') } ` { param([int]$arg) @@ -64,7 +37,7 @@ class Vban : IRemote { else { $opts = @(11025, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000) if ($opts.Contains($arg)) { - $this._port = $this.Setter('sr', $arg) + $this._sr = $this.Setter('sr', $arg) } else { Write-Warning ('Expected one of', $opts) @@ -75,7 +48,7 @@ class Vban : IRemote { hidden $_channel = $($this | Add-Member ScriptProperty 'channel' ` { - $this.Getter('channel') + [int]$this.Getter('channel') } ` { param([int]$arg) @@ -113,36 +86,31 @@ class Vban : IRemote { hidden $_quality = $($this | Add-Member ScriptProperty 'quality' ` { - $this.Getter('quality') + [int]$this.Getter('quality') } ` { param([int]$arg) - if ($this.direction -eq 'in') { Write-Warning ('Error, read only value') } + if ($arg -ge 0 -and $arg -le 4) { + $this._quality = $this.Setter('quality', $arg) + } else { - if ($arg -ge 0 -and $arg -le 4) { - $this._quality = $this.Setter('quality', $arg) - } - else { - Write-Warning ('Expected value from 0 to 4') - } + Write-Warning ('Expected value from 0 to 4') } } ) hidden $_route = $($this | Add-Member ScriptProperty 'route' ` { - $this.Getter('route') + [int]$this.Getter('route') } ` { param([int]$arg) - if ($this.direction -eq 'in') { Write-Warning ('Error, read only value') } + $rt = $this.remote.kind['p_' + $this.direction] + $this.remote.kind['v_' + $this.direction] - 1 + if ($arg -ge 0 -and $arg -le $rt) { + $this._route = $this.Setter('route', $arg) + } else { - if ($arg -ge 0 -and $arg -le 8) { - $this._route = $this.Setter('route', $arg) - } - else { - Write-Warning ('Expected value from 0 to 8') - } + Write-Warning ("Expected value from 0 to $rt") } } ) @@ -179,11 +147,25 @@ function Make_Vban ([Object]$remote) { $CustomObject | Add-Member ScriptProperty 'enable' ` { - return Write-Warning ('ERROR: vban.enable is write only') + return [bool]( Param_Get -PARAM 'vban.enable' ) } ` { param([bool]$arg) - Param_Set -PARAM 'vban.Enable' -Value $(if ($arg) { 1 } else { 0 }) + Param_Set -PARAM 'vban.enable' -Value $(if ($arg) { 1 } else { 0 }) + } + + $CustomObject | Add-Member ScriptProperty 'port' ` + { + return [int]( Param_Get -PARAM 'vban.instream[0].port' ) + } ` + { + param([int]$arg) + if ($arg -ge 1024 -and $arg -le 65535) { + Param_Set -PARAM 'vban.instream[0].port' -Value $arg + } + else { + Write-Warning ('Expected value from 1024 to 65535') + } } $CustomObject