is it possible to READ a midi file with seq~ ?

vojko v's icon

Hi,

I am trying to loop a MIDI file and vary it's speed during playback, so I thought of using seq driven by ticks but it is very imprecise. So I searched the forums and found out that seq~ is much more precise.

But I didn't find a clear way of reading MIDI files into seq~. Yes there is the help file about recording midi but I am interested in reading MIDI files from disk.

What is the way?

vojko v's icon

here is a simple midi loop patch with seq, maybe I connected it wrong but it's WAY off, it seems the right outlet of seq is always late to restart the loop

Max Patch
Copy patch and select New From Clipboard in Max.

broc's icon

Reading a MIDI file into [seq~] is possible with several steps.

1. Read the MIDI file into [seq]
2. Write to a text file
3. Convert text into format of [seq~]
4. Read the data into [seq~]

The conversion mainly requires mapping of the start times,
from ms of [seq] to fractions 0..1 for the phasor of [seq~].
So it's a bit tricky, but you get a loop with accurate timing.

vojko v's icon

Damn that seems really complicated

Thanks for the reply but I got so many more questions:

- How do I do that conversion, with regexp or something??
- How do I save to a .txt file from seq automatically? (something like "writemax something.txt" message in detonate, without having to open dialog box and choose .txt file output)
- How do I know the full length of the MIDI file so I can scale it to 0-1 for phasor~??
- Is there some documentation about seq and seq~ text output? they are not really similar

broc's icon

Well, complicated but automatable.

Sending the message [write MIDI.txt] to seq will save without open dialog.
Then send [read MIDI.txt, dump] to a [text] object to get the MIDI events.
The first item is the start time in ms which needs to be converted.
After conversion/scaling you can fill seq~ using 'add' messages.

As you've said, scaling needs the full length of the file in ms.
It can be calculated using the formula: number_of_beats*60000/bpm.
If the file has no tempo information, bpm=120 is assumed by default.
Notice that the number of beats is generally needed for proper looping,
because the last event usually happens within the last bar (before the end).

vojko v's icon

when I send "write MIDI.txt" to seq I get "error -1 creating file"

broc's icon

Strange, it works well for me.
Try to put an empty MIDI.txt file in the same folder as your patch.

Quote from the seq reference page:
"With a symbol as an argument, write will write a file with the specified name"

vojko v's icon

nope, still error.

I've seen the reference.

What version are you on?

Also when you send message "write MIDI.txt" where does it save it for you?

broc's icon

I'm on Mac OS 10.14.6, Max 7.3.6.
For me MIDi.txt is automatically created and saved in the application folder.
Or, if I create the file manually in the search path it's used instead.

vojko v's icon

I'm on Windows 8 // Max 8.12. Should I report this as an error/bug?

broc's icon

Yes, looks like a bug which can easily be reproduced.
But make sure you don't have another file with name MIDI in the search path.

vojko v's icon

this works really good. and the windows bug has been reported. thanks broc

SallySel's icon

Yo, I’m also a huge noob who are having lot of trouble with this one.

First of all, how do you apply the Bpm formula so it calculate the first column of the data in ‘text’, or in which order and more specific how does this step work?

Second. I’ve mostly had problems with the seq~. After I’ve made the MIDI.txt and dumped it into the ‘text’ object(where everything looks just fine), I’ve tried to run a message a la ‘add MIDI.text <1> <1>‘ and that lazy ass seq~ doesn’t show any sign of life. I’m using it with mc. but I don’t think that influence the process cause I’ve also tried it without mc. but that didn’t work as well.

I know this should be ez but I freaked on this.
hope someone can help or even better attach their solution:))) x o