Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working outside cmd/vsCode #6

Open
RubenSasiain opened this issue Sep 10, 2024 · 0 comments
Open

not working outside cmd/vsCode #6

RubenSasiain opened this issue Sep 10, 2024 · 0 comments

Comments

@RubenSasiain
Copy link

Hey
I had some problems running the script from outside the console and I found this way to solve it, I leave it here in case you want to add it to the code, I think I can't send pull requests

add:

def control(midi, pitch_modulation=10):
    print("Playing")
    curr_pitch = 'f2'
    pyautogui.press(curr_pitch)
    pyautogui.PAUSE = 0

    for msg in midi.play():
        if msg.type == 'note_on' and msg.velocity != 0:
            pitch, key = map_piano_note_to_key(msg.note + pitch_modulation)
            if curr_pitch != pitch:
                pyautogui.press(pitch)
                curr_pitch = pitch
            if key:
                pyautogui.press(key)
        if keyboard.is_pressed("F6"):
            print("Stop")
            break

and in the main:

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python macro.py 'path'")
        sys.exit(1)

    midi_path = sys.argv[1]
    midi = mido.MidiFile(midi_path)
    print("Press F5 to play. F6 to stop")
    keyboard.add_hotkey('F5', lambda: control(midi=midi), suppress=True, trigger_on_release=True)
    keyboard.wait('F6', suppress=True)

for some reason the keyboard.add_hotkey works outside the console, but the keyboard.wait doesn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant