Skip to content

Commit

Permalink
do not warn template's placeholder path
Browse files Browse the repository at this point in the history
  • Loading branch information
3096 committed Mar 30, 2021
1 parent db8d973 commit 398add3
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import time
import traceback
from typing import List

import mido
Expand All @@ -29,7 +30,8 @@
START_COMBO_KEY = [pynput.keyboard.Key.tab]
STOP_KEY_COMBO = [pynput.keyboard.Key.space]
RELOAD_CONFIG_KEY = pynput.keyboard.KeyCode.from_char('`')
CONFIG_FILE_NAME = "midi_config.json"
DEFAULT_CONFIG_FILE_PATH = "midi_config.json"
TEMPLATE_DEFAULT_PATH_MSG = "put the path to your midi file here"


class NoteKeyMap:
Expand Down Expand Up @@ -116,7 +118,7 @@ def load_config(self):
self.song_key_dict[pynput.keyboard.KeyCode.from_char(song_config["key"])] \
= self.SongConfig(song_config)
print(f"{song_config['key']} - {os.path.basename(song_config['file'])}")
else:
elif song_config["file"] != TEMPLATE_DEFAULT_PATH_MSG:
print(f"file not found: {song_config['file']}")

print(f"loaded {len(self.song_key_dict)} songs from config!")
Expand Down Expand Up @@ -197,11 +199,11 @@ async def play(self, song_config: SongConfig):
keyboard.release(key)
return

# skip if fast forward
if fast_forward_time > 0:
if fast_forward_time > 0: # skip if fast forward
fast_forward_time -= msg.time
continue
elif msg.time > 0:
# sleep msg.time based on time.time()
await asyncio.sleep(msg.time - (time.time() - last_clock))
last_clock += msg.time

Expand Down Expand Up @@ -250,13 +252,18 @@ def on_release(self, key):

def start(self):
pynput.keyboard.Listener(on_press=self.on_press, on_release=self.on_release).start()
self.playing_event_loop.run_forever()
self.playing_event_loop.run_forever() # thank you forever


if __name__ == "__main__":
print(LICENSE)
if ctypes.windll.shell32.IsUserAnAdmin():
LyrePlayer(CONFIG_FILE_NAME).start()
else:
print("Admin mode is required, please run as administrator and try again...")
input()

try:
if ctypes.windll.shell32.IsUserAnAdmin():
LyrePlayer(DEFAULT_CONFIG_FILE_PATH).start()
else:
print("Admin mode is required, please run as administrator and try again...")
except:
traceback.print_exc()
finally:
input("press any key to exit...")

0 comments on commit 398add3

Please sign in to comment.