From 4c4d913368c16be6cbd42a7a2e589841236fdbb6 Mon Sep 17 00:00:00 2001 From: casey langen Date: Fri, 18 Nov 2016 22:25:47 -0800 Subject: [PATCH] Added a global hotkey playback remote. --- musikcube.sln | 7 + src/contrib/win32globalhotkeys/pch.cpp | 35 +++ src/contrib/win32globalhotkeys/pch.h | 35 +++ .../win32globalhotkeys.filters | 26 +++ .../win32globalhotkeys.vcproj | 201 ++++++++++++++++++ .../win32globalhotkeys.vcxproj | 112 ++++++++++ .../win32globalhotkeys_plugin.cpp | 115 ++++++++++ 7 files changed, 531 insertions(+) create mode 100644 src/contrib/win32globalhotkeys/pch.cpp create mode 100644 src/contrib/win32globalhotkeys/pch.h create mode 100644 src/contrib/win32globalhotkeys/win32globalhotkeys.filters create mode 100644 src/contrib/win32globalhotkeys/win32globalhotkeys.vcproj create mode 100644 src/contrib/win32globalhotkeys/win32globalhotkeys.vcxproj create mode 100644 src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp diff --git a/musikcube.sln b/musikcube.sln index ca71e2b45..a1c5337ba 100644 --- a/musikcube.sln +++ b/musikcube.sln @@ -4,6 +4,7 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "musikbox", "src\musikbox\musikbox.vcxproj", "{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}" ProjectSection(ProjectDependencies) = postProject + {3E30064E-B9C4-4690-8AC2-2C694176A319} = {3E30064E-B9C4-4690-8AC2-2C694176A319} {54764854-5A73-4329-9BAD-9AF22C72D9E2} = {54764854-5A73-4329-9BAD-9AF22C72D9E2} {465EF178-91C1-4068-BE1D-F9616ECCB6DE} = {465EF178-91C1-4068-BE1D-F9616ECCB6DE} {4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8} = {4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8} @@ -31,6 +32,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpg123decoder", "src\contri EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "m4adecoder", "src\contrib\m4adecoder\m4adecoder.vcxproj", "{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "win32globalhotkeys", "src\contrib\win32globalhotkeys\win32globalhotkeys.vcxproj", "{3E30064E-B9C4-4690-8AC2-2C694176A319}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -77,6 +80,10 @@ Global {4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Debug|Win32.Build.0 = Debug|Win32 {4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Release|Win32.ActiveCfg = Release|Win32 {4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Release|Win32.Build.0 = Release|Win32 + {3E30064E-B9C4-4690-8AC2-2C694176A319}.Debug|Win32.ActiveCfg = Debug|Win32 + {3E30064E-B9C4-4690-8AC2-2C694176A319}.Debug|Win32.Build.0 = Debug|Win32 + {3E30064E-B9C4-4690-8AC2-2C694176A319}.Release|Win32.ActiveCfg = Release|Win32 + {3E30064E-B9C4-4690-8AC2-2C694176A319}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/contrib/win32globalhotkeys/pch.cpp b/src/contrib/win32globalhotkeys/pch.cpp new file mode 100644 index 000000000..9e3cc1e2e --- /dev/null +++ b/src/contrib/win32globalhotkeys/pch.cpp @@ -0,0 +1,35 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.h" \ No newline at end of file diff --git a/src/contrib/win32globalhotkeys/pch.h b/src/contrib/win32globalhotkeys/pch.h new file mode 100644 index 000000000..6c3d6ade0 --- /dev/null +++ b/src/contrib/win32globalhotkeys/pch.h @@ -0,0 +1,35 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 diff --git a/src/contrib/win32globalhotkeys/win32globalhotkeys.filters b/src/contrib/win32globalhotkeys/win32globalhotkeys.filters new file mode 100644 index 000000000..db16ba102 --- /dev/null +++ b/src/contrib/win32globalhotkeys/win32globalhotkeys.filters @@ -0,0 +1,26 @@ + + + + + {803aac08-5b94-432d-8333-c6feb1c0484b} + h;hpp;hxx;hm;inl;inc;xsd;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {9b4fd5cc-1eb5-4194-b8af-a813d01a73c0} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + plugin + + + plugin + + + + + plugin + + + \ No newline at end of file diff --git a/src/contrib/win32globalhotkeys/win32globalhotkeys.vcproj b/src/contrib/win32globalhotkeys/win32globalhotkeys.vcproj new file mode 100644 index 000000000..db54c0725 --- /dev/null +++ b/src/contrib/win32globalhotkeys/win32globalhotkeys.vcproj @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/win32globalhotkeys/win32globalhotkeys.vcxproj b/src/contrib/win32globalhotkeys/win32globalhotkeys.vcxproj new file mode 100644 index 000000000..16fdf698e --- /dev/null +++ b/src/contrib/win32globalhotkeys/win32globalhotkeys.vcxproj @@ -0,0 +1,112 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {3E30064E-B9C4-4690-8AC2-2C694176A319} + win32globalhotkeys + 8.1 + + + + DynamicLibrary + v140 + Unicode + + + DynamicLibrary + v140 + Unicode + + + + + + + + + + + + + <_ProjectFileVersion>14.0.25123.0 + + + $(SolutionDir)bin\$(Configuration)\plugins + ./obj/$(Configuration)\ + true + MinimumRecommendedRules.ruleset + + + + + $(SolutionDir)bin\$(Configuration)\plugins + ./obj/$(Configuration)\ + MinimumRecommendedRules.ruleset + + + + + + Disabled + ../..;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebug + Level3 + EditAndContinue + $(IntDir) + $(IntDir) + $(IntDir)vc$(PlatformToolsetVersion).pdb + + + winmm.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + MachineX86 + false + + + + + AnySuitable + true + ../..;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + Level3 + + $(IntDir) + $(IntDir) + $(IntDir)vc$(PlatformToolsetVersion).pdb + + + winmm.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + Windows + true + true + UseLinkTimeCodeGeneration + MachineX86 + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp b/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp new file mode 100644 index 000000000..ada816567 --- /dev/null +++ b/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp @@ -0,0 +1,115 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.h" + +#include +#include + +musik::core::sdk::IPlaybackService* playback; + +static HHOOK hook = NULL; + +LRESULT CALLBACK ShellProc(int code, WPARAM wParam, LPARAM lParam) { + if (code == HSHELL_APPCOMMAND && playback) { + switch (GET_APPCOMMAND_LPARAM(lParam)) { + case APPCOMMAND_MEDIA_NEXTTRACK: + playback->Next(); + return 0; + case APPCOMMAND_MEDIA_PLAY_PAUSE: + playback->PauseOrResume(); + return 0; + case APPCOMMAND_MEDIA_PREVIOUSTRACK: + playback->Previous(); + return 0; + case APPCOMMAND_MEDIA_STOP: + playback->Stop(); + return 0; + } + } + + return CallNextHookEx(nullptr, code, wParam, lParam); +} + +BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { + switch (reason) { + case DLL_PROCESS_ATTACH: + hook = SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, module, 0L); + break; + + case DLL_PROCESS_DETACH: + UnhookWindowsHookEx(hook); + hook = nullptr; + break; + } + + return TRUE; +} + +class MMShellHook: + public musik::core::sdk::IPlugin, + public musik::core::sdk::IPlaybackRemote { + public: + void Destroy() { + } + + const char* Name() { + return "win32globalhotkeys"; + } + + const char* Version() { + return "0.1"; + } + + const char* Author() { + return "clangen"; + } + + virtual void SetPlaybackService(musik::core::sdk::IPlaybackService* playback) { + ::playback = playback; + } + + virtual void OnTrackChanged(musik::core::sdk::ITrack* track) { + } +}; + +static MMShellHook plugin; + +extern "C" __declspec(dllexport) musik::core::sdk::IPlugin* GetPlugin() { + return &plugin; +} + +extern "C" __declspec(dllexport) musik::core::sdk::IPlaybackRemote* GetPlaybackRemote() { + return &plugin; +} \ No newline at end of file