2009-06-20 10:58:15 +00:00
|
|
|
|
// ================================================================================================
|
|
|
|
|
// File description
|
|
|
|
|
// ----------------
|
|
|
|
|
/* In the GUI build there is a timer that is initiated with SetTimer() that will setup a timer that
|
|
|
|
|
calls the lpTimerFunc function pointer as long as your program is running a message loop. If it
|
|
|
|
|
doesn't run one, like in a console application (the NOGUI build), you'll have to use a different
|
|
|
|
|
kind of timer API, like timeSetEvent() or CreateThreadPoolTimer(). These timers use a different
|
|
|
|
|
thread to make the callback so be careful to properly lock and synchronize. */
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
// Library requirements
|
|
|
|
|
// ----------------
|
|
|
|
|
// This program needs winmm.lib. There's no simpler or better way to make a timer withouth it.
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
// Includes
|
|
|
|
|
// ----------------
|
|
|
|
|
#include <iostream>
|
|
|
|
|
//using namespace std;
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <mmsystem.h>
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "PlayerExport.h"
|
|
|
|
|
|
|
|
|
|
#include "InputPlugin.h"
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Declarations and definitions
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
void MakeTime();
|
|
|
|
|
|
|
|
|
|
int g_Stop = 0;
|
|
|
|
|
extern std::string CurrentlyPlayingFile;
|
|
|
|
|
extern bool GlobalPause;
|
|
|
|
|
///////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Manage restart when playback for a file has reached the end of the file
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#ifdef _M_X64
|
|
|
|
|
void CALLBACK Update()
|
|
|
|
|
#else
|
|
|
|
|
void CALLBACK Update(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-06-20 11:05:52 +00:00
|
|
|
|
//NOTICE_LOG(AUDIO,"DLL > Update() > Begin (%i)\n", active_input_plugin);
|
2009-06-20 10:58:15 +00:00
|
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
|
// Manage restart when playback for a file has reached the end of the file
|
|
|
|
|
// --------------
|
|
|
|
|
// Check if the input plugin is activated
|
|
|
|
|
if(!active_input_plugin || !active_input_plugin->plugin)
|
|
|
|
|
{
|
2009-06-20 11:05:52 +00:00
|
|
|
|
//NOTICE_LOG(AUDIO,"The input plugin is not activated yet\n");
|
2009-06-20 10:58:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int ms_len = active_input_plugin->plugin->GetLength();
|
|
|
|
|
const int ms_cur = active_input_plugin->plugin->GetOutputTime();
|
|
|
|
|
|
|
|
|
|
// Get the current playback progress
|
|
|
|
|
float progress;
|
|
|
|
|
if(ms_len > 0)
|
|
|
|
|
progress = (float)ms_cur / ms_len;
|
|
|
|
|
else
|
|
|
|
|
progress = 0;
|
|
|
|
|
|
|
|
|
|
if ( progress > 0.7 ) // Only show this if we are getting close to the end, for bugtesting
|
|
|
|
|
// basically
|
|
|
|
|
{
|
2009-06-20 11:05:52 +00:00
|
|
|
|
//NOTICE_LOG(AUDIO,"Playback progress <%i of %i>\n", ms_cur, ms_len);
|
2009-06-20 10:58:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Because cur never go all the way to len we can't use a == comparison. Insted of this
|
|
|
|
|
// we could also check if the location is the same as right before.
|
|
|
|
|
if(ms_cur > ms_len - 1000 && !GlobalPause) // avoid restarting in cases where we just pressed pause
|
|
|
|
|
{
|
2009-06-20 11:05:52 +00:00
|
|
|
|
NOTICE_LOG(AUDIO,"Restart <%s>\n", CurrentlyPlayingFile.c_str());
|
2009-06-20 10:58:15 +00:00
|
|
|
|
Player_Play((char *)CurrentlyPlayingFile.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// --------------
|
|
|
|
|
|
2009-06-20 11:05:52 +00:00
|
|
|
|
//NOTICE_LOG(AUDIO,"Make new time\n");
|
2009-06-20 10:58:15 +00:00
|
|
|
|
MakeTime(); // Make a new one
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeTime()
|
|
|
|
|
{
|
|
|
|
|
timeSetEvent(
|
|
|
|
|
2000, // Interval in ms
|
|
|
|
|
0,
|
|
|
|
|
#ifdef _M_X64
|
|
|
|
|
(LPTIMECALLBACK) Update, // The function
|
|
|
|
|
#else
|
|
|
|
|
Update,
|
|
|
|
|
#endif
|
|
|
|
|
0,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
///////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Start the timer
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int MainTimer()
|
|
|
|
|
{
|
|
|
|
|
MakeTime();
|
|
|
|
|
|
|
|
|
|
//while( g_Stop == 0 )
|
|
|
|
|
//{
|
|
|
|
|
// cout << ".";
|
|
|
|
|
//}
|
|
|
|
|
|
2009-06-20 11:05:52 +00:00
|
|
|
|
//NOTICE_LOG(AUDIO,"MakeTime\n");
|
2009-06-20 10:58:15 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
///////////////////////////
|