Removing measures from MIDI files

Recently while creating a song arrangement, I had an application where I needed to remove measures from a MIDI file. In this case, the file was a section of a Yamaha-format style (IntroB) exported from a style file using Style Master. The overly complex introduction meandered on for eight measures — the last four measures would have been sufficient. So all I had to do was to remove the first four measures. Seemed simple.

The MIDI editors I discussed in a previous article failed at the task. MidiEditor could remove individual notes, but was unable to delete measures, leaving four measures of silence. Speedy MIDI could remove measures, but corrupted the file beyond use. The next step was to search the Internet for a utility. I couldn’t find anything, but I did encounter several posts from people seeking the same function. Accordingly, I decided to add a measure removal capability to MIDI Doctor 2.0.

Figure 1 shows the MIDI Doctor 2.0 interface. New features include a indication of total measures in the file (A), a measure and time counter added to the playback function (B) and new Global settings capabilities (C).

MIDI Doctor 2.0 main window.

Figure 1. MIDI Doctor 2.0 main window.

Figure 2 shows the Global settings dialog. There are three control groups. The Dynamic range group adjusts volume levels of all note messages in a file. A user can use the Play duration group to set a precise temporal length for the MIDI file. The measure removal function is accomplished with the controls of the Make excerpt group. The radio buttons determine whether the excerpt is specified by time or measure number. In the first case, the Start time and End time text fields are active. Their initial values are set to the beginning and end of the file. The user changes the start and end times and clicks Apply to narrow the file duration. Because of MIDI conventions, the excerpt process is not simply a case of saving messages within the time window. The effect of a MIDI message continues indefinitely until a following message counteracts it. Therefore, the state of the synthesizer at any time represents the cumulative effect of preceding messages. Eliminating these messages may result in incorrect instrument voices or volumes. Similarly, deletion of messages after the excerpt may leave hanging notes that play to infinity. MIDI Doctor uses the following process:

Global settings dialog.

Figure 2. Global settings dialog.

  • The absolute times of all messages before TStart are set to t = 0. The velocity values of all NoteOn messages are set to 0.
  • The absolute times of messages between TStart and TEnd are shifted to t = t – TStart.
  • Messages after TEnd are deleted. A message AllNotesOff is appended to prevent hanging notes.

Transfer of the sequence of initial non-sounding messages is limited by the MIDI serial rate. As a result, there may be a slight starting delay for large files. Measures are removed by clicking the By measure radio button, filling in the first and last measures to include in the excerpt and clicking the Apply button. Global operations are performed on MIDI message values stored in memory and determine the duration of the file on save.

Comments are closed.