| COS 126 MIDIGuitarHero |
OPTIONAL: MIDI Keyboards and MIDI Files Assignment Page |
Optional Write a program MidiGuitarHero.java that is similar to GuitarHero.java, but works with a with a MIDI keyboard controller keyboard or a MIDI keyboard controller app (running on your smartphone connected to your laptop). (See the bottom of the page for more information about MIDI controllers.)
Briefly, MIDI (Musical Instrument Digital Interface) is a technical standard for digitial music. More details can be found at on the Wikepedia page.
To implement MidiGuitarHero.java, you will need to download the MidiSource.java class. The MidiSource.java class maintains a queue of short MIDI messages. See javax.sound.midi.ShortMessage for details. The basic steps are:
The API for the MidiSource.java class:
public class MidiSource {
public MidiSource(boolean verbose, boolean connectToSynth) // Creates a MidiSource object listens to the first
// found connected Midi input device.
public MidiSource(String filename, boolean verbose, boolean connectToSynth) // Creates a MidiSource object that produces
// Midi messages from a time-stamped Midi file
public void start() // Starts the MidiSource so it can produce messages.
public void close() // Closes the MidiSource.
public boolean isEmpty() // Does the MidiSource have more messages?
public javax.sound.midi.ShortMessage nextMessage() // Returns next short Midi message produced by a MidiSource
public static void main(String[] args) // Demonstrates the MidiSource class - playing from a
// keyboard or a Midi file - using the default Java synthesizer
}
To get started:
Each time you press a key on the MIDI keyboard controller, a MIDI message is produced. The message contains:MidiSource verison .2 DEVICE 0: Gervill, OpenJDK, Software MIDI Synthesizer, Midi device available, Not a MIDI keyboard controller, trying next... DEVICE 1: Port1, YAMAHA, YAMAHA PSR-1100 Port1, Midi device available, Valid MIDI controller connected. ShortMessage: Command: NOTE_ON (144) Channel: 0 Number: 77 Velocity: 21 ShortMessage: Command: NOTE_ON (144) Channel: 0 Number: 77 Velocity: 0
More options:
java-introcs MidiSource -p chopstik.mid
As you can see, different channels correspond to different instruments. If you have implemenented multiple instruments, you can write an MidiAutoGuitar.java that plays your instruments from an exisiting MIDI file.