Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions documentation/source/installing/installAdditional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,4 @@ On the Mac, run::

pip3 install pygame



Pygame 1.9 or later is required for correct error handling
12 changes: 4 additions & 8 deletions music21/midi/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Authors: Michael Scott Asato Cuthbert
# (from an idea by Joe "Codeswell")
#
# Copyright: Copyright © 2012 Michael Scott Asato Cuthbert
# Copyright: Copyright © 2012-25 Michael Scott Asato Cuthbert
# License: BSD, see license.txt
# ------------------------------------------------------------------------------
'''
Expand All @@ -18,7 +18,7 @@

https://stackoverflow.com/questions/10983462/how-can-i-produce-real-time-audio-output-from-music-made-with-music21

Requires pygame: pip3 install pygame
Requires pygame 2 (or 1.9) install with: pip3 install pygame
'''
from __future__ import annotations

Expand Down Expand Up @@ -87,9 +87,6 @@ def __init__(
# noinspection PyPackageRequirements
import pygame # type: ignore
self.pygame = pygame
# noinspection PyPackageRequirements
import pygame.exceptions # type: ignore
self.pygame_exceptions = pygame.exceptions # type: ignore # pylint: disable=no-member
except ImportError:
raise StreamPlayerException('StreamPlayer requires pygame. Install first')
if self.mixerInitialized is False or reinitMixer:
Expand Down Expand Up @@ -152,10 +149,9 @@ def playStringIOFile(self, stringIOFile, busyFunction=None, busyArgs=None,
pygameClock = self.pygame.time.Clock()
try:
self.pygame.mixer.music.load(stringIOFile)
except self.pygame_exceptions.PygameError as pge:
except self.pygame.error as pge:
raise StreamPlayerException(
f'Could not play music file {stringIOFile} because: '
+ f'{self.pygame_exceptions.get_error()}'
f'Could not play music file {stringIOFile} because: {pge}'
) from pge
self.pygame.mixer.music.play()
if not blocked:
Expand Down