You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you attempt using pygame.mixer.Channel.queue with a Sound derived class, pygame will raise an error as if you didn't pass a Sound-based class at all. Here is the class I use, which netted me the error:
# _SoundBase is an alias for pygame.mixer.SoundclassSound(_SoundBase):
def__init__(self, file: str|ndarray|_SoundBase):
ifisinstance(file,str):
super().__init__(resource_path(file)) # Keep the source directory in case it's needed, and use an absolute path instead of a relative oneself.dir=fileelifisinstance(file, _SoundBase):
super().__init__(file) # Clone the original Sound objectelse:
super().__init__(array=file)
volume=property(
_SoundBase.get_volume, _SoundBase.set_volume, doc="The current sound's volume."
) # Access the volume as a property for convenience.num_channels=property(_SoundBase.get_num_channels)
# Convenience conversion methodsdef__bytes__(self):
returnself.get_raw()
def__len__(self):
returnself.get_length()
def__copy__(self):
returnself.__class__(self.dir)
defplay(self, loops: int=0, maxtime: int=0, fade_ms: int=0):
ifis_played(self): # is_played is a function checking if a sound is played by at least one channel.super().stop() # Stop the previous playback to avoid sound overlappingreturnsuper().play(loops, maxtime, fade_ms)
copy=__copy____deepcopy__=__copy__
And here is the error I got (pygame-ce 2.3.2 (SDL 2.26.5, Python 3.12.0)):
Traceback (most recent call last):
File "C:\Users\XXXXXXX\Documents\Python\Oracle-Project\testEngine.py", line 1733, in <module>
get_channel(wooshpart1).queue(wooshpart2) # wooshpart1 and wooshpart2 are both instances of Sound (the derived class)
TypeError: The argument must be an instance of Sound
Line 1070 in src_c/mixer.c reveals Channel.queue's code uses an exact type check instead of the usual instance verification to block non-sound classes from being queued, like this :
#definepgSound_Check(x) (Py_TYPE(x) == &pgSound_Type) //i.e. type(x) == pygame.mixer.Sound
...
if (!pgSound_Check(sound)) { //Line 1070returnRAISE(PyExc_TypeError,
"The argument must be an instance of Sound");
}
The text was updated successfully, but these errors were encountered:
If you attempt using
pygame.mixer.Channel.queue
with a Sound derived class, pygame will raise an error as if you didn't pass a Sound-based class at all. Here is the class I use, which netted me the error:And here is the error I got (pygame-ce 2.3.2 (SDL 2.26.5, Python 3.12.0)):
Line 1070 in src_c/mixer.c reveals
Channel.queue
's code uses an exact type check instead of the usual instance verification to block non-sound classes from being queued, like this :The text was updated successfully, but these errors were encountered: