Lecture Slides
Download
Report
Transcript Lecture Slides
Field Trip #20
Creating Simple Music
By Keith Lynn
Midi
Midi stands for Musical Instrument Digital
Interface
It is an interface that allows a variety of
instruments to connect and communicate with
each other
A single midi link can carry up to 16 channels of
information
We can connect a channel to a different device
Midi cont'd
A Midi Event message carries information about
Pitch
Notation
Velocity
Volume
etc
Instrument
An instrument is represented by an integer
between 0 and 255
You can find a list of instruments at
http://www.ccarh.org/courses/253/handout/gmii
nstruments
Creating the Midi
In order to create the midi, we will create a
Sequencer
After we create the Sequencer, we open it
We create a Sequence
The Sequence is made of Tracks
The Tracks are made up of MidiEvents
The MidiEvent is composted of a MidiMessage
and a tick. The tick indicates the time in the
sequence where the event fires
MidiMessage
In this app, we will create a simple message
A ShortMessage contains two bytes of
information
To create the ShortMessage, we specify four
things
A Midi command
A channel
The first data byte
The second data byte
Midi Commands
The ShortMessage class contains constants
that represent Midi commands
Some of the most common are
Note on – Start Playing
Note off – Stop Playing
Program change – Specify what instrument is on a
channel
Playing Notes
The third parameter to create the
ShortMessage is a note
Middle C is 60
The fourth parameter is the velocity
Typically we can use 100
Playing the sound
In order to play the Midi sound, we create the
ShortMessages and create a MidiEvent
The MidiEvent specifies the ShortMessage and
the tick
The tick is the time when the event fires
Creating the Midi Player
In our app, we allow the user to specify through
Java components, the values to create a
ShortMessage
These ShortMessages appear in a Jpanel
When we are ready to play, we click Play and
each of the MidiMessages are put into a track,
and the track put in a sequence, and the
sequence put in the sequencer
Storing MidiEvents
In our app, we create a Jpanel called a
MidiMessagePanel
This class is declared to be Serialiazable
This means that instances of the class can be
written to a file
Later we can read them back in
In order to write the objects, we use an
ObjectOutputStream, and in order to read the
objects, we use an ObjectInputStream