# juce::AudioParameterFloat default value not reacting same way between xcode (mac os x) and visual studio (windows) ?!

**URL:** <https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781>\
**Category:** MacOSX and iOS\
**Created:** [June 10, 2024, 8:39am UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781 "2024-06-10T08:39:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skynext](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Skynext](https://forum.juce.com/u/Skynext)\
**Post date:** [June 10, 2024, 8:39am UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781/1 "2024-06-10T08:39:21Z")

</div>

I made a little video to show the “problem”

[![](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/0/a/0aefa72309c067f208dc92d0580b16be91426066.jpeg "Juce mac os x xcode float not the same than windows visual studio ?") ](https://www.youtube.com/watch?v=aFlVNC7GP5o)

I try to ask chatgpt the same questions but the answers did not help …

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [June 10, 2024, 9:45am UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781/2 "2024-06-10T09:45:25Z")

</div>

What does your code look like that decides when to draw the label in yellow?

---

<div class="post-metadata">

**Author:** ![Skynext](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Skynext](https://forum.juce.com/u/Skynext)\
**Post date:** [June 10, 2024, 10:02am UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781/3 "2024-06-10T10:02:14Z")

</div>

```auto
struct ComprendreParametres
{
    float seuil{ 0.0f };
    ...
}

ComprendreParametres obtenirParametres(juce::AudioProcessorValueTreeState& apvts);

ComprendreAudioProcessor::ComprendreAudioProcessor()
    : AudioProcessor(BusesProperties()
      ...
    ),
    ...
    altere {
      {"seuil", false},
      ...
    },
    pardefaut {
        {"seuil", -20.0f},
        ...
    }
{
    ...
    ecoutes();
}

ComprendreParametres obtenirParametres(juce::AudioProcessorValueTreeState& apvts)
{
    ComprendreParametres parametres;
    parametres.seuil = apvts.getRawParameterValue("seuil")->load();
    ...
    return parametres;
}

juce::AudioProcessorValueTreeState::ParameterLayout ComprendreAudioProcessor::creationParametres()
{
    juce::AudioProcessorValueTreeState::ParameterLayout layout;

    layout.add(std::make_unique<juce::AudioParameterFloat>("seuil", "Threshold", juce::NormalisableRange<float>(-60.0f, 0.0f, 0.01f), -20.0f));
    ....
}

void ComprendreAudioProcessor::ecoutes()
{
    apvts.addParameterListener("seuil", this);
    ...
}

void ComprendreAudioProcessor::parameterChanged(const juce::String& idIn, float valueIn)
{
    ...
        rafraichit(false);
    ...
}

void ComprendreAudioProcessor::rafraichit(bool premier)
{

    ...
    ComprendreParametres parametres = obtenirParametres(apvts);
    altere["ratio"] = (pardefaut["ratio"] != parametres.ratio);
    ...
    etat_reonglet = true;
}

void ComprendreAudioProcessorEditor::paint (juce::Graphics& g)
{
    ...
    texte_ratio.setGras(audioProcessor.altere["ratio"]);
    ...
}

void ComprendreAudioProcessorEditor::timerCallback()
{ 
    if (audioProcessor.etat_reonglet)
    {
        repaint();
        ...
    }
    ...
}

	class Texte : public juce::Component
	{
	public:
		void paint(juce::Graphics& g) override
		{
			g.setColour(juce::Colours::white);
			juce::Font font(15.0f);
			if (gras)
			{
				g.setColour(juce::Colours::yellow);
			}
			g.setFont(font);
			g.drawFittedText(texte, getLocalBounds(), aligne, 1);
		}
                ....
        }

```

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [June 10, 2024, 1:13pm UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781/4 "2024-06-10T13:13:53Z")

</div>

One obvious issue is that this code isn’t thread-safe. The `etat_reonglet` and `altere["ratio"]` variables are written to by the audio thread and read from by the UI thread. The compiler doesn’t know about this, and so it may have created code that works OK on Windows but not on Mac.

The comparison `pardefaut["ratio"] != parametres.ratio` is also problematic, since the default is `-20.0f` but the current value may be something like `-19.9999f`. So using `approximatelyEqual` to do the comparison might work better than `!=`. However, `!=` should still work OK for when the user resets the knob to the default position by Alt-clicking or double-clicking. So I don’t think that’s the issue.

---

<div class="post-metadata">

**Author:** ![Skynext](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Skynext](https://forum.juce.com/u/Skynext)\
**Post date:** [June 10, 2024, 1:58pm UTC](https://forum.juce.com/t/juce-audioparameterfloat-default-value-not-reacting-same-way-between-xcode-mac-os-x-and-visual-studio-windows/61781/5 "2024-06-10T13:58:13Z")

</div>

What i find “worrying” is the fact that instead of having “0.00” on parameters, mac version purpose “-0.00” and when i enter “0.00” with keyboard it remains “-0.00”. I have more big suspicion on how clang handles float with arm architecture. Windows version is already clang ('done that to prevent futur incompatibility problem with mac …). I don’t know if there is some “float precision” stuff to give to xcode, that is known by every juce/xcode plugin devs (have i miss a “big thing” ?)
