Kaydet (Commit) 58230c3a authored tarafından Guido van Rossum's avatar Guido van Rossum

Changed caching code

üst 9ac9063c
...@@ -53,11 +53,11 @@ class Readcd(): ...@@ -53,11 +53,11 @@ class Readcd():
def pmsf2msf(self, track, min, sec, frame): def pmsf2msf(self, track, min, sec, frame):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not self.trackinfo:
dummy = self.gettrackinfo()
if track < self.status[5] or track > self.status[6]: if track < self.status[5] or track > self.status[6]:
raise Error, 'track number out of range' raise Error, 'track number out of range'
if not self.trackinfo:
self.cacheinfo()
start, total = self.trackinfo[track] start, total = self.trackinfo[track]
start = ((start[0] * 60) + start[1]) * 75 + start[2] start = ((start[0] * 60) + start[1]) * 75 + start[2]
total = ((total[0] * 60) + total[1]) * 75 + total[2] total = ((total[0] * 60) + total[1]) * 75 + total[2]
...@@ -77,7 +77,7 @@ class Readcd(): ...@@ -77,7 +77,7 @@ class Readcd():
def appendstretch(self, start, end): def appendstretch(self, start, end):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not start: if not start:
start = 1 start = 1
if not end: if not end:
...@@ -149,13 +149,9 @@ class Readcd(): ...@@ -149,13 +149,9 @@ class Readcd():
def gettrackinfo(self, *arg): def gettrackinfo(self, *arg):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not self.trackinfo: if not self.trackinfo:
self.trackinfo = [] self.cacheinfo()
for i in range(self.status[5]):
self.trackinfo.append(None)
for i in range(self.status[5], self.status[6]+1):
self.trackinfo.append(self.player.gettrackinfo(i))
if len(arg) == 0: if len(arg) == 0:
return self.trackinfo[self.status[5]:self.status[6]+1] return self.trackinfo[self.status[5]:self.status[6]+1]
result = [] result = []
...@@ -165,13 +161,27 @@ class Readcd(): ...@@ -165,13 +161,27 @@ class Readcd():
result.append(self.trackinfo[i]) result.append(self.trackinfo[i])
return result return result
def getstatus(self): def cacheinfo(self):
if not self.status:
self.cachestatus()
self.trackinfo = []
for i in range(self.status[5]):
self.trackinfo.append(None)
for i in range(self.status[5], self.status[6]+1):
self.trackinfo.append(self.player.gettrackinfo(i))
def cachestatus(self):
self.status = self.player.getstatus() self.status = self.player.getstatus()
return self.status if self.status[0] == CD.NODISK:
self.status = None
raise Error, 'no disk in player'
def getstatus(self):
return self.player.getstatus()
def play(self): def play(self):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
size = self.player.bestreadsize() size = self.player.bestreadsize()
self.listindex = 0 self.listindex = 0
self.playing = 0 self.playing = 0
......
...@@ -53,11 +53,11 @@ class Readcd(): ...@@ -53,11 +53,11 @@ class Readcd():
def pmsf2msf(self, track, min, sec, frame): def pmsf2msf(self, track, min, sec, frame):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not self.trackinfo:
dummy = self.gettrackinfo()
if track < self.status[5] or track > self.status[6]: if track < self.status[5] or track > self.status[6]:
raise Error, 'track number out of range' raise Error, 'track number out of range'
if not self.trackinfo:
self.cacheinfo()
start, total = self.trackinfo[track] start, total = self.trackinfo[track]
start = ((start[0] * 60) + start[1]) * 75 + start[2] start = ((start[0] * 60) + start[1]) * 75 + start[2]
total = ((total[0] * 60) + total[1]) * 75 + total[2] total = ((total[0] * 60) + total[1]) * 75 + total[2]
...@@ -77,7 +77,7 @@ class Readcd(): ...@@ -77,7 +77,7 @@ class Readcd():
def appendstretch(self, start, end): def appendstretch(self, start, end):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not start: if not start:
start = 1 start = 1
if not end: if not end:
...@@ -149,13 +149,9 @@ class Readcd(): ...@@ -149,13 +149,9 @@ class Readcd():
def gettrackinfo(self, *arg): def gettrackinfo(self, *arg):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
if not self.trackinfo: if not self.trackinfo:
self.trackinfo = [] self.cacheinfo()
for i in range(self.status[5]):
self.trackinfo.append(None)
for i in range(self.status[5], self.status[6]+1):
self.trackinfo.append(self.player.gettrackinfo(i))
if len(arg) == 0: if len(arg) == 0:
return self.trackinfo[self.status[5]:self.status[6]+1] return self.trackinfo[self.status[5]:self.status[6]+1]
result = [] result = []
...@@ -165,13 +161,27 @@ class Readcd(): ...@@ -165,13 +161,27 @@ class Readcd():
result.append(self.trackinfo[i]) result.append(self.trackinfo[i])
return result return result
def getstatus(self): def cacheinfo(self):
if not self.status:
self.cachestatus()
self.trackinfo = []
for i in range(self.status[5]):
self.trackinfo.append(None)
for i in range(self.status[5], self.status[6]+1):
self.trackinfo.append(self.player.gettrackinfo(i))
def cachestatus(self):
self.status = self.player.getstatus() self.status = self.player.getstatus()
return self.status if self.status[0] == CD.NODISK:
self.status = None
raise Error, 'no disk in player'
def getstatus(self):
return self.player.getstatus()
def play(self): def play(self):
if not self.status: if not self.status:
self.status = self.player.getstatus() self.cachestatus()
size = self.player.bestreadsize() size = self.player.bestreadsize()
self.listindex = 0 self.listindex = 0
self.playing = 0 self.playing = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment