2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 #include <Application.h>
8 #include <MediaRoster.h>
9 #include <ParameterWeb.h>
16 extern const char *__progname
;
17 static const char *sProgramName
= __progname
;
21 main(int argc
, char **argv
)
23 BApplication
app("application/x-vnd.haiku.setvolume");
25 BMediaRoster
*roster
= BMediaRoster::Roster();
27 fprintf(stderr
, "%s: media roster not available\n", sProgramName
);
32 status_t status
= roster
->GetAudioMixer(&mixer
);
34 fprintf(stderr
, "%s: cannot get audio mixer: %s\n", sProgramName
, strerror(status
));
39 status
= roster
->GetParameterWebFor(mixer
, &web
);
41 roster
->ReleaseNode(mixer
);
42 // the web is all we need :-)
45 fprintf(stderr
, "%s: cannot get parameter web for audio mixer: %s\n",
46 sProgramName
, strerror(status
));
50 BContinuousParameter
*gain
= NULL
;
52 BParameter
*parameter
;
53 for (int32 index
= 0; (parameter
= web
->ParameterAt(index
)) != NULL
; index
++) {
54 if (!strcmp(parameter
->Kind(), B_MASTER_GAIN
)) {
55 gain
= dynamic_cast<BContinuousParameter
*>(parameter
);
61 fprintf(stderr
, "%s: could not found master gain!\n", sProgramName
);
70 volume
= strtod(argv
[1], &end
);
72 fprintf(stderr
, "usage: %s <volume>\n", sProgramName
);
74 // make sure our parameter is in range
75 if (volume
> gain
->MaxValue())
76 volume
= gain
->MaxValue();
77 else if (volume
< gain
->MinValue())
78 volume
= gain
->MinValue();
80 gain
->SetValue(&volume
, sizeof(volume
), system_time());
85 size_t size
= sizeof(volume
);
86 gain
->GetValue(&volume
, &size
, &when
);
88 printf("Current volume: %g (min = %g, max = %g)\n", volume
, gain
->MinValue(), gain
->MaxValue());