I got one of those new-fangled gadgets. They call them the "smartphone". I got to admit, they are pretty nifty. Mine is hooked up to two accounts (personal and corporate). I get a lot of messages and notifications on my phone. Some of those are important, some less so. When I say a lot of messages, I mean a *lot*. (Look at me; I forget the emphasis HTML tag and I'm too lazy to look it up; I'm not to lazy to leave this note, though.) I also got one of those cool new smart watches (Sony SmartWatch3). Those are cool because when my phone makes a weird beeping sound I can glance at my wrist and see what the noise is all about. Unfortunately, with the watch requiring a charge every night or two, it tends not to stay on my wrist as much as my conventional watch used to stay on my wrist. I realized I need a better solution to figuring out what my phone is trying to tell me when it is beeping at me.

It occurred to me that ringtones (or notification-tones) is the answer. I can set up different tones for different apps and use those to differentiate and tell if I need to pause the movie, extract myself from the comfy beanbag (and arms/legs of people if I'm watching with a friend), hunt down the phone and look at whatever it wants me to look at. (I swear, my 4 year old nephew doesn't ask for half as much attention as my phone does!) Brilliant idea! I browse some websites for a simple, unobtrusive ringtone and get a bunch of really loud and jarring jingles and sound tracks. Really? Next up, the Google Play Store. Lots of apps with tones, nothing simple and short. (Why can't I find any tones under 5 seconds?) Ring tone generators? Meh. Nothing looks great. (I found Sound Creator to be cool with some decent potential for those who like coding.)

Abandoning the Android front, I switched to Linux. I could just make sound files on my computer, right? I install timidity++. I install rosegarden. I don't know what I'm doing. MIDI sounds right but I have no clue what a MIDI actually is. It's a simple sound file, right? I find the python-midi library on GitHub. I install swig. I get the python-midi library working. I run the example script and get an example MIDI file. timidity can open the file ... but spits out some garbage about sound bands and no sound. Drat. I install timidity-freepats and soundfont-fluid. I have no idea what they are but the Archlinux Wiki said I should install them. Who am I to argue? I also set up the timidity conf as per the Wiki. All good? Not in the least. Still no sound. I download a random MIDI file off the web. This one plays in timidity. I'm getting somewhere! The python-midi lib comes with a nifty script that takes a MIDI file and prints out a python-midi representation. Awesome!! Except the library doesn't handle MIDI event 0x0A. Add that in. Get the MIDI event list. Copy the first ... 20 lines! Now I got a Python script that spits out a MIDI file that I can actually play. Woooo!

Tidy up the code, figure out what it does, write some code of my own. I now got a bunch of MIDI files. Muck around with timidy and lame and I got four mp3 files! Success!
Sound files:
MIDI to WAV to MP3
$ for i in *mid; do timidity -Ow $i; done
$ for i in *wav; do lame $i; done

Python code
import midi

def NotePair(ticks, pitch, velocity):
  on = midi.NoteOnEvent(tick=0, pitch=pitch, velocity=velocity)
  off = midi.NoteOffEvent(tick=ticks, pitch=pitch)
  return on, off

def PatternFromNotes(events, instrument=26, title='Foo'):
  # Instantiate a MIDI Pattern (contains a list of tracks)
  pattern = midi.Pattern()
  # Instantiate a MIDI Track (contains a list of MIDI events)
  track = midi.Track()
  # Append the track to the pattern

  # Add some title text
  title = title + '\0'
  midi.ProgramNameEvent(tick=0, text=title),

  # Set the instrument
  track.append(midi.ProgramChangeEvent(tick=0, value=instrument))

  for event in events:

  # Mark the end of the track

  return pattern

def main():
  data = {
    'Email': (43, [ # Cello
      ( 0, 65, 40),
      (80, 68, 80),
      (60, 65, 0),
      (30, 71, 60),
      (30, 68, 0),
      (30, 74, 40),
      (30, 71, 0),
      (00, 74, 0),
    'SMS': (74, [ # Flute
      (  0, 90, 120),
      (200, 90, 0),
      (200, 93, 100),
      (200, 93, 0),
      (200, 96, 80),
      (300, 96, 0),
    'CorpEmail': (115, [ # Steel drum
      (  0, 65, 100),
      (100, 65, 0),
      (  0, 71, 100),
      (100, 71, 0),
      (  0, 65, 100),
      (100, 65, 0),
      (  0, 59, 100),
      (100, 59, 0),
    'Calendar': (12, [ # Vibraphone
      (  0, 85, 120),
      (200, 71, 80),
      (100, 85, 0),
      (300, 71, 0),

  for item in data:
    instrument, tpv = data[item]
    notes = [midi.NoteOnEvent(tick=t, pitch=p, velocity=v) for t, p, v in tpv]
    pattern = PatternFromNotes(notes, instrument=instrument, title=item)

    # Save the pattern to disk
    midi.write_midifile(item + ".mid", pattern)