Skip to content

Commit

Permalink
maybe fixed?
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Jan 3, 2024
1 parent 15593d7 commit 58d2927
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions music21/chord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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)

Expand Down
12 changes: 8 additions & 4 deletions music21/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 58d2927

Please sign in to comment.