Example: Playing a MIDI File

The following procedure uses the Media Control Interface to play a MIDI file.

TO PLAY.MIDI
  IGNORE MCI [open c:\\windows\\media\\flourish.mid type sequencer alias flourish]
  MCI [play flourish]
  WAIT 600
  MCI [stop flourish]
  MCI [close flourish]
END

Let's take a closer look at each instruction in the example above.

The procedure first opens the MIDI file "c:\windows\media\flourish.mid" by issuing an open command. The type parameter is set to sequencer, which is the device name for the MIDI sequencer. We use the alias parameter so that we can refer to this media entity as flourish instead of always using the full path to flourish.mid. Unlike most other commands, the open command outputs a value on success. Since Logo programs must do something with every value that is output, we simply IGNORE it.

The play command is used to start playing the MIDI file. The music plays asynchronously, which means that FMSLogo doesn't wait for the music to finish playing before running the next instruction.

The WAIT instructions just waits for ten seconds. This has nothing to do with MCI, it just gives you some time to listen to the music before it is stopped.

The stop command stops the song from playing.

The close command is used to tell the Media Control Interface that you are done with the MIDI file.


SourceForge.net Logo