-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdx7sheet.py
More file actions
335 lines (274 loc) · 12.6 KB
/
dx7sheet.py
File metadata and controls
335 lines (274 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
###########################################
# DX7 Voice Data Sheet Generator #
###########################################
# Description:
# A unified Python script that generates human-readable data sheets from Yamaha DX7
# 32-voice SysEx files (.syx).
#
# Features:
# - Interactive file selection
# - Choice between Single Patch Export or Batch Export (All 32)
# - Output formatting based on the "Dexed-Style" layout
# - CALCULATES FREQUENCIES CORRECTLY (Ratio & Fixed)
# - HIGH PRECISION DISPLAY (Matching Dexed)
#
# Author: Peter Berghoff / Soundplantage
# Version: 2.3 (High Precision Fixed Freq)
# Last Modified: 2026-02-12
#
# SPDX-License-Identifier: MIT
###########################################
# -*- coding: utf-8 -*-
import sys
import os
import re
import math
# --- Constants and Mapping Tables ---
NOTE_NAMES = [
'A-1', 'A#-1', 'B-1', 'C0', 'C#0', 'D0', 'D#0', 'E0', 'F0', 'F#0', 'G0', 'G#0',
'A0', 'A#0', 'B0', 'C1', 'C#1', 'D1', 'D#1', 'E1', 'F1', 'F#1', 'G1', 'G#1',
'A1', 'A#1', 'B1', 'C2', 'C#2', 'D2', 'D#2', 'E2', 'F2', 'F#2', 'G2', 'G#2',
'A2', 'A#2', 'B2', 'C3', 'C#3', 'D3', 'D#3', 'E3', 'F3', 'F#3', 'G3', 'G#3',
'A3', 'A#3', 'B3', 'C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4',
'A4', 'A#4', 'B4', 'C5', 'C#5', 'D5', 'D#5', 'E5', 'F5', 'F#5', 'G5', 'G#5',
'A6', 'A#6', 'B6', 'C7', 'C#7', 'D7', 'D#7', 'E7', 'F7', 'F#7', 'G7', 'G#7',
'A7', 'A#7', 'B7', 'C8'
]
CURVE_MODES = {0: '-LIN', 1: '-EXP', 2: '+EXP', 3: '+LIN'}
LFO_WAVES = {0: 'TRIANGLE', 1: 'SAW UP', 2: 'SAW DOWN', 3: 'SQUARE', 4: 'SINE', 5: 'S+HOLD'}
DX7_32_VOICE_HEADER = b'\xf0\x43\x00\x09\x20\x00'
SYSEX_SIZE = 4104
def parse_single_voice(data):
"""
Parses the 128 bytes of a single voice patch.
Calculates the actual frequency (Ratio or Hz) for display.
"""
params = {'ops': []}
for i in range(6):
offset = i * 17
op_data = data[offset : offset + 17]
op = {}
# Envelope (EG)
op['eg_rate'] = list(op_data[0:4])
op['eg_level'] = list(op_data[4:8])
# Keyboard Scaling
op['breakpoint'] = NOTE_NAMES[op_data[8]] if 0 <= op_data[8] <= 99 else 'N/A'
op['l_depth'] = op_data[9]
op['r_depth'] = op_data[10]
op['l_curve'] = CURVE_MODES[op_data[11] & 3]
op['r_curve'] = CURVE_MODES[(op_data[11] >> 2) & 3]
# Sensitivity & Rate Scaling
op['rate_scaling'] = op_data[12] & 0x07
op['amp_mod_sens'] = op_data[13] & 0x03
op['key_vel_sens'] = (op_data[13] >> 2) & 0x07
# Output Level
op['level'] = op_data[14]
# Oscillator Sektion
op['mode'] = 'FIX' if op_data[15] & 1 else 'RATIO'
# Frequenz Rohdaten
coarse_raw = op_data[15] >> 1
fine_raw = op_data[16]
op['coarse_display'] = coarse_raw
op['fine_raw'] = fine_raw
# --- BERECHNUNG DER ECHTEN FREQUENZ ---
if op['mode'] == 'RATIO':
# Im Ratio Mode ist Coarse 0 eigentlich 0.5
base_ratio = 0.5 if coarse_raw == 0 else float(coarse_raw)
op['coarse_display'] = base_ratio
# Formel: Coarse * (1 + Fine/100)
calculated_val = base_ratio * (1.0 + (fine_raw / 100.0))
op['freq_string'] = f"{calculated_val:.2f}" # z.B. "1.20"
else: # FIXED MODE (in Hz)
# User Info: Coarse stellt 1, 10, 100, 1000 Hz ein und wiederholt sich.
# Fine ist logarithmisch über diese Dekade.
# Formel: 10 ^ ( (Coarse % 4) + (Fine / 100) )
exponent = (coarse_raw % 4) + (fine_raw / 100.0)
calculated_val = math.pow(10, exponent)
# Formatierung: Dynamische Nachkommastellen ohne "Hz"
# Ziel: Maximale Ausnutzung der 7 Zeichen Spaltenbreite
if calculated_val >= 1000:
op['freq_string'] = f"{calculated_val:.2f}" # z.B. 2630.27
elif calculated_val >= 100:
op['freq_string'] = f"{calculated_val:.3f}" # z.B. 987.654
elif calculated_val >= 10:
op['freq_string'] = f"{calculated_val:.4f}" # z.B. 12.3456
else:
op['freq_string'] = f"{calculated_val:.5f}" # z.B. 1.69824
# Detune
op['detune'] = ((op_data[12] & 120) >> 3) - 7
params['ops'].append(op)
# Reverse ops to match 1-6 layout
params['ops'].reverse()
# Global Parameters
pitch_eg_data = data[102:110]
params['pitch_eg_rate'] = list(pitch_eg_data[0:4])
params['pitch_eg_level'] = list(pitch_eg_data[4:8])
params['algorithm'] = (data[110] & 0x1F) + 1
params['feedback'] = data[111] & 0x07
params['osc_sync'] = 'ON' if data[111] & 8 else 'OFF'
params['lfo_speed'] = data[112]
params['lfo_delay'] = data[113]
params['lfo_pmd'] = data[114]
params['lfo_amd'] = data[115]
params['lfo_sync'] = 'ON' if (data[116] & 0x01) else 'OFF'
params['lfo_wave'] = LFO_WAVES[(data[116] >> 1) & 0x07]
params['p_mod_sens'] = (data[116] >> 4) & 0x07
params['transpose'] = data[117] - 24
params['name'] = data[118:128].decode('ascii', errors='ignore').replace('\x00', '').strip()
return params
def create_op_row(label, values):
return f"{label:<14} " + " ".join(f"{str(v):<7}" for v in values)
def generate_datasheet(params, bank_name, voice_num):
ops = params['ops']
sheet = []
# Header
sheet.append("="*62)
sheet.append(" DX7 VOICE DATA SHEET by SOUNDPLANTAGE.COM")
sheet.append("="*62)
# Patch Name zuerst, dann Bank Name
sheet.append(f"Voice #{voice_num:02d}: {params['name']:<20} Bank: {bank_name}")
sheet.append("="*62)
sheet.append(f"ALGORITHM: {params['algorithm']:<4} FEEDBACK: {params['feedback']:<4} TRANSPOSE: {params['transpose']}")
sheet.append("-"*62)
# Operator Sektion
sheet.append(f"{'PARAM':<14} {'OP1':<7} {'OP2':<7} {'OP3':<7} {'OP4':<7} {'OP5':<7} {'OP6':<7}")
sheet.append("-" * 62)
# 1. Oscillator (VCO Ebene)
sheet.append(create_op_row("OSC MODE", [op['mode'] for op in ops]))
sheet.append(create_op_row("COARSE", [f"{op['coarse_display']}" for op in ops]))
sheet.append(create_op_row("FINE (FREQ)", [op['freq_string'] for op in ops]))
sheet.append(create_op_row("DETUNE", [f"{op['detune']:+d}" for op in ops]))
sheet.append("-" * 62)
# 2. Sens & Level (VCA Ebene)
sheet.append(create_op_row("AMP MOD SENS", [op['amp_mod_sens'] for op in ops]))
sheet.append(create_op_row("VEL SENS", [op['key_vel_sens'] for op in ops]))
sheet.append(create_op_row("OUT LEVEL", [op['level'] for op in ops]))
sheet.append("-" * 62)
# 3. Keyboard Scaling
sheet.append(create_op_row("BREAK POINT", [op['breakpoint'] for op in ops]))
sheet.append(create_op_row("L DEPTH", [op['l_depth'] for op in ops]))
sheet.append(create_op_row("R DEPTH", [op['r_depth'] for op in ops]))
sheet.append(create_op_row("L CURVE", [op['l_curve'] for op in ops]))
sheet.append(create_op_row("R CURVE", [op['r_curve'] for op in ops]))
sheet.append(create_op_row("RATE SCALING", [op['rate_scaling'] for op in ops]))
sheet.append("-" * 62)
# 4. Envelopes
for l in range(1, 5):
sheet.append(create_op_row(f"EG LEVEL {l}", [op['eg_level'][l-1] for op in ops]))
sheet.append(" " * 3)
for r in range(1, 5):
sheet.append(create_op_row(f"EG RATE {r}", [op['eg_rate'][r-1] for op in ops]))
# Modulation & Pitch
sheet.append("="*62)
sheet.append(" LFO, PITCH EG & SYNC")
sheet.append("="*62)
sheet.append(f"LFO WAVE: {params['lfo_wave']:<10} SPEED: {params['lfo_speed']:<5} DELAY: {params['lfo_delay']}")
sheet.append(f"PMD: {params['lfo_pmd']:<10} AMD: {params['lfo_amd']:<7} P MOD SENS: {params['p_mod_sens']}")
sheet.append(f"LFO SYNC: {params['lfo_sync']:<9} OSC SYNC: {params['osc_sync']}")
sheet.append("-" * 62)
# Pitch EG
p_rates = params['pitch_eg_rate']
p_levels = params['pitch_eg_level']
sheet.append(f"PITCH EG LEVEL: L1={p_levels[0]:<3} L2={p_levels[1]:<3} L3={p_levels[2]:<3} L4={p_levels[3]}")
sheet.append(f"PITCH EG RATE : R1={p_rates[0]:<3} R2={p_rates[1]:<3} R3={p_rates[2]:<3} R4={p_rates[3]}")
sheet.append("="*62)
return "\n".join(sheet)
def sanitize_filename(name):
name = name.replace('\x00', '').strip()
return re.sub(r'[\\/*?:"<>|]', "", name).strip()
def main():
# 1. Scan directory
syx_files = sorted([f for f in os.listdir('.') if f.lower().endswith('.syx')])
if not syx_files:
print("Error: No .syx files found in the current directory.")
sys.exit(1)
print("--- DX7 Voice Data Sheet Generator (Master) ---")
print("Available SysEx files:")
print("-" * 35)
for i, filename in enumerate(syx_files, 1):
print(f" {i:02d}: {filename}")
print("-" * 35)
# 2. Select File
file_choice = -1
while not (1 <= file_choice <= len(syx_files)):
try:
raw_choice = input(f"Which file to load? (1-{len(syx_files)}): ")
file_choice = int(raw_choice)
except (ValueError, TypeError):
pass
filepath = syx_files[file_choice - 1]
bank_name = os.path.basename(filepath)
try:
with open(filepath, 'rb') as f:
sysex_data = f.read()
except IOError as e:
print(f"Error reading the file: {e}")
sys.exit(1)
if len(sysex_data) != SYSEX_SIZE or not sysex_data.startswith(DX7_32_VOICE_HEADER):
print("Error: Invalid Yamaha DX7 32-Voice SysEx file.")
sys.exit(1)
voice_bulk_data = sysex_data[6:4102]
voices = [voice_bulk_data[i:i+128] for i in range(0, 4096, 128)]
# 3. Select Mode
print("\nFile loaded successfully.")
print("Choose operation mode:")
print(" 1: Export ALL 32 patches (Batch)")
print(" 2: Export SINGLE patch (Interactive)")
mode_choice = -1
while mode_choice not in [1, 2]:
try:
mode_choice = int(input("Selection (1 or 2): "))
except ValueError:
pass
# Create Output Directory
output_dir = "Sheet"
os.makedirs(output_dir, exist_ok=True)
# --- BATCH MODE ---
if mode_choice == 1:
print(f"\nProcessing all 32 voices from '{bank_name}'...")
print(f"Saving to directory: ./{output_dir}/")
for i in range(32):
voice_data = voices[i]
params = parse_single_voice(voice_data)
voice_num = i + 1
datasheet = generate_datasheet(params, bank_name, voice_num)
# Filename e.g., "01_E.PIANO 1.txt"
safe_name = sanitize_filename(params['name'])
filename = f"{voice_num:02d}_{safe_name}.txt"
full_path = os.path.join(output_dir, filename)
try:
with open(full_path, 'w', encoding='utf-8') as f:
f.write(datasheet)
print(f" Saved: {filename}")
except IOError as e:
print(f" Error saving {filename}: {e}")
print("\n--- Batch export complete! ---")
# --- SINGLE MODE ---
else:
voice_names = [v[118:128].decode('ascii', errors='ignore').strip() for v in voices]
print("-" * 50)
for i in range(0, 32, 2):
print(f" {i+1:02d}: {voice_names[i]:<10} {i+2:02d}: {voice_names[i+1]:<10}")
print("-" * 50)
voice_choice = -1
while not (1 <= voice_choice <= 32):
try:
voice_choice = int(input("Select patch number (1-32): "))
except ValueError:
pass
params = parse_single_voice(voices[voice_choice - 1])
datasheet = generate_datasheet(params, bank_name, voice_choice)
# Filename e.g., "E.PIANO 1.txt"
safe_name = sanitize_filename(params['name'])
filename = f"{safe_name}.txt"
full_path = os.path.join(output_dir, filename)
try:
with open(full_path, 'w', encoding='utf-8') as f:
f.write(datasheet)
print(f"\n--- Data sheet generated! ---")
print(datasheet)
print(f"\nSaved as: '{full_path}'")
except IOError as e:
print(f"\nError saving file: {e}")
if __name__ == '__main__':
main()