Hide the main window immediately on exit in the Win32 build. This allows

us to cross fade the audio out without appearing to be frozen.
This commit is contained in:
casey langen 2016-12-25 20:44:18 -08:00
parent eb175cd66c
commit 5f64b205cf
6 changed files with 155 additions and 3 deletions

View File

@ -165,7 +165,7 @@ void DirectSoundOut::SetVolume(double volume) {
if (this->secondaryBuffer) {
double db = (volume < 0.0001f)
? DSBVOLUME_MIN
: (float) log10f(this->volume) * 6000.f;
: log10(this->volume) * 6000.f;
if (db > DSBVOLUME_MAX) {
db = DSBVOLUME_MAX;
@ -264,6 +264,7 @@ bool DirectSoundOut::Play(IBuffer *buffer, IBufferProvider *provider) {
void DirectSoundOut::Drain() {
static const int drainCount = 4;
static const int bufferResendDelayMs = 50;
int channels = this->channels;
int rate = this->rate;
@ -286,7 +287,7 @@ void DirectSoundOut::Drain() {
int count = drainCount + 1;
while (count > 0 && this->state != StateStopped) {
if (!this->Play(&buffer, &buffer)) {
Sleep(250); /* eh */
Sleep(bufferResendDelayMs); /* eh */
}
else {
--count;

View File

@ -50,6 +50,7 @@
#include <core/library/LibraryFactory.h>
#include <core/audio/GaplessTransport.h>
#include <core/audio/CrossfadeTransport.h>
#include <core/support/PreferenceKeys.h>
#include <core/audio/Visualizer.h>
@ -60,6 +61,7 @@
#include <boost/chrono.hpp>
#ifdef WIN32
#include <app/util/Win32Util.h>
#undef MOUSE_MOVED
#endif
@ -108,7 +110,8 @@ int main(int argc, char* argv[])
LibraryPtr library = LibraryFactory::Libraries().at(0);
GaplessTransport transport;
//GaplessTransport transport;
CrossfadeTransport transport;
PlaybackService playback(library, transport);
GlobalHotkeys globalHotkeys(playback, library);
@ -157,6 +160,10 @@ int main(int argc, char* argv[])
});
app.Run(mainLayout);
#ifdef WIN32
musik::box::win32::HideMainWindow();
#endif
}
musik::core::audio::vis::HideSelectedVisualizer();

View File

@ -0,0 +1,86 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "stdafx.h"
#include <Windows.h>
#ifdef WIN32
static std::basic_string<TCHAR> className = "Curses_App";
static HWND mainWindow = nullptr;
static void findMainWindow() {
static TCHAR buffer[256];
if (mainWindow == nullptr) {
DWORD dwProcID = GetCurrentProcessId();
HWND hWnd = GetTopWindow(GetDesktopWindow());
while (hWnd) {
DWORD dwWndProcID = 0;
GetWindowThreadProcessId(hWnd, &dwWndProcID);
if (dwWndProcID == dwProcID) {
GetClassName(hWnd, buffer, sizeof(buffer));
if (className == std::string(buffer)) {
mainWindow = hWnd;
return;
}
}
hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
}
}
}
namespace musik {
namespace box {
namespace win32 {
void ShowMainWindow() {
findMainWindow();
if (mainWindow) {
ShowWindow(mainWindow, SW_SHOWNORMAL);
}
}
void HideMainWindow() {
findMainWindow();
if (mainWindow) {
ShowWindow(mainWindow, SW_HIDE);
}
}
}
}
}
#endif

View File

@ -0,0 +1,50 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "stdafx.h"
#ifdef WIN32
namespace musik {
namespace box {
namespace win32 {
void ShowMainWindow();
void HideMainWindow();
}
}
}
#endif

View File

@ -141,6 +141,7 @@
<ClCompile Include="app\util\Hotkeys.cpp" />
<ClCompile Include="app\util\Playback.cpp" />
<ClCompile Include="app\util\PreferenceKeys.cpp" />
<ClCompile Include="app\util\Win32Util.cpp" />
<ClCompile Include="app\window\CategoryListView.cpp" />
<ClCompile Include="app\window\EntryWithHeader.cpp" />
<ClCompile Include="app\window\LogWindow.cpp" />
@ -198,6 +199,7 @@
<ClInclude Include="app\util\Playback.h" />
<ClInclude Include="app\util\PreferenceKeys.h" />
<ClInclude Include="app\util\Version.h" />
<ClInclude Include="app\util\Win32Util.h" />
<ClInclude Include="app\window\CategoryListView.h" />
<ClInclude Include="app\window\EntryWithHeader.h" />
<ClInclude Include="app\window\LogWindow.h" />

View File

@ -144,6 +144,9 @@
<ClCompile Include="app\overlay\OutputOverlay.cpp">
<Filter>app\overlay</Filter>
</ClCompile>
<ClCompile Include="app\util\Win32Util.cpp">
<Filter>app\util</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
@ -336,6 +339,9 @@
<ClInclude Include="cursespp\IViewRoot.h">
<Filter>cursespp</Filter>
</ClInclude>
<ClInclude Include="app\util\Win32Util.h">
<Filter>app\util</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="cursespp">