Public/Renderer.ps1



function Set-ASRFrameTiming
{
    Param(
        [String]$Shell,
        [ValidateSet('0', '1', '2', '3', '4')]
        [Parameter()][int]$VSync,
        [ValidateSet('0', '30', '60', '120')]
        [Parameter()][int]$Frames
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell']) {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal)) {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $object = New-Object –TypeName PSObject
        foreach ($boundParam in $PSBoundParameters.GetEnumerator())
        {
            $object | Add-Member –MemberType NoteProperty –Name $boundParam.Key –Value $boundParam.Value
        }
        
        $body = $object | ConvertTo-Json -Depth 8
        $uri = "http://$($shellLocal):4444/api/renderer/SetFrameTimingOptions" 
        $result = Invoke-RestMethod -Uri $uri -Body $body -Method POST -ContentType 'application/json'
}


function Set-ASRResolution
{
    [CmdletBinding(DefaultParameterSetName = 'ByName')]

    Param(
        [String]$Shell,
        [Parameter(Mandatory, Position=0, ParameterSetName='ByNumbers')][int]$x,
        [Parameter(Mandatory, Position=1, ParameterSetName='ByNumbers')][int]$y,
        
        [ValidateSet('4k', '2.5k', 'FullHD', 'HDReady', '1024x768', '800x600')]
        [Parameter(Mandatory, Position=0, ParameterSetName='ByName')][string]$resolution
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell']) {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal)) {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $_x = 0;
        $_y = 0;

        if($x)
        {
            $_x = $x;
            $_y = $y;
        }
        if($resolution)
        {
            if([System.String]::IsNullOrEmpty($resolution)) {
                Write-Host "You must provide both x and y for resolution. You can do so by specifying both -x and -y parameters, or pass size in 000x000 format.";
                return;
            }
            if($resolution.ToLower() -eq "4k") {
                $_x = 3840;
                $_y = 2160;
            }elseif($resolution.ToLower() -eq "2.5k") {
                $_x = 2560;
                $_y = 1440;
            }elseif($resolution.ToLower() -eq "fullhd") {
                $_x = 1920;
                $_y = 1080;
            }elseif($resolution.ToLower() -eq "hdready") {
                $_x = 1280;
                $_y = 720;
            }elseif($resolution.Contains("x")) {
                $split = $resolution.Split('x');
                $_x = [System.Int32]::Parse($split[0]);
                $_y = [System.Int32]::Parse($split[1]);
            }  
        }

        Write-Host "Setting resolution to $($_x)x$($_y)"

        $uri = "http://$($shellLocal):4444/api/renderer/setresolution?width=$($_x)&height=$($_y)" 
        $result = Invoke-RestMethod -Uri $uri -Method POST
        Write-Host $result
}


function Get-ASRHDR
{
    Param(
        [String]$Shell
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell']) {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal)) {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $uri = "http://$($shellLocal):4444/api/renderer/GetHDRStatus" 
        $responce = (Invoke-RestMethod -Uri $uri -Method GET -SkipCertificateCheck -AllowUnencryptedAuthentication)  

        if(!$responce.success)
        {
            Write-Error $responce.error -ErrorAction Stop
        }
        else {
            $responce.value
        }
}


function Set-ASRHDR
{
    Param(
        [String]$Shell,
        [Parameter(Mandatory=$false)][bool]$enableHDR,
        [Parameter(Mandatory=$false)][bool]$automaticHDRTonemapping,
        [Parameter(Mandatory=$false)][int]$paperWhiteNits
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell']) {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal)) {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $object = New-Object –TypeName PSObject

        if($enableHDR)
        {
            $object | Add-Member –MemberType NoteProperty –Name "enableHDR" –Value $enableHDR
        }

        if($automaticHDRTonemapping)
        {
            $object | Add-Member –MemberType NoteProperty –Name "automaticHDRTonemapping" –Value $automaticHDRTonemapping
        }
        if($paperWhiteNits)
        {
            $object | Add-Member –MemberType NoteProperty –Name "paperWhiteNits" –Value $paperWhiteNits
        }

        $body = $object | ConvertTo-Json -Depth 8

        $uri = "http://$($shellLocal):4444/api/renderer/SetHDRStatus" 
        $responce = (Invoke-RestMethod -Uri $uri -Method POST -Body $body -ContentType 'application/json' -SkipCertificateCheck -AllowUnencryptedAuthentication)  

        if(!$responce.success)
        {
            Write-Error $responce.error -ErrorAction Stop
        }
        else {
            $responce.value
        }
}