mutwo-org / mutwo.music Goto Github PK
View Code? Open in Web Editor NEWMusic extension for event based library mutwo
Home Page: https://mutwo-org.github.io/
License: GNU General Public License v3.0
Music extension for event based library mutwo
Home Page: https://mutwo-org.github.io/
License: GNU General Public License v3.0
JustIntonationPitch
is due to historical reasons both a Pitch
and a PitchInterval
. But comparison with other pitch intervals doesn't work as expected:
def _compare(
self,
other: typing.Any,
compare: typing.Callable[[core_constants.Real, core_constants.Real], bool],
raise_exception: bool,
):
"""Compare itself with other object"""
try:
value_pair = (
getattr(self, self.value_name), # type: ignore
other
if isinstance(other, self.direct_comparison_type_tuple)
else getattr(other, self.value_name), # type: ignore
)
except AttributeError:
if raise_exception:
> raise TypeError(
f"Can't compare object '{self}' of type '{type(self)}' with"
f" object '{other}' of type '{type(other)}'!"
)
E TypeError: Can't compare object 'JustIntonationPitch(frequency = 440.0)' of type '<class 'mutwo.music_parameters.pitches.JustIntonationPitch.JustIntonationPitch'>' with object 'DirectPitchInterval(interval = -6000)' of type '<class 'mutwo.music_parameters.pitch_intervals.DirectPitchInterval'>'!
This doesn't work for a general interval class:
music_parameters.RepeatingScaleFamily(
[
music_parameters.WesternPitchInterval(interval)
for interval in "p1 m3 p4 p5 M7".split(" ")
],
repetition_interval=music_parameters.WesternPitchInterval("p8"),
),
leads to
self = <mutwo.music_parameters.scales.RepeatingScaleFamily object at 0x7fa261dc92a0>
repeating_interval_sequence = [WesternPitchInterval('p1'), WesternPitchInterval('m3'), WesternPitchInterval('p4'), WesternPitchInterval('p5'), WesternPitchInterval('M7')]
repetition_interval = WesternPitchInterval('p8'), min_pitch_interval = <mutwo.music_parameters.pitch_intervals.DirectPitchInterval object at 0x7fa265e10490>
max_pitch_interval = <mutwo.music_parameters.pitch_intervals.DirectPitchInterval object at 0x7fa265e104f0>, repeating_weight_sequence = None, repeating_scale_degree_sequence = None
repeating_period_repetition_count_sequence = None
def __init__(
self,
repeating_interval_sequence: IntervalSequence,
repetition_interval: music_parameters.abc.PitchInterval = music_parameters.DirectPitchInterval(
1200
),
min_pitch_interval: music_parameters.abc.PitchInterval = music_parameters.DirectPitchInterval(
-1200 * 5
),
max_pitch_interval: music_parameters.abc.PitchInterval = music_parameters.DirectPitchInterval(
1200 * 5
),
repeating_weight_sequence: typing.Optional[WeightSequence] = None,
repeating_scale_degree_sequence: typing.Optional[ScaleDegreeSequence] = None,
repeating_period_repetition_count_sequence: typing.Optional[
PeriodRepetitionCountSequence
] = None,
):
# TODO(Make this somehow readable.)
repeating_interval_tuple = tuple(repeating_interval_sequence)
repeating_weight_tuple = ScaleFamily._weight_sequence_to_weight_tuple(
repeating_weight_sequence, repeating_interval_tuple
)
repeating_scale_degree_tuple = (
ScaleFamily._scale_degree_sequence_to_scale_tuple(
repeating_scale_degree_sequence, repeating_interval_tuple
)
)
repeating_period_repetition_count_tuple = ScaleFamily._period_repetition_count_sequence_to_period_repetition_count_tuple(
repeating_period_repetition_count_sequence, repeating_interval_tuple
)
is_rising = ScaleFamily._is_interval_tuple_rising(repeating_interval_tuple)
interval_range = (
repeating_interval_tuple[0].interval - repeating_interval_tuple[-1].interval
)
assert abs(interval_range) < abs(repetition_interval.interval), (
"Repetition interval has to be bigger than "
"ambitus of repeating interval sequence!"
)
interval_data_list = [
(interval, weight, scale_degree, period_repetition_count)
for interval, weight, scale_degree, period_repetition_count in zip(
repeating_interval_tuple,
repeating_weight_tuple,
repeating_scale_degree_tuple,
repeating_period_repetition_count_tuple,
)
if interval >= min_pitch_interval and interval < max_pitch_interval
]
for local_repetition_interval in (
repetition_interval,
repetition_interval.inverse(mutate=False),
):
last_interval_data_list = list(
zip(
repeating_interval_tuple,
repeating_weight_tuple,
repeating_scale_degree_tuple,
repeating_period_repetition_count_tuple,
)
)
if local_repetition_interval.interval > 0:
period_repetition_delta = 1
else:
period_repetition_delta = -1
while 1:
new_interval_data_list = []
is_valid = True
for (
interval,
weight,
scale_degree,
period_repetition_count,
) in last_interval_data_list:
if (
> (new_interval := interval + local_repetition_interval)
< max_pitch_interval
) and (new_interval >= min_pitch_interval):
E TypeError: unsupported operand type(s) for +: 'WesternPitchInterval' and 'WesternPitchInterval'
>>> music_parameters.JustIntonationPitch('3/1') > music_parameters.WesternPitch()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 music_parameters.JustIntonationPitch('3/1') > music_parameters.WesternPitch()
File /nix/store/hhk4wr7hwry854sq69chmrjqyi964p7y-python3-3.10.9/lib/python3.10/functools.py:91, in _gt_from_lt(self, other, NotImplemented)
89 def _gt_from_lt(self, other, NotImplemented=NotImplemented):
90 'Return a > b. Computed by @total_ordering from (not a < b) and (a != b).'
---> 91 op_result = type(self).__lt__(self, other)
92 if op_result is NotImplemented:
93 return op_result
File /nix/store/9vxq4s7k4fz1c1hc5jjrq4kalp2dy9fp-python3.10-mutwo.music/lib/python3.10/site-packages/mutwo/music_parameters/pitches/JustIntonationPitch.py:438, in JustIntonationPitch.__lt__(self, other)
433 def __lt__(self, other: typing.Any) -> bool:
434 match other:
435 case music_parameters.abc.PitchInterval():
436 return self.interval < other.interval
437 case _: # pitch test
--> 438 return super().__lt__(self, other)
TypeError: SingleNumberParameter.__lt__() takes 2 positional arguments but 3 were given
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.