# -----------------------------------------------------------
# make_horizons_call.py – generates “Horizon's Call”
# Inspired by U2’s “Where the Streets Have No Name”
# Requires: pretty_midi, numpy, soundfile, mido, (optional) fluidsynth
# -----------------------------------------------------------
import pretty_midi as pm
import numpy as np
import os, subprocess, sys
BPM = 120 # beats per minute
BEAT_LEN = 60.0 / BPM # seconds per quarter
SECTION_BARS = 15 # 30 seconds = 15 bars at 120 BPM
TOTAL_BARS = 90 # 3 minutes
KEY = 'E' # tonal center
OUT_MIDI = 'horizons_call_3min.mid'
SOUNDFONT = 'GeneralUser.sf2' # put your .sf2 path here
# Chord progression per bar: I – V – vi – IV (E B C#m A)
CHORDS = [
[pm.note_name_to_number('E4'),
pm.note_name_to_number('B4'),
pm.note_name_to_number('E5')],
[pm.note_name_to_number('B3'),
pm.note_name_to_number('F#4'),
pm.note_name_to_number('B4')],
[pm.note_name_to_number('C#4'),
pm.note_name_to_number('G#4'),
pm.note_name_to_number('C#5')],
[pm.note_name_to_number('A3'),
pm.note_name_to_number('E4'),
pm.note_name_to_number('A4')]
]
def add_drum_pattern(drum_track, start_beat, bars):
for bar in range(bars):
bar_start = start_beat + bar*4
# Kick on 1, 3
for beat in [0, 2]:
t0 = (bar_start + beat) * BEAT_LEN
drum_track.notes.append(pm.Note(velocity=100, pitch=36,
start=t0, end=t0+0.05))
# Snare on 2, 4
for beat in [1, 3]:
t0 = (bar_start + beat) * BEAT_LEN
drum_track.notes.append(pm.Note(velocity=100, pitch=38,
start=t0, end=t0+0.05))
# 8th-note hi-hat
for sub in range(8):
t0 = (bar_start + sub*0.5) * BEAT_LEN
drum_track.notes.append(pm.Note(velocity=70, pitch=42,
start=t0, end=t0+0.03))
def main():
song = pm.PrettyMIDI(initial_tempo=BPM)
# Instruments -------------------------------------------------
guitar = pm.Instrument(program=29, name='Delayed Guitar') # Overdriven Guitar
bass = pm.Instrument(program=33, name='Electric Bass')
pad = pm.Instrument(program=91, name='Warm Pad')
drums = pm.Instrument(program=0, name='Drums', is_drum=True)
# Build the song ---------------------------------------------
for bar in range(TOTAL_BARS):
chord = CHORDS[bar % 4]
bar_start_beat = bar * 4
# Guitar: arpeggiated eighth-notes
for sub in range(8):
note = chord[sub % len(chord)]
t0 = (bar_start_beat + sub*0.5) * BEAT_LEN
t1 = t0 + 0.25
guitar.notes.append(pm.Note(velocity=90, pitch=note,
start=t0, end=t1))
# Bass: root quarters
bass_note = chord[0] - 24
for beat in range(4):
t0 = (bar_start_beat + beat) * BEAT_LEN
bass.notes.append(pm.Note(velocity=100, pitch=bass_note,
start=t0, end=t0+0.45))
# Pad: whole-note swell
t0 = bar_start_beat * BEAT_LEN
pad.notes.append(pm.Note(velocity=60, pitch=chord[0],
start=t0, end=t0+4*BEAT_LEN))
# Drums
add_drum_pattern(drums, bar_start_beat, 1)
# Add instruments to song
for inst in [guitar, bass, pad, drums]:
song.instruments.append(inst)
# Write MIDI
song.write(OUT_MIDI)
print(f'✔ Wrote {OUT_MIDI}')
# ----------------------------------------------------------------
# Optional: render to audio (requires FluidSynth)
# ----------------------------------------------------------------
if os.path.isfile(SOUNDFONT):
wav_file = OUT_MIDI.replace('.mid', '.wav')
print('Rendering to audio…')
# FluidSynth CLI command
subprocess.run(['fluidsynth', '-ni', SOUNDFONT, OUT_MIDI,
'-F', wav_file, '-r', '44100'],
check=True)
print(f'✔ Rendered {wav_file}')
else:
print('⚠ SoundFont not found -> skipping audio render.\n'
' (Edit SOUNDFONT variable to point to a valid .sf2)')
# ----------------------------------------------------------------
# Split 30-second stems
# ----------------------------------------------------------------
try:
import soundfile as sf
print('Splitting 30-second stems…')
data, sr = sf.read(wav_file)
os.makedirs('stems', exist_ok=True)
for i, t in enumerate(range(30, 121, 30), start=1):
out = f'stems/horizons_call_0-{t}s.wav'
sf.write(out, data[:int(sr*t)], sr)
print(f' • {out}')
except Exception as e:
print('Stem split skipped (need soundfile & rendered WAV).', e)
if __name__ == '__main__':
main()