libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / bin / setvolume.cpp
blobd2888c4cec0ca60ab1be11da20bfa52c58797628
1 /*
2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <Application.h>
8 #include <MediaRoster.h>
9 #include <ParameterWeb.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
16 extern const char *__progname;
17 static const char *sProgramName = __progname;
20 int
21 main(int argc, char **argv)
23 BApplication app("application/x-vnd.haiku.setvolume");
25 BMediaRoster *roster = BMediaRoster::Roster();
26 if (roster == NULL) {
27 fprintf(stderr, "%s: media roster not available\n", sProgramName);
28 return 1;
31 media_node mixer;
32 status_t status = roster->GetAudioMixer(&mixer);
33 if (status != B_OK) {
34 fprintf(stderr, "%s: cannot get audio mixer: %s\n", sProgramName, strerror(status));
35 return 1;
38 BParameterWeb *web;
39 status = roster->GetParameterWebFor(mixer, &web);
41 roster->ReleaseNode(mixer);
42 // the web is all we need :-)
44 if (status != B_OK) {
45 fprintf(stderr, "%s: cannot get parameter web for audio mixer: %s\n",
46 sProgramName, strerror(status));
47 return 1;
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);
56 break;
60 if (gain == NULL) {
61 fprintf(stderr, "%s: could not found master gain!\n", sProgramName);
62 delete web;
63 return 1;
66 float volume = 0.0;
68 if (argc > 1) {
69 char *end;
70 volume = strtod(argv[1], &end);
71 if (end == argv[1]) {
72 fprintf(stderr, "usage: %s <volume>\n", sProgramName);
73 } else {
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());
84 bigtime_t when;
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());
90 delete web;
91 return 0;