Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-05-2004, 03:00 PM   #1
Registered: Dec 2003
Location: Spain
Distribution: Slackware 14.1 64bit - multilib
Posts: 148

Rep: Reputation: 28
Post Reading midi files.

Does any one know of any libraries which read (or extract data from) midi files ?

Here is what I want to do:

1. Extract the data from the midi file.
2. Extract the note, timing information from the file.
3. Create a file to play the midi file using the PC Speaker.

I can do 2 and 3 but am stuck on the fist task: Loading the midi file.

I have already made the PC Speaker play the ending of the Batman theme song. (So I know it's possible.)
I also have a listing of all the differnet octaves and notes (with acompaning frequency in Hz).

Therefore, my program will read the midi data and then convert this data into the correct frequencies (and the lenght of the notes etc.) and output a bash script* which will play the converted midi file on the PC Speaker.

I know I can do the above but I need some sort of library which extracts midi file data so I can act upon the data I receive from this library.

* I already have a program which was created by Johnathan Nightingale to control the PC Speaker. It lets you specify the frequency, lenght and duration of the note to be played to the PC Speaker .

The reason I wanted to create a bash script is becuase I already have the aformentioned program and it can be controlled by writing a bash script.

For anyone who want to try playing the ending of the batman theme to the PC Speaker, do the following:

Download the beep-1.2.2.tar.gz file. Extract it. Compile it using make (this will then create an executable file called beep in the current directory.).

Type the following in a text console (one of the tty's). Switch to the console by pressing the CTRL+ALT+[F1-F6]. Then type the following (in the directory where you compiled the beep binary file.):

./beep -f 138.59 -d 120 -l 180 -f 138.59 -d 120 -l 180 -nf 146.83 -d 120 -l 180 -nf 146.83 -d 120 -l 180 -nf 155.56 -d 120 -l 180 -nf 155.56 -d 120 -l 180 -nf 146.83 -d 120 -l 180 -nf 146.83 -d 120 -l 180 -nf 138.59 -d 120 -l 180 -nf 138.59 -d 120 -l 180 -nf 146.8 -d 150 -l 230 -nf 155.56 -d 120 -l 180 -nf 155.56 -d 120 -l 180 -nf 19000 -l 420 -nf 207.65 -d 600 -l 180 -nf 207.65 -l 840

This should now play the ending of the batman theme on your PC Speaker.

NOTE: You will have to have read and write access to /dev/console (so you may have to be root to run the beep file.) But you can always change the permissions of the /dev/console device so you can read an write to it.

You can download the beep program from:

Thank you,

Old 08-06-2004, 02:01 AM   #2
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
There are many resources and libraries to read/write MIDI files on this website.

In java it is not that tuff to read MIDI files and to write back, you can get help form.
Old 08-07-2004, 02:42 PM   #3
Registered: Dec 2003
Location: Spain
Distribution: Slackware 14.1 64bit - multilib
Posts: 148

Original Poster
Rep: Reputation: 28
Post Thanks :)

Wow, that was just what I was looking for.

Once I get this done I can then concentrate on more useful things such as creating a printer driver for my NEC printer. (A Pinwriter CP7).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot play MIDI files! koolgentoo Linux - Hardware 2 07-24-2005 07:26 AM
How to play MIDI files: needed a MIDI mapper? vharishankar Linux - General 3 12-30-2004 12:12 AM
Cannot play midi files... djib Linux - Laptop and Netbook 1 12-04-2004 07:46 PM
midi files Mark_Grieveson Linux - Newbie 5 11-05-2004 06:25 PM
Playing MIDI files rajan_kanwar Linux - Software 1 02-05-2004 04:46 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration