add configuration and about dialogs

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@132 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-05-16 16:09:28 +00:00
parent b0e13f1973
commit b570bed451
5 changed files with 199 additions and 29 deletions

View File

@ -4,13 +4,17 @@ export LDFLAGS=-lm -L../src -lvgmstream
export CC=i586-mingw32msvc-gcc export CC=i586-mingw32msvc-gcc
export AR=i586-mingw32msvc-ar export AR=i586-mingw32msvc-ar
export STRIP=i586-mingw32msvc-strip export STRIP=i586-mingw32msvc-strip
export WINDRES=i586-mingw32msvc-windres
.PHONY: libvgmstream.a .PHONY: libvgmstream.a
in_vgmstream.dll: libvgmstream.a in_vgmstream.dll: libvgmstream.a in_vgmstream.c resource.o
$(CC) -shared $(CFLAGS) "-DVERSION=\"`../version.sh`\"" in_vgmstream.c $(LDFLAGS) -o in_vgmstream.dll $(CC) -shared $(CFLAGS) "-DVERSION=\"`../version.sh`\"" in_vgmstream.c resource.o $(LDFLAGS) -o in_vgmstream.dll
$(STRIP) in_vgmstream.dll $(STRIP) in_vgmstream.dll
resource.o: resource.rc resource.h
$(WINDRES) -o resource.o resource.rc
libvgmstream.a: libvgmstream.a:
$(MAKE) -C ../src libvgmstream.a $(MAKE) -C ../src libvgmstream.a

View File

