1 # Class interface to the CD module.
2 from warnings
import warnpy3k
3 warnpy3k("the readcd module has been removed in Python 3.0", stacklevel
=2)
8 class Error(Exception):
10 class _Stop(Exception):
13 def _doatime(self
, cb_type
, data
):
14 if ((data
[0] * 60) + data
[1]) * 75 + data
[2] > self
.end
:
15 ## print 'done with list entry', repr(self.listindex)
17 func
, arg
= self
.callbacks
[cb_type
]
19 func(arg
, cb_type
, data
)
21 def _dopnum(self
, cb_type
, data
):
23 ## print 'done with list entry', repr(self.listindex)
25 func
, arg
= self
.callbacks
[cb_type
]
27 func(arg
, cb_type
, data
)
30 def __init__(self
, *arg
):
32 self
.player
= cd
.open()
34 self
.player
= cd
.open(arg
[0])
36 self
.player
= cd
.open(arg
[0], arg
[1])
38 raise Error
, 'bad __init__ call'
40 self
.callbacks
= [(None, None)] * 8
41 self
.parser
= cd
.createparser()
55 ## print 'stop playing from eject'
58 def pmsf2msf(self
, track
, min, sec
, frame
):
61 if track
< self
.status
[5] or track
> self
.status
[6]:
62 raise Error
, 'track number out of range'
63 if not self
.trackinfo
:
65 start
, total
= self
.trackinfo
[track
]
66 start
= ((start
[0] * 60) + start
[1]) * 75 + start
[2]
67 total
= ((total
[0] * 60) + total
[1]) * 75 + total
[2]
68 block
= ((min * 60) + sec
) * 75 + frame
70 raise Error
, 'out of range'
72 min, block
= divmod(block
, 75*60)
73 sec
, frame
= divmod(block
, 75)
74 return min, sec
, frame
79 def appendtrack(self
, track
):
80 self
.appendstretch(track
, track
)
82 def appendstretch(self
, start
, end
):
89 if type(end
) == type(0):
90 if end
< self
.status
[5] or end
> self
.status
[6]:
91 raise Error
, 'range error'
95 prog
, min, sec
, frame
= end
96 if prog
< self
.status
[5] or prog
> self
.status
[6]:
97 raise Error
, 'range error'
98 end
= self
.pmsf2msf(prog
, min, sec
, frame
)
100 raise Error
, 'syntax error'
101 if type(start
) == type(0):
102 if start
< self
.status
[5] or start
> self
.status
[6]:
103 raise Error
, 'range error'
104 if len(self
.list) > 0:
106 if type(e
) == type(0):
113 prog
, min, sec
, frame
= start
114 if prog
< self
.status
[5] or prog
> self
.status
[6]:
115 raise Error
, 'range error'
116 start
= self
.pmsf2msf(prog
, min, sec
, frame
)
118 raise Error
, 'syntax error'
119 self
.list.append((start
, end
))
121 def settracks(self
, list):
124 self
.appendtrack(track
)
126 def setcallback(self
, cb_type
, func
, arg
):
127 if cb_type
< 0 or cb_type
>= 8:
128 raise Error
, 'type out of range'
129 self
.callbacks
[cb_type
] = (func
, arg
)
131 start
, end
= self
.list[self
.listindex
]
132 if type(end
) == type(0):
133 if cb_type
!= CD
.PNUM
:
134 self
.parser
.setcallback(cb_type
, func
, arg
)
136 if cb_type
!= CD
.ATIME
:
137 self
.parser
.setcallback(cb_type
, func
, arg
)
139 def removecallback(self
, cb_type
):
140 if cb_type
< 0 or cb_type
>= 8:
141 raise Error
, 'type out of range'
142 self
.callbacks
[cb_type
] = (None, None)
144 start
, end
= self
.list[self
.listindex
]
145 if type(end
) == type(0):
146 if cb_type
!= CD
.PNUM
:
147 self
.parser
.removecallback(cb_type
)
149 if cb_type
!= CD
.ATIME
:
150 self
.parser
.removecallback(cb_type
)
152 def gettrackinfo(self
, *arg
):
155 if not self
.trackinfo
:
158 return self
.trackinfo
[self
.status
[5]:self
.status
[6]+1]
161 if i
< self
.status
[5] or i
> self
.status
[6]:
162 raise Error
, 'range error'
163 result
.append(self
.trackinfo
[i
])
170 for i
in range(self
.status
[5]):
171 self
.trackinfo
.append(None)
172 for i
in range(self
.status
[5], self
.status
[6]+1):
173 self
.trackinfo
.append(self
.player
.gettrackinfo(i
))
175 def cachestatus(self
):
176 self
.status
= self
.player
.getstatus()
177 if self
.status
[0] == CD
.NODISC
:
179 raise Error
, 'no disc in player'
182 return self
.player
.getstatus()
187 size
= self
.player
.bestreadsize()
191 func
, arg
= self
.callbacks
[i
]
193 self
.parser
.setcallback(i
, func
, arg
)
195 self
.parser
.removecallback(i
)
196 if len(self
.list) == 0:
197 for i
in range(self
.status
[5], self
.status
[6]+1):
202 if self
.listindex
>= len(self
.list):
204 start
, end
= self
.list[self
.listindex
]
205 if type(start
) == type(0):
206 dummy
= self
.player
.seektrack(
209 min, sec
, frame
= start
210 dummy
= self
.player
.seek(
212 if type(end
) == type(0):
213 self
.parser
.setcallback(
214 CD
.PNUM
, _dopnum
, self
)
217 self
.callbacks
[CD
.ATIME
]
219 self
.parser
.setcallback(CD
.ATIME
, func
, arg
)
221 self
.parser
.removecallback(CD
.ATIME
)
223 min, sec
, frame
= end
224 self
.parser
.setcallback(
227 self
.end
= (min * 60 + sec
) * \
230 self
.callbacks
[CD
.PNUM
]
232 self
.parser
.setcallback(CD
.PNUM
, func
, arg
)
234 self
.parser
.removecallback(CD
.PNUM
)
236 data
= self
.player
.readda(size
)
239 self
.listindex
= self
.listindex
+ 1
242 self
.parser
.parseframe(data
)
245 self
.listindex
= self
.listindex
+ 1