Add initial bits for Qt6 support
[carla.git] / source / modules / ysfx / sources / ysfx_api_eel.hpp
blob494fbb18c41b6d98fef177f06fc779ca6ffeb3d2
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #pragma once
19 #include "ysfx.h"
20 #include <string>
22 typedef void *NSEEL_VMCTX;
23 class WDL_FastString;
25 //------------------------------------------------------------------------------
26 void ysfx_api_init_eel();
28 //------------------------------------------------------------------------------
29 void ysfx_eel_string_initvm(NSEEL_VMCTX vm);
31 //------------------------------------------------------------------------------
32 class eel_string_context_state;
33 eel_string_context_state *ysfx_eel_string_context_new();
34 void ysfx_eel_string_context_free(eel_string_context_state *state);
35 void ysfx_eel_string_context_update_named_vars(eel_string_context_state *state, NSEEL_VMCTX vm);
36 YSFX_DEFINE_AUTO_PTR(eel_string_context_state_u, eel_string_context_state, ysfx_eel_string_context_free);
38 //------------------------------------------------------------------------------
39 enum { ysfx_string_max_length = 1 << 16 };
40 bool ysfx_string_access(ysfx_t *fx, ysfx_real id, bool for_write, void (*access)(void *, WDL_FastString &), void *userdata);
41 bool ysfx_string_get(ysfx_t *fx, ysfx_real id, std::string &txt);
42 bool ysfx_string_set(ysfx_t *fx, ysfx_real id, const std::string &txt);
43 void ysfx_string_lock(ysfx_t *fx);
44 void ysfx_string_unlock(ysfx_t *fx);
45 const char *ysfx_string_access_unlocked(ysfx_t *fx, ysfx_real id, WDL_FastString **fs, bool for_write);
47 struct ysfx_string_scoped_lock {
48 ysfx_string_scoped_lock(ysfx_t *fx) : m_fx(fx) { ysfx_string_lock(fx); }
49 ~ysfx_string_scoped_lock() { ysfx_string_unlock(m_fx); }
50 private:
51 ysfx_t *m_fx = nullptr;
54 #define EEL_STRING_GET_CONTEXT_POINTER(opaque) (((ysfx_t *)(opaque))->string_ctx.get())
55 #define EEL_STRING_GET_FOR_INDEX(x, wr) (ysfx_string_access_unlocked((ysfx_t *)(opaque), x, wr, false))
56 #define EEL_STRING_GET_FOR_WRITE(x, wr) (ysfx_string_access_unlocked((ysfx_t *)(opaque), x, wr, true))
57 #define EEL_STRING_MUTEXLOCK_SCOPE ysfx_string_scoped_lock lock{(ysfx_t *)(opaque)};