diff --git a/src/cube/TransportController.cpp b/src/cube/TransportController.cpp index da5999f77..65381008a 100644 --- a/src/cube/TransportController.cpp +++ b/src/cube/TransportController.cpp @@ -107,13 +107,12 @@ void TransportController::OnVolumeSliderChange() } void TransportController::OnTrackChange(musik::core::TrackPtr track){ - win32cpp::ApplicationThread::Call1(this,&TransportController::OnTrackChangeAppThread,track); -} - -void TransportController::OnTrackChangeAppThread(musik::core::TrackPtr track){ -/* musik::core::TrackPtr track = musik::core::PlaybackQueue::Instance().CurrentTrack(); - - this->transportView.titleLabel. // HMM.. Can't find how to set the labels -*/ + if(!win32cpp::ApplicationThread::InMainThread()){ + win32cpp::ApplicationThread::Call1(this,&TransportController::OnTrackChange,track); + return; + } + +// this->transportView.titleLabel. // HMM.. Can't find how to set the labels + } diff --git a/src/cube/TransportController.hpp b/src/cube/TransportController.hpp index a3ef549fd..6a48a1f85 100644 --- a/src/cube/TransportController.hpp +++ b/src/cube/TransportController.hpp @@ -66,7 +66,6 @@ protected: void OnNextPressed(); protected: void OnPreviousPressed(); protected: void OnVolumeSliderChange(); protected: void OnTrackChange(musik::core::TrackPtr track); -protected: void OnTrackChangeAppThread(musik::core::TrackPtr track); }; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/win32cpp/ApplicationThread.cpp b/src/win32cpp/ApplicationThread.cpp index 6429c3214..f471b2d08 100644 --- a/src/win32cpp/ApplicationThread.cpp +++ b/src/win32cpp/ApplicationThread.cpp @@ -46,12 +46,23 @@ using namespace win32cpp; ApplicationThread::ApplicationThread(void) : helperWindow(NULL) { + this->applicationThreadId = GetCurrentThreadId(); } ApplicationThread::~ApplicationThread(void){ delete this->helperWindow; } +bool ApplicationThread::InMainThread(){ + ApplicationThread *thread=Application::Instance().thread; + if(thread){ + DWORD theThread = GetCurrentThreadId(); + return thread->applicationThreadId==theThread; + } + return false; +} + + void ApplicationThread::AddCall(CallClassBase *callClass){ this->calls.push_back(CallClassPtr(callClass)); this->NotifyMainThread(); diff --git a/src/win32cpp/ApplicationThread.hpp b/src/win32cpp/ApplicationThread.hpp index 2b9260608..8386a03ea 100644 --- a/src/win32cpp/ApplicationThread.hpp +++ b/src/win32cpp/ApplicationThread.hpp @@ -56,12 +56,15 @@ class ApplicationThread{ ApplicationThread(void); void MainThreadCallback(); void NotifyMainThread(); + void Initialize(); + + DWORD applicationThreadId; boost::mutex mutex; public: ~ApplicationThread(void); - void Initialize(); + static bool InMainThread(); ////////////////////////////////////////////////////////////////////////////// private: @@ -120,7 +123,7 @@ class ApplicationThread{ public: sigslot::signal1 signal; Arg1Type arg1mem; - CallClass1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type arg1) : arg1mem(arg1){ + CallClass1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type &arg1) : arg1mem(arg1){ this->signal.connect(destinationObject,memberMethod); }; @@ -131,7 +134,7 @@ class ApplicationThread{ public: template - static void Call1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type arg1){ + static void Call1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type &arg1){ win32cpp::Application::Instance().thread->AddCall(new CallClass1(destinationObject,memberMethod,arg1)); };