@ -9,16 +9,21 @@
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
#endif #endif
#include <windows.h> #include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <stdio.h> #include <stdio.h>
#include "../src/vgmstream.h" #include "../src/vgmstream.h"
#include "../src/util.h" #include "../src/util.h"
#include "in2.h" #include "in2.h"
#include "resource.h"
#ifndef VERSION #ifndef VERSION
#define VERSION #define VERSION
#endif #endif
#define BINARY_NAME "in_vgmstream.dll"
#define APP_NAME "vgmstream plugin"
#define PLUGIN_DESCRIPTION "vgmstream plugin " VERSION " " __DATE__ #define PLUGIN_DESCRIPTION "vgmstream plugin " VERSION " " __DATE__
/* post when playback stops */ /* post when playback stops */
@ -30,9 +35,23 @@ DWORD WINAPI __stdcall decode(void *arg);
char lastfn[MAX_PATH+1] = {0}; /* name of the currently playing file */ char lastfn[MAX_PATH+1] = {0}; /* name of the currently playing file */
short sample_buffer[576*2*2]; /* 576 16-bit samples, stereo, possibly doubled in size for DSP */ short sample_buffer[576*2*2]; /* 576 16-bit samples, stereo, possibly doubled in size for DSP */
/* hardcode these now, TODO will be configurable later */ #define DEFAULT_FADE_SECONDS "10"
const double fade_seconds = 10.0; #define DEFAULT_LOOP_COUNT "2"
const double loop_count = 2.0; #define DEFAULT_THREAD_PRIORITY 3
#define DEFAULT_LOOP_FOREVER 0
#define FADE_SECONDS_INI_ENTRY "fade_seconds"
#define LOOP_COUNT_INI_ENTRY "loop_count"
#define THREAD_PRIORITY_INI_ENTRY "thread_priority"
#define LOOP_FOREVER_INI_ENTRY "loop_forever"
double fade_seconds;
double loop_count;
int thread_priority;
int loop_forever;
char *priority_strings[] = {"Idle","Lowest","Below Normal","Normal","Above Normal","Highest (not recommended)","Time Critical (not recommended)"};
int priority_values[] = {THREAD_PRIORITY_IDLE,THREAD_PRIORITY_LOWEST,THREAD_PRIORITY_BELOW_NORMAL,THREAD_PRIORITY_NORMAL,THREAD_PRIORITY_ABOVE_NORMAL,THREAD_PRIORITY_HIGHEST,THREAD_PRIORITY_TIME_CRITICAL};
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
HANDLE decode_thread_handle = INVALID_HANDLE_VALUE; HANDLE decode_thread_handle = INVALID_HANDLE_VALUE;
@ -75,9 +94,13 @@ char * extension_list[EXTENSION_COUNT] = {
"mss\0MSS Audio File (*.MSS)\0", "mss\0MSS Audio File (*.MSS)\0",
}; };
/* stubs, we don't do anything fancy yet */ void about(HWND hwndParent) {
void config(HWND hwndParent) {} MessageBox(hwndParent,
void about(HWND hwndParent) {} PLUGIN_DESCRIPTION "\n"
"by hcs and FastElbja\n\n"
"http://sourceforge.net/projects/vgmstream"
,"about in_vgmstream",MB_OK);
}
void quit() {} void quit() {}
void build_extension_list() { void build_extension_list() {
@ -91,7 +114,32 @@ void build_extension_list() {
} }
} }
/* uses the configuration file plugin.ini in the same dir as the DLL (a la HE) */
void GetINIFileName(char * iniFile) {
if (GetModuleFileName(GetModuleHandle(BINARY_NAME), iniFile, MAX_PATH)) {
char * lastSlash = strrchr(iniFile, '\\');
*(lastSlash + 1) = 0;
strcat(iniFile, "plugin.ini");
}
}
void init() { void init() {
char iniFile[MAX_PATH+1];
char buf[256];
GetINIFileName(iniFile);
thread_priority=GetPrivateProfileInt(APP_NAME,THREAD_PRIORITY_INI_ENTRY,DEFAULT_THREAD_PRIORITY,iniFile);
GetPrivateProfileString(APP_NAME,FADE_SECONDS_INI_ENTRY,DEFAULT_FADE_SECONDS,buf,sizeof(buf),iniFile);
sscanf(buf,"%lf",&fade_seconds);
GetPrivateProfileString(APP_NAME,LOOP_COUNT_INI_ENTRY,DEFAULT_LOOP_COUNT,buf,sizeof(buf),iniFile);
sscanf(buf,"%lf",&loop_count);
loop_forever=GetPrivateProfileInt(APP_NAME,LOOP_FOREVER_INI_ENTRY,DEFAULT_LOOP_FOREVER,iniFile);
build_extension_list(); build_extension_list();
} }
@ -149,6 +197,7 @@ int play(char *fn)
decode_pos_samples = 0; decode_pos_samples = 0;
paused = 0; paused = 0;
stream_length_samples = get_vgmstream_play_samples(loop_count,fade_seconds,vgmstream); stream_length_samples = get_vgmstream_play_samples(loop_count,fade_seconds,vgmstream);
fade_samples = (int)(fade_seconds * vgmstream->sample_rate); fade_samples = (int)(fade_seconds * vgmstream->sample_rate);
decode_thread_handle = CreateThread( decode_thread_handle = CreateThread(
@ -159,6 +208,8 @@ int play(char *fn)
0, /* run thread immediately */ 0, /* run thread immediately */
NULL); /* don't keep track of the thread id */ NULL); /* don't keep track of the thread id */
SetThreadPriority(decode_thread_handle,priority_values[thread_priority]);
return 0; return 0;
} }
@ -215,15 +266,15 @@ int infoDlg(char *fn, HWND hwnd) {
char description[1024]; char description[1024];
description[0]='\0'; description[0]='\0';
concatn(1024,description,PLUGIN_DESCRIPTION "\n\n"); concatn(sizeof(description),description,PLUGIN_DESCRIPTION "\n\n");
if (!fn || !*fn) { if (!fn || !*fn) {
if (!vgmstream) return 0; if (!vgmstream) return 0;
describe_vgmstream(vgmstream,description,1024); describe_vgmstream(vgmstream,description,sizeof(description));
} else { } else {
infostream = init_vgmstream(fn); infostream = init_vgmstream(fn);
if (!infostream) return 0; if (!infostream) return 0;
describe_vgmstream(infostream,description,1024); describe_vgmstream(infostream,description,sizeof(description));
close_vgmstream(infostream); close_vgmstream(infostream);
infostream=NULL; infostream=NULL;
} }
@ -234,7 +285,7 @@ int infoDlg(char *fn, HWND hwnd) {
/* retrieve information on this or possibly another file */ /* retrieve information on this or possibly another file */
void getfileinfo(char *filename, char *title, int *length_in_ms) { void getfileinfo(char *filename, char *title, int *length_in_ms) {
if (!filename || !*filename) // currently playing file if (!filename || !*filename) /* currently playing file*/
{ {
if (!vgmstream) return; if (!vgmstream) return;
if (length_in_ms) *length_in_ms=getlength(); if (length_in_ms) *length_in_ms=getlength();
@ -245,7 +296,7 @@ int infoDlg(char *fn, HWND hwnd) {
strcpy(title,++p); strcpy(title,++p);
} }
} }
else // some other file else /* some other file */
{ {
VGMSTREAM * infostream; VGMSTREAM * infostream;
if (length_in_ms) if (length_in_ms)
@ -253,8 +304,8 @@ int infoDlg(char *fn, HWND hwnd) {
*length_in_ms=-1000; *length_in_ms=-1000;
if ((infostream=init_vgmstream(filename))) if ((infostream=init_vgmstream(filename)))
{ {
// these are only second-accurate, but how accurate does this need to be anyway?
*length_in_ms = get_vgmstream_play_samples(loop_count,fade_seconds,infostream)*1000LL/infostream->sample_rate; *length_in_ms = get_vgmstream_play_samples(loop_count,fade_seconds,infostream)*1000LL/infostream->sample_rate;
close_vgmstream(infostream); close_vgmstream(infostream);
infostream=NULL; infostream=NULL;
} }
@ -277,7 +328,7 @@ DWORD WINAPI __stdcall decode(void *arg) {
int samples_to_do; int samples_to_do;
int l; int l;
if (decode_pos_samples+576>stream_length_samples) if (decode_pos_samples+576>stream_length_samples && !loop_forever)
samples_to_do=stream_length_samples-decode_pos_samples; samples_to_do=stream_length_samples-decode_pos_samples;
else else
samples_to_do=576; samples_to_do=576;
@ -299,7 +350,7 @@ DWORD WINAPI __stdcall decode(void *arg) {
render_vgmstream(sample_buffer,samples_to_do,vgmstream); render_vgmstream(sample_buffer,samples_to_do,vgmstream);
/* fade! */ /* fade! */
if (vgmstream->loop_flag && fade_samples > 0) { if (vgmstream->loop_flag && fade_samples > 0 && !loop_forever) {
int samples_into_fade = decode_pos_samples - (stream_length_samples - fade_samples); int samples_into_fade = decode_pos_samples - (stream_length_samples - fade_samples);
if (samples_into_fade + samples_to_do > 0) { if (samples_into_fade + samples_to_do > 0) {
int j,k; int j,k;
@ -330,15 +381,95 @@ DWORD WINAPI __stdcall decode(void *arg) {
return 0; return 0;
} }
BOOL CALLBACK configDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
char buf[256];
char iniFile[MAX_PATH+1];
static int mypri;
HANDLE hSlider;
switch (uMsg) {
case WM_CLOSE:
EndDialog(hDlg,TRUE);
return 0;
case WM_INITDIALOG:
GetINIFileName(iniFile);
/* set CPU Priority slider */
hSlider=GetDlgItem(hDlg,IDC_THREAD_PRIORITY_SLIDER);
SendMessage(hSlider, TBM_SETRANGE,
(WPARAM) TRUE, /* redraw flag */
(LPARAM) MAKELONG(1, 7)); /* min. & max. positions */
SendMessage(hSlider, TBM_SETPOS,
(WPARAM) TRUE, /* redraw flag */
(LPARAM) thread_priority+1);
mypri=thread_priority;
SetDlgItemText(hDlg,IDC_THREAD_PRIORITY_TEXT,priority_strings[thread_priority]);
sprintf(buf,"%.1lf",fade_seconds);
SetDlgItemText(hDlg,IDC_FADE_SECONDS,buf);
sprintf(buf,"%.1lf",loop_count);
SetDlgItemText(hDlg,IDC_LOOP_COUNT,buf);
CheckDlgButton(hDlg,IDC_LOOP_FOREVER,(loop_forever?BST_CHECKED:BST_UNCHECKED));
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
case IDOK:
{
/* verify before we do anything */
}
GetINIFileName(iniFile);
thread_priority=mypri;
sprintf(buf,"%d",thread_priority);
WritePrivateProfileString(APP_NAME,THREAD_PRIORITY_INI_ENTRY,buf,iniFile);
GetDlgItemText(hDlg,IDC_FADE_SECONDS,buf,sizeof(buf));
sscanf(buf,"%lf",&fade_seconds);
WritePrivateProfileString(APP_NAME,FADE_SECONDS_INI_ENTRY,buf,iniFile);
GetDlgItemText(hDlg,IDC_LOOP_COUNT,buf,sizeof(buf));
sscanf(buf,"%lf",&loop_count);
WritePrivateProfileString(APP_NAME,LOOP_COUNT_INI_ENTRY,buf,iniFile);
loop_forever = (IsDlgButtonChecked(hDlg,IDC_LOOP_FOREVER) == BST_CHECKED);
sprintf(buf,"%d",loop_forever);
WritePrivateProfileString(APP_NAME,LOOP_FOREVER_INI_ENTRY,buf,iniFile);
EndDialog(hDlg,TRUE);
break;
case IDCANCEL:
EndDialog(hDlg,TRUE);
break;
}
case WM_HSCROLL:
if ((struct HWND__ *)lParam==GetDlgItem(hDlg,IDC_THREAD_PRIORITY_SLIDER)) {
if (LOWORD(wParam)==TB_THUMBPOSITION || LOWORD(wParam)==TB_THUMBTRACK) mypri=HIWORD(wParam)-1;
else mypri=SendMessage(GetDlgItem(hDlg,IDC_THREAD_PRIORITY_SLIDER),TBM_GETPOS,0,0)-1;
SetDlgItemText(hDlg,IDC_THREAD_PRIORITY_TEXT,priority_strings[mypri]);
}
break;
default:
return 0;
}
return 1;
}
void config(HWND hwndParent) {
DialogBox(input_module.hDllInstance, (const char *)IDD_CONFIG, hwndParent, configDlgProc);
}
In_Module input_module = In_Module input_module =
{ {
IN_VER, IN_VER,
PLUGIN_DESCRIPTION, PLUGIN_DESCRIPTION,
0, // hMainWindow 0, /* hMainWindow */
0, // hDllInstance 0, /* hDllInstance */
working_extension_list, working_extension_list,
1, // is_seekable 1, /* is_seekable */
1, // uses output 1, /* uses output */
config, config,
about, about,
init, init,

View File

@ -178,12 +178,20 @@
RelativePath=".\out.h" RelativePath=".\out.h"
> >
</File> </File>
<File
RelativePath=".\resource.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
> >
<File
RelativePath=".\resource.rc"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Source Files" Name="Source Files"

6
winamp/resource.h Normal file
View File

@ -0,0 +1,6 @@
#define IDD_CONFIG 101
#define IDC_LOOP_COUNT 1000
#define IDC_FADE_SECONDS 1001
#define IDC_LOOP_FOREVER 1002
#define IDC_THREAD_PRIORITY_SLIDER 1003
#define IDC_THREAD_PRIORITY_TEXT 1004

21
winamp/resource.rc Normal file
View File

@ -0,0 +1,21 @@
#include "resource.h"
#include "afxres.h"
IDD_CONFIG DIALOGEX 0, 0, 187, 92
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "in_vgmstream configuration"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,129,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14
EDITTEXT IDC_LOOP_COUNT,52,7,39,14,ES_AUTOHSCROLL
LTEXT "Loop Count",IDC_STATIC,7,10,44,12
LTEXT "Fade Length",IDC_STATIC,7,25,41,8
EDITTEXT IDC_FADE_SECONDS,52,23,39,14,ES_AUTOHSCROLL
LTEXT "seconds",IDC_STATIC,93,24,29,11
CONTROL "Loop forever",IDC_LOOP_FOREVER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,40,77,10
LTEXT "Thread Priority",IDC_STATIC,21,53,46,8
CONTROL "Slider1",IDC_THREAD_PRIORITY_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_TABSTOP,7,61,77,10
CTEXT "DATARIFIC",IDC_THREAD_PRIORITY_TEXT,18,74,54,11
END