Jump to content

Reading and Transforming a MIDI File


Recommended Posts

Friends,

Time for yet another blog post! This week I have described a technique that you can use to read a MIDI file and then transform the corresponding score.

 

I personally think that Opusmodus could introduce many interesting functions for working with MIDI files, not just for transforming as explained in my blog, but also for analyzing the score.

 

Hope you find this article interesting.

 

Regards,

Rangarajan   

Link to comment
Share on other sites

Hi,

 

thank you for this very nice article, very interesting !

 

I have used your fonction for convert midi files to score and it is very useful but i have a question:

 

How can i do if i want to convert all the Midi-files from a folder to score in one program ?

 

i have a bit experimenting with loop macro etc.. but can't figure how to batch convert a full folder of midi-files to scores.

 

Could you help me a bit please ?

 

Thanks

 

Stéphane

 

Link to comment
Share on other sites

SB,

It should not be difficult to read many files from a directory. In my example, each MIDI file was read into as a single def-score. How to handle the multiple MIDI files? Do you want a corresponding score for each one of them (in memory) or do you want to serialise them (i.e., write each to a separate file)?

 

if you let me know, I can work on that in my spare time and send the code to you. 

 

You can send me an email (ranga@mmsindia.com) if you do not want to use this forum for that purpose.

 

Regards,

Rangarajan

Link to comment
Share on other sites

Hi Rangarajan,

thank you for your kind proposition.

 

What i want basicaly is to serialize them (i.e., write each to a separate file).

But a would love also to be able to write them directly in Library files for algorithmic access to this material.

Imagine the creation of Library of piano accompaniment figures, strings ostinato etc... directly extracted from midi file and called in score script by the function Library....

 

i am ok to use this forum if you agree because this information could be useful for other users too and i think sharing and knowledge exchange is good.

 

Regards

Stéphane

 

Link to comment
Share on other sites

What i want to do with library is : import some midifile who have only one track, i.e. one instrument and copy and append  the :omn slot content of each of the 1st track of each score into a Library file.

 

The final result would look like this:

 

(in-package :Opusmodus)

;;;---------------------------------------------------------
;;; Melodies
;;;---------------------------------------------------------

