📄 main.c
字号:
}
// Clear the buffers...
miniInfoP->srcDataSize = 0;
miniInfoP->srcOffset = 0;
miniInfoP->destDataSize = 0;
miniInfoP->destOffset = 0;
}
/**
* Open the file and start playing.
*/
static void PrvPlayFile(MiniInfo* miniInfoP)
{
Err err = errNone;
// Check that we are not already playing
if(miniInfoP->sndRef)
PrvStopFile(miniInfoP);
// Open the file
err = PrvFileOpen(miniInfoP);
if(err) goto Done;
// Parse the mp3 file
err = PrvParseMP3(miniInfoP);
if(err) goto Done;
// Create the stream
err = PrvCreateStream(miniInfoP);
if(err) goto Done;
SndStreamSetVolume(gMiniInfo.sndRef, gMiniInfo.volume);
// Start the stream
err = SndStreamStart(miniInfoP->sndRef);
Done:
if(err)
PrvStopFile(miniInfoP);
return;
}
/**
* File info callback.
* This function is called by the file browser
*/
static void PrvGetFileInfoCallback(UInt16 volume, const Char* path, const Char* file)
{
// Create the full path name
StrCopy(gMiniInfo.fileInfo.filePath, path);
// Internally, we expect full path
StrCat(gMiniInfo.fileInfo.filePath, file);
}
#if 0
#pragma mark -
#endif
/*
* FUNCTION: MainFormDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS:
*
* command
* menu item id
*/
static Boolean MainFormDoCommand(UInt16 command)
{
Boolean handled = false;
FormType *frmAboutP = NULL;
switch (command)
{
case HelpAboutMiniMP3:
frmAboutP = FrmInitForm(HelpAboutMiniMP3);
FrmDoDialog(frmAboutP); // Display the About Box.
FrmDeleteForm(frmAboutP);
handled = true;
break;
}
return handled;
}
/**
* MainFormHandleEvent
*/
static Boolean MainFormHandleEvent(EventType * eventP)
{
Boolean handled = false;
FormType *frmP = FrmGetActiveForm();
FieldType *fieldP = NULL;
static Char time[20];
switch (eventP->eType)
{
case menuEvent:
handled = MainFormDoCommand(eventP->data.menu.itemID);
break;
case frmOpenEvent:
FrmDrawForm(frmP);
handled = true;
break;
case frmUpdateEvent:
break;
case ctlRepeatEvent:
switch(eventP->data.ctlSelect.controlID)
{
case MainVolumeFeedbackSliderControl:
gMiniInfo.volume = eventP->data.ctlRepeat.value;
// Set the volume
if(gMiniInfo.sndRef) {
SndStreamSetVolume(gMiniInfo.sndRef, gMiniInfo.volume);
}
break;
}
break;
case ctlSelectEvent:
switch(eventP->data.ctlSelect.controlID)
{
case MainStartButton:
PrvPlayFile(&gMiniInfo);
break;
case MainStopButton:
PrvStopFile(&gMiniInfo);
break;
case MainFileButton:
// Sets the callback function and return form
FileBrowserSetCallback(&PrvGetFileInfoCallback, MainForm);
FrmGotoForm(FileBrowserForm);
break;
}
break;
default:
break;
}
return handled;
}
/**
* AppHandleEvent
*/
static Boolean AppHandleEvent(EventType * eventP)
{
UInt16 formId;
FormType * frmP;
if (eventP->eType == frmLoadEvent)
{
formId = eventP->data.frmLoad.formID;
frmP = FrmInitForm(formId);
FrmSetActiveForm(frmP);
switch (formId)
{
case MainForm:
FrmSetEventHandler(frmP, MainFormHandleEvent);
break;
case FileBrowserForm:
FrmSetEventHandler(frmP, FileBrowserFormHandleEvent);
break;
default:
break;
}
return true;
}
return false;
}
/**
* AppEventLoop
*/
static void AppEventLoop(void)
{
UInt16 error = errNone;
EventType event;
do
{
EvtGetEvent(&event, evtWaitForever);
if (! SysHandleEvent(&event))
if (! MenuHandleEvent(0, &event, &error))
if (! AppHandleEvent(&event))
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
}
/**
* AppStart
* Called when the application starts.
*/
static Err AppStart(void)
{
Err err = errNone;
// Clear the global
MemSet(&gMiniInfo, sizeof(MiniInfo), 0);
// Try to find the hardware utils library
err = SysLibFind(kCodecMgrLibName, &gMiniInfo.CodecMgrLibRefNum);
if (err != errNone)
{
err = SysLibLoad(kCodecMgrLibType, kCodecMgrLibCreator, &gMiniInfo.CodecMgrLibRefNum);
if(err == errNone)
err = CodecMgrOpen(gMiniInfo.CodecMgrLibRefNum);
}
if(err) {
FrmAlert(NoMP3LibAlert);
goto Done;
}
// Allocate memory for the buffers
gMiniInfo.srcBufferP = MemPtrNew(SRC_SIZE);
if(!gMiniInfo.srcBufferP) {
err = memErrNotEnoughSpace;
goto Done;
}
gMiniInfo.srcBufferSize = SRC_SIZE;
gMiniInfo.srcDataSize = 0;
gMiniInfo.srcOffset = 0;
gMiniInfo.destBufferP = MemPtrNew(DEST_SIZE);
if(!gMiniInfo.destBufferP) {
err = memErrNotEnoughSpace;
goto Done;
}
gMiniInfo.destBufferSize = DEST_SIZE;
gMiniInfo.destDataSize = 0;
gMiniInfo.destOffset = 0;
// Volume
gMiniInfo.volume = 1024;
// Get the current application path
SysCurAppDatabase(&gMiniInfo.cardNo, &gMiniInfo.dbID);
// Register our own event - Pass the mini info
SysNotifyRegister(gMiniInfo.cardNo, gMiniInfo.dbID,
appFileCreator, NULL, sysNotifyNormalPriority, &gMiniInfo );
// Register for REM sleep, to keep playing even when device display is off
SysNotifyRegister(gMiniInfo.cardNo, gMiniInfo.dbID,
hsNotifyRemSleepRequestEvent, NULL, sysNotifyNormalPriority, &gMiniInfo);
// Quick no-auto off
gOldAutoOffTime = SysSetAutoOffTime(0);
Done:
if(err)
{
if(gMiniInfo.srcBufferP)
MemPtrFree(gMiniInfo.srcBufferP);
if(gMiniInfo.destBufferP)
MemPtrFree(gMiniInfo.destBufferP);
}
return err;
}
/**
* AppStop
* Called when the application stops.
*/
static void AppStop(void)
{
Err err = errNone;
FrmCloseAllForms();
// Restore auto off
SysSetAutoOffTime(gOldAutoOffTime);
// Make sure the file is stopped
PrvStopFile(&gMiniInfo);
// Clean the buffers
if(gMiniInfo.srcBufferP)
MemPtrFree(gMiniInfo.srcBufferP);
if(gMiniInfo.destBufferP)
MemPtrFree(gMiniInfo.destBufferP);
// Close the library
err = CodecMgrClose(gMiniInfo.CodecMgrLibRefNum);
if (err == errNone)
err = SysLibRemove(gMiniInfo.CodecMgrLibRefNum);
// Unregister the notification
SysNotifyUnregister( gMiniInfo.cardNo, gMiniInfo.dbID,
appFileCreator, sysNotifyNormalPriority );
// Unregister REM Sleep
SysNotifyUnregister(gMiniInfo.cardNo, gMiniInfo.dbID,
hsNotifyRemSleepRequestEvent, sysNotifyNormalPriority);
}
#pragma warn_a5_access on
//
// RomVersionCompatible
//
static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags)
{
UInt32 romVersion;
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
if (romVersion < requiredVersion)
{
if ((launchFlags &
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
{
FrmAlert (RomIncompatibleAlert);
if (romVersion < kPalmOS20Version)
{
AppLaunchWithCommand(
sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL);
}
}
return sysErrRomIncompatible;
}
return errNone;
}
//
// PilotMain
//
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
Err error;
SysNotifyParamType *notifyParamP = NULL;
SleepEventParamType *sleepParamP = NULL;
error = RomVersionCompatible (ourMinVersion, launchFlags);
if (error) return (error);
switch (cmd)
{
case sysAppLaunchCmdNormalLaunch:
error = AppStart();
if (error)
return error;
FrmGotoForm(MainForm);
AppEventLoop();
AppStop();
break;
case sysAppLaunchCmdNotify:
notifyParamP = (SysNotifyParamType *)cmdPBP;
if( notifyParamP == NULL ) goto Done;
switch(notifyParamP->notifyType) {
case appFileCreator:
PrvStopFile((MiniInfo*)notifyParamP->userDataP);
break;
case hsNotifyRemSleepRequestEvent:
// sleepParamP = (SleepEventParamType*)notifyParamP->notifyDetailsP;
// sleepParamP->deferSleep++;
// Start playing music when it goes to sleep (got to have a file selected first):
// PrvPlayFile((MiniInfo*)notifyParamP->userDataP);
break;
}
default:
break;
}
Done:
return errNone;
}
#pragma warn_a5_access reset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -