Midi Visualization - CMPS 161, Winter 2008

Dustin Escoffery (descoffe@ucsc.edu)

Description

Music is a form of entertainment that is mediated through sound. I believe the experience of music can be extended to other senses beyond hearing. In particular, applying graphical visualization to music can make it more vivid, memorable, and enjoyable.

MidVis is a tool that aids in identifying properties of music. It differs from classic "ambient" visualizations in that everything you see encodes information about the music. Notes and their respective velocities and instruments are viewed through color, shape, and speed.

Features

  • Playing Midi File
  • Sequencing Midi File in Real Time
  • Note Frequency and Duration in Rectangle Glyphs
  • Custom Color Maps for Instrument Channels
  • Pseudocoloring to Visualize Note Velocity
  • Customizable Fade-out Effect
  • Customizable Speed and FPS

    Implementation

    This program contains an implementation of the open-source midi player, TiMidity. Modifications were required to transform TiMidity into library form, and extract the relevant midi data while a sample is playing. When a midi file is opened, TiMidity is invoked on a separate FLTK thread (pthread). This measure is necessary to run a visualization simultaneously, as TiMidity enters a loop for the duration of the song. TiMidity raises events to the main application to signal Note-On and Note-Off events. Since TiMidity preprocesses a midi file immediately, all events are added to a queue where they will be handled once their sample timestamp has arrived. The render loop is run on the other thread, which maintains the midi time. For every frame of the animation, the event queue is tested. When a note is turned on, a GL_QUAD glyph is activated and added to the bottom of the screen. The X position of this glyph is determined by an interpolation of the note across the range of notes for the given instrument channel. When a note is turned off, the GL_QUAD glyph is deactivated. Deactive notes are moved up the screen at a rate of "speed" pixels per frame. Active notes are only "stretched". Additionally, a "fading" effect is applied, such that the alpha value of each note is decreased by "fade" alpha/frame.

    User's Guide

  • To open a midi for playing, click "Play .mid". Search for midi and click "OK".
  • To change FPS, Fade, or Speed, adjust the sliders labeled as such.
  • To select an instrument channel, choose 1-10 in the "Channel" dropdown combo box. (note the widgets in the Pseudocoloring group only effect the selected channel's colormap).
  • To select a color component choose R/G/B from the RGB menu.
  • The Min/Max sliders will adjust the color map of the selected component for the selected channel. Every channel has one such map, though not every channel is always used by a given midi file.
  • Once a Midi is being played, it cannot be paused.
  • To stop a midi, you must close the application.
  • Only one midi can be opened at a time.

    Platform

    MidVis was developed on the Windows platform using MinGW and MSYS. It uses FLTK, OpenGL, and TiMidity++. Each of these components is cross-platform, so it is conceivable that MidVis may be built for other platforms such as Linux. Doing so would undoubtedly require that the Makefile be edited, and the correct libraries be included. This process is not within the scope of my documentation.

    Output

  • Image 1 - Bass_sample.mid: A simple midi from Wikipedia. Using default colormap and low speed/fade settings.
  • Image 2 - Bach's "Toccata and Fugue in Dm", using a Red colormap for the first (and only) instrument. Low fade.
  • Image 3 - Paul Mauriat's "Love is Blue", using Red, Cyan, Magenta, and Yellow colormaps for four instruments.
  • Video Clip - Example execution of the bass midi above. Uses default colormap and low speed settings. The initial lag is not normal--it came from running HyperCam.

    Downloads

  • MidVis Binary
  • TiMidity++ 2.13 Source
  • EAWPats 12

    Instructions

    To run MidVis, download the Binary above. midvis.exe and timidity.cfg are needed to run. Also you will need to download EAWPats and save them in a local folder "eawpats". You may optionally use a different set of instrument patches if you are familiar with TiMidity customization.

    Build Instructions (MinGW + MSYS)

  • Download MidVis.zip. Extract MidVis folder.
  • Download Timidity Source (TiMidity++-2.13.0.tar.gz) to local directory /MidVis
  • % tar -xvzf TiMidity++-2.13.0.tar.gz
  • % mv TiMidity++-2.13.0 TiMidity
  • % mv timidity.c timidity_main.h playmidi.c playmidi.h TiMidity/timidity
  • Change parameter of mkstemp in /MidVis/TiMidity/utils/support.h : line 67 from template to t. (template is a keyword in C++).
  • Remove extern in /MidVis/TiMidity/timidity/wrdt.c : line 101
  • % cd TiMidity
  • % ./configure
  • % make (main is supposed to be missing)
  • Download EAWPats (eawpats12.tar.bz2) to local directory /MidVis
  • % cd ..
  • % bunzip2 eawpats12.tar.bz2
  • % tar -xvf eawpats12.tar
  • % mv eawpats12 eawpats
  • % fluid -c gui.fl
  • % make

    Conclusions

    Writing music applications is more difficult than I anticipated. 90% of my effort on this project was dedicated to retreiving relevant information from midi files. This implies working with TiMidity. TiMidity was a hassle, but in the end it proved to be powerful. TiMidity was written in C, and this program in C++. I struggled for a while trying to get all of the components to link together. Also, TiMidity is its own program which has its own main loop. This required the design of a multithreaded application. With which, I ran into some synchronization issues along the way which set me back a while. The sum of these and other little nuisances resulted in a large inconvenience that could have been avoided if I chose another subject. However, I feel that this aspect of software engineering was a useful experience. Like I say, the other 10% was merely coding the visualization. While it was not as impressive as I hoped, I still got the job done in a functional way. I guess you can call it the Minimal Midi Visualizer.