Added a midi_buffer lock to make buffer appends and pops thread safe.