Thanks Ian, minupdate works fine as far as I can see.
But...
I was almost ready to make a release when I encountered some weird behaviour.
When a thread started by the vis plugin uses XMPFUNC_MISC::PerformShortcut( 80 ) to play a track it works fine, until that thread stops. Then XMPlay's sound playing thread kind of freezes and doesn't continue until it's started again (by pressing pause/play twice for instance).
Here's the code of some mini sample plugin which reproduces the behaviour (
source/binary download):
#include <windows.h>
#include <stdio.h>
#include "vis.h"
#include "xmpfunc.h"
void initialize(void);
BOOL render(unsigned long* Video, int width, int height, int pitch, VisData* pVD);
BOOL savesettings(char* FileName) { return TRUE; }
BOOL opensettings(char* FileName) { return TRUE; }
BOOL receivequeryinterface(QueryInterface* Interface);
BOOL deinit();
BOOL clicked(int x, int y, int buttons);
VisInfo plugin = { 1, "XMPFunc Test", 0, &initialize, &render, &savesettings, &opensettings, &deinit, &clicked, &receivequeryinterface };
DLLEXPORT VisInfo* QueryModule(void) { return &plugin; }
int sentpause = 0;
int sentplay = 0;
int threadalive = 0;
XMPFUNC_MISC* XMPlay_Misc = NULL;
BOOL receivequeryinterface(QueryInterface* queryinterface)
{
QueryInterface* XMPlay_QueryInterface = queryinterface;
InterfaceProc xmpface = NULL;
if (queryinterface->QueryInt("xmplay:interface", (int*)&xmpface) && xmpface)
XMPlay_Misc = (XMPFUNC_MISC*)xmpface(XMPFUNC_MISC_FACE);
return TRUE;
}
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
threadalive = 1;
Sleep(2000);
sentpause = 1;
if (XMPlay_Misc) XMPlay_Misc->PerformShortcut(80);
Sleep(2000);
sentplay = 1;
if (XMPlay_Misc) XMPlay_Misc->PerformShortcut(80);
Sleep(2000);
threadalive = 0;
return 1;
}
HANDLE hThread = NULL;
void initialize(void)
{
hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);
}
BOOL clicked(int x, int y, int buttons)
{
if (!threadalive) initialize();
return TRUE;
}
BOOL deinit()
{
if (WaitForSingleObject(hThread, 500))
{
TerminateThread(hThread, 0);
}
CloseHandle(hThread);
return TRUE;
}
BOOL render(unsigned long* Video, int width, int height, int pitch, VisData* pVD)
{
char szText[4][128];
BITMAPINFO m_bmpInfo;
HDC m_dcPaint;
long *m_pPaintBuffer;
HBITMAP hDibSection;
HDC hDC;
HGDIOBJ OldObject;
int y;
memset(&m_bmpInfo.bmiHeader, 0, sizeof(m_bmpInfo.bmiHeader));
m_bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_bmpInfo.bmiHeader.biWidth = width+(width%4?4:0)-(width%4);
m_bmpInfo.bmiHeader.biHeight = 0-(height+(height%4?4:0)-(height%4));
m_bmpInfo.bmiHeader.biPlanes = 1;
m_bmpInfo.bmiHeader.biBitCount = 32;
hDC = GetDC(NULL);
hDibSection = CreateDIBSection(hDC, (BITMAPINFO *) &m_bmpInfo, DIB_RGB_COLORS, (void**)&m_pPaintBuffer, NULL, 0);
m_dcPaint = CreateCompatibleDC(hDC);
SetMapMode(m_dcPaint, GetMapMode(hDC));
OldObject = SelectObject(m_dcPaint, hDibSection);
PatBlt(m_dcPaint,0,0,m_bmpInfo.bmiHeader.biWidth,m_bmpInfo.bmiHeader.biHeight,RGB(0,0,0));
sprintf( szText[0], "Thread active: %d", threadalive);
sprintf( szText[1], "");
sprintf( szText[2], "sentpause (shortcut 80): %d", sentpause);
sprintf( szText[3], "sentplay (shortcut 80): %d", sentplay);
SetBkMode(m_dcPaint,RGB(255,255,255));
SetTextColor(m_dcPaint,RGB(255,200,0));
for (y = 0; y < 4; y++) TextOut( m_dcPaint, 6, 5+y*15, szText[y], strlen( szText[y] ) );
for (y = 0; y < height; y++) memcpy(&Video[y*pitch], &m_pPaintBuffer[y*m_bmpInfo.bmiHeader.biWidth], width*sizeof(long));
DeleteObject(OldObject);
DeleteDC(m_dcPaint);
DeleteDC(hDC);
DeleteObject(hDibSection);
return TRUE;
}
I deleted the previous 3.4.2.27 version already so I'm unsure if that was added due to the last update.
It works fine if the PerformShortcut calls are in the render function (even if the thread does the first 80-shortcut (pause) and then the render function does the second (play) later).
So yeah, I'm a bit struck by that whole thing... It could probably be worked around by using some queue from the vis thread so only the render function does the XMPFUNC_MISC commands. But I wanted to ask back maybe you have an idea (talk about abusing your attention now >_<).
Thanks already :-)