File size: 1,680 Bytes
5ed6698
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
测试可视化功能
"""

import os
from visualize_output import create_individual_voice_scores, convert_midi_to_jianpu

def test_visualize():
    """测试可视化功能"""
    output_dir = "output"
    midi_path = os.path.join(output_dir, "four_voice_score.mid")
    
    if not os.path.exists(midi_path):
        print(f"错误:MIDI文件 {midi_path} 不存在")
        return False
    
    print("测试简谱转换...")
    # 测试简谱转换
    test_notes = [60, 62, 64, 65, 67, 69, 71, 72]  # C4, D4, E4, F4, G4, A4, B4, C5
    for note in test_notes:
        jianpu = convert_midi_to_jianpu(note)
        print(f"MIDI {note} -> 简谱 {jianpu}")
    
    print("\n测试各声部谱子生成...")
    try:
        success = create_individual_voice_scores(midi_path, output_dir)
        if success:
            print("✅ 各声部谱子生成成功!")
            
            # 检查生成的文件
            voice_files = ['soprano_score.png', 'alto_score.png', 'tenor_score.png', 'bass_score.png']
            for voice_file in voice_files:
                file_path = os.path.join(output_dir, voice_file)
                if os.path.exists(file_path):
                    size = os.path.getsize(file_path)
                    print(f"  ✅ {voice_file}: {size:,} bytes")
                else:
                    print(f"  ❌ {voice_file}: 未生成")
            
            return True
        else:
            print("❌ 各声部谱子生成失败")
            return False
    except Exception as e:
        print(f"❌ 生成过程中出错: {e}")
        return False

if __name__ == "__main__":
    test_visualize()