[Scummvm-git-logs] scummvm master -> b05e89dc52b174327550dc2e4026fb0ae81cc554

sev- noreply at scummvm.org
Sun Dec 3 19:58:40 UTC 2023


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6b8d8c3f4e COMMON: cue - fix implicit indices
c0524f9bb7 DIRECTOR: implement more AppleCD methods
b05e89dc52 DIRECTOR: AppleCD found in a D3 game


Commit: 6b8d8c3f4e3c637bbc80dcbd0c5bb842c8eed172
    https://github.com/scummvm/scummvm/commit/6b8d8c3f4e3c637bbc80dcbd0c5bb842c8eed172
Author: Misty De Meo (mistydemeo at gmail.com)
Date: 2023-12-03T20:58:36+01:00

Commit Message:
COMMON: cue - fix implicit indices

If index 0 isn't specified, we need to be able to distinguish between
"this index has a value of 0" and "this index is missing". We now set
missing indices to -1 to help distinguish, and guard against using
a non-existent index in cases where it's not there.

Also fixes an off-by-one error in getTrackAtFrame exposed by this fix.

Changed paths:
    backends/audiocd/default/default-audiocd.cpp
    common/formats/cue.cpp


diff --git a/backends/audiocd/default/default-audiocd.cpp b/backends/audiocd/default/default-audiocd.cpp
index 54e4d54263b..482abf3c7f1 100644
--- a/backends/audiocd/default/default-audiocd.cpp
+++ b/backends/audiocd/default/default-audiocd.cpp
@@ -152,8 +152,9 @@ bool DefaultAudioCDManager::playAbsolute(int startFrame, int numLoops, int durat
 	} else {
 		warning("Playing from frame %i", startFrame);
 	}
+	int firstFrame = track->indices[0] == -1 ? track->indices[1] : track->indices[0];
 
