Saturday, December 13, 2014

Handbell Hero!

Overview


It's like Guitar Hero, with 4 to 8 players, using a set of handbells from Groth Music. No musical background is necessary to play!

Background


Every year, HelpSystems has an annual employee luncheon, which also involves some kind of game/entertainment thing that's led by a department.


Our department manager, Matt Bresnan, came up with the idea of putting together a Guitar Hero type of game, but using a set of handbells. I was asked to look into the feasibility of writing this app, and was given the MythBusters directive that If it's worth doing, it's worth overdoing!



Given the tools that I already know, Java was the easy choice because it has MIDI capabilities built into the language (which seems excessive, but extremely helpful). On the front-end, JavaFx was the right fit for this project.




Building and Running the game


The instructions for downloading, building, and running the game can be found at the GitHub repo:  https://github.com/panurgy/handbellhero

The game works best on a Windows PC (using a 720p display or projector), and you'll need the Java 8 SDK (free download) installed (and in your PATH).

After a song completes, you'll need to press Alt-F4 to return to the menu screen (yeah, it's lame - I had it coded up to auto-close the window when the MIDI player/sequencer finished, but occasionally would receive an erroneous/premature "player stopped" event, that would close the game screen)


Limitations


The most technically challenging part of this game is getting the "falling notes" to sync up with the music as it's played. This involves a bit of "lead-in" time ahead of the player, which means the UI has to understand MIDI tempo information.  For some reason, I couldn't get the math to work out, given the Sequence's Division Type, the Sequencer Tempo in MPQ, and the Sequencer Tempo in BPM.

I found numerous posts and Stack Overflow questions related to this topic, but the math never seemed to work out correctly. 

In the end, I just used a lame/dirty hack involving a properties file which specifies the number of "ticks per second" used by each of the MIDI files. Tip - the app defaults to 1700 ticks per second, so if your file happens to be close to that, there's no adjustment needed.


An even bigger limitation


This game currently ignores the MIDI Set Tempo events that occur within the MIDI Sequence.  There is code present to find/read those events, but since the math/calculations never worked out, I just stuck to fixed-tempo songs.

Adding your own MIDI files


If you'd like to use your own MIDI files (using just the key of C Major), you'll need to save them into the "midi" directory.  If you find that the UI starts at the wrong tempo (which is very likely), run the app using the command hh.bat log

Select your song, and let it play for a few seconds, then close the game (press Alt-F4 a few times).  In your Command Prompt window, you'll see stuff like this:

PLAYER TICK = 2641
Ticks 4259.0 to 4341.0
Track entries 8 to 8


PLAYER TICK = 2730
Ticks 4341.0 to 4430.0
Track entries 8 to 8

You'll need to determine how many MIDI Ticks there are in one second. Subtract two of the non-zero "PLAYER TICK" values, such as 2730 - 2641 = 89.  Then multiply that times 20, because the game refreshes the UI 20 times a second.  Thus, this song runs at 1780 MIDI ticks per second.

Edit the file resources\stupidHackTempo.props and add an entry for your song. The song's filenames are case sensitive, and you'll need to use the Unicode sequence "\u0020" for any spaces in the song's filename.

Rerun the game, select your song, and hopefully the UI will line up with your music.


Huge thanks to these people!


This was a team effort, and I'd like to give a shout out to these people:
  • Allen Fisher, for doing a superb job putting together the MIDI files.
  • Marshall Baltzell, for doing an amazing job with the two image files, especially on the Handbell Hero logo - he was dead-on with the appearance.
  • Matt Bresnan, for coming up with the initial game design, and giving me the opportunity to take some time to code up game.
  • The creator of the Nightmare Hero font, which adds to the visual effect of the game.
  • The audio effect on the selection menu, which adds to the audible effect of the game.
  • Apache FilenameUtils - they have libraries that make coding easier (and less cumbersome).

Got feedback?


If you love it, hate it, or have any questions, let me know! Either leave a comment below, or share with the entire world via Twitter @Panurgy


Tuesday, October 21, 2014

Training for a marathon - without running ragged

For the past few months, my "big project" was training for the Twin Cities Marathon (Oct 5th, 2014). I chose this "project" back in May, because I've completed several half-marathons over the last few years, and I wasn't getting faster - so I figured I may as well go farther.

