From fe7c11636b44cc40308f92ef5739896ff25eeeb7 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Thu, 2 May 2024 02:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=80=E4=BA=9B=E5=B0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater/__init__.py | 2 +- Musicreater/main.py | 35 ++++++++++++++++------------ Musicreater/plugin/websocket/main.py | 26 ++++++++++++++------- Musicreater/subclass.py | 2 +- README.md | 6 ++--- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/Musicreater/__init__.py b/Musicreater/__init__.py index f42bebd..8c89f06 100644 --- a/Musicreater/__init__.py +++ b/Musicreater/__init__.py @@ -17,7 +17,7 @@ Terms & Conditions: License.md in the root directory # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md -__version__ = "2.1.0" +__version__ = "2.1.0.1" __vername__ = "Websocket支持" __author__ = ( ("金羿", "Eilles Wan"), diff --git a/Musicreater/main.py b/Musicreater/main.py index 7e6b3dd..d085a24 100644 --- a/Musicreater/main.py +++ b/Musicreater/main.py @@ -153,7 +153,7 @@ class MusicSequence: @classmethod def from_mido( cls, - mido_file: mido.MidiFile, + mido_file: Optional[mido.MidiFile], midi_music_name: str, mismatch_error_ignorance: bool = True, speed_multiplier: float = 1, @@ -190,19 +190,24 @@ class MusicSequence: deviation: float 全曲音调偏移值 """ - ( - note_channels, - note_count_total, - inst_note_count, - ) = cls.to_music_note_channels( - midi=mido_file, - speed=speed_multiplier, - pitched_note_rtable=pitched_note_referance_table, - percussion_note_rtable=percussion_note_referance_table, - default_tempo_value=default_tempo, - vol_processing_function=volume_processing_function, - ignore_mismatch_error=mismatch_error_ignorance, - ) + if mido_file: + ( + note_channels, + note_count_total, + inst_note_count, + ) = cls.to_music_note_channels( + midi=mido_file, + speed=speed_multiplier, + pitched_note_rtable=pitched_note_referance_table, + percussion_note_rtable=percussion_note_referance_table, + default_tempo_value=default_tempo, + vol_processing_function=volume_processing_function, + ignore_mismatch_error=mismatch_error_ignorance, + ) + else: + note_channels = {} + note_count_total = 0 + inst_note_count = {} return cls( name_of_music=midi_music_name, channels_of_notes=note_channels, @@ -549,7 +554,7 @@ class MidiConvert(MusicSequence): @classmethod def from_mido_obj( cls, - midi_obj: mido.MidiFile, + midi_obj: Optional[mido.MidiFile], midi_name: str, ignore_mismatch_error: bool = True, playment_speed: float = 1, diff --git a/Musicreater/plugin/websocket/main.py b/Musicreater/plugin/websocket/main.py index 028dbca..2b34fdd 100644 --- a/Musicreater/plugin/websocket/main.py +++ b/Musicreater/plugin/websocket/main.py @@ -87,28 +87,33 @@ def to_websocket_server( if music_to_play in musics.keys(): self.check_play = True 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: break + await asyncio.sleep((0.05 - (time.time() - _time)) % 0.05) _time = time.time() if progressbar_style: await self.send_command( "title {} actionbar {}".format( whom_to_play, progressbar_style.play_output( - played_delays=delay_of_now, + played_delays=i, total_delays=musics[music_to_play][1], music_name=music_to_play, ), ), callback=self.cmd_feedback, ) - await self.send_command( - cmd.command_text.replace(replacement, whom_to_play), - callback=self.cmd_feedback, - ) - delay_of_now += cmd.delay - await asyncio.sleep((time.time() - _time) + cmd.delay / 20) + delay_of_now += 1 + if delay_of_now >= (cmd := musics[music_to_play][0][now_played_cmd]).delay: + await self.send_command( + cmd.command_text.replace(replacement, whom_to_play), + callback=self.cmd_feedback, + ) + now_played_cmd += 1 + delay_of_now = 0 else: await self.send_command( @@ -125,6 +130,11 @@ def to_websocket_server( ): 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.add_plugin(Plugin) asyncio.run(server.run_forever()) diff --git a/Musicreater/subclass.py b/Musicreater/subclass.py index 51e2211..531906b 100644 --- a/Musicreater/subclass.py +++ b/Musicreater/subclass.py @@ -736,7 +736,7 @@ class ProgressBarStyle: .replace(r"%^s", str(total_delays)) .replace(r"%%t", mctick2timestr(played_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( "_", self.played_style, diff --git a/README.md b/README.md index 4e5c03b..c42d1bd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- +

@@ -69,9 +69,9 @@ ## 作者 ✒ -**金羿 Eilles**:我的世界基岩版指令师,个人开发者,B 站不知名 UP 主,江西在校高中生。 +**金羿 Eilles**:我的世界基岩版指令作者,个人开发者,B 站不知名 UP 主,江西老表。 -**诸葛亮与八卦阵 bgArray**:我的世界基岩版玩家,喜欢编程和音乐,深圳初二学生。 +**诸葛亮与八卦阵 bgArray**:我的世界基岩版玩家,喜欢编程和音乐,深圳学生。 **偷吃不是Touch Touch**:我的世界基岩版指令师,提供 BDX 导入测试支持