-	return play(track->number, numLoops, startFrame - track->indices[0], duration, onlyEmulate);
+	return play(track->number, numLoops, startFrame - firstFrame, duration, onlyEmulate);
 }
 
 void DefaultAudioCDManager::stop() {
diff --git a/common/formats/cue.cpp b/common/formats/cue.cpp
index c5d9025ab81..7b1374abcee 100644
--- a/common/formats/cue.cpp
+++ b/common/formats/cue.cpp
@@ -298,8 +298,11 @@ void CueSheet::parseTracksContext(const char *line) {
 		int indexNum = atoi(nexttok(s, &s).c_str());
 		int frames = parseMSF(nexttok(s, &s).c_str());
 
-		for (int i = (int)_tracks[_currentTrack].indices.size(); i <= indexNum; i++)
-			_tracks[_currentTrack].indices.push_back(0);
+		for (int i = (int)_tracks[_currentTrack].indices.size(); i <= indexNum; i++) {
+			// -1 indicates "no index" to let callers guard against
+			// interpreting these as real values
+			_tracks[_currentTrack].indices.push_back(-1);
+		}
 
 		_tracks[_currentTrack].indices[indexNum] = frames;
 
@@ -353,15 +356,32 @@ CueSheet::CueTrack *CueSheet::getTrack(int tracknum) {
 CueSheet::CueTrack *CueSheet::getTrackAtFrame(int frame) {
 	for (uint i = 0; i < _tracks.size(); i++) {
 		// Inside pregap
-		if (frame >= _tracks[i].indices[0] && frame < _tracks[i].indices.back()) {
-			debug(5, "CueSheet::getTrackAtFrame: Returning track %i (pregap)", i);
+		if (_tracks[i].indices[0] >= 0 && frame >= _tracks[i].indices[0] && frame < _tracks[i].indices.back()) {
+			debug(5, "CueSheet::getTrackAtFrame: Returning track %i (pregap)", _tracks[i].number);
 			return &_tracks[i];
 		}
 
-		// Between index 1 and the start of the subsequent track
-		if (i < _tracks.size() && frame > _tracks[i].indices.back() && frame < _tracks[i+1].indices[0]) {
-			debug(5, "CueSheet::getTrackAtFrame: Returning track %i (inside content)", i);
-			return &_tracks[i];
+		// Between index 1 and the start of the subsequent track.
+		// Index 0 of the next track is the start of its pregap.
+		// For tracks which have pregaps, we want to use that as the
+		// frame to determine the edge of the track; otherwise, we'll
+		// need to use the start of index 1, eg the start of the track.
+		if (i+1 < _tracks.size()) {
+			int nextIndex;
+			CueSheet::CueTrack nextTrack = _tracks[i+1];
+			// If there's more than one index, *and* index 0 looks
+			// nullish, use index 1
+			if (nextTrack.indices.size() > 1 && nextTrack.indices[0] == -1) {
+				nextIndex = nextTrack.indices[1];
+			// Otherwise, use index 0
+			} else {
+				nextIndex = nextTrack.indices[0];
+			}
+
+			 if (frame >= _tracks[i].indices.back() && frame < nextIndex) {
+				debug(5, "CueSheet::getTrackAtFrame: Returning track %i (inside content)", _tracks[i].number);
+				return &_tracks[i];
+			}
 		}
 	}
 


Commit: c0524f9bb71bb1f606e409c994527c0103c3fb3f
    https://github.com/scummvm/scummvm/commit/c0524f9bb71bb1f606e409c994527c0103c3fb3f
Author: Misty De Meo (mistydemeo at gmail.com)
Date: 2023-12-03T20:58:36+01:00

Commit Message:
DIRECTOR: implement more AppleCD methods

Changed paths:
    engines/director/lingo/xlibs/applecdxobj.cpp
    engines/director/lingo/xlibs/applecdxobj.h


diff --git a/engines/director/lingo/xlibs/applecdxobj.cpp b/engines/director/lingo/xlibs/applecdxobj.cpp
index a346afd07de..95053fd9b71 100644
--- a/engines/director/lingo/xlibs/applecdxobj.cpp
+++ b/engines/director/lingo/xlibs/applecdxobj.cpp
@@ -109,6 +109,10 @@ static MethodProto xlibMethods[] = {
 	{ "ReadStatus",				AppleCDXObj::m_readStatus,	0,	0,	400 },	// D4
 	{ "GetValue",				AppleCDXObj::m_getValue,	0,	0,	400 },	// D4
 	{ "Eject",    				AppleCDXObj::m_eject,		0,	0,	400 },	// D4
+	{ "GetFirstTrack",    				AppleCDXObj::m_getFirstTrack,		0,	0,	400 },	// D4
+	{ "GetLastTrack",    				AppleCDXObj::m_getLastTrack,		0,	0,	400 },	// D4
+	{ "GetFirstFrame",    				AppleCDXObj::m_getFirstFrame,		1,	1,	400 },	// D4
+	{ "GetLastFrame",    				AppleCDXObj::m_getLastFrame,		1,	1,	400 },	// D4
 	{ "SetInPoint",    				AppleCDXObj::m_setInPoint,		1,	1,	400 },	// D4
 	{ "SetOutPoint",    				AppleCDXObj::m_setOutPoint,		1,	1,	400 },	// D4
 	{ "PlayCue",    				AppleCDXObj::m_playCue,		0,	0,	400 },	// D4
@@ -213,6 +217,97 @@ void AppleCDXObj::m_readPos(int nargs) {
 	}
 }
 
+void AppleCDXObj::m_getFirstTrack(int nargs) {
+	AppleCDXObject *me = static_cast<AppleCDXObject *>(g_lingo->_state->me.u.obj);
+
+	if (me->_cue) {
+		Common::Array<Common::CueSheet::CueTrack> tracks = me->_cue->tracks();
+		// If we have a set of tracks parsed, return the first track's number
+		int index;
+		if (tracks.size() >= 1) {
+			index = tracks[0].number;
+		} else {
+			index = 1;
+		}
+		debug(5, "AppleCDXObj::m_getFirstTrack: returning %i", index);
+		g_lingo->push(Datum(index));
+	} else {
+		// If we don't have a TOC, just assume the first track is 1
+		debug(5, "AppleCDXObj::m_getFirstTrack: returning default");
+		g_lingo->push(Datum(1));
+	}
+}
+
+void AppleCDXObj::m_getLastTrack(int nargs) {
+	AppleCDXObject *me = static_cast<AppleCDXObject *>(g_lingo->_state->me.u.obj);
+
+	if (me->_cue) {
+		Common::Array<Common::CueSheet::CueTrack> tracks = me->_cue->tracks();
+		// If we have a set of tracks parsed, return the final track's number
+		int index;
+		if (tracks.size() >= 1) {
+			index = tracks.back().number;
+		} else {
+			index = 1;
+		}
+		debug(5, "AppleCDXObj::m_getLastTrack: returning %i", index);
+	} else {
+		// If we don't have a TOC, just assume the last track is 1
+		debug(5, "AppleCDXObj::m_getLastTrack: returning default");
+		g_lingo->push(Datum(1));
+	}
+}
+
+void AppleCDXObj::m_getFirstFrame(int nargs) {
+	AppleCDXObject *me = static_cast<AppleCDXObject *>(g_lingo->_state->me.u.obj);
+	int trackNum = g_lingo->pop().asInt();
+
+	if (me->_cue) {
+		Common::CueSheet::CueTrack *track = me->_cue->getTrack(trackNum);
+
+		// We use index 1 here because index 0 is typically the
+		// pregap, and we don't want to describe the first sector of the
+		// pregap as being the first sector of the track. Most discs
+		// will have only two indices, and the second index is where the
+		// actual track begins.
+		int index = track->indices.size() > 1 ? track->indices[1] : track->indices[0];
+		debug(5, "AppleCDXObj::m_getFirstFrame(%i): returning %i", trackNum, index);
+		g_lingo->push(Datum(index));
+	} else {
+		// If we don't have a TOC, just provide a stub value
+		debug(5, "AppleCDXObj::m_getFirstFrame(%i): returning default", trackNum);
+		g_lingo->push(Datum(0));
+	}
+}
+
+// Currently calculated based on the start of the next track, since
+// cuesheets don't contain the duration of a song.
+void AppleCDXObj::m_getLastFrame(int nargs) {
+	AppleCDXObject *me = static_cast<AppleCDXObject *>(g_lingo->_state->me.u.obj);
+	int trackNum = g_lingo->pop().asInt();
+
+	if (me->_cue) {
+		// We look for the pregap of the next track, if there is one.
+		// TODO opening the actual audio track and getting its length
+		// in sectors would produce a more accurate result for the final track
+		Common::CueSheet::CueTrack *track = me->_cue->getTrack(trackNum + 1);
+		int index;
+		if (track) {
+			// Don't use the pregap if there is no pregap
+			index = track->indices[0] == -1 ? track->indices[1] : track->indices[0];
+		} else {
+			debug(5, "AppleCDXObj::m_getLastFrame(%i): no track at trackNum %i, setting index to 0", trackNum, trackNum + 1);
+			index = 0;
+		}
+		debug(5, "AppleCDXObj::m_getLastFrame(%i): returning %i", trackNum, index);
+		g_lingo->push(Datum(index));
+	} else {
+		// If we don't have a TOC, just provide a stub value
+		debug(5, "AppleCDXObj::m_getLastFrame(%i): returning default", trackNum);
+		g_lingo->push(Datum(0));
+	}
+}
+
 void AppleCDXObj::m_eject(int nargs) {
     debug(5, "AppleCDXObj::eject: Ejecting CD");
 }
diff --git a/engines/director/lingo/xlibs/applecdxobj.h b/engines/director/lingo/xlibs/applecdxobj.h
index 78cb773994e..413d07d6d8a 100644
--- a/engines/director/lingo/xlibs/applecdxobj.h
+++ b/engines/director/lingo/xlibs/applecdxobj.h
@@ -58,6 +58,10 @@ void m_setOutPoint(int nargs);
 void m_playCue(int nargs);
 void m_playSegment(int nargs);
 void m_readPos(int nargs);
+void m_getFirstTrack(int nargs);
+void m_getLastTrack(int nargs);
+void m_getFirstFrame(int nargs);
+void m_getLastFrame(int nargs);
 void m_eject(int nargs);
 
 } // End of namespace AppleCDXObj


Commit: b05e89dc52b174327550dc2e4026fb0ae81cc554
    https://github.com/scummvm/scummvm/commit/b05e89dc52b174327550dc2e4026fb0ae81cc554
Author: Misty De Meo (mistydemeo at gmail.com)
Date: 2023-12-03T20:58:36+01:00

Commit Message:
DIRECTOR: AppleCD found in a D3 game

Changed paths:
    engines/director/lingo/lingo-object.cpp
    engines/director/lingo/xlibs/applecdxobj.cpp


diff --git a/engines/director/lingo/lingo-object.cpp b/engines/director/lingo/lingo-object.cpp
index 55ec2baaef8..f3200935215 100644
--- a/engines/director/lingo/lingo-object.cpp
+++ b/engines/director/lingo/lingo-object.cpp
@@ -165,7 +165,7 @@ static struct XLibProto {
 	int version;
 } xlibs[] = {
 	{ AiffXObj::fileNames,				AiffXObj::open,				AiffXObj::close,			kXObj,					400 },	// D4
-	{ AppleCDXObj::fileNames,			AppleCDXObj::open,			AppleCDXObj::close,			kXObj,					400 },	// D4
+	{ AppleCDXObj::fileNames,			AppleCDXObj::open,			AppleCDXObj::close,			kXObj,					300 },	// D3
 	{ AskUser::fileNames,				AskUser::open,				AskUser::close,				kXObj,					400 },	// D4
 	{ BarakeObj::fileNames,				BarakeObj::open,			BarakeObj::close,			kXObj,					400 },	// D4
 	{ BatQT::fileNames,					BatQT::open,				BatQT::close,				kXObj,					400 },	// D4
diff --git a/engines/director/lingo/xlibs/applecdxobj.cpp b/engines/director/lingo/xlibs/applecdxobj.cpp
index 95053fd9b71..bf3937faa0b 100644
--- a/engines/director/lingo/xlibs/applecdxobj.cpp
+++ b/engines/director/lingo/xlibs/applecdxobj.cpp
@@ -24,6 +24,7 @@
  * USED IN:
  * Classical Cats
  * The Daedalus Encounter
+ * Refixion II
  *
  *************************************/
 
@@ -99,25 +100,26 @@ namespace Director {
 const char *AppleCDXObj::xlibName = "AppleCD";
 const char *AppleCDXObj::fileNames[] = {
 	"AppleCD",
+	"AppleCD XObj",
 	0
 };
 
 static MethodProto xlibMethods[] = {
-	{ "new",					AppleCDXObj::m_new,			0,	0,	400 },	// D4
-	{ "Service",				AppleCDXObj::m_service,		0,	0,	400 },	// D4
-	{ "Still",				AppleCDXObj::m_still,		0,	0,	400 },	// D4
-	{ "ReadStatus",				AppleCDXObj::m_readStatus,	0,	0,	400 },	// D4
-	{ "GetValue",				AppleCDXObj::m_getValue,	0,	0,	400 },	// D4
-	{ "Eject",    				AppleCDXObj::m_eject,		0,	0,	400 },	// D4
-	{ "GetFirstTrack",    				AppleCDXObj::m_getFirstTrack,		0,	0,	400 },	// D4
-	{ "GetLastTrack",    				AppleCDXObj::m_getLastTrack,		0,	0,	400 },	// D4
-	{ "GetFirstFrame",    				AppleCDXObj::m_getFirstFrame,		1,	1,	400 },	// D4
-	{ "GetLastFrame",    				AppleCDXObj::m_getLastFrame,		1,	1,	400 },	// D4
-	{ "SetInPoint",    				AppleCDXObj::m_setInPoint,		1,	1,	400 },	// D4
-	{ "SetOutPoint",    				AppleCDXObj::m_setOutPoint,		1,	1,	400 },	// D4
-	{ "PlayCue",    				AppleCDXObj::m_playCue,		0,	0,	400 },	// D4
-	{ "PlaySegment",    				AppleCDXObj::m_playSegment,		0,	0,	400 },	// D4
-	{ "ReadPos",    				AppleCDXObj::m_readPos,		0,	0,	400 },	// D4
+	{ "new",					AppleCDXObj::m_new,			0,	0,	300 },	// D3
+	{ "Service",				AppleCDXObj::m_service,		0,	0,	300 },	// D4
+	{ "Still",				AppleCDXObj::m_still,		0,	0,	300 },	// D3
+	{ "ReadStatus",				AppleCDXObj::m_readStatus,	0,	0,	300 },	// D3
+	{ "GetValue",				AppleCDXObj::m_getValue,	0,	0,	300 },	// D3
+	{ "Eject",    				AppleCDXObj::m_eject,		0,	0,	300 },	// D3
+	{ "GetFirstTrack",    				AppleCDXObj::m_getFirstTrack,		0,	0,	300 },	// D3
+	{ "GetLastTrack",    				AppleCDXObj::m_getLastTrack,		0,	0,	300 },	// D3
+	{ "GetFirstFrame",    				AppleCDXObj::m_getFirstFrame,		1,	1,	300 },	// D3
+	{ "GetLastFrame",    				AppleCDXObj::m_getLastFrame,		1,	1,	300 },	// D3
+	{ "SetInPoint",    				AppleCDXObj::m_setInPoint,		1,	1,	300 },	// D3
+	{ "SetOutPoint",    				AppleCDXObj::m_setOutPoint,		1,	1,	300 },	// D3
+	{ "PlayCue",    				AppleCDXObj::m_playCue,		0,	0,	300 },	// D3
+	{ "PlaySegment",    				AppleCDXObj::m_playSegment,		0,	0,	300 },	// D3
+	{ "ReadPos",    				AppleCDXObj::m_readPos,		0,	0,	300 },	// D3
     { nullptr, nullptr, 0, 0, 0 }
 };
 




More information about the Scummvm-git-logs mailing list