1 /*
2  * Copyright (c) 2017 Johannes Lorenz
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * @file default-value.h
27  * Functions for retrieving default values from metadata (and runtime)
28  *
29  * @test default-value.cpp
30  */
31 
32 #ifndef RTOSC_DEFAULT_VALUE
33 #define RTOSC_DEFAULT_VALUE
34 
35 #include <cstdint>
36 #include <rtosc/rtosc.h>
37 
38 namespace rtosc {
39 
40 /**
41  * Return a port's default value
42  *
43  * Returns the default value of a given port, if any exists, as a string.
44  * For the parameters, see the overloaded function.
45  * @note The recursive parameter should never be specified.
46  * @return The default value(s), pretty-printed, or NULL if there is no
47  *     valid default annotation
48  */
49 const char* get_default_value(const char* port_name, const struct Ports& ports,
50                               void* runtime,
51                               const struct Port* port_hint = nullptr,
52                               int32_t idx = -1, int recursive = 1);
53 
54 /**
55  * Return a port's default value
56  *
57  * Returns the default value of a given port, if any exists, as an array of
58  * rtosc_arg_vals . The values in the resulting array are being canonicalized,
59  * i.e. mapped values are being converted to integers; see
60  * canonicalize_arg_vals() .
61  *
62  * @param port_name the port's OSC path.
63  * @param port_args the port's arguments, e.g. '::i:c:S'
64  * @param ports the ports where @a portname is to be searched
65  * @param runtime object holding @a ports . Optional. Helps finding
66  *        default values dependent on others, such as presets.
67  * @param port_hint The port itself corresponding to portname (including
68  *        the args). If not specified, will be found using @p portname .
69  * @param idx If the port is an array (using the '#' notation), this specifies
70  *        the index required for the default value
71  * @param n Size of the output parameter @res . This size can not be known,
72  *        so you should provide a large enough array.
73  * @param res The output parameter for the argument values.
74  * @param strbuf String buffer for storing pretty printed strings and blobs.
75  * @param strbufsize Size of @p strbuf
76  * @return The actual number of aruments written to @p res (can be smaller
77  *         than @p n) or -1 if there is no valid default annotation
78  */
79 int get_default_value(const char* port_name, const char *port_args,
80                       const struct Ports& ports,
81                       void* runtime, const struct Port* port_hint,
82                       int32_t idx,
83                       std::size_t n, rtosc_arg_val_t* res,
84                       char *strbuf, size_t strbufsize);
85 
86 }
87 
88 #endif // RTOSC_DEFAULT_VALUE
89