All pastes #1912890 Raw Edit

Elizabeth Jennifer Myers

public text v1 · immutable
#1912890 ·published 2010-08-07 19:30 UTC
rendered paste body
#import <CoreFoundation/CoreFoundation.h>
#import <Celestial/AVController.h>

#include <stdlib.h>
#include <stdio.h>

int main (int argc, char **argv)
{
        NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
        AVController * av = [ [ AVController alloc ] init ];
        float target;
        int count = 0, retval = 0;

        if (argc < 2)
        {
                fprintf(stderr, "usage: volume [percentage]\n");
                retval = -1;
                goto cleanup;
        }

        target = strtod(argv[1], NULL) / 100;
        if ((target < 0.0) || (target > 1.0))
        {
                fprintf(stderr, "Volume must be a positive percentage not greater than 100\n");
                retval -1;
                goto cleanup;
        }

        printf("Setting volume to %f\n", target);

        /* Only try 25 times to set the volume, else give up */
        /* (Have to do this because celestial is odd) */
        while (++count < 25)
        {
                [ av setVolume: target ];
                /* Give 50 microseconds to settle */
                usleep(50000);
                if ([ av volume ] == target)
                        break;
        }

        if (count >= 25)
        {
                fprintf(stderr, "Could not set volume\n");
                retval = -1;
        }

cleanup:
        [ av release ];
        [ pool release ];

        return retval;
}