From 58d2927322a2c21b501eeb9bb4e96156b48a55e1 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Wed, 3 Jan 2024 11:53:11 -1000 Subject: [PATCH] maybe fixed? --- music21/chord/__init__.py | 7 +++---- music21/volume.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/music21/chord/__init__.py b/music21/chord/__init__.py index baf279340..db050b439 100644 --- a/music21/chord/__init__.py +++ b/music21/chord/__init__.py @@ -443,8 +443,6 @@ def volume(self) -> 'music21.volume.Volume': # do NOT change to volume.Volume, * Changed in v8: setting volume to a list of volumes is no longer supported. See :meth:`~music21.chord.ChordBase.setVolumes` instead - * Improved in v9: if hasComponentVolumes is True, then the velocity object - returned here will be regenerated with each call, and updates live. OMIT_FROM_DOCS @@ -473,6 +471,7 @@ def volume(self) -> 'music21.volume.Volume': # do NOT change to volume.Volume, if velocities: # avoid division by zero error out_volume.velocity = int(round(sum(velocities) / len(velocities))) + self._volume = out_volume return out_volume @@ -582,9 +581,9 @@ def setVolumes(self, volumes: Sequence['music21.volume.Volume'|int|float]): v = v_entry else: # create a new Volume if v_entry < 1: # assume a scalar - v = volume.Volume(velocityScalar=v_entry) + v = volume.Volume(velocityScalar=float(v_entry)) else: # assume velocity - v = volume.Volume(velocity=v_entry) + v = volume.Volume(velocity=int(v_entry)) v.client = self c._setVolume(v, setClient=False) diff --git a/music21/volume.py b/music21/volume.py index bceb3c61a..02c7315eb 100644 --- a/music21/volume.py +++ b/music21/volume.py @@ -406,13 +406,17 @@ def velocityScalar(self, value: int|float|None): if not common.isNum(value): raise VolumeException('value provided for velocityScalar must be a number, ' + f'not {value}') + + scalar: float if value < 0: - scalar = 0 + scalar = 0.0 elif value > 1: - scalar = 1 + scalar = 1.0 else: - scalar = value - self._velocityScalar = float(scalar) + if t.TYPE_CHECKING: + assert value is not None + scalar = float(value) + self._velocityScalar = scalar # ------------------------------------------------------------------------------