Play MIDI DLL

A DLL for playing MIDI files in the background

© 2003, Brad Moore

author website:

LB Connection

Home

Password Textbox API

Character Replacement

LB Isam Library

Beginning Games 2

Rubber Band Objects

WMLiberty Primer

LB Browser

Beginning Programming 5

INPUTTO Demo

Chase Button

Questionaire Wizard

MIDI Output Thoughts

MIDI-Tunes

Play MIDI DLL

Directory Search Function

Newsletter help

Index

About PlayMIDI DLL

Note: You will find the DLL file (along with the help document, sample MIDI file and test programs) as a part of the archive in the folder called PlayMIDI. You must download the newsletter from the web to get the archive.

DLL Information:

PlayMIDI32.dll

Copyright (c) 2002 by Brad Moore

Version 1.2 - Maintenance release - fixed the dll to support pathnames with spaces in them, updated 5/2/02

version 1.1 - Maintenance release - added LibMain function for full Windows support, updated on 4/29/02

version 1.0 - a final release version finally, updated on 4/18/02

version 0.1b - development, updated last on 4/16/2002

DLL Description:

The PlayMIDI32.dll is a library function (i.e. a dll) for playing MIDI media files in a continual loop in the background of the system. This dll is designed to be used with Liberty Basic version 3 and up. It should be callable by any language that supports calling external 32 bit library functions. This is a 32 bit dll. There is no16 bit counterpart to this dll.

For those interested in Liberty Basic - please check them out on the web at [http://www.libertybasic.com]

The dll was written in PowerBasic/DLL v6.0. For information about PowerBasic check them out on the web at [http://www.powerbasic.com]

Using the DLL:

This dll has one function:

	PlayMIDI (Filename as string) Result as Long

Parameters :

Filename : A string containing the name of midi file to play. The string must be Null Terminated.

Result : A long integer value that specifies success or error conditions.

-1 = Successful closure of thread
 0 = Success
 1 = Unsupported File Type		
 2 = File not found
 3 = Failure to start thread
 4 = DLL Called without filename - no midi thread playing
 5 = Function Not Implemented

Notes about the function:

To use the function pass it a filename in the form of a null terminated string. In Liberty Basic do this by appending a chr$(0) to the end of a string value.

Fname$ = "mysong.mid" + chr$(0)

The filename can be fully qualified or just a simple filename. The current working directory is assumed if the fully qualified filename is not passed. The dll will verify the existence of the file specified before attempting to stream the music. If the file does not exist the dll will return an error value (2 - File not found).

The function only supports the playing of MIDI files. These are not actual music files, but rather strings of data that instruct a sequencer how to play its built in musical instruments. Windows has a basic implementation of a sequencer build into versions 95 and up. It still requires a sound device capable of playing midi sampled sounds. The dll will not determine whether the host system can or can not play the music. (I have never tested this on a PC that does not support MIDI sequencing, so I unsure what will happen in this case) Also, the dll will insure the music file passed is of type MID based on the file extension, but it does not inspect the content of the file to determine whether it is a valid MIDI file.

The MIDI music is played in a loop continuously until instructed to quit. Telling the dll to quite playing music is done by simply passing a null as the filename. Also if you have MIDI music playing in the background (using this DLL) and you prematurely halt the program that called the dll (such as Liberty Basic running some source code of yours) - it will cause a GPF! You're program will crash!

So - Always terminate the playing of the MIDI file before quitting the execution of the program that called the PlayMIDI32 dll!

See the sample Liberty Basic program that comes with the dll for a better understanding of how to use the dll. It is called TESTMIDI.BAS and it is a Liberty Basic 3 program.

How it works:

The PlayMIDI32 dll is very simple. It gets a filename from the calling program. It verified the file and then it creates a threaded process that runs under the dll, but separate from the dll. This process issues a few commands through the Windows Multimedia DLL interface and begins the playback of the MIDI song. Every 10th of a second the process checks on the progress of the song. If it has arrived at the end of the song it simply issues a command to begin playing the song again from the starting position. This repeats until the thread gets a signal to end, at which time playback is halted and the thread is self terminated.

Getting Help:

If you have questions, please check out my website for information on how to get a hold of me. The URL is [http://www.freewebz.com/lb-connection]

Thanks.