It is possible to use at the same time two players with jFugue

54 Views Asked by At

I'm trying to make a musical game (a bit like "Guitar Hero") and I'm having some issues to notify the player when he/she is getting a wrong 'note' played. Now is just a basic system but for example if the player has to push Up Arrow and missed it (no matter if the player clicks another one or didn't click any key at all), I want to make a noise or play an out of tune note.

I'm trying two ways:

a) to use a second player that, when the miss is detected, plays an out of tune chord.

b) to modify the volume of the pattern which is already being played.

With the first one I think it is just not possible to play 2 players at the same time and I'm gonna try this weekend to use a second thread. Nevertheless in theory I think it shouldn't work due to both players will use the same PC sound board for different instructions. This is the head of the error I get in return when I try this option:

Exception in thread "Thread-2" java.lang.NumberFormatException: Value out of range. Value:"200" Radix:10

("200" is the volume value I gave to the miss note, but it doesn't matter how much I put because it always fails.)

With the second one I found no example of any pattern which is being reproduced and modified, or any question here that confirm it is possible.

Any idea of what should I try?

1

There are 1 best solutions below

0
David Koelle On

A Player plays music by connecting to a MIDI Sequencer, and there is only one of those on your system, so you can really have only one Player. (I'm realizing now that the JFugue API doesn't enforce that, and perhaps it should.)

MIDI has 16 channels, which JFugue calls Voices. Instead of having two Players, you could play the main melody of your song in Voice 0, and the player's feedback in, say, Voice 5. Notes in each of those voices could use different instruments. If the player gets the note right, the Voice 0 and Voice 5 notes will sound together. If they get it wrong, you can play something different in Voice 5, or if they don't play anything at all, you could play nothing on Voice 5.

If you are playing the Voice 0 and Voice 5 notes one at a time (instead of sending a full pattern at the beginning of the game), you could also modify the on velocity and off velocity of the note on Voice 0 to make it sound fainter.

(Voice 9 is the percussion track, so don't play on that!)

We would need to see some source code to see why you're getting that error with the volume.