Spaces:
Sleeping
Sleeping
Update harmonic_engine.py
Browse files- harmonic_engine.py +47 -0
harmonic_engine.py
CHANGED
|
@@ -506,3 +506,50 @@ class MidiExporter:
|
|
| 506 |
files[lane] = fname
|
| 507 |
|
| 508 |
return files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
files[lane] = fname
|
| 507 |
|
| 508 |
return files
|
| 509 |
+
|
| 510 |
+
@staticmethod
|
| 511 |
+
def export_combined(progression_data, filename_prefix="session"):
|
| 512 |
+
"""Export combined MIDI with both LH and RH as separate tracks"""
|
| 513 |
+
mid = mido.MidiFile(ticks_per_beat=480)
|
| 514 |
+
|
| 515 |
+
# Track 1: LH/Bass
|
| 516 |
+
track_lh = mido.MidiTrack()
|
| 517 |
+
mid.tracks.append(track_lh)
|
| 518 |
+
track_lh.append(mido.MetaMessage('track_name', name='LH/Bass'))
|
| 519 |
+
|
| 520 |
+
for chord_data in progression_data:
|
| 521 |
+
notes = chord_data['lh']
|
| 522 |
+
velocity = 70
|
| 523 |
+
|
| 524 |
+
for n in notes:
|
| 525 |
+
n = max(0, min(127, n))
|
| 526 |
+
track_lh.append(mido.Message('note_on', note=n, velocity=velocity, time=0))
|
| 527 |
+
|
| 528 |
+
if notes:
|
| 529 |
+
track_lh.append(mido.Message('note_off', note=max(0, min(127, notes[0])), velocity=0, time=1920))
|
| 530 |
+
for n in notes[1:]:
|
| 531 |
+
n = max(0, min(127, n))
|
| 532 |
+
track_lh.append(mido.Message('note_off', note=n, velocity=0, time=0))
|
| 533 |
+
|
| 534 |
+
# Track 2: RH/Chords
|
| 535 |
+
track_rh = mido.MidiTrack()
|
| 536 |
+
mid.tracks.append(track_rh)
|
| 537 |
+
track_rh.append(mido.MetaMessage('track_name', name='RH/Chords'))
|
| 538 |
+
|
| 539 |
+
for chord_data in progression_data:
|
| 540 |
+
notes = chord_data['rh']
|
| 541 |
+
velocity = 85
|
| 542 |
+
|
| 543 |
+
for n in notes:
|
| 544 |
+
n = max(0, min(127, n))
|
| 545 |
+
track_rh.append(mido.Message('note_on', note=n, velocity=velocity, time=0))
|
| 546 |
+
|
| 547 |
+
if notes:
|
| 548 |
+
track_rh.append(mido.Message('note_off', note=max(0, min(127, notes[0])), velocity=0, time=1920))
|
| 549 |
+
for n in notes[1:]:
|
| 550 |
+
n = max(0, min(127, n))
|
| 551 |
+
track_rh.append(mido.Message('note_off', note=n, velocity=0, time=0))
|
| 552 |
+
|
| 553 |
+
fname = f"{filename_prefix}_COMPLETE.mid"
|
| 554 |
+
mid.save(fname)
|
| 555 |
+
return fname
|