Skip to content

Commit e7f034e

Browse files
committed
NEW
1 parent 7caa64b commit e7f034e

3 files changed

Lines changed: 187 additions & 0 deletions

File tree

3.03 MB
Binary file not shown.

src/pkg/Fymew/backup/cover.jpg

161 KB
Loading

src/pkg/Fymew/backup/mu.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
"""
2+
伤感回忆钢琴曲 - 使用mingus生成(扩展版)
3+
需要安装: pip install mingus
4+
"""
5+
6+
from mingus.containers import Note, NoteContainer, Track, Composition
7+
from mingus.midi import midi_file_out
8+
import mingus.core.chords as chords
9+
10+
# 创建作曲
11+
composition = Composition()
12+
composition.set_author("AI Composer")
13+
composition.set_title("Memories in Rain (雨中回忆) - Extended")
14+
15+
# 创建左右手音轨
16+
right_hand = Track()
17+
left_hand = Track()
18+
19+
# 设置速度 (BPM)
20+
bpm = 65
21+
22+
# 定义和弦进行(左手伴奏)- 扩展版
23+
chord_progression = [
24+
# 第一部分:引子与主题
25+
('Am', 4), ('F', 4), ('C', 4), ('G', 4),
26+
('Am', 4), ('Dm', 4), ('E7', 4), ('Am', 4),
27+
('F', 4), ('G', 4), ('Em', 4), ('Am', 4),
28+
('Dm', 4), ('G', 4), ('C', 4), ('Am', 4),
29+
30+
# 第二部分:发展与回忆
31+
('Am', 4), ('F', 4), ('C', 4), ('G', 4),
32+
('Am', 4), ('Dm', 4), ('E7', 4), ('Am', 4),
33+
('F', 4), ('G', 4), ('Em', 4), ('Am', 4),
34+
('Dm', 4), ('G', 4), ('C', 4), ('E7', 4),
35+
36+
# 第三部分:变奏(新增)
37+
('Am', 4), ('C', 4), ('F', 4), ('Dm', 4),
38+
('Bdim', 4), ('E7', 4), ('Am', 4), ('Am', 4),
39+
('F', 4), ('G', 4), ('C', 4), ('Am', 4),
40+
('Dm', 4), ('E7', 4), ('Am', 4), ('Am', 4),
41+
42+
# 第四部分:情感高潮(新增)
43+
('F', 4), ('G', 4), ('Am', 4), ('Am', 4),
44+
('Dm', 4), ('E7', 4), ('Am', 4), ('C', 4),
45+
('F', 4), ('G', 4), ('Em', 4), ('Am', 4),
46+
('Dm', 4), ('G', 4), ('C', 4), ('Am', 4),
47+
]
48+
49+
# 右手旋律音符
50+
melody_phrases = [
51+
# === 第一部分:引子与主题 ===
52+
# 引子 - 孤独的开始
53+
[('A-4', 4), ('C-5', 4), ('E-5', 4), ('A-5', 8), ('G-5', 8), ('E-5', 4)],
54+
[('F-5', 4), ('E-5', 8), ('D-5', 8), ('C-5', 4), ('A-4', 4)],
55+
[('G-4', 4), ('B-4', 4), ('D-5', 4), ('E-5', 2)],
56+
[('E-5', 8), ('D-5', 8), ('C-5', 8), ('B-4', 8), ('A-4', 4), ('C-5', 4)],
57+
58+
# 主题 - 回忆涌现
59+
[('A-5', 8), ('G-5', 8), ('E-5', 4), ('C-5', 8), ('D-5', 8), ('E-5', 4)],
60+
[('F-5', 4), ('A-5', 8), ('G-5', 8), ('F-5', 4), ('D-5', 4)],
61+
[('E-5', 8), ('F-5', 8), ('E-5', 8), ('D-5', 8), ('C-5', 4), ('B-4', 4)],
62+
[('A-4', 4), ('C-5', 8), ('E-5', 8), ('A-5', 2)],
63+
64+
# 发展 - 情绪高涨
65+
[('C-6', 8), ('B-5', 8), ('A-5', 4), ('G-5', 4), ('F-5', 4)],
66+
[('G-5', 4), ('E-5', 8), ('F-5', 8), ('D-5', 4), ('E-5', 4)],
67+
[('E-5', 8), ('D-5', 8), ('C-5', 4), ('B-4', 4), ('A-4', 4)],
68+
[('A-4', 4), ('C-5', 4), ('E-5', 4), ('A-5', 4)],
69+
70+
# 回忆片段 - 温柔回想
71+
[('D-5', 4), ('F-5', 8), ('E-5', 8), ('D-5', 4), ('C-5', 4)],
72+
[('B-4', 4), ('D-5', 4), ('G-5', 4), ('F-5', 8), ('E-5', 8)],
73+
[('C-5', 4), ('E-5', 4), ('G-5', 8), ('F-5', 8), ('E-5', 4)],
74+
[('E-5', 8), ('D-5', 8), ('C-5', 4), ('B-4', 4), ('A-4', 4)],
75+
76+
# === 第二部分:深入回忆(优化旋律流畅度)===
77+
[('A-4', 4), ('C-5', 4), ('E-5', 4), ('A-5', 8), ('G-5', 8)],
78+
[('F-5', 4), ('E-5', 4), ('D-5', 4), ('C-5', 4)],
79+
[('G-4', 4), ('B-4', 4), ('D-5', 4), ('E-5', 4)],
80+
[('E-5', 4), ('D-5', 4), ('C-5', 4), ('B-4', 4)],
81+
82+
[('A-4', 4), ('C-5', 4), ('E-5', 4), ('G-5', 8), ('F-5', 8)],
83+
[('F-5', 4), ('E-5', 4), ('D-5', 4), ('F-5', 4)],
84+
[('E-5', 4), ('D-5', 4), ('C-5', 4), ('B-4', 4)],
85+
[('C-5', 4), ('B-4', 4), ('A-4', 2)],
86+
87+
# === 第三部分:变奏(新增)===
88+
# 更加细腻的情感表达
89+
[('A-5', 8), ('B-5', 8), ('C-6', 4), ('B-5', 8), ('A-5', 8), ('G-5', 4)],
90+
[('E-5', 4), ('G-5', 8), ('F-5', 8), ('E-5', 4), ('D-5', 4)],
91+
[('C-5', 8), ('D-5', 8), ('E-5', 4), ('D-5', 8), ('C-5', 8), ('B-4', 4)],
92+
[('A-4', 4), ('C-5', 4), ('E-5', 4), ('A-5', 4)],
93+
94+
[('F-5', 4), ('E-5', 8), ('D-5', 8), ('C-5', 4), ('A-4', 4)],
95+
[('B-4', 4), ('D-5', 4), ('G-5', 8), ('F-5', 8), ('E-5', 4)],
96+
[('A-5', 8), ('G-5', 8), ('E-5', 4), ('C-5', 4), ('A-4', 4)],
97+
[('E-5', 8), ('D-5', 8), ('C-5', 4), ('B-4', 4), ('A-4', 4)],
98+
99+
# === 第四部分:情感高潮(新增)===
100+
[('C-6', 4), ('B-5', 8), ('A-5', 8), ('G-5', 4), ('F-5', 4)],
101+
[('E-5', 4), ('F-5', 4), ('G-5', 8), ('A-5', 8), ('E-5', 4)],
102+
[('D-5', 4), ('E-5', 4), ('F-5', 4), ('E-5', 8), ('D-5', 8)],
103+
[('C-5', 4), ('E-5', 8), ('D-5', 8), ('C-5', 4), ('A-4', 4)],
104+
105+
# 渐弱过渡
106+
[('F-5', 8), ('E-5', 8), ('D-5', 4), ('C-5', 4), ('B-4', 4)],
107+
[('B-4', 4), ('C-5', 4), ('D-5', 4), ('E-5', 4)],
108+
[('E-5', 8), ('D-5', 8), ('C-5', 4), ('B-4', 4), ('A-4', 4)],
109+
[('C-5', 8), ('B-4', 8), ('A-4', 4), ('E-4', 4), ('A-4', 4)],
110+
]
111+
112+
def add_left_hand_pattern(track, chord_name, duration_per_note, variation=0):
113+
"""添加左手分解和弦伴奏,支持不同变化"""
114+
try:
115+
chord_notes = chords.from_shorthand(chord_name)
116+
if len(chord_notes) >= 3:
117+
if variation == 0:
118+
# 标准分解和弦
119+
bass = Note(chord_notes[0], 3)
120+
track.add_notes(bass, duration_per_note * 2)
121+
122+
nc1 = NoteContainer([Note(chord_notes[1], 3), Note(chord_notes[2], 4)])
123+
track.add_notes(nc1, duration_per_note)
124+
125+
nc2 = NoteContainer([Note(chord_notes[0], 4), Note(chord_notes[2], 4)])
126+
track.add_notes(nc2, duration_per_note)
127+
elif variation == 1:
128+
# 和弦型伴奏(情感高潮处)
129+
bass = Note(chord_notes[0], 3)
130+
track.add_notes(bass, duration_per_note)
131+
132+
nc = NoteContainer([Note(chord_notes[0], 4), Note(chord_notes[1], 4), Note(chord_notes[2], 4)])
133+
track.add_notes(nc, duration_per_note * 3)
134+
except:
135+
track.add_notes(None, duration_per_note * 4)
136+
137+
# 生成音乐
138+
print("正在创作《雨中回忆 - 扩展版》...")
139+
print("结构:引子 → 主题 → 发展 → 回忆 → 变奏 → 高潮 → 尾声")
140+
141+
# 遍历每个小节
142+
for i, (chord_name, duration) in enumerate(chord_progression):
143+
# 在高潮部分使用不同的伴奏型
144+
variation = 1 if i >= 32 else 0
145+
146+
# 左手:和弦伴奏
147+
add_left_hand_pattern(left_hand, chord_name, 8, variation)
148+
149+
# 右手:旋律
150+
if i < len(melody_phrases):
151+
for note_name, note_duration in melody_phrases[i]:
152+
right_hand.add_notes(Note(note_name), note_duration)
153+
else:
154+
right_hand.add_notes(None, 1)
155+
156+
# 尾声 - 渐弱消失
157+
print("添加尾声...")
158+
ending_melody = [
159+
('E-5', 8), ('C-5', 8), ('A-4', 4), ('C-5', 4), ('E-5', 4),
160+
('A-5', 8), ('G-5', 8), ('E-5', 4), ('C-5', 4), ('A-4', 4),
161+
('E-5', 4), ('D-5', 4), ('C-5', 4), ('B-4', 4),
162+
('A-4', 2), ('C-5', 4), ('E-4', 2), ('A-4', 1)
163+
]
164+
for note_name, note_duration in ending_melody:
165+
right_hand.add_notes(Note(note_name), note_duration)
166+
167+
# 左手:结束和弦
168+
left_hand.add_notes(Note('A-3'), 4)
169+
left_hand.add_notes(Note('E-3'), 4)
170+
left_hand.add_notes(Note('C-3'), 4)
171+
left_hand.add_notes(NoteContainer([Note('A-2'), Note('E-3'), Note('A-3')]), 1)
172+
173+
# 添加音轨到作曲
174+
composition.add_track(right_hand)
175+
composition.add_track(left_hand)
176+
177+
# 导出MIDI文件
178+
output_file = "memories_in_rain_extended.mid"
179+
midi_file_out.write_Composition(output_file, composition, bpm=bpm)
180+
181+
print(f"\n✓ MIDI文件已生成: {output_file}")
182+
print(f" 速度: {bpm} BPM")
183+
print(f" 调性: A小调")
184+
print(f" 时长: 约2分钟")
185+
print(f" 段落: 7个部分,更丰富的情感层次")
186+
print(f"\n请使用MIDI播放器播放此文件")
187+
print("推荐播放器: Windows Media Player, VLC, MuseScore, GarageBand等")

0 commit comments

Comments
 (0)