aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src
diff options
context:
space:
mode:
authorChris Apers2005-10-12 20:28:11 +0000
committerChris Apers2005-10-12 20:28:11 +0000
commitb9cb9b6802bdd1427e595743ad3cdfbb0673b074 (patch)
tree0b8acc0f0603e0626d18696a61bf03026f347b17 /backends/PalmOS/Src
parent6330435331a32fba582fc3f7052b07492619cd74 (diff)
downloadscummvm-rg350-b9cb9b6802bdd1427e595743ad3cdfbb0673b074.tar.gz
scummvm-rg350-b9cb9b6802bdd1427e595743ad3cdfbb0673b074.tar.bz2
scummvm-rg350-b9cb9b6802bdd1427e595743ad3cdfbb0673b074.zip
Revamped PocketTunes support
svn-id: r19046
Diffstat (limited to 'backends/PalmOS/Src')
-rw-r--r--backends/PalmOS/Src/cd_pockettunes.cpp147
-rw-r--r--backends/PalmOS/Src/cd_pockettunes.h27
2 files changed, 97 insertions, 77 deletions
diff --git a/backends/PalmOS/Src/cd_pockettunes.cpp b/backends/PalmOS/Src/cd_pockettunes.cpp
index 08f2807dbd..abcc2e62f8 100644
--- a/backends/PalmOS/Src/cd_pockettunes.cpp
+++ b/backends/PalmOS/Src/cd_pockettunes.cpp
@@ -34,66 +34,93 @@ bool PckTunesCDPlayer::init() {
PocketTunesStart();
_isInitialized = PocketTunesIsRunning();
_isPlaying = false;
+ _pAction = NULL;
+
+ if (_isInitialized) {
+ _pAction = (PocketTunesAction*)MemPtrNew(sizeof(PocketTunesAction));
+ _volumeLimit = getVolumeLimit();
+ }
+
+ _isInitialized = (_isInitialized && _pAction);
return _isInitialized;
}
void PckTunesCDPlayer::release() {
- // self delete
PocketTunesStop();
+ if (_pAction)
+ MemPtrFree(_pAction);
+
+ // self delete
delete this;
}
-UInt32 PckTunesCDPlayer::getStatus() {
- if (!_isPlaying)
- return kPtunesStopped;
+UInt32 PckTunesCDPlayer::getVolumeLimit() {
+ UInt32 value = 0;
- EventType e;
- UInt32 status;
+ if (!_pAction)
+ return value;
- PocketTunesAction *pAction = (PocketTunesAction*)MemPtrNew (sizeof(PocketTunesAction));
- if (!pAction)
- return kPtunesStopped;
+ _pAction->action = kPocketTunesActionGetValue;
+ _pAction->data.getValueAction.which = kPtunesValueMaxVolume;
+
+ EvtGetEvent(&_eAction, evtNoWait);
+ if (PocketTunesCallSynch(_pAction) == errNone)
+ value = _pAction->data.getValueAction.value;
+
+ return value;
+}
- pAction->action = kPocketTunesActionGetStatus;
- EvtGetEvent(&e, evtNoWait);
- if (PocketTunesCallSynch(pAction) == errNone)
- status = pAction->data.getStatusAction.status;
- else
- status = kPtunesStopped;
+UInt32 PckTunesCDPlayer::getStatus() {
+ UInt32 status = kPtunesStopped;
+
+ if (!_isPlaying || !_pAction)
+ return status;
+
+ _pAction->action = kPocketTunesActionGetStatus;
- MemPtrFree(pAction);
- return status;
+ EvtGetEvent(&_eAction, evtNoWait);
+ if (PocketTunesCallSynch(_pAction) == errNone)
+ status = _pAction->data.getStatusAction.status;
+
+ return status;
}
UInt32 PckTunesCDPlayer::getPosition(UInt32 deflt) {
- if (!_isPlaying)
- return deflt;
+ UInt32 value = deflt;
- EventType e;
- UInt32 value;
+ if (!_isPlaying || !_pAction)
+ return value;
- PocketTunesAction *pAction = (PocketTunesAction*)MemPtrNew (sizeof(PocketTunesAction));
- if (!pAction)
- return deflt;
+ _pAction->action = kPocketTunesActionGetValue;
+ _pAction->data.getValueAction.which = kPtunesValueSongPosition;
+
+ EvtGetEvent(&_eAction, evtNoWait);
+ if (PocketTunesCallSynch(_pAction) == errNone)
+ value = _pAction->data.getValueAction.value;
- pAction->action = kPocketTunesActionGetValue;
- pAction->data.getValueAction.which = kPtunesValueSongPosition;
+ return value;
+}
- EvtGetEvent(&e, evtNoWait);
- if (PocketTunesCallSynch(pAction) == errNone)
- value = pAction->data.getValueAction.value;
- else
- value = deflt;
+UInt32 PckTunesCDPlayer::getDuration() {
+ UInt32 value = gVars->CD.defaultTrackLength;
- MemPtrFree(pAction);
- return value;
+ if (!_isPlaying || !_pAction)
+ return value;
+
+ _pAction->action = kPocketTunesActionGetValue;
+ _pAction->data.getValueAction.which = kPtunesValueSongDuration;
+
+ EvtGetEvent(&_eAction, evtNoWait);
+ if (PocketTunesCallSynch(_pAction) == errNone)
+ value = _pAction->data.getValueAction.value;
+
+ return value;
}
void PckTunesCDPlayer::setPosition(UInt32 value) {
if (!_isPlaying)
return;
- EventType e;
PocketTunesAction *pAction = AllocateAsynchronousActionStruct();
if (!pAction)
return;
@@ -102,32 +129,23 @@ void PckTunesCDPlayer::setPosition(UInt32 value) {
pAction->data.getValueAction.which = kPtunesValueSongPosition;
pAction->data.getValueAction.value = value;
- EvtGetEvent(&e, evtNoWait);
+ EvtGetEvent(&_eAction, evtNoWait);
PocketTunesCall(pAction);
}
-UInt32 PckTunesCDPlayer::getDuration() {
- if (!_isPlaying)
- return gVars->CD.defaultTrackLength;
+void PckTunesCDPlayer::setVolume(int volume) {
+ _volumeLevel = volume;
- EventType e;
- UInt32 value;
-
- PocketTunesAction *pAction = (PocketTunesAction*)MemPtrNew (sizeof(PocketTunesAction));
+ PocketTunesAction *pAction = AllocateAsynchronousActionStruct();
if (!pAction)
- return gVars->CD.defaultTrackLength;
-
- pAction->action = kPocketTunesActionGetValue;
- pAction->data.getValueAction.which = kPtunesValueSongDuration;
+ return;
- EvtGetEvent(&e, evtNoWait);
- if (PocketTunesCallSynch(pAction) == errNone)
- value = pAction->data.getValueAction.value;
- else
- value = gVars->CD.defaultTrackLength;
+ pAction->action = kPocketTunesActionSetValue;
+ pAction->data.getValueAction.which = kPtunesValueVolume;
+ pAction->data.getValueAction.value = (_volumeLimit * volume) / 100;
- MemPtrFree(pAction);
- return value;
+ EvtGetEvent(&_eAction, evtNoWait);
+ PocketTunesCall(pAction);
}
bool PckTunesCDPlayer::poll() {
@@ -146,9 +164,7 @@ void PckTunesCDPlayer::update() {
}
// not fully played
-// if (_sys->getMillis() < _pckTrackEndFrame)
-// return;
- if (getPosition(_pckTrackEndFrame) < _pckTrackEndFrame)
+ if (getPosition(_pckTrackEndFrame) < _pckTrackEndFrame && getStatus() != kPtunesStopped)
return;
PocketTunesStop();
@@ -162,14 +178,13 @@ void PckTunesCDPlayer::update() {
// loop if needed
if (_pckLoops != 0 && _isPlaying) {
- PocketTunesPlay();
-
if (_pckTrackStartFrame == 0 && _pckTrackDuration == 0) {
setPosition(0);
} else {
setPosition(_pckTrackStartFrame);
}
-// _pckTrackEndFrame = _pckTrackStartFrame + _pckTrackDuration;
+
+ PocketTunesPlay();
}
}
@@ -185,21 +200,17 @@ void PckTunesCDPlayer::play(int track, int num_loops, int start_frame, int durat
EventType e;
Char nameP[256], fileP[100];
- Char *ext[] = { "mp3", "ogg" };
-
-// if (duration > 0)
-// duration += 5;
-
+ static const Char *ext[] = { "mp3", "ogg" };
+
_pckTrack = track;
_pckLoops = num_loops;
_pckTrackStartFrame = TO_MSECS(start_frame);
_pckTrackDuration = TO_MSECS(duration);
- // stop current play if any
- VFSVolumeGetLabel(gVars->volRefNum, nameP, 256);
-
+ VFSVolumeGetLabel(gVars->VFS.volRefNum, nameP, 256);
+
StrPrintF(fileP, "/Palm/Programs/ScummVM/Audio/%s_%03ld.%s", gameP, (track + gVars->CD.firstTrack - 1), ext[gVars->CD.format]);
-
+
if (PocketTunesOpenFile(nameP, fileP, 0) == errNone) {
EvtGetEvent(&e, evtNoWait);
PocketTunesPauseIfPlaying();
diff --git a/backends/PalmOS/Src/cd_pockettunes.h b/backends/PalmOS/Src/cd_pockettunes.h
index 34273f4696..e7c12ed73f 100644
--- a/backends/PalmOS/Src/cd_pockettunes.h
+++ b/backends/PalmOS/Src/cd_pockettunes.h
@@ -19,39 +19,48 @@
* $Header$
*
*/
-
+
#ifndef CD_POCKETTUNES_H
#define CD_POCKETTUNES_H
-
+
#include "cdaudio.h"
#include "pockettunes.h"
-
+
class PckTunesCDPlayer : public CDAudio {
public:
PckTunesCDPlayer(OSystem *sys);
bool init();
void release();
-
+
bool poll();
void update();
void play(int track, int num_loops, int start_frame, int duration);
void stop();
-
+
+ void setVolume(int volume);
+
private:
OSystem *_sys;
Char gameP[15];
-
+
+ PocketTunesAction *_pAction; // prevent memory fragmentation
+ EventType _eAction;
+
UInt32 getStatus();
void setPosition(UInt32 value);
UInt32 getDuration();
UInt32 getPosition(UInt32 deft);
-
+
+ UInt32 _volumeLimit;
+ UInt32 getVolumeLimit();
+
Boolean _isPlaying;
// cdrom
UInt16 _pckLoops, _pckTrack;
UInt32 _pckTrackStartFrame, _pckTrackEndFrame;
UInt32 _pckStopTime, _pckTrackDuration;
};
-
- #endif \ No newline at end of file
+
+ #endif
+ \ No newline at end of file