From 73bcca6b32127f28ddaa3723f6496cd826fd7f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 6 Jan 2005 15:32:59 +0000 Subject: [PATCH] Added a small command to set the volume of the master gain in the audio mixer. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10592 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/Jamfile | 1 + src/apps/bin/setvolume.cpp | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/apps/bin/setvolume.cpp diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index fcbd691f69..22350ddbd5 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -77,6 +77,7 @@ StdBinCommands # standard commands that need libbe.so, libmedia.so StdBinCommands installsound.cpp + setvolume.cpp : be libmedia.so ; diff --git a/src/apps/bin/setvolume.cpp b/src/apps/bin/setvolume.cpp new file mode 100644 index 0000000000..d2888c4cec --- /dev/null +++ b/src/apps/bin/setvolume.cpp @@ -0,0 +1,93 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + +#include +#include +#include + + +extern const char *__progname; +static const char *sProgramName = __progname; + + +int +main(int argc, char **argv) +{ + BApplication app("application/x-vnd.haiku.setvolume"); + + BMediaRoster *roster = BMediaRoster::Roster(); + if (roster == NULL) { + fprintf(stderr, "%s: media roster not available\n", sProgramName); + return 1; + } + + media_node mixer; + status_t status = roster->GetAudioMixer(&mixer); + if (status != B_OK) { + fprintf(stderr, "%s: cannot get audio mixer: %s\n", sProgramName, strerror(status)); + return 1; + } + + BParameterWeb *web; + status = roster->GetParameterWebFor(mixer, &web); + + roster->ReleaseNode(mixer); + // the web is all we need :-) + + if (status != B_OK) { + fprintf(stderr, "%s: cannot get parameter web for audio mixer: %s\n", + sProgramName, strerror(status)); + return 1; + } + + BContinuousParameter *gain = NULL; + + BParameter *parameter; + for (int32 index = 0; (parameter = web->ParameterAt(index)) != NULL; index++) { + if (!strcmp(parameter->Kind(), B_MASTER_GAIN)) { + gain = dynamic_cast(parameter); + break; + } + } + + if (gain == NULL) { + fprintf(stderr, "%s: could not found master gain!\n", sProgramName); + delete web; + return 1; + } + + float volume = 0.0; + + if (argc > 1) { + char *end; + volume = strtod(argv[1], &end); + if (end == argv[1]) { + fprintf(stderr, "usage: %s \n", sProgramName); + } else { + // make sure our parameter is in range + if (volume > gain->MaxValue()) + volume = gain->MaxValue(); + else if (volume < gain->MinValue()) + volume = gain->MinValue(); + + gain->SetValue(&volume, sizeof(volume), system_time()); + } + } + + bigtime_t when; + size_t size = sizeof(volume); + gain->GetValue(&volume, &size, &when); + + printf("Current volume: %g (min = %g, max = %g)\n", volume, gain->MinValue(), gain->MaxValue()); + + delete web; + return 0; +} +