title: Why does my script output empty .bin files?
body: <p>So I am trying to convert a .midi file to a .bin (audio) file for a small bootloader. The code gets executed successfully, but the output file is empty. Can Anyone see why? I have not found any solutions to this online.</p>
  <pre><code>import midi, sys
  
  pattern = midi.read_midifile(&quot;G:\PayloadMBR\Data\Song\RickRoll.midi&quot;)
  
  def pitchconv(pitch):
      return int(round(1193180.0 / (2**((pitch-69)/12.0)*440), 0))
  
  with open(&quot;G:\PayloadMBR\Data\Song\Out.bin&quot;, &quot;wb&quot;) as out:
      pitches = [pitchconv(event.pitch) for event in pattern[1] if isinstance(event, midi.NoteOnEvent)]
  
      b = 0
      d = 0
      
      t = 0
      o = -1
      for event in pattern[1]:
          if isinstance(event, midi.NoteOnEvent):
              if event.velocity == 0:
                  d += int(round(event.tick/48.0, 0))
                  p = pitchconv(event.pitch)
                  out.write(chr(p &amp; 0xff) + chr(d &lt;&lt; 5 | p &gt;&gt; 8))
                  b = 0
              else:
                  d = int(round(event.tick/48.0, 0))
  </code></pre>
  <p>Edit: <a href="https://mega.nz/file/OWByhbQK#YJJtDw8ryYsU35nSine8Wp2TP5FSjO1y_eDEZSSgxIc" rel="nofollow noreferrer">Midi File</a></p>