FreePIE works ok when testing, doesn't work in-game.

Official forum for open source FreePIE discussion and development.
Post Reply
Greeb
One Eyed Hopeful
Posts: 1
Joined: Thu Apr 02, 2015 12:40 pm

FreePIE works ok when testing, doesn't work in-game.

Post by Greeb »

Hi. For the past few days I've been trying to get my e-drums work with Guitar Hero: World Tour. I've tried many old pieces of software that did absolutely nothing until I found FreePIE.

Currently, I'm at a point where I translate midi messages from my drumkit to keystrokes on keyboard. The whole script looks like this:

Code: Select all

def onMidi(): 
	#blue
   keyboard.setKey(Key.Y, (midi[0].data.buffer[0] == 48) and (midi[0].data.status == MidiStatus.NoteOn))
   keyboard.setKey(Key.U, (midi[0].data.buffer[0] == 51) and (midi[0].data.status == MidiStatus.NoteOn))
   keyboard.setKey(Key.I, (midi[0].data.buffer[0] == 53) and (midi[0].data.status == MidiStatus.NoteOn))
	#kick
   keyboard.setKey(Key.Space, (midi[0].data.buffer[0] == 36) and (midi[0].data.status == MidiStatus.NoteOn))
	#red
	keyboard.setKey(Key.S, (midi[0].data.buffer[0] == 38) and (midi[0].data.status == MidiStatus.NoteOn))
	#yellow
	keyboard.setKey(Key.W, (midi[0].data.buffer[0] == 46) and (midi[0].data.status == MidiStatus.NoteOn))
	#green
	keyboard.setKey(Key.H, (midi[0].data.buffer[0] == 45) and (midi[0].data.status == MidiStatus.NoteOn))
	keyboard.setKey(Key.J, (midi[0].data.buffer[0] == 49) and (midi[0].data.status == MidiStatus.NoteOn))
	keyboard.setKey(Key.K, (midi[0].data.buffer[0] == 55) and (midi[0].data.status == MidiStatus.NoteOn))

if starting: 
	system.setThreadTiming(TimingTypes.HighresSystemTimer)
	system.threadExecutionInterval = 1
	midi[0].update += onMidi
This works just fine when testing in notepad. I can beat the drums as fast as I want and it never fails. 5 hits = 5 letters in notepad. However when I start up the game It's like it randomly doesn't register the hit. I hit 5 times, not even that fast, and only first and third get registered or so. No dealy or stuff like that.

So far I've tried setting the process priority to realtime but that didn't help at all. Any suggestions?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE works ok when testing, doesn't work in-game.

Post by CyberVillain »

Strange, I have seen the other way around that it does not work well in notepad but in game. Could you try another game just so we know if its the game or not?
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Re: FreePIE works ok when testing, doesn't work in-game.

Post by HarvesteR »

Realtime might not be the solution here... You might actually want your script to run slower in this case.

I see you've got your update cycle driven by the midi loop, which might just be too fast for the game to pick up your input (your note event might be on and off before the game has had a chance to read inputs again). GH being a console port, I would expect it to run clamped at 60hz (or you can force it turning vsync on), so you may get better results if you set up a 'queue' for your inputs to live long enough to be read by the game.

You could do that using an input buffer (an array of notes on for the next frame) that you write to for every note-on event on the midi loop, and then on a function in the main thread, set the keys on and off based on that, and clear the buffer for the next frame.

I'm assuming here that the midi update is running on another thread... which it very well might be.

Hope it helps. should be worth a shot at least. :)

Cheers
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE works ok when testing, doesn't work in-game.

Post by CyberVillain »

We queue the midi messages and trigger the event on the main script thread so they can't trigger faster then default 64hz. You can over clock freepie if you need higher speeds

Edit:you run the script at 1000hz so it could very well be the problem
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE works ok when testing, doesn't work in-game.

Post by CyberVillain »

Also you should use setPressed in this case, freepie will then send one key down and in the next frame key up. Problem is if you run at 1000 hz the game might miss that. I should change the set Pressed code so that it uses a timer instead and always wait for a specific time until release instead of releasing directly in the next frame
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Re: FreePIE works ok when testing, doesn't work in-game.

Post by HarvesteR »

Good to know about the MIDI message queue! @OP, disregard my suggestion of queuing messages then. That's already being done. :)

Cheers
Last edited by HarvesteR on Mon Sep 14, 2015 12:08 pm, edited 1 time in total.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE works ok when testing, doesn't work in-game.

Post by CyberVillain »

I would replace

Code: Select all

keyboard.setKey(Key.Y, (midi[0].data.buffer[0] == 48) and (midi[0].data.status == MidiStatus.NoteOn))
With

Code: Select all

if midi[0].data.buffer[0] == 48 and midi[0].data.status == MidiStatus.NoteOn:
   keyboard.setPressed(Key.Y)
Post Reply

Return to “FreePIE”