@Override
   public void setBuffer()
   {
      if (isDirty())
      {
         int numTempoChangeBytes = 0;
         for(TempoChange tempoChange : tempoChanges)
            numTempoChangeBytes += ((tempoChange.getBeatsPerMinute() < 256 ? 1 : 2) + 4);

         buffer = new byte[1 + numTempoChangeBytes];

         int    index  = 0;
         buffer[index] = (byte)timeStampFormat.getValue();
         index++;
         for(TempoChange tempoChange : tempoChanges)
         {
            int bpm = tempoChange.getBeatsPerMinute();
            if (bpm != 0xFF)
            {
               buffer[index] = (byte)bpm;
               index++;
            }
            else
            {
               buffer[index]     = (byte)0xFF;
               buffer[index + 1] = (byte)(bpm - 0xFF);
               index += 2;
            }
            System.arraycopy(intToBytes(tempoChange.getTimeStamp()), 0, buffer, index, 4);
         }
         dirty = false;    // data has already been saved
      }
   }