(def-library melodies
  (:section s1
   title-of-the-score-1  '((-q. e d5 0.63 c5 bb4 -q) (h bb4 tie e e a4 g4 a4) (h g4 tie z^3y q gb4 e d4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (z^q g4 3y d4 -191/768 q a4 bb4 e. c5 s) (h. d5 -e d5) (q. eb5 e d5 c5 c5 f5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^h d5 tie 3y g4 -383/768 e d5 a4 bb4 g4) (h. d4 -q) (q bb4 e e e c5 c5 bb4 c5) (q d5 tie e tie z^3y t c5 tie 3t^u. t d5 tie 3t^u. 3u c5 tie tu h bb4 tie) (z^q c5 3y bb4 -191/768 e c5 c5 c5 c5 bb4 c5) (h. d5 q 0.76) (q. g5 e f5 eb5 d5 c5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^q d5 3y g4 -17/64 e a4 1.0 tie s tie t tie u tie 3x tie 3y -3t.. e bb4 tie s tie t tie 3t tie 3u -y e g4 tie s tie t tie x..) (-s -3x h d4 tie e tie t tie x tie 3t -q) (q eb5 0.76 e e e e e f5 eb5) (e d5 tie z^3y s eb5 tie z^s d5 tie 3y eb5 -47/768 z^3y d5 s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s f5 tie z^s eb5 tie 3y f5 -47/768 z^3y eb5 q d5 -) (q c5 e e e. s eb5 e d5 c5) (h. bb4 -q) (q a4 e e e e e. d5 s) (q d5 tie s tie z^s gb5 tie 3y d5 -47/768 z^3y gb5 s e5 tie z^s d5 3y e5 -47/768 q d5 tie z^3y e a4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (3y a4 -x -3x -3y e d5 1.0 tie s tie t tie u -3x -3y e a4 tie s tie t tie x tie u tie 3y -x e bb4 tie s.. -x. e g4 tie s tie t tie u) (-s -3y h d5 tie e tie t tie x tie u tie 3x tie 3y e. a4 0.76 s) (q d5 1.0 tie z^q a4 mf tie 3y d5 1.0 -191/768 3y a4 mf 23/768^t 0.19 t c5 1.0 q bb4 tie s tie z^e a4 0.76 tie 3y bb4 1.0 -95/768) (z^3y a4 0.76 h. g4 mf))

title-of-the-score-2 '((q b4 0.5 e. a4 s) (q b4 e a4 b4) (q g4 e fs4 a4) (q e4 e -) (q fs4 e e) (q c5 e. e4 s) (q ds4 e e4 e4) (q b4 -e b4) (q. a4 e) (q g4 -e g4) (e fs4 fs4 b4 b4) (q g4 e -s g4) (q. fs4 e) (q e4 e e b3) (q b3 tie 3y 23/768^t 0.12 t d4 mf e c4 0.5 tie z^s b3 0.12 tie 3y c4 0.5 -47/768) (3y b3 q tie e tie s tie t tie x tie u tie 3x tie 3y) (q b4 e e a4) (q g4 e e fs4) (q e4 e e) (q. c5 -e) (q c5 e e b4) (q. a4 -s a4) (e. d5 s e. s c5) (h b4) (q e5 e d5 c5) (q b4 e as4 b4) (q d5 e c5 b4) (q. a4 -e) (q c5 e b4 a4) (q g4 e. fs4 s g4) (q e4 e. c5 s) (q b4 -) (e b4 -q.) (e. b4 s a4 g4 fs4 g4 fs4) (s e4 tie z^3y s ds4 tie z^s e4 tie 3y ds4 -47/768 z^3y e4 s fs4 q b3 tie) (z^e e4 tie 3y b3 -95/768 s e4 tie z^3y s fs4 tie z^s g4 tie 3y fs4 -47/768 x g4 tie 3x tie z^3y s fs4 tie x tie 3x tie z^3q e4 3y fs4 -21/256) (q c5 tie 3y -95/768 s c5 tie z^3y s a4) (e fs4 s c5 a4 fs4 a4 c5 a4) (q fs4 -) (q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 tie 3y g4 -95/768 z^3y fs4 e e4 fs4 tie z^e a4 tie 3y fs4 -95/768) (z^3y a4 e g4 tie z^e e5 3y g4 -95/768 q d5 tie) (z^3y d5 q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 3y g4 -95/768 e e4 fs4 a4) (e g4 tie z^3y e e5 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e e) (e d5 tie z^e g5 3y d5 -95/768 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e. s) (h d5) (q b4 e e) (q b4 tie z^3y t d5 0.12 tie z^t c5 mf 3y d5 0.12 -23/768 e. b4 0.5 tie) (z^3y b4 0.5 q a4 mf e e d5) (q g4))

title-of-the-score-3 '((-s g4 0.5 g4 g4 g4 g4 g4 b4) (h g4) (-s a4 a4 a4 a4 a4 a4 c5) (q. a4 -e) (-s b4 b4 b4 b4 b4 b4 d5) (h d5) (-s g4 0.11 g4 a4 b4 g4 a4 b4) (q a4 tie z^3y e g4 -) (-s d5 d5 b4 t s g4 g4 d4 -t) (h d4) (-s d5 d5 b4 b4 g4 g4 d4) (q. e4 -e) (-s c5 c5 a4 a4 fs4 fs4 d4) (h d4) (-s d4 d4 d4 cs4 d4 e4 fs4) (q a4 tie z^e g4 3y a4 -191/768) (-s d5 d5 b4 t s g4 g4 g4 -t) (h c5) (-s c5 c5 c5 c5 e5 g5 e5) (q. d5 -e) (-s d5 d5 b4 b4 g4 g4 g4) (h c4) (-s c4 c4 c4 d4 d4 e4 fs4) (q a4 tie z^3y e g4))

etc...
))

 SB.

Link to comment
Share on other sites

Is there something you want me to do for this? 

 

The library file you have shown as example, is it your own file, or is it in the OM system and you are modifying it? If it is a new file you are creating, it should be possible to create this automatically by a function (except that it is not clear how to create the sections and get the score titles).

 

-Rangarajan

Link to comment
Share on other sites

Hi Rangarajan,

 

indeed, i would like your help for the end of this project.

 

the library file i show in example is made manually but what i'm searching for is an automatic way by function to create such file and feed it with the instrument OMN slot content from score files.

 

