|
|
|
@@ -0,0 +1,170 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Build this fixture's authoring manifest. AudioBankPacker serializes the bank."""
|
|
|
|
|
import hashlib
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1] / 'music'
|
|
|
|
|
PPQ = 960
|
|
|
|
|
TEMPO = 357143 # nearest integer microseconds/quarter to 168 BPM
|
|
|
|
|
MINOR = [0, 2, 3, 5, 7, 8, 10]
|
|
|
|
|
MAJOR = [0, 2, 4, 5, 7, 9, 11]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_json(name, value):
|
|
|
|
|
(ROOT / name).write_text(json.dumps(value, indent=2) + '\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def degree(sd, octave):
|
|
|
|
|
accidental = sd.count('#') - sd.count('b')
|
|
|
|
|
return 71 + MINOR[int(sd[-1]) - 1] + accidental + octave * 12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chord_notes(chord):
|
|
|
|
|
scale = MAJOR if chord['borrowed'] == 'major' else MINOR
|
|
|
|
|
first = chord['root'] - 1
|
|
|
|
|
notes = [47 + scale[(first + step) % 7] + 12 * ((first + step) // 7)
|
|
|
|
|
for step in range(0, 6 if chord['type'] == 5 else 8, 2)]
|
|
|
|
|
for _ in range(chord['inversion']):
|
|
|
|
|
notes.append(notes.pop(0) + 12)
|
|
|
|
|
return notes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
source = json.loads((ROOT / 'transcription.json').read_text())
|
|
|
|
|
sf = json.loads((ROOT / 'soundfont-source.json').read_text())
|
|
|
|
|
assert len(source['notes']) == 90 and len(source['chords']) == 20
|
|
|
|
|
assert source['source_ppq_inferred_from_paired_beat_tick_fields'] == 480
|
|
|
|
|
duration = source['source_duration_ticks'] * 2
|
|
|
|
|
assert duration == 72 * PPQ
|
|
|
|
|
samples = []
|
|
|
|
|
for sample in sf['samples']:
|
|
|
|
|
samples.append({'file': sample['file'], 'codec': 'PCM16_LE'})
|
|
|
|
|
# Samples retain their original rate and PCM. Only cartridge encoding changes.
|
|
|
|
|
for i in [3, 4, 5, 7]:
|
|
|
|
|
samples[i]['codec'] = 'IMA_ADPCM_WAV4'
|
|
|
|
|
for i in [0, 1, 2, 6]:
|
|
|
|
|
start, end = sf['samples'][i]['validated_loop_frames']
|
|
|
|
|
samples[i].update(loop_start=start, loop_end=end)
|
|
|
|
|
|
|
|
|
|
instruments = []
|
|
|
|
|
mapping = []
|
|
|
|
|
|
|
|
|
|
def instrument(identifier, sample_index, *, root=None, gain=128, pan=128,
|
|
|
|
|
attack=2, decay=0, sustain=65535, release=12, looping=False,
|
|
|
|
|
vibrato=0, send=0, preset=None, articulation=''):
|
|
|
|
|
sample = sf['samples'][sample_index]
|
|
|
|
|
raw = sf['instruments'][preset] if preset is not None else None
|
|
|
|
|
inst = dict(id=identifier, sample=sample_index, low=0, high=127,
|
|
|
|
|
root=sample['root_note_midi'] if root is None else root,
|
|
|
|
|
tuning_cents=sample['pitch_correction_cents'], gain=gain, pan=pan,
|
|
|
|
|
attack_ms=attack, decay_ms=decay, sustain=sustain,
|
|
|
|
|
release_ms=release, looping=looping, curve=1,
|
|
|
|
|
vibrato_millihz=5000 if vibrato else 0,
|
|
|
|
|
vibrato_cents=vibrato, send=send)
|
|
|
|
|
instruments.append(inst)
|
|
|
|
|
mapping.append({'instrument_id': identifier, 'sample_name': sample['name'],
|
|
|
|
|
'source_sample_id': sample['sample_id'],
|
|
|
|
|
'source_file_pcm_sha256': sample['pcm_sha256'],
|
|
|
|
|
'source_instrument': raw, 'target': inst,
|
|
|
|
|
'arrangement_articulation': articulation})
|
|
|
|
|
|
|
|
|
|
instrument(0, 0, gain=180, release=9, looping=True, vibrato=15, send=6500, preset=0,
|
|
|
|
|
articulation='Lead: source root/rate/correction and 5 Hz/15-cent LFO; clamp invalid negative SF2 sustain attenuation to zero; 2 ms attack/9 ms release prevent clicks. Mod-envelope/delay stages are not emulated.')
|
|
|
|
|
instrument(1, 2, gain=95, release=8, looping=True, preset=2,
|
|
|
|
|
articulation='Bass: source root/rate and loop; replace source hold/modulation envelope with short articulated eighth notes and 2 ms attack/8 ms release.')
|
|
|
|
|
instrument(2, 1, gain=52, release=8, looping=True, preset=1,
|
|
|
|
|
articulation='Rhythm: source root/rate/loop/correction. Gain is a musical mix trim; no SF2 mod-envelope/delayed LFO. Three/four chord tones retain harmony and inversion.')
|
|
|
|
|
instrument(3, 3, root=36, gain=165, attack=0, release=4, preset=3,
|
|
|
|
|
articulation='Kick: Drum Kit root override 36; one-shot PCM envelope, no loop.')
|
|
|
|
|
instrument(4, 4, root=38, gain=115, attack=0, release=6, preset=3,
|
|
|
|
|
articulation='Heavy snare: Drum Kit root override 38; one-shot, no loop.')
|
|
|
|
|
instrument(5, 5, root=42, gain=52, pan=178, attack=0, release=4, preset=3,
|
|
|
|
|
articulation='Closed hi-hat: Drum Kit root override 42; one-shot, explicit short note-off; no source hold stage.')
|
|
|
|
|
instrument(6, 6, root=49, gain=65, pan=70, attack=0, decay=900,
|
|
|
|
|
sustain=0, release=90, looping=True, preset=3,
|
|
|
|
|
articulation='Crash: Drum Kit root override 49 and source loop; 900 ms exponential decay replaces SF2 hold/decay for this arrangement.')
|
|
|
|
|
instrument(7, 7, root=41, gain=105, pan=90, attack=0, release=6, preset=3,
|
|
|
|
|
articulation='Tom: Drum Kit root override 41; one-shot, fill notes select pitch.')
|
|
|
|
|
events = []
|
|
|
|
|
note_id = 0
|
|
|
|
|
|
|
|
|
|
def note(tick, length, track, inst, pitch, velocity):
|
|
|
|
|
nonlocal note_id
|
|
|
|
|
note_id += 1
|
|
|
|
|
end = min(duration - 1, tick + length)
|
|
|
|
|
assert 0 <= tick < end < duration
|
|
|
|
|
events.append(dict(tick=tick, kind=1, track=track, a=note_id, b=inst, c=pitch, d=velocity))
|
|
|
|
|
events.append(dict(tick=end, kind=2, track=track, a=note_id))
|
|
|
|
|
|
|
|
|
|
for n in source['notes']:
|
|
|
|
|
note(n['startTick'] * 2, n['durationTicks'] * 2, 0, 0,
|
|
|
|
|
degree(n['sd'], n['octave']), 235)
|
|
|
|
|
|
|
|
|
|
voicings = []
|
|
|
|
|
for chord in source['chords']:
|
|
|
|
|
start, length = chord['startTick'] * 2, chord['durationTicks'] * 2
|
|
|
|
|
tones = chord_notes(chord)
|
|
|
|
|
bass = tones[0]
|
|
|
|
|
while bass >= 47:
|
|
|
|
|
bass -= 12
|
|
|
|
|
while min(tones) < 54:
|
|
|
|
|
tones = [n + 12 for n in tones]
|
|
|
|
|
voicings.append(dict(source=chord, target_tones=tones, bass=bass))
|
|
|
|
|
# Each chord keeps its authored harmony; repeated stabs add rock articulation.
|
|
|
|
|
for beat in range(0, length, PPQ * 4):
|
|
|
|
|
for offset in [0, PPQ, PPQ * 3 // 2, PPQ * 5 // 2, PPQ * 3]:
|
|
|
|
|
tick = start + beat + offset
|
|
|
|
|
if tick >= start + length:
|
|
|
|
|
continue
|
|
|
|
|
for voice, pitch in enumerate(tones):
|
|
|
|
|
note(tick, min(PPQ * 2 // 5, start + length - tick),
|
|
|
|
|
2 + voice, 2, pitch, 180 if offset == 0 else 145)
|
|
|
|
|
for offset in range(0, length, PPQ // 2):
|
|
|
|
|
pitch = bass + (12 if offset % (PPQ * 4) == PPQ * 5 // 2 else 0)
|
|
|
|
|
note(start + offset, PPQ * 2 // 5, 1, 1, pitch, 215 if offset % PPQ == 0 else 190)
|
|
|
|
|
|
|
|
|
|
for bar in range(18):
|
|
|
|
|
at = bar * PPQ * 4
|
|
|
|
|
for eighth in range(8):
|
|
|
|
|
note(at + eighth * PPQ // 2, PPQ // 5, 8, 5, 42,
|
|
|
|
|
190 if eighth % 2 == 0 else 135)
|
|
|
|
|
for offset in [0, PPQ * 3 // 2, PPQ * 2, PPQ * 7 // 2]:
|
|
|
|
|
note(at + offset, PPQ // 2, 6, 3, 36, 235)
|
|
|
|
|
for offset in [PPQ, PPQ * 3]:
|
|
|
|
|
note(at + offset, PPQ * 3 // 4, 7, 4, 38, 235)
|
|
|
|
|
if bar in [0, 4, 8, 12, 16]:
|
|
|
|
|
note(at, PPQ * 2, 9, 6, 49, 200)
|
|
|
|
|
if bar in [3, 7, 11, 15, 17]:
|
|
|
|
|
for i in range(3):
|
|
|
|
|
note(at + PPQ * 3 + i * PPQ // 3, PPQ // 3, 10, 7, 45 - i * 2, 180 + 15 * i)
|
|
|
|
|
|
|
|
|
|
# Stereo placement is shared by each logical track, including four-tone sevenths.
|
|
|
|
|
for track, pan in [(2, 52), (3, 100), (4, 192), (5, 214)]:
|
|
|
|
|
events.append(dict(tick=0, kind=5, track=track, c=pan))
|
|
|
|
|
# Stable ties: note-off precedes note-on at the same tick, so repeated notes release correctly.
|
|
|
|
|
events.sort(key=lambda e: (e['tick'], 0 if e['kind'] == 2 else 1))
|
|
|
|
|
manifest = dict(name='Storm Eagle — Stress Console arrangement', ppq=PPQ,
|
|
|
|
|
tempo_us_per_quarter=TEMPO, duration_ticks=duration,
|
|
|
|
|
loop_start_tick=0, track_count=11, samples=samples,
|
|
|
|
|
instruments=instruments, events=events)
|
|
|
|
|
write_json('song.json', manifest)
|
|
|
|
|
write_json('instrument-mapping.json', {
|
|
|
|
|
'source': 'User-supplied MegaManX-SF-3.0.sf2 by CliffyJiffy (SF2 INFO)',
|
|
|
|
|
'source_sha256': sf['source_sf2_sha256'], 'instruments': mapping,
|
|
|
|
|
'conversion': 'Source root, sample rate, pitch correction, selected Drum Kit overrides and loop bounds retained. The sign of pitch correction adds to playback cents. Gains, ADSR and articulation are explicit arrangement choices. This is not a complete SF2 conversion.',
|
|
|
|
|
'pitch_reference': 'https://github.com/FluidSynth/fluidsynth/blob/master/src/synth/fluid_voice.c (root key minus sample pitch correction)',
|
|
|
|
|
'gain_and_envelope': 'SF2 has modulation/hold stages unavailable in this machine and negative sustain attenuation on melodic patches. Retain raw generators in soundfont-source.json; use declared target ADSR/mix trims rather than emulating unsupported stages.',
|
|
|
|
|
'voicings': voicings, 'tempo_bpm_requested': source['bpm'],
|
|
|
|
|
'tempo_microseconds_per_quarter': TEMPO,
|
|
|
|
|
'actual_bpm': 60_000_000 / TEMPO,
|
|
|
|
|
'loop_seconds': duration * TEMPO / (PPQ * 1_000_000),
|
|
|
|
|
'source_melody_notes': len(source['notes']), 'source_chords': len(source['chords']),
|
|
|
|
|
'total_note_ons': note_id,
|
|
|
|
|
'authoring_sha256': hashlib.sha256((ROOT / 'song.json').read_bytes()).hexdigest(),
|
|
|
|
|
})
|
|
|
|
|
print(f'Prepared {note_id} notes, {len(events)} events, {len(samples)} samples; {duration} ticks')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|