chrislo27 / PolyrhythmMania

A game that faithfully recreates the Polyrhythm minigame from Rhythm Tengoku (リズム天国), with a built-in level editor
https://polyrhythmmania.rhre.dev
GNU General Public License v3.0
246 stars 19 forks source link

[Bug]: Lightpad block (midi drumpad) doesn’t register inputs correctly #46

Closed SushiiZ closed 2 years ago

SushiiZ commented 2 years ago

Version

V1.2.0-20220201a

Operating System

Windows 11

Problem Description

I tried using midikey2keywith my lightpad block to use it with polyrhythm heaven, but it’s not picking up the keystrokes specified, but when I try to input, it just fills in the slot with “unknown” rather than the keystroke

Steps to Reproduce Problem

Use midikey2key to turn your midi input into a keystroke

enter polyrhythm mania and go to input settings, try to use selected keystrokes

Relevant log output

No response

(Optional) Other useful information

No response

chrislo27 commented 2 years ago

Have you tried using midikey2key to translate the block inputs into the default keys (J, WASD, etc)? If the inputs are being picked up as "Unknown" then it means that keystroke isn't detected by the underlying game engine, this can happen with non-standard keys like function keys past 12.

SushiiZ commented 2 years ago

Yeah I was trying to have it use the default keys but it seems like the other input takes priority, it types fine in other applications.

On Apr 11, 2022, at 11:50 AM, Chris @.***> wrote:

 Have you tried using midikey2key to translate the block inputs into the default keys (J, WASD, etc)? If the inputs are being picked up as "Unknown" then it means that keystroke isn't detected by the underlying game engine, this can happen with non-standard keys like function keys past 12.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

chrislo27 commented 2 years ago

If you set the input keybindings using your keyboard (not the MIDI device) and then play the game with the MIDI device, does that work?

SushiiZ commented 2 years ago

Nope, it seems like that “unknown” input takes over completely, it could also be a midikey2key thing, but I feel like it should still work as long as it sends the keystroke, right?

On Apr 11, 2022, at 12:19 PM, Chris @.***> wrote:

 If you set the input keybindings using your keyboard (not the MIDI device) and then play the game with the MIDI device, does that work?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

chrislo27 commented 2 years ago

but I feel like it should still work as long as it sends the keystroke, right?

Yes, I think it should work. Maybe it won't work in the input rebinding screen because it's sending multiple keystrokes (?) but in gameplay it should work.

If you can export your midikey2key settings to a file, I can try taking a look with a MIDI keyboard in the coming days. But I am suspecting that this is a midikey2key quirk or configuration issue.

SushiiZ commented 2 years ago

I’ll mess with it tn, but I’m just getting C4 and A#7 into L and D inputs (moved the A input) I’ll look around and see if I can find an alternative, but it might just be an issue with how polyrhythm takes both inputs at the same time, I’ll mess with another way if I find one, I think autohotkey can, it’d be cool if polyrhythm could just use the noteon midi trigger as inputs, that’d be pretty cool

On Apr 11, 2022, at 12:44 PM, Chris @.***> wrote:

 but I feel like it should still work as long as it sends the keystroke, right?

Yes, I think it should work. Maybe it won't work in the input rebinding screen because it's sending multiple keystrokes (?) but in gameplay it should work.

If you can export your midikey2key settings to a file, I can try taking a look with a MIDI keyboard in the coming days. But I am suspecting that this is a midikey2key quirk or configuration issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

SushiiZ commented 2 years ago

Hm, no luck with anything as of yet

On Apr 11, 2022, at 12:44 PM, Chris @.***> wrote:

 but I feel like it should still work as long as it sends the keystroke, right?

Yes, I think it should work. Maybe it won't work in the input rebinding screen because it's sending multiple keystrokes (?) but in gameplay it should work.

If you can export your midikey2key settings to a file, I can try taking a look with a MIDI keyboard in the coming days. But I am suspecting that this is a midikey2key quirk or configuration issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

chrislo27 commented 2 years ago

