Accessing Midi events inside a custom plugin

I’ve done a bit more reading, and I’ve realized that I probably need to provide more information about what I am trying to accomplish.

When the Midi event is triggered, I need it to write to a ValueTree (a ValueTree which is also used by the message thread). There are two problems that I don’t know how to solve:

  1. What’s the best way to ensure that a race condition doesn’t occur, ie. if the audio thread and the message thread are trying to access the same ValueTree at the same time?
  2. How can I find the correct ValueTree to edit? I have a potential solution ready for this which I’ve been using on the message thread: I give ValueTrees a path stored as a String. But what I’ve read so far suggests that you can’t use Strings on the audio thread.

I hope that this all makes sense. This is the first time that I’ve worked with threading, so please be patient if I’m going off track.