Jump to content

Logic Not Reading MIDI File?


Xigwon
Go to solution Solved by Dewdman42,

Recommended Posts

Hello, I am trying to write a program to generate a MIDI file for Logic to read.

 

I've taken a look at the MIDI files that Logic generates, and they are littered with control characters (gremlins) that cannot be read by anywhere else I know. Converting to ASCII and back made the file unreadable for Logic. In addition, Logic cannot read hexadecimal MIDI files. What can I do?

Link to comment
Share on other sites

Midifiles are binary files, they are not text files. You can’t make a midi file in a text editor, and if you are trying, then you are almost certainly not making a genuine midifile that is readable by anything.

 

As soon as you can make a genuine midi file (plenty of documentation out there on this) then Logic and anything else will be able to read your file just fine.

 

Short answer: it’s you, not Logic :)

Link to comment
Share on other sites

Midifiles are binary files, they are not text files. You can’t make a midi file in a text editor, and if you are trying, then you are almost certainly not making a genuine midifile that is readable by anything.

 

As soon as you can make a genuine midi file (plenty of documentation out there on this) then Logic and anything else will be able to read your file just fine.

 

Short answer: it’s you, not Logic :)

 

Thank you so much for your response, I have looked around online but have not been able to find any programs or websites that could help me do the conversion or the creation of a MIDI file. Did you have any sources in mind that you might be able to point me towards? Thank you

Link to comment
Share on other sites

How about this one...

 

Thank you for the recommendation. I read it, but I'm not exactly sure what to do. I understand that I need to type Hex characters for the track, channel, and events. But once I'm done with that, I just have a text file filled with Hex characters. How do I convert it to a MIDI file that Logic can read? Just changing the extension from .txt to .midi does not make the file readable.

 

If someone just shows me a MIDI to HEX converter, then I can drop one of Logic's own MIDI files into that, look at the HEX, and then just figure out what's going on.

Link to comment
Share on other sites

I think you’re a bit confused as to how to write binary files and you probably need to go back to some fundamentals to get the hang of programming this kind of thing.

 

As I said already, midifiles are not text files. You can’t type “hex characters” into an ascii text file and expect this to work - it doesn’t work like this.

 

The article linked to is the exact one that I used to implement midi file import and export into some software I made back in the day. I don’t know what software you are using to write a midifile, but you can’t do this in a text editor, because text files are fundamentally stored in a different way to binary files.

 

If you want to write raw bytes to a file manually (!) you can use a hex editor like Hex Fiend, but this is a very poor way to do this.

 

There is also no such thing as a “midi to hex converter”, if you want to look at the binary data, Hex Fiend will show you just fine - and will display the numbers in decimal, hex, binary, octal or whatever format you want.

 

What exactly are you trying to do, are you trying to write a computer program to write these files, and if so, what are you using?

 

Note - programming topics are way off topic for this Logic forum, so I’m not sure how far to go with this…

Link to comment
Share on other sites

I think you’re a bit confused as to how to write binary files and you probably need to go back to some fundamentals to get the hang of programming this kind of thing.

 

As I said already, midifiles are not text files. You can’t type “hex characters” into an ascii text file and expect this to work - it doesn’t work like this.

 

The article linked to is the exact one that I used to implement midi file import and export into some software I made back in the day. I don’t know what software you are using to write a midifile, but you can’t do this in a text editor, because text files are fundamentally stored in a different way to binary files.

 

If you want to write raw bytes to a file manually (!) you can use a hex editor like Hex Fiend, but this is a very poor way to do this.

 

There is also no such thing as a “midi to hex converter”, if you want to look at the binary data, Hex Fiend will show you just fine - and will display the numbers in decimal, hex, binary, octal or whatever format you want.

 

What exactly are you trying to do, are you trying to write a computer program to write these files, and if so, what are you using?

 

Note - programming topics are way off topic for this Logic forum, so I’m not sure how far to go with this…

 

Thank you for your reply and for clarifying. You're right that it is off-topic, so I will answer your question as to my goal and if you would like, you can provide some pointers.

 

I am in an Algorithmic and Generative Composition in Python class. We were given a module (from the opensource library "pyknon") that allegedly can take user input (note lengths, pitches) and generate a MIDI file, but the module is too old for my version of Python. I figured that such a module was just doing some sort of conversion, so I wanted to just program my own converter. If MIDI files were (or could be converted from) text files, I could just take a day or two to figure out the conversions. But since, as you say, MIDI files are not text files, then I have no idea how to generate a MIDI file and no idea how pyknon could do such a thing (I dug through the library and did not find any python file that appeared to do the conversion work).

Link to comment
Share on other sites

  • Solution

There are various different utilities that can convert between a text file format and a binary midi file...and some python add on libraries can just manipulate midi files directly. I have in the past use midicsv quite a bit...

 

https://www.fourmilab.ch/webtools/midicsv/

 

which is a tool that can convert a midi file into a csv text file or back again...then you can edit the csv file however you want. The csv format is quite simple so it would be easy to generate a midicsv file with python, then convert to a midifile using csvmidi utility.

Link to comment
Share on other sites

In case its of any help, here is a Scripter script I wrote a while back that can stream midicsv output to the Scripter window as you playback a sequencer track. its in javascript. there is also a javascript in there for actually using midicsv as the raw input to playback the sequence from Scripter (useful in MainStage primarily).

 

https://gitlab.com/dewdman42/MainstageMidiPlayer

Link to comment
Share on other sites

