mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 03:39:50 +00:00
First checking of the win32cpp::ApplicationThread. Connected the TransportController, but it does not really DO anything at the moment :)
The only call implemented so far is the win32cpp::ApplicationThread::Call0(...);
This commit is contained in:
parent
43f62d7b8a
commit
70b53353ef
@ -38,6 +38,7 @@
|
||||
|
||||
#include <pch.hpp>
|
||||
#include <cube/TransportController.hpp>
|
||||
#include <win32cpp/ApplicationThread.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -72,6 +73,8 @@ void TransportController::OnViewCreated()
|
||||
this->transportView.volumeSlider->Repositioned.connect(
|
||||
this, &TransportController::OnVolumeSliderChange);
|
||||
this->transportView.volumeSlider->SetPosition(musik::core::PlaybackQueue::Instance().Volume());
|
||||
|
||||
musik::core::PlaybackQueue::Instance().CurrentTrackChanged.connect(this,&TransportController::OnTrackChange);
|
||||
}
|
||||
|
||||
void TransportController::OnViewResized(Size size)
|
||||
@ -102,3 +105,15 @@ void TransportController::OnVolumeSliderChange()
|
||||
{
|
||||
musik::core::PlaybackQueue::Instance().SetVolume(transportView.volumeSlider->Position());
|
||||
}
|
||||
|
||||
void TransportController::OnTrackChange(musik::core::TrackPtr track){
|
||||
win32cpp::ApplicationThread::Call0(this,&TransportController::OnTrackChangeAppThread);
|
||||
}
|
||||
|
||||
void TransportController::OnTrackChangeAppThread(){
|
||||
/* musik::core::TrackPtr track = musik::core::PlaybackQueue::Instance().CurrentTrack();
|
||||
|
||||
this->transportView.titleLabel. // HMM.. Can't find how to set the labels
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,8 @@ protected: void OnStopPressed();
|
||||
protected: void OnNextPressed();
|
||||
protected: void OnPreviousPressed();
|
||||
protected: void OnVolumeSliderChange();
|
||||
protected: void OnTrackChange(musik::core::TrackPtr track);
|
||||
protected: void OnTrackChangeAppThread();
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
#include <pch.hpp>
|
||||
#include <win32cpp/Application.hpp>
|
||||
#include <win32cpp/ApplicationThread.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -55,9 +56,16 @@ Application Application::sMainApplication;
|
||||
, commandLine(_T(""))
|
||||
, showCommand(NULL)
|
||||
, mainWindow(NULL)
|
||||
, thread(new win32cpp::ApplicationThread())
|
||||
, helperWindow(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*dtor*/ Application::~Application()
|
||||
{
|
||||
delete this->thread;
|
||||
}
|
||||
|
||||
///\brief
|
||||
///Initialize the Application instance.
|
||||
///
|
||||
@ -117,10 +125,16 @@ void Application::Run(TopLevelWindow& mainWindow)
|
||||
|
||||
this->mainWindow = &mainWindow;
|
||||
|
||||
// Create helper window
|
||||
this->helperWindow = new Application::HelperWindow();
|
||||
|
||||
if ( ! mainWindow) // shortcut for IsInitialized()
|
||||
{
|
||||
mainWindow.Initialize();
|
||||
}
|
||||
|
||||
this->helperWindow->Initialize(&mainWindow);
|
||||
|
||||
//
|
||||
mainWindow.Destroyed.connect(this, &Application::OnMainWindowDestroyed);
|
||||
//
|
||||
@ -133,6 +147,8 @@ void Application::Run(TopLevelWindow& mainWindow)
|
||||
::DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
delete this->helperWindow;
|
||||
|
||||
this->mainWindow = NULL;
|
||||
}
|
||||
|
||||
@ -196,4 +212,58 @@ void Application::Terminate() const
|
||||
Application::operator HINSTANCE() const
|
||||
{
|
||||
return this->instance;
|
||||
}
|
||||
}
|
||||
|
||||
///\brief
|
||||
///Constructor for HelperWindow
|
||||
Application::HelperWindow::HelperWindow(){
|
||||
}
|
||||
|
||||
///\brief
|
||||
///Create HelperWindow
|
||||
HWND Application::HelperWindow::Create(Window* parent){
|
||||
HINSTANCE hInstance = Application::Instance();
|
||||
|
||||
// create the window
|
||||
DWORD style = WS_CHILD;
|
||||
//
|
||||
HWND hwnd = CreateWindowEx(
|
||||
NULL, // ExStyle
|
||||
_T("Message"), // Class name
|
||||
_T("HelperWindow"), // Window name
|
||||
style, // Style
|
||||
0, // X
|
||||
0, // Y
|
||||
0, // Width
|
||||
0, // Height
|
||||
parent->Handle(), // Parent
|
||||
NULL, // Menu
|
||||
hInstance, // Instance
|
||||
NULL); // lParam
|
||||
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
///\brief
|
||||
///HelperWindow message handler.
|
||||
LRESULT Application::HelperWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam){
|
||||
switch (message)
|
||||
{
|
||||
case WM_USER+1:
|
||||
// This is a ApplicationTread message
|
||||
ApplicationThread *thread = Application::Instance().thread;
|
||||
if(thread){
|
||||
thread->MainThreadCallback();
|
||||
}
|
||||
return 0; // 0 = processed
|
||||
}
|
||||
|
||||
return this->DefaultWindowProc(message, wParam, lParam);
|
||||
}
|
||||
|
||||
void Application::HelperWindow::OnCreated(){
|
||||
ApplicationThread *thread = Application::Instance().thread;
|
||||
if(thread){
|
||||
thread->MainThreadCallback();
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <win32cpp/Types.hpp>
|
||||
#include <win32cpp/Window.hpp>
|
||||
#include <win32cpp/TopLevelWindow.hpp>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
@ -46,6 +47,9 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace win32cpp {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// forward declaration
|
||||
class ApplicationThread;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -69,6 +73,7 @@ public: class ApplicationAlreadyInitializedException: public Exception { };
|
||||
public: class ApplicationAlreadyRunningException: public Exception { };
|
||||
|
||||
private: /*ctor*/ Application();
|
||||
private: /*dtor*/ ~Application();
|
||||
|
||||
public: static void Initialize(HINSTANCE instance, HINSTANCE previousInstance, LPTSTR commandLine, int showCommand);
|
||||
public: void Run(TopLevelWindow& mainWindow);
|
||||
@ -93,8 +98,25 @@ private: int showCommand;
|
||||
private: TopLevelWindow* mainWindow;
|
||||
// class data
|
||||
private: static Application sMainApplication;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
friend class ApplicationThread;
|
||||
|
||||
private: ApplicationThread *thread;
|
||||
|
||||
class HelperWindow : public win32cpp::Window{
|
||||
public: HelperWindow();
|
||||
public: virtual HWND Create(Window* parent);
|
||||
public: virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
public: virtual void OnCreated();
|
||||
};
|
||||
|
||||
private: HelperWindow *helperWindow;
|
||||
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // win32cpp
|
||||
} // win32cpp
|
||||
|
72
src/win32cpp/ApplicationThread.cpp
Normal file
72
src/win32cpp/ApplicationThread.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License Agreement:
|
||||
//
|
||||
// The following are Copyright © 2007, Daniel Önnerby
|
||||
//
|
||||
// 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.hpp"
|
||||
|
||||
#include "ApplicationThread.hpp"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace win32cpp;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ApplicationThread::ApplicationThread(void){
|
||||
}
|
||||
|
||||
ApplicationThread::~ApplicationThread(void){
|
||||
}
|
||||
|
||||
void ApplicationThread::AddCall(CallClassBase *callClass){
|
||||
this->calls.push_back(CallClassPtr(callClass));
|
||||
this->NotifyMainThread();
|
||||
}
|
||||
|
||||
void ApplicationThread::MainThreadCallback(){
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
while(!this->calls.empty()){
|
||||
CallClassPtr currentCall = this->calls.front();
|
||||
currentCall->Call();
|
||||
this->calls.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationThread::NotifyMainThread(){
|
||||
if(Application::Instance().helperWindow){
|
||||
::PostMessage(Application::Instance().helperWindow->Handle(),WM_USER+1,NULL,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
108
src/win32cpp/ApplicationThread.hpp
Normal file
108
src/win32cpp/ApplicationThread.hpp
Normal file
@ -0,0 +1,108 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License Agreement:
|
||||
//
|
||||
// The following are Copyright © 2007, Daniel Önnerby
|
||||
//
|
||||
// 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 <sigslot/sigslot.h>
|
||||
#include <list>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <win32cpp/Application.hpp>
|
||||
#include <win32cpp/Window.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace win32cpp {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ApplicationThread{
|
||||
protected:
|
||||
friend class Application;
|
||||
friend class Application::HelperWindow;
|
||||
|
||||
ApplicationThread(void);
|
||||
public: ~ApplicationThread(void);
|
||||
protected: void MainThreadCallback();
|
||||
protected: void NotifyMainThread();
|
||||
|
||||
protected: boost::mutex mutex;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
class CallClassBase{
|
||||
public:
|
||||
virtual ~CallClassBase(void){};
|
||||
virtual void Call()=0;
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
typedef boost::shared_ptr<CallClassBase> CallClassPtr;
|
||||
typedef std::list<CallClassPtr> CallVector;
|
||||
|
||||
CallVector calls;
|
||||
|
||||
void AddCall(CallClassBase *callClass);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
template<class DestinationType>
|
||||
class CallClass0 : public CallClassBase{
|
||||
public:
|
||||
sigslot::signal0<> signal;
|
||||
CallClass0(DestinationType* destinationObject,void (DestinationType::*memberMethod)()){
|
||||
this->signal.connect(destinationObject,memberMethod);
|
||||
};
|
||||
|
||||
void Call(){
|
||||
this->signal();
|
||||
};
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
template<class DestinationType>
|
||||
static void Call0(DestinationType* destinationObject,void (DestinationType::*memberMethod)()){
|
||||
win32cpp::Application::Instance().thread->AddCall(new CallClass0<DestinationType>(destinationObject,memberMethod));
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
} // win32cpp
|
||||
//////////////////////////////////////////////////////////////////////////////
|
@ -377,6 +377,14 @@
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ApplicationThread.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ApplicationThread.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Timer.cpp"
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user