Show dimension markup for first chord using refs within same chord
- Add _find_ref_in_same_chord() to find adjacent pitches within the same chord - Update first chord handling to show refs to other pitches in chord
This commit is contained in:
parent
658837b83e
commit
a0723e5ae3
|
|
@ -387,6 +387,33 @@ def _find_ref_and_dim_diff(
|
|||
return adjacent[0]
|
||||
|
||||
|
||||
def _find_ref_in_same_chord(pitch_idx: int, chord_pitches: list) -> tuple[int, int]:
|
||||
"""Find ref (other pitch index) and dim_diff within the same chord.
|
||||
|
||||
Args:
|
||||
pitch_idx: index of the current pitch in the chord
|
||||
chord_pitches: list of hs_arrays for all pitches in the chord
|
||||
|
||||
Returns:
|
||||
(ref, dim_diff) tuple where ref is index of adjacent pitch in same chord
|
||||
"""
|
||||
current_hs = chord_pitches[pitch_idx]
|
||||
adjacent = []
|
||||
|
||||
for idx, other_hs in enumerate(chord_pitches):
|
||||
if idx == pitch_idx:
|
||||
continue
|
||||
if _is_adjacent(current_hs, other_hs):
|
||||
dim_diff = _compute_dim_diff(current_hs, other_hs)
|
||||
adjacent.append((idx, dim_diff))
|
||||
|
||||
if not adjacent:
|
||||
return -1, 0
|
||||
|
||||
adjacent.sort(key=lambda x: abs(x[1]))
|
||||
return adjacent[0]
|
||||
|
||||
|
||||
def output_chords_to_music_data(chords, fundamental=55, chord_duration=4):
|
||||
"""Convert output_chords.json format to generic music data.
|
||||
|
||||
|
|
@ -425,8 +452,7 @@ def output_chords_to_music_data(chords, fundamental=55, chord_duration=4):
|
|||
current_hs_array = current_hs[voice_idx]
|
||||
|
||||
if prev_chord is None:
|
||||
ref = -1
|
||||
dim_diff = 0
|
||||
ref, dim_diff = _find_ref_in_same_chord(voice_idx, current_hs)
|
||||
elif current_hs_array == prev_chord[voice_idx]:
|
||||
ref = -1
|
||||
dim_diff = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue