3 Replies - 161 Views - Last Post: 15 August 2014 - 10:15 PM Rate Topic: -----

#1 gordlonious  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 27-March 13

Odd midi file characters.

Posted 15 August 2014 - 07:16 PM

Here's the code:
with open(path + "/OneChance1.mid", 'rb') as f:
    byte = f.read(8)
    print(byte)


I was expecting to receive binary but got this instead: MThd\x00\x00\x00\x06\x00\x01\x00\x03\x01\x80MT

What is that and how can I open a midi file and read it as binary instead of this? I've tried different encoding parameters for the open method and this has gotten me the farthest as far as no errors.

Any help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Odd midi file characters.

#2 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7743
  • View blog
  • Posts: 13,083
  • Joined: 19-March 11

Re: Odd midi file characters.

Posted 15 August 2014 - 07:23 PM

Well, it's all binary, right? This is just the hexadecimal representation of your binary - 0 , 0, 0, 6, 1, 0, 3, 1, oxty. I'm not sure what the MT on either end and the hd are for - those are new to me - but the binary represenation of this would be 0000 0000 0000 0000 0000 0000 0000 0110 0000 0001 0000 0000 0000 0011 0000 0001 1000 0000.

Why is binary important to you? What are you doing that makes you want binary representation? Do you want to look at the binary representations, or are you trying to do computations based on the binary representation, or what are you up to?
Was This Post Helpful? 0
  • +
  • -

#3 gordlonious  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 27-March 13

Re: Odd midi file characters.

Posted 15 August 2014 - 08:59 PM

Thanks! Basically, I want to dynamically order midi files but also have the ability to play them like they were one file. That means linking them somehow and creating/finding a media player that can handle that. I need to somehow create a music stream that is playing and has a plan of what is going to play; but it has to be modifiable upon execution. Any ideas? My next move is to just look through how a midi file works and then see if I can modify it dynamically.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7743
  • View blog
  • Posts: 13,083
  • Joined: 19-March 11

Re: Odd midi file characters.

Posted 15 August 2014 - 10:15 PM

Hm. I think I'd be looking at existing sound packages to see if any of them can do what you need. That's assuming your main goal is to get this piece of code running, of course

If your goal is to get experience working with midi files at a low level, you'd want to start by understanding the structure of a midi file and learning how to parse them. Since midi is not an audio encoding, but a series of instructions to a synthesizer of some sort, just chopping out bits and sticking them together looks like it's not going to be where you want to be.

This might be a useful resource if you really want to get down into the nuts and bolts.

And please do keep us posted on this, it looks like an interesting project you've taken on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1