home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
vrac
/
visvideo.zip
/
WPLAYER.C_
/
WPLAYER.bin
Wrap
Text File
|
1994-08-31
|
68KB
|
2,174 lines
/*
* Program : WPLAYER.EXE
* Module : WPLAYER.C
* Description : WPLAYER provides user playback Video CD, CDI-Movie and the
* other MPEG files.
*
* Function and Hot Ket supported --
*
* Ctrl+Alt+Q
* Minimize The MPEG Master will become an icon, at
* this time, all of the Hot-Key is disabled.
* Always On Top The MPEG Master control panel will be
* bring to top above all the windows.
* Exit The MPEG Master will be shutdown.
*
* Ctrl+Alt+F
* Fast Forward.
*
* Ctrl+Alt+L
* Slow Forward.
*
* Ctrl+Alt+P
* Normal Play.
*
* Ctrl+Alt+U
* Pause.
*
* Ctrl+Alt+M
* Mute on/off audio.
*
* Ctrl+Alt+N
* Skip forward 2 minutes during CDI-FMV disc playing.
*
* Ctrl+Alt+B
* Skip backward 2 minutes during CDI-FMV disc playing.
*
* Ctrl+Alt+S
* Stop.
*
* Ctrl+Alt+UP Arrow key
* Increment Volume, Treble or Bass depends on the activate
* button that user selected.
*
* Ctrl+Alt+DOWN Arrow key
* Decrement Volume, Treble or Bass depends on the activate
* button that user selected.
*
* Ctrl+Alt+LEFT (RIGHT) Arrow key
* Balance volume.
*
* Ctrl+Alt+SPACE BAR
* Toggle VGA/VIDEO output to VGA monitor.
*
* Ctrl+Alt+[F2]
* Adjust display screen left to 1 pixel.
*
* Ctrl+Alt+[F3]
* Adjust display screen up to 1 line.
*
* Ctrl+Alt+[F4]
* Adjust display screen right to 1 pixel.
*
* Ctrl+Alt+[F5]
* Adjust display screen down to 1 line.
*
* Note : If an MCI driver activated that provided by Visionetics,
* the WPLAYER will perform audio control function and toggle
* VGA/VIDEO to VGA monitor only.
*
* Date: : August 19, 1994.
* Author : Visionetics Int'l / Morris Lu.
*
* Copyright (C) Visionetics Int'l, Inc. 1994.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <conio.h>
#include <commdlg.h>
#include "mpeg.h"
#include "wplayer.h"
#include "music.h"
#include "keyhook.h"
/*
* Define Hot-Key table. (ASCII/Scan code)
*/
#define Key_Q 0x5110
#define Key_q 0x7110
#define Key_F 0x4621
#define Key_f 0x6621
#define Key_L 0x4c26
#define Key_l 0x6c26
#define Key_P 0x5019
#define Key_p 0x7019
#define Key_U 0x5516
#define Key_u 0x7516
#define Key_M 0x4d32
#define Key_m 0x6d32
#define Key_S 0x531f
#define Key_s 0x731f
#define Key_N 0x4e31
#define Key_n 0x6e31
#define Key_B 0x4230
#define Key_b 0x6230
#define Key_sp 0x2039
#define Key_up 0x2648
#define Key_dn 0x2850
#define Key_F2 0x713c
#define Key_F3 0x723d
#define Key_F4 0x733e
#define Key_F5 0x743f
KeyTable keys = {
25, // no of key defined
{Key_q,Key_Q, // power off, quit application
Key_f,Key_F, // fast forward
Key_l,Key_L, // slow forward
Key_p,Key_P, // normal play
Key_u,Key_U, // pause
Key_m,Key_M, // mute on/off toggle
Key_s,Key_S, // stop
Key_n,Key_N, // skip forward 2 minutes
Key_b,Key_B, // skip backward 2 minutes
Key_up, // increment volume
Key_dn, // decrement volume
Key_sp, // toggle VGA/MPEG output to VGA monitor
Key_F2, // adjust display screen left to 1 pixel
Key_F3, // adjust display screen up to 1 line
Key_F4, // adjust display screen right to 1 pixel
Key_F5 // adjust display screen down to 1 line
},
// the relative message
{IDM_POWER,IDM_POWER,
IDM_FASTMOTION,IDM_FASTMOTION,
IDM_SLOWMOTION,IDM_SLOWMOTION,
IDM_PLAY,IDM_PLAY,
IDM_PAUSE,IDM_PAUSE,
IDM_MUTE,IDM_MUTE,
IDM_STOP,IDM_STOP,
IDM_NEXT_SONG,IDM_NEXT_SONG,
IDM_PRE_SONG,IDM_PRE_SONG,
IDM_UP,
IDM_DOWN,
IDM_SPACE,
IDM_SCREEN_LF,
IDM_SCREEN_UP,
IDM_SCREEN_RT,
IDM_SCREEN_DN
},
IDM_OtherKeyPressed // message for undefined keys
};
/*
** Variable Define for Global Variable
*/
static char MesgStr[120];
static BOOL alwaysOnTop = FALSE;
static BOOL showVer = FALSE;
static BOOL showOnVGA = FALSE;
static HMENU hSysMenu;
static BOOL MPEGExist = FALSE;
static HWND hPanelWnd; // Window main control panel handles
static HANDLE hAccel; // Handle to accelerator table
static HANDLE hInst;
static RECT rcWindow; // Current Window rectangle
static RECT rcOutline;
static POINT ptStart; // When LBUTTON down coordinate
static POINT ptStop; // Wneh LBUTTON up coordinate
static char szHelpFileName[EXE_NAME_MAX_SIZE+1]; // Help file name
static char szTFileName[MAXFILENAME];
static char szFileTitle[MAXFILENAME];
static int nMpegFiles;
static int nFileIndex;
static int seek = NORMAL;
static HBRUSH hCurveBackgnd;
static HBRUSH hCurveForegnd;
static BOOL fMove = FALSE; // Moving the control panel
static BOOL mscdex = TRUE; // suppose MSCDEX been installed
static BOOL cdrom = TRUE; // suppose CD-ROM been installed
static int selectCD;
static int cddrv_no = 0;
static int sync = 1; // 0 for scsi bus, 1 for at bus
static int cdi = 0; // 1 for Philip CD-I, 0 otherwise
static BOOL pause = FALSE;
static BOOL playing = FALSE;
static BOOL theFirstPlay = TRUE;
static int motion_old;
static int motion_flg = NPF; // normal play
static BOOL load = FALSE; // not load yet
static int idTimer = 0;
static int track_no = 1; // the first song
static int preTrack = 0; // previous song
static int preFile = 0; // previous file
static BOOL demostop = FALSE;
static BOOL fMute = FALSE; // audio status - mute, audio
static BOOL songGray = TRUE; // when bitstream is not Karaoke
static int cdType; // ALL, KARAOKE, CDIFMV
static int prvCDType;
static int defCDType; // according to INI
static BOOL repeat = FALSE;
static int nSongs;
static int ActiveItem = IDM_STOP;
static int OldActiveItem;
static int curWlevel;
static int curMsg[80];
static HBITMAP hParentBmp;
static HBITMAP hGrayBmp;
static HBITMAP hGrayPlay;
static HBITMAP hPreOn;
static HBITMAP hPreOff;
static HBITMAP hNxtOn;
static HBITMAP hNxtOff;
static HCURSOR hPrevCursor;
static HDC hScreenDC;
static HFONT hCurrentFont;
static BOOL theFirstFMV = TRUE;
static int startTimeSec; // strat play time in second for CDIFMV
static int skipTimeSec; // skip play time in second for CDIFMV
static int discTime; // time in second of the CDIFMV disc
static int dspMode = VGA;
static BOOL TimerExist = FALSE;
// Volume control
static int defVolL = 0xfc; // default left volume, 0db
static int defVolR = 0xfc; // default right volume, 0db
static int defBass = 0xf6; // default bass, 0db
static int defTreble = 0xf6; // default treble, 0db
static int nVolL; // current left volume
static int nVolR; // current right volume
static int nBass; // current bass
static int nTreble; // current treble
static int nStereo; // current stereo
static int idStereo; // current stereo id
static int idVol; // current volume id
static int minVol = 0xda;
static int maxVol = 0xfe;
static int minBass = 0xf2;
static int maxBass = 0xfb;
static int minTre = 0xf2;
static int maxTre = 0xfa;
// Global variables for Audio display curve
#define UP (BOOL)TRUE // curve upward
#define DOWN (BOOL)FALSE // curve downward
#define LEFT (BOOL)TRUE // left curve
#define RIGHT (BOOL)FALSE // right curve
static int curVolLY;
static int curVolRY;
static int curTreLY;
static int curTreRY;
static int curBassLY;
static int curBassRY;
static BOOL done = FALSE;
static ATOM mainAtom;
static BOOL MPEGMCIExist = FALSE;
static TIMERPROC lpfnTimerProc;
static WNDPROC butOrgPowerProc;
static HMENU hPowerMenu = NULL;
static BOOL keyHookOn = FALSE;
/* Function Declaration */
int PASCAL WinMain (HANDLE,HANDLE,LPSTR,int);
BOOL InitApplication (HANDLE);
BOOL InitInstance (HANDLE,int);
long FAR PASCAL PanelWndProc (HWND,UINT,WPARAM,LPARAM);
int FAR PASCAL SelectDiscDlg (HWND,UINT,WPARAM,LPARAM);
void dspCurve (int,BOOL,int,BOOL);
int MpegLoader (char *);
int initMpeg (LPSTR);
int strtoi (LPSTR);
void VideoVGASwitcher (int);
void getINIStr (LPSTR);
UINT getINIint (LPSTR);
void putINIStr (LPSTR);
void saveCfg (void);
void OutlineRect (HDC,RECT *);
void DrawButton (int,BOOL);
void MakeHelpPathName (char *);
void set_to_play (void);
void WriteText (int,LPSTR);
int loadTrack (void);
int selectFile (char *,char *,int);
BOOL processing (void);
void FAR PASCAL TimerProc (HWND,UINT,WORD,DWORD);
LRESULT FAR PASCAL butPowerProc (HWND,UINT,WPARAM,LPARAM);
void FreeTimer (void);
/************************************************************************
* WinMain(HANDLE,HANDLE,LPSTR,int) *
* *
* Procedure to accept Windows message from kernal and dispatch *
*************************************************************************/
int PASCAL WinMain (HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
int rtn;
if (GlobalFindAtom ((LPCSTR)"MPEGMasterMCI"))
MPEGMCIExist = TRUE;
// check enhance mode ?
if (!(GetWinFlags () & WF_ENHANCED)){
wsprintf (MesgStr,"%s requires Windows to be running in the 386 enhanced mode !!",ProductName);
MessageBox (NULL,MesgStr,ProductName,MB_ICONSTOP);
return (FALSE);
}
// Try to initialize the MPEG system. If error, just exit.
if (rtn = initMpeg (lpCmdLine)){
if (rtn == EVXD){
MessageBox (NULL,"VXD not installed",ProductName,MB_ICONSTOP);
return (FALSE);
}else{
wsprintf (MesgStr,"%s is not ready !!",ProductName);
MessageBox (NULL,MesgStr,ProductName,MB_ICONSTOP);
return (FALSE);
}
}
if (hPrevInstance){
ShowWindow (hPanelWnd,SW_SHOWNORMAL);
return (FALSE);
}
if (!InitApplication (hInstance))
return (FALSE);
if (!InitInstance (hInstance,nCmdShow))
return (FALSE);
if (!MPEGMCIExist)
mainAtom = GlobalAddAtom ((LPCSTR)"MPEGMasterMAIN");
SetHook (hPanelWnd,(KeyTable far *)&keys); // Set the Keyboard Hook
keyHookOn = TRUE;
while (GetMessage (&msg,NULL,NULL,NULL)){
if (!TranslateAccelerator (msg.hwnd,hAccel,&msg)){
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
if (keyHookOn)
RemoveHook (); // Remove the Keyboard Hook
if (!MPEGMCIExist)
GlobalDeleteAtom (mainAtom);
return (msg.wParam);
}/* WinMain */
/************************************************************************
* InitApplication(HANDLE) *
* *
* Procedure to register window classes for the video and control panel *
* windows. *
*************************************************************************/
BOOL InitApplication (hInstance)
HANDLE hInstance;
{
WNDCLASS wc;
/* Register the control panel window class. */
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = (WNDPROC)PanelWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance,MAKEINTRESOURCE (IDS_PANEL_ICON));
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = IDS_PANEL_CLASS;
return (RegisterClass (&wc));
}/* InitApplication */
/************************************************************************
* InitInstance(HANDLE,int) *
* *
* Saves instance handle read initialization file and creates the video *
* and panel windows. *
*************************************************************************/
BOOL InitInstance (hInstance,nCmdShow)
HANDLE hInstance;
int nCmdShow;
{
int i;
hInst = hInstance;
hPanelWnd = CreateWindow (IDS_PANEL_CLASS,IDS_PANEL_TITLE,
WS_POPUP,
PANEL_X,PANEL_Y,
PANEL_WIDTH,PANEL_HEIGHT,
NULL,NULL,hInstance,NULL
);
if( !hPanelWnd )
return (FALSE);
ShowWindow (hPanelWnd,nCmdShow);
UpdateWindow (hPanelWnd);
/* Create the button controls and assign them IDs. */
for (i = 0;i < PANEL_BUTTONS;i++){
Button[i].hWnd = CreateWindow ("Button",NULL,WS_CHILD |
BS_OWNERDRAW | WS_VISIBLE,
Button[i].pos.x,
Button[i].pos.y,
Button[i].bdWidth,
Button[i].bdHeight,
hPanelWnd,Button[i].msg,
hInstance,NULL);
}
// Subclassing the button control.
butOrgPowerProc = (WNDPROC)SetWindowLong (Button[iPOWER].hWnd,GWL_WNDPROC,
(LONG)(WNDPROC)butPowerProc);
// Set init state of audio control
DrawButton (idStereo,ON);
idVol = iVOLUME;
DrawButton (idVol,ON);
/* fill in non-variant fields of OPENFILENAME struct. */
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hPanelWnd;
ofn.lpstrFilter = szFilterSpec;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szTFileName;
ofn.nMaxFile = MAXFILENAME;
ofn.lpstrInitialDir = NULL;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MAXFILENAME;
ofn.lpstrTitle = NULL;
ofn.lpstrDefExt = "MPG";
ofn.Flags = OFN_ALLOWMULTISELECT;
MakeHelpPathName (szHelpFileName);
return (TRUE);
}/* InitInstance */
/*
* butPowerProc subclasses the button control in the client area.
* It intercepts all incoming messages and monitor user action. It
* PostMessage() to the parent window to invoke a floating popup menu.
*/
LRESULT FAR PASCAL butPowerProc (hWnd,Message,wParam,lParam)
HWND hWnd;
UINT Message;
WPARAM wParam;
LPARAM lParam;
{
WORD xPos,yPos;
static BOOL fInBox;
switch (Message){
// Set the boolean flag for the floating popup menu.
case WM_LBUTTONDOWN:
fInBox = TRUE;
break;
// Trace whether cursor is moving outside.
case WM_MOUSEMOVE:
xPos = LOWORD (lParam);
yPos = HIWORD (lParam);
if (xPos < POWER_COL || xPos > POWER_COL + POWER_WIDTH ||
yPos < POWER_ROW || yPos > POWER_ROW + POWER_HEIGHT)
fInBox = FALSE;
break;
// Triggle occurs!
case WM_LBUTTONUP:
if (fInBox){
PostMessage (GetParent(hWnd),WM_COMMAND,IDM_POWER,0L);
fInBox = FALSE;
}
break;
}
// Pass messages to original window procedure and return its result.
return (CallWindowProc ((FARPROC)butOrgPowerProc,hWnd,Message,wParam,lParam));
}/* butPwoerProc */
/************************************************************************
* PanelWndProc(HWND,UINT,WPARAM,LPARAM) *
* *
* Main panel process procedure to handle each button condition *
*************************************************************************/
long FAR PASCAL PanelWndProc (hWnd,message,wParam,lParam)
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
LPDRAWITEMSTRUCT lpdis;
PAINTSTRUCT ps;
FARPROC lpSelector;
char s[80];
static char oldMsg[80];
HDC hDC,hMemoryDC;
int i,rtn;
BOOL on,off;
HMENU hSubMenu;
POINT sPt;
switch (message){
case WM_COMMAND:
if (MPEGMCIExist && ((wParam == IDM_HELP) ||
(wParam >= IDM_LOADER && wParam <= IDM_REPEAT)))
break;
switch (wParam){
case IDM_HELP:
if (dspMode == VIDEO)
break;
WinHelp (hWnd,szHelpFileName,HELP_INDEX,0L);
break;
/*
* Video Control
*/
case IDM_POWER:
if (dspMode == VIDEO)
break;
hSubMenu = GetSubMenu (hPowerMenu,0);
sPt.x = POWER_COL;
sPt.y = POWER_ROW + POWER_HEIGHT;
ClientToScreen (hWnd,(POINT FAR *)&sPt);
// This API does the magic.
TrackPopupMenu (hSubMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
sPt.x,sPt.y,0,hWnd,NULL);
break;
// Messages from the floating popup menu.
case IDM_ICON:
ShowWindow (hPanelWnd,SW_MINIMIZE);
RemoveHook (); // Remove the Keyboard Hook
keyHookOn = FALSE;
break;
case IDM_TOP:
alwaysOnTop = !alwaysOnTop;
if (alwaysOnTop){
SetWindowPos (hPanelWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE |
SWP_NOMOVE | SWP_SHOWWINDOW);
CheckMenuItem (hPowerMenu,IDM_TOP,MF_CHECKED);
}else{
SetWindowPos (hPanelWnd,HWND_NOTOPMOST,0,0,0,0,
SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
CheckMenuItem (hPowerMenu,IDM_TOP,MF_UNCHECKED);
}
break;
case IDM_EXIT:
DestroyWindow (hWnd);
break;
case IDM_LOADER:
if (dspMode == VIDEO)
break;
if (playing){
WriteText (W1,(LPSTR)"Stop First");
DrawButton (iLOAD,OFF);
break;
}
if (lParam != 0xbbL){
prvCDType = cdType;
lpSelector = MakeProcInstance (SelectDiscDlg,hInst);
rtn = DialogBox (hInst,"SelectDiscDlg",hWnd,lpSelector);
FreeProcInstance (lpSelector);
if (rtn <= 0)
return (FALSE);
if (cdType == ALL){
szTFileName[0] = '\0';
if (!GetOpenFileName ((LPOPENFILENAME)&ofn)){
cdType = prvCDType;
return (FALSE);
}
nMpegFiles = selectFile (szTFileName,(char *)NULL,0);
nFileIndex = 1;
}
}
prvCDType = cdType;
if ((cdType == KARAOKE || cdType == CDIFMV)){
if (!mscdex){
WriteText (W1,(LPSTR)"mscdex not installed");
load = FALSE;
break;
}else if (!cdrom){
WriteText (W1,(LPSTR)"CD-ROM not installed");
load = FALSE;
break;
}
}
songGray = TRUE;
WriteText (W0,(LPSTR)"Waiting...");
if (cdType == KARAOKE || cdType == CDIFMV){ // Karaoke CD, can specify song#
Button[iPRE].hOff = hPreOff;
Button[iPRE].hOn = hPreOn;
DrawButton (iPRE,OFF);
Button[iNEXT].hOff = hNxtOff;
Button[iNEXT].hOn = hNxtOn;
DrawButton (iNEXT,OFF);
songGray = FALSE;
}else{
Button[iPRE].hOff = hGrayBmp;
Button[iPRE].hOn = hGrayBmp;
DrawButton (iPRE,OFF);
Button[iNEXT].hOff = hGrayBmp;
Button[iNEXT].hOn = hGrayBmp;
DrawButton (iNEXT,OFF);
}
hPrevCursor = SetCursor (LoadCursor (NULL,IDC_WAIT));
if (cdType == CDIFMV){ // CDI-Movie, 1 track/disc
cdi = 1;
if (!(discTime = WMpegGetTrackTime (cddrv_no,CDIFMV,(LPSTR)NULL))){
MessageBox (hWnd,"Check CDI-FMV disc error !!",
ProductName,MB_ICONSTOP);
break;
}
}else
cdi = 0;
if (cdType == KARAOKE){
nSongs = WMpegGetCDSongs ((WORD)cddrv_no);
if (!nSongs){
load = FALSE;
WriteText (W1,(LPSTR)"Wrong Karaoke CD");
break;
}
}
SetCursor (hPrevCursor);
track_no = 1;
if (lParam != 0xbbL)
WriteText (W0,(LPSTR)"Press PLAY to Start");
load = TRUE;
break;
case IDM_STEP:
if (!load){
WriteText (W1,(LPSTR)"Load First");
DrawButton (iSTEP,OFF);
break;
}
if (ActiveItem != IDM_STEP)
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
ActiveItem = IDM_STEP;
WriteText (W0,(LPSTR)"Step");
pause = FALSE;
motion_flg = SFF;
Mute (TRUE);
WMpegCommand (SFF);
if (!playing)
set_to_play ();
break;
case IDM_SLOWMOTION:
if (!load){
WriteText (W1,(LPSTR)"Load First");
DrawButton (iSLOW,OFF);
break;
}
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
ActiveItem = IDM_SLOWMOTION;
DrawButton (iSLOW,ON);
WriteText (W0,(LPSTR)"Slow Forward");
if (!processing ())
break;
pause = FALSE;
motion_flg = SMF;
Mute (TRUE);
WMpegCommand (SMF);
if (!playing)
set_to_play ();
break;
case IDM_STOP:
// switch to console output
if (dspMode == VIDEO)
VideoVGASwitcher (VGA);
if (ActiveItem != IDM_STOP)
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
ActiveItem = IDM_STOP;
WriteText (W0,(LPSTR)"Stop");
FreeTimer ();
WMpegCommand (STP);
playing = FALSE;
demostop = TRUE;
preTrack = 0;
preFile = 0;
theFirstFMV = TRUE;
done = TRUE;
break;
case IDM_PLAY:
if (!load){
cdType = prvCDType;
SendMessage (hWnd,WM_COMMAND,IDM_LOADER,0xbbL);
if (!load)
break;
}
if (!processing ())
break;
pause = FALSE;
if (ActiveItem != IDM_PLAY)
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
DrawButton (iPLAY,ON);
ActiveItem = IDM_PLAY;
motion_flg = NPF;
Mute ((BYTE)fMute);
WMpegCommand (NPF);
if (cdType == KARAOKE){
wsprintf (s,"Track %d",track_no);
WriteText (W0,(LPSTR)s);
}else
WriteText (W0,(LPSTR)"Play");
if (!playing)
set_to_play ();
// Volume setting
if (theFirstPlay){
Mute ((BYTE)fMute);
VolumeLeft ((BYTE)nVolL);
VolumeRight ((BYTE)nVolR);
Bass ((BYTE)nBass);
Treble ((BYTE)nTreble);
Stereo ((BYTE)nStereo);
theFirstPlay = FALSE;
if (showOnVGA)
VideoVGASwitcher (VIDEO);
}
break;
case IDM_PAUSE:
if (!load){
WriteText (W1,(LPSTR)"Load First");
DrawButton (iPAUSE,OFF);
break;
}
if (ActiveItem != IDM_PAUSE){
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
Button[iPAUSE].bdState = ON;
OldActiveItem = ActiveItem;
ActiveItem = IDM_PAUSE;
lstrcpy (oldMsg,(LPSTR)curMsg);
WriteText (W0,(LPSTR)"Pause");
}else{
Button[iPAUSE].bdState = OFF;
ActiveItem = OldActiveItem;
DrawButton (ActiveItem-BUTTON_START_ID,ON);
WriteText (W0,(LPSTR)oldMsg);
}
pause = !pause;
if (pause){
WMpegCommand (PAU);
motion_old = motion_flg;
motion_flg = PAU;
}else{
motion_flg = motion_old;
if (motion_flg != NPF)
WMpegCommand (motion_flg);
else
WMpegCommand (NPF);
}
break;
case IDM_FASTMOTION:
if (!load){
WriteText (W1,(LPSTR)"Load First");
DrawButton (iFAST,OFF);
break;
}
if (ActiveItem != IDM_FASTMOTION)
DrawButton (ActiveItem-BUTTON_START_ID,OFF);
ActiveItem = IDM_FASTMOTION;
DrawButton (iFAST,ON);
WriteText (W0,(LPSTR)"Fast Forward");
if (!processing ())
break;
pause = FALSE;
motion_flg = FMF;
Mute (TRUE);
WMpegCommand (FMF);
if (!playing)
set_to_play ();
break;
case IDM_PRE_SONG:
if (cdType == ALL)
break;
if ((cdType == KARAOKE) && (songGray || dspMode == VIDEO))
break;
DrawButton (iPRE,OFF);
if (cdType == KARAOKE && playing){
WriteText (W1,(LPSTR)"Stop First");
DrawButton (iPRE,OFF);
break;
}
if (cdType == KARAOKE){
track_no = (track_no <= 1) ? nSongs : track_no - 1;
wsprintf (s,"Track %d",track_no);
WriteText (W0,s);
}else if (ActiveItem == IDM_PLAY){
seek = BACKWARD;
set_to_play ();
}
break;
case IDM_NEXT_SONG:
if (cdType == ALL)
break;
if ((cdType == KARAOKE) && (songGray || dspMode == VIDEO))
break;
DrawButton (iNEXT,OFF);
if (cdType == KARAOKE && playing){
WriteText (W1,(LPSTR)"Stop First");
DrawButton (iNEXT,OFF);
break;
}
if (cdType == KARAOKE){
track_no = (track_no >= nSongs) ? 1 : track_no + 1;
wsprintf (s,"Track %d",track_no);
WriteText (W0,s);
break;
}else if (ActiveItem == IDM_PLAY){
seek = FORWARD;
set_to_play ();
}
break;
case IDM_REPEAT:
repeat = !repeat;
DrawButton (iREPEAT,repeat);
break;
case IDM_SPACE:
if (MPEGMCIExist){
if (GetFocus () != hPanelWnd)
break;
}
if (dspMode == VGA){
VideoVGASwitcher (VIDEO);
WriteText (W2,(LPSTR)"Ctrl+Alt+SPACE to return");
}else{
VideoVGASwitcher (VGA);
WriteText (curWlevel,(LPSTR)curMsg);
}
break;
case IDM_MousePressed:
WriteText (W2,(LPSTR)"Ctrl+Alt+SPACE to return");
break;
/*
* Adjust display screen
*/
case IDM_SCREEN_LF:
if (!playing && !MPEGMCIExist)
break;
WMpegAdjustScreen (SCREEN_LF);
break;
case IDM_SCREEN_UP:
if (!playing && !MPEGMCIExist)
break;
WMpegAdjustScreen (SCREEN_UP);
break;
case IDM_SCREEN_RT:
if (!playing && !MPEGMCIExist)
break;
WMpegAdjustScreen (SCREEN_RT);
break;
case IDM_SCREEN_DN:
if (!playing && !MPEGMCIExist)
break;
WMpegAdjustScreen (SCREEN_DN);
break;
/*
* Audio Control
*/
case IDM_SPATIAL:
nStereo = SPATIAL_STEREO;
Stereo ((BYTE)nStereo);
if (idStereo != iSPATIAL)
DrawButton (idStereo,OFF);
DrawButton (iSPATIAL,ON);
idStereo = iSPATIAL;
break;
case IDM_LINEAR:
nStereo = LINEAR_STEREO;
Stereo ((BYTE)nStereo);
if (idStereo != iLINEAR)
DrawButton (idStereo,OFF);
DrawButton (iLINEAR,ON);
idStereo = iLINEAR;
break;
case IDM_PSEUDO:
nStereo = PSEUDO_STEREO;
Stereo ((BYTE)nStereo);
if (idStereo != iPSEUDO)
DrawButton (idStereo,OFF);
DrawButton (iPSEUDO,ON);
idStereo = iPSEUDO;
break;
case IDM_MONO:
nStereo = FORCED_MONO;
Stereo ((BYTE)nStereo);
if (idStereo != iMONO)
DrawButton (idStereo,OFF);
DrawButton (iMONO,ON);
idStereo = iMONO;
break;
case IDM_VOLUME:
if (idVol != iVOLUME)
DrawButton (idVol,OFF);
DrawButton (iVOLUME,ON);
idVol = iVOLUME;
break;
case IDM_TREBLE:
if (idVol != iTREBLE)
DrawButton (idVol,OFF);
DrawButton (iTREBLE,ON);
idVol = iTREBLE;
break;
case IDM_BASS:
if (idVol != iBASS)
DrawButton (idVol,OFF);
DrawButton (iBASS,ON);
idVol = iBASS;
break;
case IDM_MUTE:
fMute = !fMute;
Mute ((BYTE)fMute);
DrawButton (iMUTE,fMute);
break;
case IDM_UP:
if (MPEGMCIExist){
if (GetFocus () != hPanelWnd)
break;
}
switch (idVol){
case iVOLUME:
nVolL++;
nVolR++;
nVolL = (nVolL > maxVol) ? maxVol : nVolL;
nVolR = (nVolR > maxVol) ? maxVol : nVolR;
VolumeLeft ((BYTE)nVolL);
VolumeRight ((BYTE)nVolR);
// draw curve
if ((nVolL - minVol) % 2)
dspCurve (iVOLUME,UP,1,LEFT);
if ((nVolR - minVol) % 2)
dspCurve (iVOLUME,UP,1,RIGHT);
break;
case iTREBLE:
nTreble++;
nTreble = (nTreble > maxTre) ? maxTre : nTreble;
Treble ((BYTE)nTreble);
dspCurve (iTREBLE,UP,2,LEFT);
dspCurve (iTREBLE,UP,2,RIGHT);
break;
case iBASS:
nBass++;
nBass = (nBass > maxBass) ? maxBass : nBass;
Bass ((BYTE)nBass);
dspCurve (iBASS,UP,2,LEFT);
dspCurve (iBASS,UP,2,RIGHT);
break;
}
break;
case IDM_DOWN:
if (MPEGMCIExist){
if (GetFocus () != hPanelWnd)
break;
}
switch (idVol){
case iVOLUME:
nVolL--;
nVolR--;
nVolL = (nVolL < minVol) ? minVol : nVolL;
nVolR = (nVolR < minVol) ? minVol : nVolR;
VolumeLeft ((BYTE)nVolL);
VolumeRight ((BYTE)nVolR);
// draw curve
if ((nVolL - minVol) % 2)
dspCurve (iVOLUME,DOWN,1,LEFT);
if ((nVolR - minVol) % 2)
dspCurve (iVOLUME,DOWN,1,RIGHT);
break;
case iTREBLE:
nTreble--;
nTreble = (nTreble < minTre) ? minTre : nTreble;
Treble ((BYTE)nTreble);
dspCurve (iTREBLE,DOWN,2,LEFT);
dspCurve (iTREBLE,DOWN,2,RIGHT);
break;
case iBASS:
nBass--;
nBass = (nBass < minBass) ? minBass : nBass;
Bass ((BYTE)nBass);
dspCurve (iBASS,DOWN,2,LEFT);
dspCurve (iBASS,DOWN,2,RIGHT);
break;
}
break;
case IDM_LEFT:
if (idVol != iVOLUME)
break;
nVolL++;
nVolR--;
nVolL = (nVolL > maxVol) ? maxVol : nVolL;
nVolR = (nVolR < minVol) ? minVol : nVolR;
VolumeLeft ((BYTE)nVolL);
VolumeRight ((BYTE)nVolR);
if ((nVolL - minVol) % 2)
dspCurve (iVOLUME,UP,1,LEFT);
if ((nVolR - minVol) % 2)
dspCurve (iVOLUME,DOWN,1,RIGHT);
break;
case IDM_RIGHT:
if (idVol != iVOLUME)
break;
nVolL--;
nVolR++;
nVolL = (nVolL < minVol) ? minVol : nVolL;
nVolR = (nVolR > maxVol) ? maxVol : nVolR;
VolumeLeft ((BYTE)nVolL);
VolumeRight ((BYTE)nVolR);
if ((nVolL - minVol) % 2)
dspCurve (iVOLUME,DOWN,1,LEFT);
if ((nVolR - minVol) % 2)
dspCurve (iVOLUME,UP,1,RIGHT);
break;
}
break;
case WM_RBUTTONDOWN:
if (dspMode == VIDEO)
break;
showVer = !showVer;
if (showVer)
WriteText (W2,(LPSTR)Version);
else
WriteText (curWlevel,(LPSTR)curMsg);
break;
case WM_LBUTTONDBLCLK:
if (MPEGMCIExist)
break;
if (dspMode == VIDEO)
break;
if (playing && ActiveItem == IDM_PLAY)
WMpegGOP ();
break;
case WM_CREATE:
hPowerMenu = LoadMenu (hInst,"MPOWER");
/*
* Create a DC for the whole screen. This will be used to display
* the window outline when we handle the move ourselves.
*/
hScreenDC = CreateDC ("DISPLAY",NULL,NULL,NULL);
hParentBmp = LoadBitmap (hInst,MAKEINTRESOURCE (IDB_PARENT));
hGrayBmp = LoadBitmap (hInst,MAKEINTRESOURCE (IDB_GRAY));
if (MPEGMCIExist){
hGrayPlay = LoadBitmap (hInst,MAKEINTRESOURCE (IDB_GRAYP));
for (i = 0;i <= iLOAD;i++){
Button[i].hOff = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOff));
Button[i].hOn = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOn));
}
for (i = iPRE;i <= iREPEAT;i++){
if (i == iPLAY)
Button[i].hOff = Button[i].hOn = hGrayPlay;
else
Button[i].hOff = Button[i].hOn = hGrayBmp;
}
for (i > iREPEAT;i < PANEL_BUTTONS;i++){
Button[i].hOff = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOff));
Button[i].hOn = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOn));
}
}else{
for (i = 0;i < PANEL_BUTTONS;i++){
Button[i].hOff = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOff));
Button[i].hOn = LoadBitmap (hInst,MAKEINTRESOURCE (Button[i].idOn));
}
hPreOn = Button[iPRE].hOn;
hPreOff = Button[iPRE].hOff;
hNxtOn = Button[iNEXT].hOn;
hNxtOff = Button[iNEXT].hOff;
// Init Pre-Song & Next-Song to gray
Button[iPRE].hOff = Button[iPRE].hOn =
Button[iNEXT].hOff = Button[iNEXT].hOn = hGrayBmp;
}
// Create pen brush for audio display curve
hCurveBackgnd = CreateSolidBrush (RGB (0,0,0));
hCurveForegnd = CreateSolidBrush (RGB (0,255,0));
// Get current font
hCurrentFont = GetStockObject (ANSI_VAR_FONT);
break;
case WM_DRAWITEM:
/*
* The state of one of the buttons has changed. Redraw the button
* to reflect its new state.
*/
lpdis = (DRAWITEMSTRUCT FAR*)lParam;
// Abort if it is not our button
if ((lpdis->CtlType != ODT_BUTTON) ||
(lpdis->CtlID < BUTTON_START_ID) ||
(lpdis->CtlID >= BUTTON_START_ID + PANEL_BUTTONS)
)
return (DefWindowProc (hWnd,message,wParam,lParam));
// Draw every button during init
i = lpdis->CtlID - BUTTON_START_ID;
switch (lpdis->itemAction){ // Action to be taken
case ODA_DRAWENTIRE: // Redraw entire button
DrawButton (i,Button[i].bdState);
WriteText (curWlevel,(LPSTR)curMsg);
break;
case ODA_SELECT: // The buttons selection status has changed
if (i == iPOWER){ // power status is different from others
on = OFF;
off = ON;
}else{
on = ON;
off = OFF;
}
if (lpdis->itemState & ODS_SELECTED) // Button is being selected
DrawButton (i,on);
else{ // Button is being deselected
DrawButton (i,off);
SetFocus (hPanelWnd);
}
break;
case ODA_FOCUS: // The buttons focus has changed
break;
}
return(TRUE);
case WM_LBUTTONDOWN:
if (dspMode == VIDEO)
break;
fMove = TRUE; // Moving the control panel window
GetCursorPos (&ptStart);
GetWindowRect (hWnd,&rcWindow);
CopyRect (&rcOutline,&rcWindow);
OutlineRect (hScreenDC,&rcOutline);
SetCapture (hWnd);
break;
case WM_LBUTTONUP:
if (dspMode == VIDEO)
break;
if (fMove){
fMove = FALSE;
OutlineRect (hScreenDC,&rcOutline); // Erase outline
GetCursorPos (&ptStop);
SetWindowPos (hWnd,NULL,
rcWindow.left + (ptStop.x - ptStart.x),
rcWindow.top + (ptStop.y - ptStart.y),
0,0,SWP_NOSIZE
);
ReleaseCapture ();
}
break;
case WM_MOUSEMOVE:
if (dspMode == VIDEO)
break;
if (fMove){
GetCursorPos (&ptStop);
OutlineRect (hScreenDC,&rcOutline); // Erase old outline
CopyRect (&rcOutline,&rcWindow);
OffsetRect (&rcOutline,ptStop.x - ptStart.x,ptStop.y - ptStart.y);
OutlineRect (hScreenDC,&rcOutline); // Draw new outline
}
break;
case WM_PAINT:
hDC = BeginPaint (hWnd,&ps);
hMemoryDC = CreateCompatibleDC (hDC);
SelectObject (hMemoryDC,hParentBmp);
BitBlt (hDC,0,0,PANEL_WIDTH,PANEL_HEIGHT,hMemoryDC,0,0,SRCCOPY);
ReleaseDC (hPanelWnd,hDC);
DeleteDC (hMemoryDC);
EndPaint (hWnd,&ps);
if (!keyHookOn){
SetHook (hPanelWnd,(KeyTable far *)&keys);
keyHookOn = TRUE;
}
break;
case WM_CLOSE:
DestroyWindow (hWnd);
break;
case WM_DESTROY:
done = TRUE;
KillTimer (hWnd,idTimer);
if (!MPEGExist){
PostQuitMessage (0);
break;
}
if (!MPEGMCIExist){
WMpegCommand (STP); // stop
WMpegExit ();
WinHelp (hWnd,szHelpFileName,HELP_QUIT,0L);
}
// Release float menu
DestroyMenu (hPowerMenu);
// Destroy buttons
DeleteObject (hParentBmp);
for (i = 0;i < PANEL_BUTTONS;i++){
DestroyWindow (Button[i].hWnd);
DeleteObject (Button[i].hOff);
DeleteObject (Button[i].hOn);
}
DeleteObject (hGrayBmp);
if (MPEGMCIExist)
DeleteObject (hGrayPlay);
DeleteDC (hScreenDC);
// Delete solid brush
DeleteObject (hCurveBackgnd);
DeleteObject (hCurveForegnd);
VideoVGASwitcher (VGA);
saveCfg ();
/*
* Set to min volume, this setting must be after saveCfg function
* such that the user specified volume status can be saved to INI
* file.
*/
if (!MPEGMCIExist){
VolumeLeft ((BYTE)minVol);
VolumeRight ((BYTE)minVol);
Mute ((BYTE)TRUE); // turn off audio
WMpegAudioEnable (FALSE); // release the audio controller
}
PostQuitMessage (0);
break;
default:
return (DefWindowProc (hWnd,message,wParam,lParam));
}
return (FALSE);
}/* PanelWndProc */
int FAR PASCAL SelectDiscDlg (hDlg,message,wParam,lParam)
HWND hDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
static int type;
int id;
RECT winRect,cliRect;
switch (message){
case WM_INITDIALOG:
GetWindowRect (hPanelWnd,(LPRECT)&winRect);
GetWindowRect (hDlg,(LPRECT)&cliRect);
MoveWindow (hDlg,cliRect.left,winRect.top + (winRect.bottom - winRect.top) / 2,
cliRect.right - cliRect.left,
cliRect.bottom - cliRect.top,
FALSE);
if (!cdType)
id = IDD_CDIFMV;
else
id = cdType + IDD_ALL - 1;
CheckRadioButton (hDlg,IDD_ALL,IDD_CDIFMV,id);
type = id - IDD_ALL + 1;
break;
case WM_COMMAND:
switch (wParam){
case IDD_ALL:
CheckRadioButton (hDlg,IDD_ALL,IDD_CDIFMV,IDD_ALL);
type = ALL;
break;
case IDD_KARAOKE:
CheckRadioButton (hDlg,IDD_ALL,IDD_CDIFMV,IDD_KARAOKE);
type = KARAOKE;
break;
case IDD_CDIFMV:
CheckRadioButton (hDlg,IDD_ALL,IDD_CDIFMV,IDD_CDIFMV);
type = CDIFMV;
break;
case IDD_OK:
EndDialog (hDlg,TRUE);
cdType = type;
return (TRUE);
break;
case IDD_CANCEL:
EndDialog (hDlg,FALSE);
return (FALSE);
break;
default:
break;
break;
}
}
return (FALSE);
}/* SelectDiscDlg */
void dspCurve (item,up,step,left)
int item;
BOOL up;
int step;
BOOL left;
{
HBRUSH hbrOld;
HDC hDC;
int x;
int i;
int far *y;
switch (item){
case iVOLUME:
if (left){
x = VolLeft_X0;
y = (int far *)&curVolLY;
}else{
x = VolRight_X0;
y = (int far *)&curVolRY;
}
break;
case iTREBLE:
if (left){
x = TreLeft_X0;
y = (int far *)&curTreLY;
}else{
x = TreRight_X0;
y = (int far *)&curTreRY;
}
break;
case iBASS:
if (left){
x = BassLeft_X0;
y = (int far *)&curBassLY;
}else{
x = BassRight_X0;
y = (int far *)&curBassRY;
}
break;
default:
return;
}
hDC = GetDC (Button[iDSPA].hWnd);
if (up)
hbrOld = SelectObject (hDC,hCurveForegnd);
else
hbrOld = SelectObject (hDC,hCurveBackgnd);
for (i = 0;i < step;i++){
if (up){
if (*y < TopCurveY)
break;
BitBlt (hDC,x,*y,CurveWidth,CurveHeight,NULL,0,0,PATCOPY);
*y = *y - (CurveHeight + GAPY_CURVE);
}else{
*y = *y + (CurveHeight + GAPY_CURVE);
if (*y > BottomCurveY){
*y = BottomCurveY;
break;
}
BitBlt (hDC,x,*y,CurveWidth,CurveHeight,NULL,0,0,PATCOPY);
}
}
SelectObject (hDC,hbrOld);
ReleaseDC (Button[iDSPA].hWnd,hDC);
}/* dspCurve */
#define DSPX 5
#define DSPY 15
/************************************************************************
* WriteText *
* *
* Draw a string of text to display window for information *
*************************************************************************/
void WriteText (wLevel,msg)
int wLevel;
LPSTR msg;
{
HDC hDC;
HBRUSH hBrush;
int R,G,B;
HFONT hOldFont;
hDC = GetDC (Button[iDSPV].hWnd);
hBrush = SelectObject (hDC,GetStockObject (BLACK_BRUSH));
BitBlt (hDC,2,2,136,30,NULL,0,0,PATCOPY);
SelectObject (hDC,hBrush);
SetBkMode (hDC,TRANSPARENT);
SetROP2 (hDC,R2_COPYPEN);
if (wLevel == W0){
R = G = 255;
B = 0;
}else if (wLevel == W1){
R = 255;
G = B = 0;
}else{
R = B = 255;
G = 0;
}
SetTextColor (hDC,RGB (R,G,B));
hOldFont = SelectObject (hDC,hCurrentFont);
TextOut (hDC,DSPX,DSPY,msg,lstrlen (msg));
SelectObject (hDC,hOldFont);
if (wLevel <= W1){
curWlevel = wLevel;
lstrcpy ((LPSTR)curMsg,msg);
}
ReleaseDC (Button[iDSPV].hWnd,hDC);
}/* WriteText */
/************************************************************************
* OutlineRect *
* *
* Draw a rectangle with a line weight equal to the border width using *
* the XOR mix mode. *
*************************************************************************/
void OutlineRect (hDC,rp)
HDC hDC;
RECT *rp;
{
int xWidth;
int yWidth;
xWidth = GetSystemMetrics (SM_CXBORDER);
yWidth = GetSystemMetrics (SM_CYBORDER);
BitBlt (hDC,rp->left-xWidth,rp->top-yWidth, xWidth,
rp->bottom-rp->top+yWidth,NULL,0,0,DSTINVERT);
BitBlt (hDC,rp->left,rp->top-yWidth,rp->right-rp->left+xWidth,
yWidth,NULL,0,0,DSTINVERT);
BitBlt (hDC,rp->right,rp->top,xWidth,
rp->bottom-rp->top+yWidth,NULL,0,0,DSTINVERT);
BitBlt (hDC,rp->left-xWidth,rp->bottom,rp->right-rp->left+xWidth,
yWidth,NULL,0,0,DSTINVERT);
}/* OutlineRect */
/************************************************************************
* DrawButton *
* *
* Draw the specified button up or down and on or off. *
*************************************************************************/
void DrawButton (i,fOn)
int i; // button index
BOOL fOn;
{
HDC hDC,hMemoryDC;
int step;
/* Create a memory DC for use in drawing buttons. */
hDC = GetDC (Button[i].hWnd);
hMemoryDC = CreateCompatibleDC (hDC);
if (fOn)
SelectObject (hMemoryDC,Button[i].hOn);
else
SelectObject (hMemoryDC,Button[i].hOff);
BitBlt (hDC,0,0,Button[i].bdWidth,Button[i].bdHeight,hMemoryDC,0,0,SRCCOPY);
ReleaseDC (Button[i].hWnd,hDC);
DeleteDC (hMemoryDC);
Button[i].bdState = fOn;
if (i == iDSPA){ // draw music curve
curVolLY = BottomCurveY;
curVolRY = BottomCurveY;
curTreLY = BottomCurveY;
curTreRY = BottomCurveY;
curBassLY= BottomCurveY;
curBassRY= BottomCurveY;
// draw volume left curve
step = (nVolL - minVol) / 2;
dspCurve (iVOLUME,UP,step,LEFT);
// draw volume right curve
step = (nVolR - minVol) / 2;
dspCurve (iVOLUME,UP,step,RIGHT);
// draw treble left and right curve
step = (nTreble - minTre) * 2;
dspCurve (iTREBLE,UP,step,LEFT);
dspCurve (iTREBLE,UP,step,RIGHT);
// draw bass left and right curve
step = (nBass - minBass) * 2;
dspCurve (iBASS,UP,step,LEFT);
dspCurve (iBASS,UP,step,RIGHT);
}
}/* DrawButton */
/****************************************************************************
* FUNCTION: MakeHelpPathName *
* *
* PURPOSE: HelpEx assumes that the .HLP help file is in the same *
* directory as the HelpEx executable.This function derives *
* the full path name of the help file from the path of the *
* executable. *
****************************************************************************/
void MakeHelpPathName (szName)
char *szName;
{
char * pcFileName;
int nFileNameLen;
nFileNameLen = GetModuleFileName (hInst,szName,EXE_NAME_MAX_SIZE);
pcFileName = szName + nFileNameLen;
while (pcFileName > szName){
if (*pcFileName == '\\' || *pcFileName == ':'){
*(++pcFileName) = '\0';
break;
}
nFileNameLen--;
pcFileName--;
}
if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE)
lstrcat (szName,"wplayer.hlp");
else
lstrcat (szName,"?");
}/* MakeHelpPathName */
/************************************************************************
* Set_to_play *
* *
* The button is either being pressed or released. Draw it up or down. *
* If it is being released, send the corresponding message to the panel *
* window. It is being pressed, toggle the state between on and off. *
*************************************************************************/
void set_to_play (void)
{
int rtn;
MSFTime timeSeek;
int timeSec;
if (cdType == CDIFMV && theFirstFMV){
timeSec = startTimeSec;
theFirstFMV = FALSE;
}else if (cdType == CDIFMV){
if (seek == FORWARD){
timeSec = WMpegGetCurrentPTS () + skipTimeSec;
if (timeSec >= discTime){
PostMessage (hPanelWnd,WM_COMMAND,IDM_STOP,0L);
return;
}
}else if (seek == BACKWARD){
timeSec = WMpegGetCurrentPTS () - skipTimeSec;
if (timeSec < 0){
preTrack = 0;
SendMessage (hPanelWnd,WM_COMMAND,IDM_PLAY,0L);
timeSec = 0;
}
}else
timeSec = 0;
}else
timeSec = 0;
hPrevCursor = SetCursor (LoadCursor (NULL,IDC_WAIT));
if (timeSec == 0)
rtn = WMpegPlayEnable ((LPMSFTime)NULL);
else{
timeSeek.frm = 0;
timeSeek.sec = (BYTE)(timeSec % 60);
timeSeek.min = (BYTE)(timeSec / 60);
rtn = WMpegPlayEnable ((LPMSFTime)&timeSeek);
}
SetCursor (hPrevCursor);
if (rtn){
WriteText (W1,(LPSTR)"Error Init DSP");
return;
}
if (!TimerExist){
lpfnTimerProc = MakeProcInstance ((FARPROC)TimerProc,hInst);
idTimer = SetTimer (hPanelWnd,1,20,(FARPROC)lpfnTimerProc);
TimerExist = TRUE;
}
demostop = FALSE;
pause = FALSE;
playing = TRUE;
done = FALSE;
seek = NORMAL;
}/* set_to_play */
BOOL processing (void)
{
load = FALSE;
if (cdType == KARAOKE || cdType == CDIFMV){
if (preTrack != track_no){
if (!loadTrack ())
return (FALSE);
}
}else if (preFile != nFileIndex){
char szFile[128];
selectFile (szTFileName,szFile,nFileIndex);
if (MpegLoader (szFile))
return (FALSE);
}
load = TRUE;
return (TRUE);
}/* processing */
int MpegLoader (name)
char *name;
{
int rtn,media;
media = 0;
if (cdType == KARAOKE || cdType == CDIFMV)
media = 1;
hPrevCursor = SetCursor (LoadCursor (NULL,IDC_WAIT));
rtn = WMpegLoad (media,name,(WORD)cddrv_no,sync,cdi);
SetCursor (hPrevCursor);
if (rtn < 0){
switch (rtn){
case EMPEGFile:
WriteText (W1,(LPSTR)"Open error");
break;
case EBitStream:
WriteText (W1,(LPSTR)"Unknown BitStream");
break;
case EVXD:
WriteText (W1,(LPSTR)"VXD not installed");
break;
case EVolumeSize:
case ESectorSize:
case EInitCDROM:
case ESeekTop:
case EReadCD:
case EGetStartSector:
case EGetLastSector:
case ESeek:
WriteText (W1,(LPSTR)"Read CDROM error");
break;
case EInitVideo:
WriteText (W1,(LPSTR)"Error init Video");
break;
case EInitAudio:
WriteText (W1,(LPSTR)"Error init Audio");
break;
case EWINENH:
WriteText (W1,(LPSTR)"Not in enhanced mode");
break;
case EDMA:
WriteText (W1,(LPSTR)"Init DMA error");
break;
case EDecodeAudio:
WriteText (W1,(LPSTR)"Unknown BitStream");
break;
case ECDReady:
WriteText (W1,(LPSTR)"CD-ROM not ready");
break;
default:
WriteText (W1,(LPSTR)"System error");
break;
}
return (1);
}
track_no = rtn;
return (0);
}/* MpegLoader */
int loadTrack (void)
{
char szTrack[5];
wsprintf (szTrack,"%d",track_no);
if (MpegLoader (szTrack)){
load = FALSE;
selectCD = 0;
return (0);
}
load = TRUE;
selectCD = 1;
preTrack = track_no;
return (track_no);
}/* loadTrack */
int selectFile (fileSpec,fileRtn,index)
char *fileSpec;
char *fileRtn;
int index;
{
char files[256];
char *szPtr;
int nfiles;
lstrcpy (files,(LPSTR)fileSpec);
if (!(szPtr = strtok (files," "))) // error
return (0);
nfiles = 0;
while (szPtr = strtok (NULL," ")){
nfiles++;
if (index == nfiles)
break;
}
preFile = index;
if (fileRtn != (char *)NULL)
lstrcpy (fileRtn,(LPSTR)files); // path
if (nfiles == 0) // just one file selected
return (1);
if (fileRtn != (char *)NULL){
if (fileRtn[lstrlen (fileRtn) - 1] != '\\')
lstrcat (fileRtn,(LPSTR)"\\");
lstrcat (fileRtn,(LPSTR)szPtr); // full name
}
return (nfiles);
}/* selectFile */
char szCfgFileSpec[128];
char pStr[128];
int initMpeg (lpVideo)
LPSTR lpVideo;
{
int VideoSource; // NTSC, PAL
int rtn;
GetWindowsDirectory (szCfgFileSpec,128);
strcat (szCfgFileSpec,"\\winmpeg.ini");
if (!MPEGMCIExist){
// Get default setting from command line
if (!lstrcmpi (lpVideo,(LPCSTR)"N")) // force to NTSC
VideoSource = NTSC;
else if (!lstrcmpi (lpVideo,(LPCSTR)"P")) // force to PAL
VideoSource = PAL;
else
VideoSource = 0; // from INI file
cddrv_no = WMpegGetCDDriveID ();
if (cddrv_no == EMSCDEX)
mscdex = FALSE;
if (cddrv_no == EDRIVE)
cdrom = FALSE;
getINIStr ("BusType");
if (!lstrcmpi (pStr,"SCSI"))
sync = 0;
else
sync = 1;
getINIStr ((LPSTR)"DiscType");
if (!lstrcmpi (pStr,"KARAOKE"))
defCDType = KARAOKE;
else
defCDType = CDIFMV;
cdType = prvCDType = defCDType;
}
getINIStr ((LPSTR)"Volume left");
nVolL = (pStr[0] == '\0') ? defVolL : strtoi (pStr);
getINIStr ((LPSTR)"Volume right");
nVolR = (pStr[0] == '\0') ? defVolR : strtoi (pStr);
getINIStr ((LPSTR)"Bass");
nBass = (pStr[0] == '\0') ? defBass : strtoi (pStr);
getINIStr ((LPSTR)"Treble");
nTreble = (pStr[0] == '\0') ? defTreble : strtoi (pStr);
getINIStr ((LPSTR)"Stereo");
if (!lstrcmp (pStr,(LPSTR)"Spatial")){
nStereo = SPATIAL_STEREO;
idStereo = iSPATIAL;
}else if (!lstrcmp (pStr,(LPSTR)"Mono")){
nStereo = FORCED_MONO;
idStereo = iMONO;
}else if (!lstrcmp (pStr,(LPSTR)"Pseudo")){
nStereo = PSEUDO_STEREO;
idStereo = iPSEUDO;
}else{
nStereo = LINEAR_STEREO;
idStereo = iLINEAR;
}
if (!MPEGMCIExist){
getINIStr ((LPSTR)"ShowOnVGA");
if (!lstrcmpi (pStr,(LPSTR)"yes"))
showOnVGA = TRUE;
else
showOnVGA = FALSE;
startTimeSec = getINIint ((LPSTR)"StartTimeSec");
skipTimeSec = getINIint ((LPSTR)"SkipTimeSec");
if (!skipTimeSec)
skipTimeSec = 120;
if (rtn = WMpegInit (VideoSource))
return (rtn);
WMpegAudioEnable (TRUE);
}
MPEGExist = TRUE;
return (0);
}/* initMpeg */
void saveCfg (void)
{
wsprintf (pStr,"%d",nVolL);
putINIStr ((LPSTR)"Volume left");
wsprintf (pStr,"%d",nVolR);
putINIStr ((LPSTR)"Volume right");
wsprintf (pStr,"%d",nBass);
putINIStr ((LPSTR)"Bass");
wsprintf (pStr,"%d",nTreble);
putINIStr ((LPSTR)"Treble");
switch (nStereo){
case SPATIAL_STEREO:
lstrcpy (pStr,(LPSTR)"Spatial");
break;
case PSEUDO_STEREO:
lstrcpy (pStr,(LPSTR)"Pseudo");
break;
case LINEAR_STEREO:
lstrcpy (pStr,(LPSTR)"Linear");
break;
case FORCED_MONO:
default:
lstrcpy (pStr,(LPSTR)"Mono");
break;
}
putINIStr ((LPSTR)"Stereo");
}/* saveCfg */
void getINIStr (key)
LPSTR key;
{
int rtn;
rtn = GetPrivateProfileString ((LPCSTR)"UserDef", // Section
(LPCSTR)key, // Entry
(LPCSTR)NULL, // Default string
(LPSTR)pStr, // string returned
(int)128, // length
(LPCSTR)szCfgFileSpec // Initialize filename
);
if (!rtn)
pStr[0] = '\0';
}/* getINIStr */
UINT getINIint (key)
LPSTR key;
{
UINT rtn;
rtn = GetPrivateProfileInt ((LPCSTR)"UserDef", // Section
(LPCSTR)key, // Entry
0, // Default value
(LPCSTR)szCfgFileSpec // Initialize filename
);
return (rtn);
}/* getINIStr */
void putINIStr (key)
LPSTR key;
{
WritePrivateProfileString ((LPCSTR)"UserDef", // Section
(LPCSTR)key, // Entry
(LPSTR)pStr, // string returned
(LPCSTR)szCfgFileSpec // Initialize filename
);
pStr[0] = '\0';
}/* putINIStr */
int strtoi (str)
LPSTR str;
{
int hex[4] = {1,16,256,4096};
int dec[4] = {1,10,100,1000};
int len,i,j,numRtn = 0;
LPSTR tmp;
char tmp1;
BOOL Hex = FALSE;
tmp = str;
if (tmp[0] == '0' && tmp[1] == 'x'){ // hex
tmp += 2;
Hex = TRUE;
}
len = lstrlen ((LPSTR)tmp);
if (len > 3) // int may be overflow
return (0);
for (i = len-1,j = 0;(i >= 0 && j <= 3);i--,j++){
tmp1 = *(tmp + i);
if (tmp1 >= 0x00 && tmp1 <= 0x39)
tmp1 -= 0x30; // 0 - 9
else if (tmp1 >= 'a' && tmp1 <= 'f')
tmp1 = (tmp1 - 'a') + 10; // 'a' - 'f'
else if (tmp1 >= 'A' && tmp1 <= 'F')
tmp1 = (tmp1 - 'A') + 10; // 'A' - 'F'
else
return (0);
if (Hex)
numRtn += tmp1 * hex[j];
else
numRtn += tmp1 * dec[j];
}
return (numRtn);
}/* strtoi */
LPSTR DecToHex (i,sz)
int i;
LPSTR sz;
{
LPSTR szSav = sz;
int temp,j,index;
char hexTable[]={'0','1','2','3','4','5','6','7','8',
'9','A','B','C','D','E','F'};
char tempBuffer[10];
temp = i;
index = 0;
while (temp >= 16){
tempBuffer[index++] = hexTable[temp % 16];
temp = temp / 16;
}
if (temp > 0)
tempBuffer[index] = hexTable[temp];
for (j=index;j>=0;j--)
*sz++ = tempBuffer[j];
*sz = '\0';
return (szSav);
}/* DecToHex */
/*
* Control the console output (VGA monitor).
* mode = VGA
* VGA output to console.
* mode = VIDEO
* Video output to console.
* At this time, the mouse input be disabled.
* If any button pressed, it will switch back to VGA output and
* the mouse input enabled again.
*/
void VideoVGASwitcher (mode)
int mode;
{
if (WMpegSwitcher (mode)) // cannot switch
return;
dspMode = mode;
if (dspMode == VIDEO)
SetMouseHook (hPanelWnd,IDM_MousePressed); // disable mouse input
else
RemoveMouseHook (); // enable mouse input
}/* VideoVGASwitcher */
void FAR PASCAL TimerProc (hWnd,iMessage,wTimerID,dwSystemTime)
HWND hWnd;
UINT iMessage;
WORD wTimerID;
DWORD dwSystemTime;
{
int rtn;
rtn = WMpegTransfer ();
if (demostop || !rtn){
FreeTimer ();
playing = FALSE;
WMpegCommand (STP);
if (!demostop){ // normal play to end
if (selectCD)
track_no++;
if ((cdType == KARAOKE) && track_no <= nSongs){
PostMessage (hPanelWnd,WM_COMMAND,IDM_PLAY,0L);
return;
}
if (cdType == ALL){
if (nFileIndex < nMpegFiles){
nFileIndex++;
PostMessage (hPanelWnd,WM_COMMAND,IDM_PLAY,0L);
return;
}else{
nFileIndex = 1;
preFile = 0;
}
}
if (repeat)
PostMessage (hPanelWnd,WM_COMMAND,IDM_PLAY,0L);
else
PostMessage (hPanelWnd,WM_COMMAND,IDM_STOP,0L);
}else
PostMessage (hPanelWnd,WM_COMMAND,IDM_STOP,0L);
return;
}
if (rtn > 1){ // fatal error on MPEG chip
switch (rtn){
case EM_FFERR:
WriteText (W1,(LPSTR)"Video FIFO Error");
break;
case EM_HAERR:
WriteText (W1,(LPSTR)"Host access Error");
break;
case EM_BSERR:
WriteText (W1,(LPSTR)"Decoding Error");
break;
case EM_SBERR:
WriteText (W1,(LPSTR)"System Bus Error");
break;
case EM_VSYNCERR:
WriteText (W1,(LPSTR)"VSync Error");
break;
case EE_EMPTY:
WriteText (W1,(LPSTR)"Audio FIFO Empty");
break;
default:
wsprintf (MesgStr,"%s system error",ProductName);
WriteText (W1,MesgStr);
break;
}
playing = FALSE;
WMpegCommand (STP);
FreeTimer ();
}
}/* TimerProc */
void FreeTimer (void)
{
if (TimerExist){
KillTimer (hPanelWnd,idTimer);
FreeProcInstance (lpfnTimerProc);
TimerExist = FALSE;
}
}/* FreeTimer */