If MIDI files were (or could be converted from) text files, I could just take a day or two to figure out the conversions. But since, as you say, MIDI files are not text files, then I have no idea how to generate a MIDI file and no idea how pyknon could do such a thing

 

I mean, you can write a utility to do whatever you want - that's kind of what programming is.

 

If you want to have a utility that's converts a text format file (of "instructions") into a midifile, you can of course implement that. Your program would open your source text file, and create a destination binary output file for the midifile, then then read the text input, and output the appropriate binary MIDI data into the MIDIfile.

 

And yes, you could write this yourself, but if you have the Python code that does this already, it seems it would be far less work to modify that to work on your system than to reimplement it yourself from scratch (handy programmer tip - programmers don't reinvent wheels!).

 

But like any skill, programming is a journey, so it's something you have to embark upon yourself and kind of figure out these things you go - programming is largely about solving problems much of the time. Luckily, there is a wealth of resources to draw upon these days, which is a massive help.

 

But you'll need to understand the differences between text and binary files. You'll need to learn how to load and parse text files, and you'll need to learn how to create and write to binary files. Then you'll need to have code to output the various header data that always is in a midifile to be valid, and then how to parse whatever text commands are in your input text file into the necessary MIDI data to write to the MIDIfile.

 

You'll also probably need to understand how timing and event timestamps works, as you'll need to write events with the correct time positions on them too. None of this stuff is hard, but does involve a learning curve if you're a novice programmer, so take it one step at a time, and solve each problem as you go, implement each stage, until you end up with the result you want - a program to parse your arbitary text file of "instructions" into a valid MIDI file that can be loaded into any program that supports loading of standard MIDI files.

Link to comment
Share on other sites

There are numerous extensions for python which automatically handle all the internal storage of midifile structures and can be used through their own API's to create and export a midifile.

 

However, what I found when I was looking into it a while back is that they were often needlessly complex for some simple tasks. Some of them may provide interesting structures for maintaining musical structures in a python program and if that is useful, and if it also exports midifiles, then it still may be worth all the overhead of learning and using that API.

 

However, midicsv is a very simple format...and most python programmers are quite adept at filtering text files with python..which is why its very easy to just use that format for processing midi in Python and exporting in that format.. which easily converts into the final binary format.

 

I agree with what Des is saying, if you want to deal with midi files directly, you have to learn about binary files..if you have never handled binary files before, this is probably an area where you would have much to learn and I don't recommend it..unless you are just interested in the programming challenge.

Link to comment
Share on other sites

If MIDI files were (or could be converted from) text files, I could just take a day or two to figure out the conversions. But since, as you say, MIDI files are not text files, then I have no idea how to generate a MIDI file and no idea how pyknon could do such a thing

 

I mean, you can write a utility to do whatever you want - that's kind of what programming is.

 

If you want to have a utility that's converts a text format file (of "instructions") into a midifile, you can of course implement that. Your program would open your source text file, and create a destination binary output file for the midifile, then then read the text input, and output the appropriate binary MIDI data into the MIDIfile.

 

And yes, you could write this yourself, but if you have the Python code that does this already, it seems it would be far less work to modify that to work on your system than to reimplement it yourself from scratch (handy programmer tip - programmers don't reinvent wheels!).

 

But like any skill, programming is a journey, so it's something you have to embark upon yourself and kind of figure out these things you go - programming is largely about solving problems much of the time. Luckily, there is a wealth of resources to draw upon these days, which is a massive help.

 

But you'll need to understand the differences between text and binary files. You'll need to learn how to load and parse text files, and you'll need to learn how to create and write to binary files. Then you'll need to have code to output the various header data that always is in a midifile to be valid, and then how to parse whatever text commands are in your input text file into the necessary MIDI data to write to the MIDIfile.

 

You'll also probably need to understand how timing and event timestamps works, as you'll need to write events with the correct time positions on them too. None of this stuff is hard, but does involve a learning curve if you're a novice programmer, so take it one step at a time, and solve each problem as you go, implement each stage, until you end up with the result you want - a program to parse your arbitary text file of "instructions" into a valid MIDI file that can be loaded into any program that supports loading of standard MIDI files.

 

Thank you for the detailed response, I appreciate it! I am fluent only in creating text-based programs in Python to run in Terminal—not at all in writing files. But I will definitely look into that. I appreciate the help!

Link to comment
Share on other sites

There are various different utilities that can convert between a text file format and a binary midi file...and some python add on libraries can just manipulate midi files directly. I have in the past use midicsv quite a bit...

 

https://www.fourmilab.ch/webtools/midicsv/

 

which is a tool that can convert a midi file into a csv text file or back again...then you can edit the csv file however you want. The csv format is quite simple so it would be easy to generate a midicsv file with python, then convert to a midifile using csvmidi utility.

 

 

Thank you so much. Alas, I have a Mac, and am unwilling (at least right now, just to do this assignment) to download extra software to run .exe on my computer. But thank you, that would have been exactly what I was looking for.

Link to comment
Share on other sites

We were given a module (from the opensource library "pyknon") that allegedly can take user input (note lengths, pitches) and generate a MIDI file, but the module is too old for my version of Python.

 

Interesting that it's incompatible with a newer version of Python. I assume what you mean is that the module that needs to be rewritten to run in the newer version. It's open source, so if[/b] you have the time and expertise it's just a lot more extra work for this particular class :evil:

 

Have you talked about this with your instructor, are any other class members having issues, can you just use an older compatible Python version for the class? Etc. As a retired EE/CS guy who ran into this crap more than once over the years, it's totally unacceptable to me that a course would provide tools that don't actually work for all students.

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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