I made this one manually just for the example.

 

for section name, finally, i think it would be better if section name was the name of the score-file and eaxh the entry of the section would be the name of the track/instrument from the score-file.

 

It would look like this:

 

 

(in-package :Opusmodus)

;;;---------------------------------------------------------
;;; Melodies
;;;---------------------------------------------------------

(def-library melodies
  (:section title-of-the-score-1
   name-of-the track-1  '((-q. e d5 0.63 c5 bb4 -q) (h bb4 tie e e a4 g4 a4) (h g4 tie z^3y q gb4 e d4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (z^q g4 3y d4 -191/768 q a4 bb4 e. c5 s) (h. d5 -e d5) (q. eb5 e d5 c5 c5 f5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^h d5 tie 3y g4 -383/768 e d5 a4 bb4 g4) (h. d4 -q) (q bb4 e e e c5 c5 bb4 c5) (q d5 tie e tie z^3y t c5 tie 3t^u. t d5 tie 3t^u. 3u c5 tie tu h bb4 tie) (z^q c5 3y bb4 -191/768 e c5 c5 c5 c5 bb4 c5) (h. d5 q 0.76) (q. g5 e f5 eb5 d5 c5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^q d5 3y g4 -17/64 e a4 1.0 tie s tie t tie u tie 3x tie 3y -3t.. e bb4 tie s tie t tie 3t tie 3u -y e g4 tie s tie t tie x..) (-s -3x h d4 tie e tie t tie x tie 3t -q) (q eb5 0.76 e e e e e f5 eb5) (e d5 tie z^3y s eb5 tie z^s d5 tie 3y eb5 -47/768 z^3y d5 s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s f5 tie z^s eb5 tie 3y f5 -47/768 z^3y eb5 q d5 -) (q c5 e e e. s eb5 e d5 c5) (h. bb4 -q) (q a4 e e e e e. d5 s) (q d5 tie s tie z^s gb5 tie 3y d5 -47/768 z^3y gb5 s e5 tie z^s d5 3y e5 -47/768 q d5 tie z^3y e a4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (3y a4 -x -3x -3y e d5 1.0 tie s tie t tie u -3x -3y e a4 tie s tie t tie x tie u tie 3y -x e bb4 tie s.. -x. e g4 tie s tie t tie u) (-s -3y h d5 tie e tie t tie x tie u tie 3x tie 3y e. a4 0.76 s) (q d5 1.0 tie z^q a4 mf tie 3y d5 1.0 -191/768 3y a4 mf 23/768^t 0.19 t c5 1.0 q bb4 tie s tie z^e a4 0.76 tie 3y bb4 1.0 -95/768) (z^3y a4 0.76 h. g4 mf))

name-of-the track-2 '((q b4 0.5 e. a4 s) (q b4 e a4 b4) (q g4 e fs4 a4) (q e4 e -) (q fs4 e e) (q c5 e. e4 s) (q ds4 e e4 e4) (q b4 -e b4) (q. a4 e) (q g4 -e g4) (e fs4 fs4 b4 b4) (q g4 e -s g4) (q. fs4 e) (q e4 e e b3) (q b3 tie 3y 23/768^t 0.12 t d4 mf e c4 0.5 tie z^s b3 0.12 tie 3y c4 0.5 -47/768) (3y b3 q tie e tie s tie t tie x tie u tie 3x tie 3y) (q b4 e e a4) (q g4 e e fs4) (q e4 e e) (q. c5 -e) (q c5 e e b4) (q. a4 -s a4) (e. d5 s e. s c5) (h b4) (q e5 e d5 c5) (q b4 e as4 b4) (q d5 e c5 b4) (q. a4 -e) (q c5 e b4 a4) (q g4 e. fs4 s g4) (q e4 e. c5 s) (q b4 -) (e b4 -q.) (e. b4 s a4 g4 fs4 g4 fs4) (s e4 tie z^3y s ds4 tie z^s e4 tie 3y ds4 -47/768 z^3y e4 s fs4 q b3 tie) (z^e e4 tie 3y b3 -95/768 s e4 tie z^3y s fs4 tie z^s g4 tie 3y fs4 -47/768 x g4 tie 3x tie z^3y s fs4 tie x tie 3x tie z^3q e4 3y fs4 -21/256) (q c5 tie 3y -95/768 s c5 tie z^3y s a4) (e fs4 s c5 a4 fs4 a4 c5 a4) (q fs4 -) (q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 tie 3y g4 -95/768 z^3y fs4 e e4 fs4 tie z^e a4 tie 3y fs4 -95/768) (z^3y a4 e g4 tie z^e e5 3y g4 -95/768 q d5 tie) (z^3y d5 q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 3y g4 -95/768 e e4 fs4 a4) (e g4 tie z^3y e e5 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e e) (e d5 tie z^e g5 3y d5 -95/768 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e. s) (h d5) (q b4 e e) (q b4 tie z^3y t d5 0.12 tie z^t c5 mf 3y d5 0.12 -23/768 e. b4 0.5 tie) (z^3y b4 0.5 q a4 mf e e d5) (q g4))

name-of-the track-3 '((-s g4 0.5 g4 g4 g4 g4 g4 b4) (h g4) (-s a4 a4 a4 a4 a4 a4 c5) (q. a4 -e) (-s b4 b4 b4 b4 b4 b4 d5) (h d5) (-s g4 0.11 g4 a4 b4 g4 a4 b4) (q a4 tie z^3y e g4 -) (-s d5 d5 b4 t s g4 g4 d4 -t) (h d4) (-s d5 d5 b4 b4 g4 g4 d4) (q. e4 -e) (-s c5 c5 a4 a4 fs4 fs4 d4) (h d4) (-s d4 d4 d4 cs4 d4 e4 fs4) (q a4 tie z^e g4 3y a4 -191/768) (-s d5 d5 b4 t s g4 g4 g4 -t) (h c5) (-s c5 c5 c5 c5 e5 g5 e5) (q. d5 -e) (-s d5 d5 b4 b4 g4 g4 g4) (h c4) (-s c4 c4 c4 d4 d4 e4 fs4) (q a4 tie z^3y e g4))

)

(:section title-of-the-score-2
   name-of-the track-1  '((-q. e d5 0.63 c5 bb4 -q) (h bb4 tie e e a4 g4 a4) (h g4 tie z^3y q gb4 e d4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (z^q g4 3y d4 -191/768 q a4 bb4 e. c5 s) (h. d5 -e d5) (q. eb5 e d5 c5 c5 f5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^h d5 tie 3y g4 -383/768 e d5 a4 bb4 g4) (h. d4 -q) (q bb4 e e e c5 c5 bb4 c5) (q d5 tie e tie z^3y t c5 tie 3t^u. t d5 tie 3t^u. 3u c5 tie tu h bb4 tie) (z^q c5 3y bb4 -191/768 e c5 c5 c5 c5 bb4 c5) (h. d5 q 0.76) (q. g5 e f5 eb5 d5 c5 eb5) (e d5 tie s tie z^3y s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s c5 tie z^s bb4 tie 3y c5 -47/768 z^3y bb4 s a4 tie z^e bb4 3y a4 -95/768 s g4 tie z^3y s a4 tie z^e bb4 tie 3y a4 -95/768 z^3y bb4 e g4 tie) (z^q d5 3y g4 -17/64 e a4 1.0 tie s tie t tie u tie 3x tie 3y -3t.. e bb4 tie s tie t tie 3t tie 3u -y e g4 tie s tie t tie x..) (-s -3x h d4 tie e tie t tie x tie 3t -q) (q eb5 0.76 e e e e e f5 eb5) (e d5 tie z^3y s eb5 tie z^s d5 tie 3y eb5 -47/768 z^3y d5 s c5 tie z^s d5 tie 3y c5 -47/768 z^3y d5 s f5 tie z^s eb5 tie 3y f5 -47/768 z^3y eb5 q d5 -) (q c5 e e e. s eb5 e d5 c5) (h. bb4 -q) (q a4 e e e e e. d5 s) (q d5 tie s tie z^s gb5 tie 3y d5 -47/768 z^3y gb5 s e5 tie z^s d5 3y e5 -47/768 q d5 tie z^3y e a4 tie s tie 3y t tie x tie u tie 3x tie 3y tie) (3y a4 -x -3x -3y e d5 1.0 tie s tie t tie u -3x -3y e a4 tie s tie t tie x tie u tie 3y -x e bb4 tie s.. -x. e g4 tie s tie t tie u) (-s -3y h d5 tie e tie t tie x tie u tie 3x tie 3y e. a4 0.76 s) (q d5 1.0 tie z^q a4 mf tie 3y d5 1.0 -191/768 3y a4 mf 23/768^t 0.19 t c5 1.0 q bb4 tie s tie z^e a4 0.76 tie 3y bb4 1.0 -95/768) (z^3y a4 0.76 h. g4 mf))

name-of-the track-2 '((q b4 0.5 e. a4 s) (q b4 e a4 b4) (q g4 e fs4 a4) (q e4 e -) (q fs4 e e) (q c5 e. e4 s) (q ds4 e e4 e4) (q b4 -e b4) (q. a4 e) (q g4 -e g4) (e fs4 fs4 b4 b4) (q g4 e -s g4) (q. fs4 e) (q e4 e e b3) (q b3 tie 3y 23/768^t 0.12 t d4 mf e c4 0.5 tie z^s b3 0.12 tie 3y c4 0.5 -47/768) (3y b3 q tie e tie s tie t tie x tie u tie 3x tie 3y) (q b4 e e a4) (q g4 e e fs4) (q e4 e e) (q. c5 -e) (q c5 e e b4) (q. a4 -s a4) (e. d5 s e. s c5) (h b4) (q e5 e d5 c5) (q b4 e as4 b4) (q d5 e c5 b4) (q. a4 -e) (q c5 e b4 a4) (q g4 e. fs4 s g4) (q e4 e. c5 s) (q b4 -) (e b4 -q.) (e. b4 s a4 g4 fs4 g4 fs4) (s e4 tie z^3y s ds4 tie z^s e4 tie 3y ds4 -47/768 z^3y e4 s fs4 q b3 tie) (z^e e4 tie 3y b3 -95/768 s e4 tie z^3y s fs4 tie z^s g4 tie 3y fs4 -47/768 x g4 tie 3x tie z^3y s fs4 tie x tie 3x tie z^3q e4 3y fs4 -21/256) (q c5 tie 3y -95/768 s c5 tie z^3y s a4) (e fs4 s c5 a4 fs4 a4 c5 a4) (q fs4 -) (q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 tie 3y g4 -95/768 z^3y fs4 e e4 fs4 tie z^e a4 tie 3y fs4 -95/768) (z^3y a4 e g4 tie z^e e5 3y g4 -95/768 q d5 tie) (z^3y d5 q g4 e e) (e g4 tie z^e d5 3y g4 -95/768 e b4 tie z^3y e g4 tie) (z^e fs4 3y g4 -95/768 e e4 fs4 a4) (e g4 tie z^3y e e5 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e e) (e d5 tie z^e g5 3y d5 -95/768 q d5 tie) (3y d5 e tie s tie t tie x tie u tie 3x tie 3y e. s) (h d5) (q b4 e e) (q b4 tie z^3y t d5 0.12 tie z^t c5 mf 3y d5 0.12 -23/768 e. b4 0.5 tie) (z^3y b4 0.5 q a4 mf e e d5) (q g4))

name-of-the track-3 '((-s g4 0.5 g4 g4 g4 g4 g4 b4) (h g4) (-s a4 a4 a4 a4 a4 a4 c5) (q. a4 -e) (-s b4 b4 b4 b4 b4 b4 d5) (h d5) (-s g4 0.11 g4 a4 b4 g4 a4 b4) (q a4 tie z^3y e g4 -) (-s d5 d5 b4 t s g4 g4 d4 -t) (h d4) (-s d5 d5 b4 b4 g4 g4 d4) (q. e4 -e) (-s c5 c5 a4 a4 fs4 fs4 d4) (h d4) (-s d4 d4 d4 cs4 d4 e4 fs4) (q a4 tie z^e g4 3y a4 -191/768) (-s d5 d5 b4 t s g4 g4 g4 -t) (h c5) (-s c5 c5 c5 c5 e5 g5 e5) (q. d5 -e) (-s d5 d5 b4 b4 g4 g4 g4) (h c4) (-s c4 c4 c4 d4 d4 e4 fs4) (q a4 tie z^3y e g4))

)
etc...
)

Regards

 

SB. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy