LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reading midi files. (https://www.linuxquestions.org/questions/programming-9/reading-midi-files-213904/)

gbowden 08-05-2004 03:00 PM

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: http://johnath.com/beep/

Thank you,


Greg

cppkid 08-06-2004 02:01 AM

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

http://www.programmersheaven.com/zone10/cat136

In java it is not that tuff to read MIDI files and to write back, you can get help form.

http://jmusic.ci.qut.edu.au/jmtutorial/ReadUseMIDI.htm

gbowden 08-07-2004 02:42 PM

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).


All times are GMT -5. The time now is 01:03 PM.