解决一些小问题

This commit is contained in:
EillesWan 2024-05-02 02:00:04 +08:00
parent 382b0e1601
commit fe7c11636b
5 changed files with 43 additions and 28 deletions

View File

@ -17,7 +17,7 @@ Terms & Conditions: License.md in the root directory
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
__version__ = "2.1.0" __version__ = "2.1.0.1"
__vername__ = "Websocket支持" __vername__ = "Websocket支持"
__author__ = ( __author__ = (
("金羿", "Eilles Wan"), ("金羿", "Eilles Wan"),

View File

@ -153,7 +153,7 @@ class MusicSequence:
@classmethod @classmethod
def from_mido( def from_mido(
cls, cls,
mido_file: mido.MidiFile, mido_file: Optional[mido.MidiFile],
midi_music_name: str, midi_music_name: str,
mismatch_error_ignorance: bool = True, mismatch_error_ignorance: bool = True,
speed_multiplier: float = 1, speed_multiplier: float = 1,
@ -190,6 +190,7 @@ class MusicSequence:
deviation: float deviation: float
全曲音调偏移值 全曲音调偏移值
""" """
if mido_file:
( (
note_channels, note_channels,
note_count_total, note_count_total,
@ -203,6 +204,10 @@ class MusicSequence:
vol_processing_function=volume_processing_function, vol_processing_function=volume_processing_function,
ignore_mismatch_error=mismatch_error_ignorance, ignore_mismatch_error=mismatch_error_ignorance,
) )
else:
note_channels = {}
note_count_total = 0
inst_note_count = {}
return cls( return cls(
name_of_music=midi_music_name, name_of_music=midi_music_name,
channels_of_notes=note_channels, channels_of_notes=note_channels,
@ -549,7 +554,7 @@ class MidiConvert(MusicSequence):
@classmethod @classmethod
def from_mido_obj( def from_mido_obj(
cls, cls,
midi_obj: mido.MidiFile, midi_obj: Optional[mido.MidiFile],
midi_name: str, midi_name: str,
ignore_mismatch_error: bool = True, ignore_mismatch_error: bool = True,
playment_speed: float = 1, playment_speed: float = 1,

View File

@ -87,28 +87,33 @@ def to_websocket_server(
if music_to_play in musics.keys(): if music_to_play in musics.keys():
self.check_play = True self.check_play = True
delay_of_now = 0 delay_of_now = 0
for cmd in musics[music_to_play][0]: now_played_cmd = 0
_time = time.time()
for i in range(musics[music_to_play][1]):
if not self.check_play: if not self.check_play:
break break
await asyncio.sleep((0.05 - (time.time() - _time)) % 0.05)
_time = time.time() _time = time.time()
if progressbar_style: if progressbar_style:
await self.send_command( await self.send_command(
"title {} actionbar {}".format( "title {} actionbar {}".format(
whom_to_play, whom_to_play,
progressbar_style.play_output( progressbar_style.play_output(
played_delays=delay_of_now, played_delays=i,
total_delays=musics[music_to_play][1], total_delays=musics[music_to_play][1],
music_name=music_to_play, music_name=music_to_play,
), ),
), ),
callback=self.cmd_feedback, callback=self.cmd_feedback,
) )
delay_of_now += 1
if delay_of_now >= (cmd := musics[music_to_play][0][now_played_cmd]).delay:
await self.send_command( await self.send_command(
cmd.command_text.replace(replacement, whom_to_play), cmd.command_text.replace(replacement, whom_to_play),
callback=self.cmd_feedback, callback=self.cmd_feedback,
) )
delay_of_now += cmd.delay now_played_cmd += 1
await asyncio.sleep((time.time() - _time) + cmd.delay / 20) delay_of_now = 0
else: else:
await self.send_command( await self.send_command(
@ -125,6 +130,11 @@ def to_websocket_server(
): ):
self.check_play = False self.check_play = False
elif response["body"]["message"].startswith(
("。终止连接", ".terminate", ".endconnection")
):
await self.disconnect()
server = fcwslib.Server(server=server_dist, port=server_port, debug_mode=True) server = fcwslib.Server(server=server_dist, port=server_port, debug_mode=True)
server.add_plugin(Plugin) server.add_plugin(Plugin)
asyncio.run(server.run_forever()) asyncio.run(server.run_forever())

View File

@ -736,7 +736,7 @@ class ProgressBarStyle:
.replace(r"%^s", str(total_delays)) .replace(r"%^s", str(total_delays))
.replace(r"%%t", mctick2timestr(played_delays)) .replace(r"%%t", mctick2timestr(played_delays))
.replace(r"%^t", mctick2timestr(total_delays)) .replace(r"%^t", mctick2timestr(total_delays))
.replace(r"%%%", str(int(10000 * played_delays / total_delays) / 100) + "%") .replace(r"%%%", "{:0>5.2f}%".format(int(10000 * played_delays / total_delays) / 100))
.replace( .replace(
"_", "_",
self.played_style, self.played_style,

View File

@ -3,7 +3,7 @@
</h1> </h1>
<p align="center"> <p align="center">
<img width="128" height="128" src="https://gitee.com/TriM-Organization/Musicreater/raw/master/resources/msctIcon.ico"> <img width="128" height="128" src="https://gitee.com/TriM-Organization/Musicreater/raw/master/resources/msctIcon.png">
</img> </img>
</p> </p>
@ -69,9 +69,9 @@
## 作者 ✒ ## 作者 ✒
**金羿 Eilles**我的世界基岩版指令个人开发者B 站不知名 UP 江西在校高中生 **金羿 Eilles**我的世界基岩版指令作者个人开发者B 站不知名 UP 江西老表
**诸葛亮与八卦阵 bgArray**我的世界基岩版玩家喜欢编程和音乐深圳初二学生 **诸葛亮与八卦阵 bgArray**我的世界基岩版玩家喜欢编程和音乐深圳学生
**偷吃不是Touch Touch**我的世界基岩版指令师提供 BDX 导入测试支持 **偷吃不是Touch Touch**我的世界基岩版指令师提供 BDX 导入测试支持