I just tried MIDIkey2key on a MIDI keyboard. Two things:

  1. It was not trivial to set up. My keyboard doesn't send NoteOff events but rather NoteOn at 0 velocity, which causes it to send two inputs. Their suggested workaround only works if the on velocity is a static value (like 127), which isn't the case for me. Instead, I had to set my keyboard to not react to velocity so it would only output a velocity of 64. This may be something to keep in mind but I don't know how your device works.
  2. It doesn't actually emulate key presses correctly! It sends a bad key input that resolves to being unknown, but correctly "types" the letter. See below for some debug output when I was testing. The first four inputs were from MIDIkey2key, the last two were me typing it on a keyboard. Accepting "typed" inputs doesn't work due to key repeats. You can also check with KeyboardTester.com (https://www.keyboardtester.com/tester.html) -- I wasn't able to get it to type correctly in here too.
    Keycode: 0  Unknown
    Typed: j
    Keycode: 0  Unknown
    Typed: d
    Keycode: 0  Unknown
    Typed: j
    Keycode: 0  Unknown
    Typed: d
    Keycode: 32  D
    Typed: d
    Keycode: 53  Y
    Typed: y

Therefore, I believe this is an issue with MIDIkey2key. I would suggest trying a different program to translate MIDI inputs. Personally, I have used FreePIE to translate MIDI inputs to keyboard inputs but it takes a little bit of programming. https://andersmalmgren.github.io/FreePIE/

I have a sample script for FreePIE you could adapt -- I originally wrote this to try playing Minecraft: Java Edition on a MIDI keyboard a few years ago.

def negPos(n, p):
    if n and p:
        return 0
    elif n and not p:
        return -1
    elif p and not n:
        return 1
    else:
        return 0

def update():
    global lastPedal
    global pressedNotes

    data = midi[0].data
    buf1 = data.buffer[0]
    buf2 = data.buffer[1]

    volume = buf2 / 127.0
    semitone = buf1 - 60 # semitones from middle C

    diagnostics.watch(buf1)
    diagnostics.watch(buf2)

    if data.status == MidiStatus.Control and buf1 == 64: # buf1 = control change
        lastPedal = buf2 >= 64
    elif data.status == MidiStatus.NoteOn:
        if volume <= 0:
            pressedNotes[semitone] = False
        else:
            pressedNotes[semitone] = True
    elif data.status == MidiStatus.NoteOff:
        pressedNotes[semitone] = False

    # Map to keyboard (Yamaha NP-30)
    def n(semitone):
        return pressedNotes.get(semitone, False)

    # Reference: C is middle C, C+ is one octave up, C- is one octave down
    # Escape key (last note on keyboard)
    keyboard.setKey(Key.Escape, n(-32))

    # Movement:
    # W -> E (+4)
    # S -> D# (+3)
    # A -> D (+2)
    # D -> F (+5)
    # Jump -> G (+7)
    # Sneak (shift) -> Damper pedal
    # Sprint (ctrl) -> C (0)
    keyboard.setKey(Key.LeftShift, lastPedal)
    keyboard.setKey(Key.LeftControl, n(0))
    keyboard.setKey(Key.W, n(4))
    keyboard.setKey(Key.S, n(3))
    keyboard.setKey(Key.A, n(2))
    keyboard.setKey(Key.D, n(5))
    keyboard.setKey(Key.Space, n(7))

    # Camera:
    # C+ and G+ (+12 and +19) look left and right respectively
    # D#+ and E+ (+15 and +16) look up and down respectively
    delta = 14
    invertX = False
    invertY = False
    mouse.deltaX = delta * negPos(n(12), n(19)) * (-1 if invertX else 1)
    mouse.deltaY = delta * negPos(n(15), n(16)) * (-1 if invertY else 1)

    # Mouse buttons
    # D+ (+14) -> Attack (left click)
    # F+ (+17) -> Action (right click)
    mouse.leftButton = n(14)
    mouse.rightButton = n(17)

    # Num row for hotbar
    # On the NP-30 this corresponds to the SONG number buttons 1-10
    keyboard.setKey(Key.D1, n(-12))
    keyboard.setKey(Key.D2, n(-11))
    keyboard.setKey(Key.D3, n(-10))
    keyboard.setKey(Key.D4, n(-9))
    keyboard.setKey(Key.D5, n(-8))
    keyboard.setKey(Key.D6, n(-7))
    keyboard.setKey(Key.D7, n(-6))
    keyboard.setKey(Key.D8, n(-5))
    keyboard.setKey(Key.D9, n(-4))
    keyboard.setKey(Key.D0, n(-3))

    # Inventory -> A+ (+21)
    keyboard.setKey(Key.E, n(21))

if starting:
    lastPedal = False
    pressedNotes = dict() # key = semitones from middle C, value = Boolean
    midi[0].update += update

Closing this issue because the issue is with an external program.