xref: /MusicPlayer2/MusicPlayer2/CDevicesManager.cpp (revision 7914c23a3beb85a4c985b706a9ea79555e019792)
1 /******************************************************************************
2 * This file is part of DefaultAudioChanger.
3 * Copyright (c) 2011 Sergiu Giurgiu
4 *
5 * DefaultAudioChanger is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * DefaultAudioChanger is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with DefaultAudioChanger.  If not, see <http://www.gnu.org/licenses/>.
17 ******************************************************************************/
18 
19 #include "stdafx.h"
20 #include "MusicPlayer2.h"
21 #include "CDevicesManager.h"
22 #include "CMMNotificationClient.h"
23 
24 #define SAFE_RELEASE(punk)  \
25               if ((punk) != nullptr)  \
26                 { (punk)->Release(); (punk) = nullptr; }
27 
CDevicesManager(void)28 CDevicesManager::CDevicesManager(void) :pEnum(nullptr), client(nullptr)
29 {
30 
31 }
32 
33 
~CDevicesManager(void)34 CDevicesManager::~CDevicesManager(void)
35 {
36     ReleaseDeviceEnumerator();
37     delete client;
38 }
39 
InitializeDeviceEnumerator()40 HRESULT CDevicesManager::InitializeDeviceEnumerator()
41 {
42     HRESULT hr = S_OK;
43     if (!pEnum)
44     {
45         hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,
46             CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnum);
47         client = new CMMNotificationClient(pEnum, this);
48         pEnum->RegisterEndpointNotificationCallback(client);
49     }
50     return hr;
51 }
52 
53 
ReleaseDeviceEnumerator()54 void CDevicesManager::ReleaseDeviceEnumerator()
55 {
56     if (pEnum) {
57         pEnum->UnregisterEndpointNotificationCallback(client);
58     }
59     SAFE_RELEASE(pEnum)
60 }
61 
DefaultMultimediaDeviceChanged()62 void CDevicesManager::DefaultMultimediaDeviceChanged()
63 {
64     TRACE("PostMessage: WM_RE_INIT_BASS_CONTINUE_PLAY\n");
65     PostMessage(theApp.m_pMainWnd->GetSafeHwnd(), WM_RE_INIT_BASS_CONTINUE_PLAY, 0, 0);
66 }
67 
68