Skip to content

Testing and short key signature events

Thomas E. Janzen edited this page Feb 22, 2023 · 1 revision

Part of the testing of the conversion utilities **miditext** and textmidi is performed on linux with a script similar to this:

  1. /usr/bin/env bash
function testmidi {
    temporary_directory=$(mktemp -d)
    bn=$(basename ${1} .mid)
    ~/me/janzent/miscprog/textmidi/miditext --midi ${1} --textmidi ${temporary_directory}/${bn}.txt
    sed -i -f ~/me/janzent/sed/starttrack.sed ${temporary_directory}/${bn}.txt
    ~/me/janzent/miscprog/textmidi/textmidi --textmidi ${temporary_directory}/${bn}.txt --midi ${temporary_directory}/${bn}.mid
    if [ -s ${temporary_directory}/${bn}.mid ]; then
        echo "new MIDI file is finite length";
    else
        echo "new MIDI file is either absent or zero length";
    fi
    ~/me/janzent/miscprog/textmidi/miditext --midi ${temporary_directory}/${bn}.mid --textmidi ${temporary_directory}/${bn}_B.txt
    sed -i -f ~/me/janzent/sed/starttrack.sed ${temporary_directory}/${bn}_B.txt
    ls -l ${1} ${temporary_directory}/${bn}.mid
    diff -s ${1} ${temporary_directory}/${bn}.mid 
    diff -q -bBw -s ${temporary_directory}/${bn}.txt ${temporary_directory}/${bn}_B.txt 

} testmidi ${BASH_ARGV[0]}

This script can be invoked with

./testmidi prelude.mid

The result is to create a temporary directory and create the files prelude.txt,



prelude.txt prelude.mid prelude_B.txt

The original MIDI file and the temporary prelude.mid are compared. The two textmidi text files are compared. The test set consists of 6340 classical music files. 64 MIDI files were put aside after having prompting error messages from an independent scoring program. The remaining 6276 files all compare the text files as identical, and about a third of the pairs of MIDI files compare as identical. The differences between MIDI files are still being investigated, but causes known so far include the following:

-Some of the imported MIDI files did not use running status,

  in which voice-channel events can drop the command byte if
  the command and channel are the same in consecutive voice-channel events.
  textmidi always uses running status.
  Running status as used by @command{textmidi} is marked undefined
  at the beginning of each track, and set by the first voice-channel event.
  From then to the end of the track, running status is set only by
  voice-channel events.  It is not reset by non-voice-channel events,
  including Channel Change.  In some files running-status is reset
  by a control event.  Voice-Channel events are one of:

. . Channel Pressure . . Note On/Off . . Polyphonic Key Pressure . . Pitch Bend . . Program Change . . Control Change (including omni/poly on/off)

  In text events (including TRACK, INSTRUMENT, COPYRIGHT, etc.)
  miditext drops both prefacing and trailing spaces, as well 
  as terminating "nul" (a character with a numeric value of zero) bytes.
  Therefore, TEXT events in the round-trip, recreated MIDI file may
  differ from those in the original MIDI file.

- miditext recognizes the short key signature event,

  but textmidi always creates the standard event with five total bytes:
  (0xFF, 0x59, 2 [the following data length], sharps/flats, mode).
Clone this wiki locally