PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/indra/media_plugins/webkit/windows_volume_catcher.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 117 lines | 67 code | 19 blank | 31 comment | 4 complexity | dd9d935dfb957cf0333e06e0de3d3ce9 MD5 | raw file
  1/** 
  2 * @file windows_volume_catcher.cpp
  3 * @brief A Windows implementation of volume level control of all audio channels opened by a process.
  4 *
  5 * @cond
  6 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 * @endcond
 27 */
 28
 29#include "volume_catcher.h"
 30#include <windows.h>
 31#include "llsingleton.h"
 32class VolumeCatcherImpl : public LLSingleton<VolumeCatcherImpl>
 33{
 34friend LLSingleton<VolumeCatcherImpl>;
 35public:
 36
 37	void setVolume(F32 volume);
 38	void setPan(F32 pan);
 39	
 40private:
 41	// This is a singleton class -- both callers and the component implementation should use getInstance() to find the instance.
 42	VolumeCatcherImpl();
 43	~VolumeCatcherImpl();
 44
 45	typedef void (WINAPI *set_volume_func_t)(F32);
 46	typedef void (WINAPI *set_mute_func_t)(bool);
 47
 48	set_volume_func_t mSetVolumeFunc;
 49	set_mute_func_t mSetMuteFunc;
 50
 51	F32 	mVolume;
 52	F32 	mPan;
 53};
 54VolumeCatcherImpl::VolumeCatcherImpl()
 55:	mVolume(1.0f),	// default volume is max
 56	mPan(0.f)		// default pan is centered
 57{
 58	HMODULE handle = ::LoadLibrary(L"winmm.dll");
 59	if(handle)
 60	{
 61		mSetVolumeFunc = (set_volume_func_t)::GetProcAddress(handle, "setPluginVolume");
 62		mSetMuteFunc = (set_mute_func_t)::GetProcAddress(handle, "setPluginMute");
 63	}
 64}
 65
 66VolumeCatcherImpl::~VolumeCatcherImpl()
 67{
 68}
 69
 70
 71void VolumeCatcherImpl::setVolume(F32 volume)
 72{
 73	mVolume = volume;
 74
 75	if (mSetMuteFunc)
 76	{
 77		mSetMuteFunc(volume == 0.f);
 78	}
 79	if (mSetVolumeFunc)
 80	{
 81		mSetVolumeFunc(mVolume);
 82	}
 83}
 84
 85void VolumeCatcherImpl::setPan(F32 pan)
 86{	// remember pan for calculating individual channel levels later
 87	mPan = pan;
 88}
 89
 90/////////////////////////////////////////////////////
 91
 92VolumeCatcher::VolumeCatcher()
 93{
 94	pimpl = VolumeCatcherImpl::getInstance();
 95}
 96
 97VolumeCatcher::~VolumeCatcher()
 98{
 99	// Let the instance persist until exit.
100}
101
102void VolumeCatcher::setVolume(F32 volume)
103{
104	pimpl->setVolume(volume);
105}
106
107void VolumeCatcher::setPan(F32 pan)
108{
109	pimpl->setPan(pan);
110}
111
112void VolumeCatcher::pump()
113{
114	// No periodic tasks are necessary for this implementation.
115}
116
117