@@ -81,7 +81,8 @@ def evaluate_absence_of_voice_crossing(
81
81
"""
82
82
Evaluate absence of voice crossing.
83
83
84
- Voice crossing may result in wrong perception of tone row and in incoherence of the fragment.
84
+ Voice crossing may result in wrong perception of the tone row
85
+ (especially, if voices are played with the same timbre).
85
86
86
87
:param fragment:
87
88
a fragment to be evaluated
@@ -161,8 +162,8 @@ def find_melodic_interval(
161
162
:param melodic_line:
162
163
melodic line containing the event
163
164
:param shift:
164
- -1 if interval of arrival in the event is needed or
165
- 1 if interval of departure from the event is needed
165
+ -1 if interval of arrival in the event is needed
166
+ or 1 if interval of departure from the event is needed
166
167
:return:
167
168
size of melodic interval (in semitones)
168
169
"""
@@ -188,13 +189,13 @@ def evaluate_dissonances_preparation_and_resolution(
188
189
:param fragment:
189
190
a fragment to be evaluated
190
191
:param n_semitones_to_pt_and_ngh_preparation_penalty:
191
- mapping from melodic interval size in semitones to a penalty for moving by this interval
192
+ mapping from melodic interval size ( in semitones) to a penalty for moving by this interval
192
193
to a dissonance considered to be an analogue of passing tone or neighbor dissonance
193
194
:param n_semitones_to_pt_and_ngh_resolution_penalty:
194
- mapping from melodic interval size in semitones to a penalty for moving by this interval
195
+ mapping from melodic interval size ( in semitones) to a penalty for moving by this interval
195
196
from a dissonance considered to be an analogue of passing tone or neighbor dissonance
196
197
:param n_semitones_to_suspension_resolution_penalty:
197
- mapping from melodic interval size in semitones to a penalty for moving by this interval
198
+ mapping from melodic interval size ( in semitones) to a penalty for moving by this interval
198
199
from a dissonance considered to be an analogue of suspended dissonance
199
200
:return:
200
201
average over all vertical intervals penalty for their preparation and resolution
@@ -278,8 +279,8 @@ def find_sonority_type(
278
279
:param regular_positions:
279
280
parameters of regular positions (for example, downbeats or relatively strong beats)
280
281
:param ad_hoc_positions:
281
- parameters of ad hoc positions which appear just once (for example, the beginning of
282
- the fragment or the 11th reference beat)
282
+ parameters of ad hoc positions which appear just once
283
+ (for example, the beginning of the fragment or the 11th reference beat)
283
284
:param n_beats:
284
285
total duration of a fragment (in reference beats)
285
286
:return:
@@ -316,8 +317,8 @@ def evaluate_harmony_dynamic_by_positions(
316
317
:param regular_positions:
317
318
parameters of regular positions (for example, downbeats or relatively strong beats)
318
319
:param ad_hoc_positions:
319
- parameters of ad hoc positions which appear just once (for example, the beginning of
320
- the fragment or the 11th reference beat)
320
+ parameters of ad hoc positions which appear just once
321
+ (for example, the beginning of the fragment or the 11th reference beat)
321
322
:param ranges:
322
323
mapping from position type to minimum and maximum desired levels of harmonic stability
323
324
:param n_semitones_to_stability:
@@ -441,7 +442,7 @@ def evaluate_motion_to_perfect_consonances(fragment: Fragment) -> float:
441
442
:param fragment:
442
443
a fragment to be evaluated
443
444
:return:
444
- minus one multiplied by fraction of sonorities with wrong motion to perfect consonances
445
+ minus one multiplied by average over sonorities number of violations
445
446
"""
446
447
score = 0
447
448
previous_events = [None for _ in fragment .melodic_lines ]
@@ -450,6 +451,7 @@ def evaluate_motion_to_perfect_consonances(fragment: Fragment) -> float:
450
451
for line_index , (previous_event , current_event ) in enumerate (zipped ):
451
452
if previous_event != current_event :
452
453
previous_events [line_index ] = previous_event
454
+
453
455
pairs = itertools .combinations (sonority .non_pause_events , 2 )
454
456
for first_event , second_event in pairs :
455
457
n_semitones = first_event .position_in_semitones - second_event .position_in_semitones
@@ -458,29 +460,19 @@ def evaluate_motion_to_perfect_consonances(fragment: Fragment) -> float:
458
460
if interval_type != IntervalTypes .PERFECT_CONSONANCE :
459
461
continue
460
462
461
- first_previous_event = previous_events [first_event .line_index ]
462
- first_event_continues = (
463
- first_previous_event is None
464
- or (
465
- first_previous_event .start_time + first_previous_event .duration
466
- < sonority .start_time
467
- )
468
- )
469
- second_previous_event = previous_events [second_event .line_index ]
470
- second_event_continues = (
471
- second_previous_event is None
472
- or (
473
- second_previous_event .start_time + second_previous_event .duration
474
- < sonority .start_time
475
- )
476
- )
463
+ first_event_continues = first_event .start_time < sonority .start_time
464
+ second_event_continues = second_event .start_time < sonority .start_time
477
465
if first_event_continues and second_event_continues :
478
466
continue
479
467
480
468
if first_event_continues :
481
469
first_previous_event = first_event
482
- elif second_event_continues :
470
+ else :
471
+ first_previous_event = previous_events [first_event .line_index ]
472
+ if second_event_continues :
483
473
second_previous_event = second_event
474
+ else :
475
+ second_previous_event = previous_events [second_event .line_index ]
484
476
485
477
any_previous_pauses = (
486
478
first_previous_event .pitch_class == 'pause'
@@ -576,8 +568,8 @@ def evaluate_pitch_class_distribution_among_lines(
576
568
"""
577
569
Evaluate that pitch classes are distributed among lines according to user specifications.
578
570
579
- For example, it is possible to use some pitch classes only in melody and the remaining
580
- pitch classes only in accompaniment.
571
+ For example, it is possible to use some pitch classes only in the melody
572
+ and the remaining pitch classes only in the accompaniment.
581
573
582
574
:param fragment:
583
575
a fragment to be evaluated
@@ -612,12 +604,12 @@ def evaluate_presence_of_vertical_intervals(
612
604
:param intervals:
613
605
intervals (in semitones) from top to bottom
614
606
:param min_n_weighted_occurrences:
615
- minimal sum of weights of intervallic sonorities occurrences
607
+ minimum sum of weights of intervallic sonorities occurrences
616
608
:param regular_positions:
617
609
parameters of regular positions (for example, downbeats or relatively strong beats)
618
610
:param ad_hoc_positions:
619
- parameters of ad hoc positions which appear just once (for example, the beginning of
620
- the fragment or the 11th reference beat)
611
+ parameters of ad hoc positions which appear just once
612
+ (for example, the beginning of the fragment or the 11th reference beat)
621
613
:param position_weights:
622
614
mapping from position name to its weight
623
615
:return:
0 commit comments