# Final Cut and the MessageThread

**URL:** <https://forum.juce.com/t/final-cut-and-the-messagethread/24659>\
**Category:** Audio Plugins\
**Created:** [October 14, 2017, 11:53am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659 "2017-10-14T11:53:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 14, 2017, 11:53am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/1 "2017-10-14T11:53:39Z")

</div>

Hi everybody,

I am writing an audio plugin for FinalCutProX, and I am using the AudioProcessorValueTreeState.  
FinalCut opens several instances of the plugin, to render the waveform previews in the timeline. But this triggers an assert in AudioProcessorValueTreeState.cpp:199:

> <https://github.com/WeAreROLI/JUCE/blob/eda613c6db698f31ab2189cc289c9de2db821142/modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.cpp#L199>

What can be done, so that the AudioProcessorValueTreeState can be used in FinalCut and possibly other hosts we are not aware of?

The MessageManager is shared amongst all JUCE plugin instances, right?

This assert means, that the creation of a plugin instance is not thread safe, right?

Can this assert be changed into a lock, because creating a plugin instance is not time critical anyway?

Thanks,  
Daniel

EDIT: just confirming that changing the assert into

```
    const MessageManagerLock mmLock;

```

works fine in FinalCutProX…

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 14, 2017, 1:01pm UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/2 "2017-10-14T13:01:58Z")

</div>

I don’t think it’ particularly important that this parameter creation is done on the message thread? Just needs to be guaranteed to be complete before the plugin processor constructor is complete, before the ValueTree is added, and to only be done on a single thread?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 17, 2017, 9:19am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/3 "2017-10-17T09:19:15Z")

</div>

Thanks @jimc, I think so too, but can’t make an educated statement, if locking is necessary.  
All I know is, that in FinalCut it is called from non-message threads.

@jules, @fabian, could you please comment on that and if positive make the changes?  
I would like to get back to a non-patched JUCE…

Cheers!

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [October 18, 2017, 11:14am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/4 "2017-10-18T11:14:24Z")

</div>

This change will appear on the develop branch shortly.

Thanks for reporting!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 18, 2017, 11:15am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/5 "2017-10-18T11:15:59Z")

</div>

Great, thanks @t0m!

---

<div class="post-metadata">

**Author:** ![midiculous](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/midiculous/32/582_2.png) [@midiculous](https://forum.juce.com/u/midiculous)\
**Post date:** [October 19, 2017, 6:19pm UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/6 "2017-10-19T18:19:52Z")

</div>

@daniel I’m curious as to what Plugin you are writing for Final Cut?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 19, 2017, 6:57pm UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/7 "2017-10-19T18:57:37Z")

</div>

Hi MIDIculous,  
thanks for asking. We integrate our [dynamic music library Filmstro](https://filmstro.com) into Final Cut, so you can add music to your movie. It needs to be a plugin, because you can keyframe musical parameters momentum, depth and power and change the style while playing.

I am happy to tell more about, but I don’t want to spam the board (actually I want to, but I try to be nice 😄 )

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 19, 2017, 8:46pm UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/8 "2017-10-19T20:46:19Z")

</div>

Hi @t0m, unfortunately I realised, that it doesn’t work like that.  
It is ok, if I have already at least one instance in the project.  
However, when I try to drag the plugin the first time on an audio clip, the MessageManagerLock stops FCPX completely (0%-CPU, waiting forever).  
This is reproducible every time here.

I only could make it work removing the MessageManagerLock.

When I have the instance on the timeline, I can close the project, recompile the plugin with the lock and restart FCPX with no problem. Very strange.

Is it safe to remove the lock completely?

Thank you for looking again,  
Daniel

…just in case, this is my constructor, nothing special:

```auto
FilmstroAudioProcessor::FilmstroAudioProcessor()
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput ("Input", AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
                     #endif
                       )
, state (*this, &undo)
{
    state.createAndAddParameter ("momentum", "Momentum", "Momentum",
                                 NormalisableRange<float> (0.0, 2.0, 0.001), 0.0, nullptr, nullptr);
    state.createAndAddParameter ("depth", "Depth", "Depth",
                                 NormalisableRange<float> (0.0, 2.0, 0.001), 0.0, nullptr, nullptr);
    state.createAndAddParameter ("power", "Power", "Power",
                                 NormalisableRange<float> (0.0, 2.0, 0.001), 0.0, nullptr, nullptr);

    state.state = ValueTree (getName());

    state.addParameterListener ("momentum", this);
    state.addParameterListener ("depth", this);
    state.addParameterListener ("power", this);
}

```

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [October 20, 2017, 9:14am UTC](https://forum.juce.com/t/final-cut-and-the-messagethread/24659/9 "2017-10-20T09:14:20Z")

</div>

I think it would be OK to remove the lock completely - I was originally torn between including it and not, so this simplifies things.
