Skip to content

Commit

Permalink
Add more midi signals, trying to reduce delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Independent-Dreamer committed Nov 22, 2022
1 parent ccb2c66 commit b6a9941
Show file tree
Hide file tree
Showing 5 changed files with 1,878 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ https://www.bilibili.com/video/BV1D8411x78X

### 运行方式:

安装pygame, mido等相关库,执行virtual_piano.py;virtual_piano_exe中包含pyinstaller生成的可执行文件,可直接运行
安装pygame, mido等相关库,执行virtual_piano.py或virtual_piano_mt.py(针对多线程实现midi输入做了一些改进)

### global_settings.ini中的相关设置:

Expand Down
5 changes: 4 additions & 1 deletion Update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
5. global_settings.ini加入瀑布流偏移量设置
6. 优化琴键间距、瀑布流间距(主要为手机端考虑)
7. 琴键上方增加(渐变)灯条效果
8. 增加琴键白色灯光效果
8. 增加琴键白色灯光效果

# 20221122
1.增加单次读取midi信息数量,(或许可以)降低一点延迟?
2 changes: 1 addition & 1 deletion global_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bkg_offset_y = 0
piano_key_offset = 0
[MusicScoreOffset]
music_score_offset_x = 0
music_score_offset_y = -55
music_score_offset_y = -39
[TimeDelta]
time_delta = 2.07983193277311
[RootDelta]
Expand Down
75 changes: 38 additions & 37 deletions virtual_piano.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,44 +758,45 @@ def input_midi():
break
if if_exit == 1:
break
c = midi1.read(1)
if len(c) > 0:
if c[0][0][0] == 144:
if sustain == 1:
if c[0][0][1] in on_sustain:
on_sustain.remove(c[0][0][1])
if midi2 != 'Unable':
midi2.note_off(c[0][0][1])
if midi2 != 'Unable':
midi2.note_on(c[0][0][1], c[0][0][2])
notes_count[(c[0][0][1] - 21) % 12] += 1
all_note_size += 1
key_note.append(c[0][0][1] - 21)
if mode_id == 0 or mode_id == 2:
waterfalls[c[0][0][1] - 21].append([0, 0, 0, get_wf_color(c[0][0][1] - 21)])
elif c[0][0][0] == 128:
if sustain == 0:
c_all = midi1.read(10)
if len(c_all) > 0:
for c in c_all:
if c[0][0] == 144:
if sustain == 1:
if c[0][1] in on_sustain:
on_sustain.remove(c[0][1])
if midi2 != 'Unable':
midi2.note_off(c[0][1])
if midi2 != 'Unable':
midi2.note_off(c[0][0][1])
elif sustain == 1:
on_sustain.append(c[0][0][1])
if len(key_note) > 0:
key_note.remove(c[0][0][1] - 21)
if (mode_id == 0 or mode_id == 2) and len(waterfalls[c[0][0][1] - 21]) - 1 >= 0:
waterfalls[c[0][0][1] - 21][len(waterfalls[c[0][0][1] - 21]) - 1][0] = 1
elif c[0][0][0] == 176:
if c[0][0][1] == 64:
if c[0][0][2] == 127:
sustain = 1
sustain_state = font2.render('√', True, sustain_text_color)
elif c[0][0][2] == 0:
sustain = 0
sustain_state = font2.render('×', True, sustain_text_color)
for y in on_sustain:
if (y - 21) not in key_note:
if midi2 != 'Unable':
midi2.note_off(y)
on_sustain = []
midi2.note_on(c[0][1], c[0][2])
notes_count[(c[0][1] - 21) % 12] += 1
all_note_size += 1
key_note.append(c[0][1] - 21)
if mode_id == 0 or mode_id == 2:
waterfalls[c[0][1] - 21].append([0, 0, 0, get_wf_color(c[0][1] - 21)])
elif c[0][0] == 128:
if sustain == 0:
if midi2 != 'Unable':
midi2.note_off(c[0][1])
elif sustain == 1:
on_sustain.append(c[0][1])
if len(key_note) > 0:
key_note.remove(c[0][1] - 21)
if (mode_id == 0 or mode_id == 2) and len(waterfalls[c[0][1] - 21]) - 1 >= 0:
waterfalls[c[0][1] - 21][len(waterfalls[c[0][1] - 21]) - 1][0] = 1
elif c[0][0] == 176:
if c[0][1] == 64:
if c[0][2] == 127:
sustain = 1
sustain_state = font2.render('√', True, sustain_text_color)
elif c[0][2] == 0:
sustain = 0
sustain_state = font2.render('×', True, sustain_text_color)
for y in on_sustain:
if (y - 21) not in key_note:
if midi2 != 'Unable':
midi2.note_off(y)
on_sustain = []
time.sleep(0.001)


Expand Down
Loading

0 comments on commit b6a9941

Please sign in to comment.