Skip to content

Commit cf71793

Browse files
authored
Merge pull request #1836 from cuthbertLab/pygame-2.0
Update pygame code
2 parents 781a818 + d259d5a commit cf71793

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

documentation/source/installing/installAdditional.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,4 @@ On the Mac, run::
126126

127127
pip3 install pygame
128128

129-
130-
129+
Pygame 1.9 or later is required for correct error handling

music21/midi/realtime.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Authors: Michael Scott Asato Cuthbert
77
# (from an idea by Joe "Codeswell")
88
#
9-
# Copyright: Copyright © 2012 Michael Scott Asato Cuthbert
9+
# Copyright: Copyright © 2012-25 Michael Scott Asato Cuthbert
1010
# License: BSD, see license.txt
1111
# ------------------------------------------------------------------------------
1212
'''
@@ -18,7 +18,7 @@
1818
1919
https://stackoverflow.com/questions/10983462/how-can-i-produce-real-time-audio-output-from-music-made-with-music21
2020
21-
Requires pygame: pip3 install pygame
21+
Requires pygame 2 (or 1.9) install with: pip3 install pygame
2222
'''
2323
from __future__ import annotations
2424

@@ -87,9 +87,6 @@ def __init__(
8787
# noinspection PyPackageRequirements
8888
import pygame # type: ignore
8989
self.pygame = pygame
90-
# noinspection PyPackageRequirements
91-
import pygame.exceptions # type: ignore
92-
self.pygame_exceptions = pygame.exceptions # type: ignore # pylint: disable=no-member
9390
except ImportError:
9491
raise StreamPlayerException('StreamPlayer requires pygame. Install first')
9592
if self.mixerInitialized is False or reinitMixer:
@@ -152,10 +149,9 @@ def playStringIOFile(self, stringIOFile, busyFunction=None, busyArgs=None,
152149
pygameClock = self.pygame.time.Clock()
153150
try:
154151
self.pygame.mixer.music.load(stringIOFile)
155-
except self.pygame_exceptions.PygameError as pge:
152+
except self.pygame.error as pge:
156153
raise StreamPlayerException(
157-
f'Could not play music file {stringIOFile} because: '
158-
+ f'{self.pygame_exceptions.get_error()}'
154+
f'Could not play music file {stringIOFile} because: {pge}'
159155
) from pge
160156
self.pygame.mixer.music.play()
161157
if not blocked:

0 commit comments

Comments
 (0)