VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_basics / native / accessibility / juce_win32_UIARangeValueProvider.h
blob4b0c743aaaafd33f3e0b5ec814f1ac69476f3f76
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 //==============================================================================
30 class UIARangeValueProvider : public UIAProviderBase,
31 public ComBaseClassHelper<ComTypes::IRangeValueProvider>
33 public:
34 using UIAProviderBase::UIAProviderBase;
36 //==============================================================================
37 JUCE_COMRESULT SetValue (double val) override
39 if (! isElementValid())
40 return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
42 const auto& handler = getHandler();
44 if (auto* valueInterface = handler.getValueInterface())
46 auto range = valueInterface->getRange();
48 if (range.isValid())
50 if (val < range.getMinimumValue() || val > range.getMaximumValue())
51 return E_INVALIDARG;
53 if (! valueInterface->isReadOnly())
55 valueInterface->setValue (val);
57 VARIANT newValue;
58 VariantHelpers::setDouble (valueInterface->getCurrentValue(), &newValue);
59 sendAccessibilityPropertyChangedEvent (handler, UIA_RangeValueValuePropertyId, newValue);
61 return S_OK;
66 return (HRESULT) UIA_E_NOTSUPPORTED;
69 JUCE_COMRESULT get_Value (double* pRetVal) override
71 return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
73 return valueInterface.getCurrentValue();
74 });
77 JUCE_COMRESULT get_IsReadOnly (BOOL* pRetVal) override
79 return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
81 return valueInterface.isReadOnly();
82 });
85 JUCE_COMRESULT get_Maximum (double* pRetVal) override
87 return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
89 return valueInterface.getRange().getMaximumValue();
90 });
93 JUCE_COMRESULT get_Minimum (double* pRetVal) override
95 return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
97 return valueInterface.getRange().getMinimumValue();
98 });
101 JUCE_COMRESULT get_LargeChange (double* pRetVal) override
103 return get_SmallChange (pRetVal);
106 JUCE_COMRESULT get_SmallChange (double* pRetVal) override
108 return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
110 return valueInterface.getRange().getInterval();
114 private:
115 template <typename Value, typename Callback>
116 JUCE_COMRESULT withValueInterface (Value* pRetVal, Callback&& callback) const
118 return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
120 if (auto* valueInterface = getHandler().getValueInterface())
122 if (valueInterface->getRange().isValid())
124 *pRetVal = callback (*valueInterface);
125 return S_OK;
129 return (HRESULT) UIA_E_NOTSUPPORTED;
133 //==============================================================================
134 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIARangeValueProvider)
137 } // namespace juce