Conventional wisdom assumes that this would involve a lot of running - most of the plans that you find on the Internet require four (or more) days of running every week, but now that I qualify as a "master runner", I knew that my knees wouldn't enjoy all of the pavement pounding required for a "proper training". 



Time to train smarter


From a geek's perspective, here's what it takes to be successful in a marathon:
  • Efficiency - get the most "mpg" out of your muscles
  • Endurance - the size of your "gas tank"
  • Determination - the mental fortitude to finish the job 


Essential equipment


  • Good pair of shoes, purchased from a running store, not a big-box sporting goods store. I personally have a slight pronation.
  • Lightweight moisture-wicking shirt and shorts (hopefully, your climate isn't like mine).
  • An HRM - I prefer the older Polar models - this is your "tachometer", and helps identify when you're hitting the "red line" and need to ease up.

A helpful item is a GPS enabled smartphone, and the means to take it on the run (arm band, fanny pack, whatever). I'm a huge addict of the site MapMyRun, with the ability to plan a safe/sane route (due to the dearth of running trails in my town), and then mapping it as I run it (I'm a huge stats/data geek). 


Getting started - finding the baseline


Since I was becoming "comfortable" running a half marathon, the first question was finding the max distance until I hit the wall. In late May, the Sunday morning forecast was a temperature in the low 50's and foggy - which is pretty much the perfect conditions, because fog means no wind. I managed to plod along at my usual pace for 18 miles, struggled for the next 2 miles, and then ended up "doing intervals" for the last 3 miles (yeah, that's a fancy way of saying "walk and run"). 

After that long run, my quads were complaining the most, so I needed a training plan that would build up that muscle group. The solution: hills and stairs!


Figuring out a training plan


The Twin Cities Marathon is a fairly flat course. I read a bunch of blogs and reviews from people who had run it, and most people agreed that the most difficult part was miles 20-23, which are uphill, coming up 200 feet from the river valley. I figured that hill training would probably be a good component of my training.

During the summer, my weeks pretty much went like this:
Sunday: Long run - either 10 miles (or more) of hills, or 13-16 miles of flatter terrain.
Monday: Relax
Tuesday: Intervals on a Stair machine
Wednesday: Swim laps (half mile or so)
Thursday: Variety day - outdoor run (4.5 miles) at a faster pace, or cardio exercise class, or more stairs/intervals.
Friday: Occasional indoor rock climbing (my favorite addiction)
Saturday: Relax


Peaking and Tapering


In the middle of September, I was three weeks away from the big event, and apparently that's the time to peak and start tapering. My Sunday morning run was 20 miles (and the first few miles were in darkness, sigh). At the end, the biggest problem was fueling and hydration - I had only packed two energy gels and a 20oz water bottle (with one refill at a park along the way).

The next weekend (two weeks out), I did a 13 mile run, and tried the Cliff Shot Blocks (chewy things), and discovered that they're really hard to chew while running. On the plus side, they have caffeine, which helps keep things moving.

Finally, one week away, ran a "big" run of 6 miles. Seemed almost "too short" compared to the weekly runs I had been doing.  A few days later, I was itching for a short run, so I did a 4.5 mile loop on mostly flat terrain, just to keep the familiar stride.


The big day


I always arrive at these events obscenely early, so that I can figure out where the starting corrals are, the gear/bag drop-off, and the most essential equipment: porta-potties! The temperature was in the upper 30's, which isn't quite warm enough for the basic "t-shirt and shorts" weather, so I threw on a wicking loose-fitting long-sleeved shirt.

The race was an amazing experience - many of the neighborhoods along the course make a huge production of cheering on the runners. With all of that energy being thrown at you, it's hard not to enjoy the event. One of the spectators teased me for smiling too much, claiming that I was "wasting precious endorphins" and that I should save them for the 20+ mile mark. I just smiled even more.

Just past the 15-mile mark, I had some amazing friends helping me out, and I peeled off the sweat-saturated shirt, and threw on a fresh (and dry!) wicking t-shirt, which was big improvement.

In the end, I completed the event in 4 hours and 5 minutes, which seemed like a pretty good finish for my first time. Huge thanks to all of volunteers that help make this event "run smoothly"!