midi-carver: A Data Carver for MIDI Files

Overview

MIDI-Carver is a tool for extracting (partial or complete) MIDI files from a binary block of data.  It can be used against a solid data file – e.g. an ISO image – to attempt to retrieve MIDI data into standalone files.  It also can parse images of damaged filesystems and makes some attempt at recovery even when the source has damaged one or more tracks, or obliterated the MIDI header.

If your disk has crashed, and you need your music back, midi-carver may be your best bet.

Introduction

Data recovery is tricky business.  The best solution is not to have to do it at all: MAKE REGULAR BACKUPS.  But if you have not done this – or even if you have and are unlucky enough to have bad backups – then it becomes a much more painful process.

Starting with an image of the damaged source material (create using ddrescue or some other tool), the next best thing is to mount it locally.  If that fails, one should try to somehow rebuild / recover the FAT table, so the disk image may become usable again.  If that fails, the last resort is “data carving”: searching the binary image for some indicators of file types, and then extracting them to disk.  Some popular tools for doing this are foremost, scalpel, and PhotoRec.

midi-carver is a data carver specifically designed to recover MIDI files.  It has a more intelligent extractor, in that it can skip damaged information and create MIDI files with the remaining good stuff.  It can also, if you’re lucky, locate deleted items on the disk and recover them.

Features

  • Attempts extraction of MIDI files from any binary blob
  • Locates “orphaned” MIDI tracks (where the header is missing) and creates a new MIDI header to contain the tracks
  • Copes gracefully with missing tracks by re-writing the header to the correct structure
  • Detects MIDIs which were overwritten by others, and truncates / splits into two separate tracks

Usage

The hardest part of this would be compiling midi-carver.  If you’re on Linux, FreeBSD or OSX this is easy.  Download midi-carver.c, open a terminal and:

gcc -o midi-carver midi-carver.c

This will compile midi-carver into an application which can be run on a block file, like this:

./midi-carver <filename>

midi-carver will create a folder titled “mcut-out” in the same directory as <filename>, and save any MIDIs it finds into that folder.

Of course, you’ll need something to work on.  I highly recommend using ddrescue on your damaged disk to create images.  It’s very effective at getting the most undamaged data off the disk possible.  Once you’ve done that, run midi-carver as described above, and look in the mcut-out to see if anything detected was usable.

Limitations

  • midi-carver does not handle source fragmentation.  This is ordinarily not a problem with iso images, but it is an issue with hard disks (and especially, floppy disk images) where files have been deleted and then added frequently.  In this case the file system may break the files into blocks and rearrange them to effectively use all the disk capacity.  midi-carver cannot read (or recreate) a file allocation table, so it cannot determine how to follow fragments.  There is hope for a “last-block fragmented” recovery feature, but its usefulness would be slim.
  • midi-carver will happily terminate tracks without checking the actual MIDI events in the track.  This produces a MIDI file which is structurally valid, but which media players may choke and die on, if the MIDI events in the track are not of the proper format.
  • There are a few pathological cases which may cause midi-carver to do the wrong thing – e.g. a tiny MIDI file embedded within a huge MIDI track will be missed.

Future Plans

Fix limitations 2 and 3 above!  This would mean adding a real track validator that could follow MIDI events in a track and then terminate it as soon as things appear to go sour.

Download

midi-carver.c – 12.1 kb, version 1.0.

License

It’s just 3-clause BSD.

Copyright (c) 2010, Greg Kennedy

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of midi-carver nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Leave a Reply

Your email address will not be published. Required fields are marked *