diff --git a/CMakeLists.txt b/CMakeLists.txt index 4da7db2..89c4b02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,10 @@ cmake_minimum_required(VERSION 3.11) cmake_policy(SET CMP0074 NEW) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + if (APPLE) set(CMAKE_XCODE_GENERATE_SCHEME ON) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8) @@ -107,10 +111,11 @@ foreach (project_dir ${PROJECT_DIRS}) list(APPEND json_files "${CMAKE_BINARY_DIR}/json/${project_dir}.json") add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/json/${project_dir}.json" + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/json/" COMMAND $ ARGS "${CMAKE_BINARY_DIR}/json/" COMMENT "Generating JSON for ${project_dir}" - ) - + DEPENDS ${project_dir} + ) endif () endforeach () diff --git a/flucoma/doc/cli/driver.py b/flucoma/doc/cli/driver.py index 2c5d6f9..3d92054 100644 --- a/flucoma/doc/cli/driver.py +++ b/flucoma/doc/cli/driver.py @@ -105,7 +105,7 @@ def transform_data(client, data): 'glob_filter': lambda x: re.match('Buf(?!Compose).*',x.stem) is not None, 'parameter_link': cli_jinja_parameter_link, 'write_cross_ref': (cli_visit_flucoma_reference,cli_depart_flucoma_reference), - 'code_block': '{}', + 'code_block': lambda p: f'{p.lower()}', 'writer': FluidHTMLWriter, 'rst_render': rst_filter, 'topic_extension':'html', diff --git a/flucoma/doc/max/driver.py b/flucoma/doc/max/driver.py index c571e15..e9def74 100644 --- a/flucoma/doc/max/driver.py +++ b/flucoma/doc/max/driver.py @@ -96,7 +96,7 @@ def write_max_indices(idx,program_args): 'types': max_type_map, 'glob': '**/*.json', 'parameter_link': max_jinja_parameter_link, - 'code_block': '{}', + 'code_block': lambda p: f"{p.lower()}", 'writer': FluidHTMLWriter, 'rst_render': rst_filter, 'write_cross_ref': (max_visit_flucoma_reference, diff --git a/flucoma/doc/pd/driver.py b/flucoma/doc/pd/driver.py index 7693d3b..17c03bd 100644 --- a/flucoma/doc/pd/driver.py +++ b/flucoma/doc/pd/driver.py @@ -93,7 +93,7 @@ def transform_data(client, data): 'glob': '**/*.json', 'parameter_link': pd_jinja_parameter_link, 'write_cross_ref': (pd_visit_flucoma_reference,pd_depart_flucoma_reference), - 'code_block': '{}', + 'code_block': lambda p: f'{p.lower()}', 'writer': FluidHTMLWriter, 'rst_render': rst_filter, 'topic_extension': 'html', diff --git a/flucoma/doc/rst/html.py b/flucoma/doc/rst/html.py index 8165376..53639a6 100644 --- a/flucoma/doc/rst/html.py +++ b/flucoma/doc/rst/html.py @@ -9,6 +9,7 @@ from .common import LoggingDocutilsReader +from docutils import nodes from docutils.utils import Reporter from docutils.core import publish_parts from docutils.writers import html4css1 @@ -35,6 +36,10 @@ def depart_reference(self,node): self.depart_flucoma_reference(node) else: super().depart_reference(node) + + + + class FluidHTMLWriter(html4css1.Writer): """docutils writer for Max ref @@ -55,6 +60,12 @@ def visit_flucoma_topic(self,node): def depart_flucoma_reference(self,node): partial(driver['write_cross_ref'][1], data = index)(self,node) + + def visit_literal(self, node) : + f = driver.get('code_block',lambda x: x) + self.body.append(f(node.astext())) + raise nodes.SkipNode + self.translator_class = ConcreteTranslator diff --git a/flucoma/doc/sc/driver.py b/flucoma/doc/sc/driver.py index 1a02c17..53b7cbf 100644 --- a/flucoma/doc/sc/driver.py +++ b/flucoma/doc/sc/driver.py @@ -11,6 +11,7 @@ from ..transformers import tidy_split, filter_fixed_controls from flucoma.doc.rst.scdoc import SCDocWriter,rst_filter from .defaults import defaults +import copy def buffer_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): @@ -72,9 +73,13 @@ def sc_transform_data(object_name,data): params = {x['name']:x for x in data.pop('parameters')} data['attributes'] = OrderedDict( - (filter_fixed_controls(params,fixed=False)) + **filter_fixed_controls(params,fixed=False) ) + + + # filter(lambda x: x['runtimemax'] == True, params) + fftSettings = data['attributes'].pop('fftSettings',None) if fftSettings: #only works because they're last in the list data['attributes'] = { @@ -84,6 +89,29 @@ def sc_transform_data(object_name,data): 'fftSize': fftSettings['fft'] } + + def maxParamName(pname): + return 'max' + pname[0].upper() + pname[1:] + + def maxParamDoc(v): + return { + 'name': maxParamName(v['name']), + 'constraints':{}, + 'default': -1, + 'description': f"Manually sets a maximum value for ``{v['name']}``. Can only be set at object instantiation. Default value of -1 sets this to the initial value of ``{v['name']}``", + 'displayName': f"Maximum {v['displayName']}", + 'fixed':False, + 'size':1 + } + + if(object_name.startswith('Buf') == False): + runtime_max_params = { maxParamName(name): maxParamDoc(data) for name, data in params.items() if data.get('runtimemax',False) == True} + + data['attributes'] = { + **data['attributes'], + **runtime_max_params + } + #HPSS horrors def spliceAttrs(key): if key in data['attributes']: @@ -104,7 +132,7 @@ def spliceAttrs(key): data['attributes'] = {**data['attributes'], 'padding': padding} data['arguments'] = OrderedDict( - filter_fixed_controls(params,fixed=True) + **filter_fixed_controls(params,fixed=True) ) data['messages'] = {x['name']:x for x in data.pop('messages')} @@ -128,7 +156,7 @@ def configure_jinja(environment, client_index, args): 'glob': '**/*.json', 'parameter_link': sc_jinja_parameter_link, # 'write_cross_ref': (sc_visit_flucoma_reference,sc_depart_flucoma_reference), - 'code_block': 'code::{}::', + 'code_block': lambda p: f'code::{p}::', 'writer': SCDocWriter, 'rst_render': rst_filter, 'topic_extension': 'schelp', diff --git a/flucoma/doc/transformers.py b/flucoma/doc/transformers.py index 97138fa..1a52ca4 100644 --- a/flucoma/doc/transformers.py +++ b/flucoma/doc/transformers.py @@ -9,14 +9,28 @@ import logging from flucoma.doc import logger from collections import OrderedDict +import copy """ takes a an nested dict of controls, each assumed to have a 'fixed' key, returns an iterator to fixed = True by default. If elements don't have a 'fixed' key then you'll get a KeyError returns an iterator """ -def filter_fixed_controls(controls,fixed=True): - return filter(lambda x: x[1]['fixed'] == fixed, controls.items()) +def filter_fixed_controls(controls,fixed=True): + + # def fil(item): + # return item[1].get('fixed',False) == fixed + + return { k: v for k,v in controls.items() if v.get('fixed',False) == fixed} + # return [ (k,v) for k,v in controls.items() if v.get('fixed',False) == True] + # return filter(lambda x: x[1]['fixed'] == fixed, controls.items()) + +def filter_primary_controls(controls): + # primaries = filter(lambda x: x[1].get('primary',False) == True, controls.items()) + primaries = copy.deepcopy({ k: v for k,v in controls.items() if v.get('primary',False) == True}) + for n,v in primaries.items(): + v['description'] = f"Shorthand argument for ``{n}``" + return primaries """ given a [comma] separated string,break it up discarding empty items and trimming whitespace @@ -59,6 +73,21 @@ def default_transform(object_name, data): 'type': 'long' }) + runtime_max_params = filter(lambda x: x.get('runtimemax',False) ==True, data['parameters']) + + for r in runtime_max_params: + r['size'] = 1 + data['parameters'].append({ + 'name': f"max{r['name']}", + 'constraints':{}, + 'default': -1, + 'description': f"Manually sets a maximum value for ``{r['name']}``. Can only be set at object instantiation. The default of -1 sets this equal to the initial value of ``{r['name']}``", + 'displayName': f"Maximum {r['displayName']}", + 'fixed':False, + 'size':1, + 'type': r['type'] + }) + if(data['input_type'] == 'control'): data['parameters'].insert(0,{ 'name':'inputsize', @@ -80,17 +109,18 @@ def default_transform(object_name, data): 'size': 1, 'type': 'long' }) - + params = {x['name']:x for x in data.pop('parameters')} data['attributes'] = OrderedDict( - sorted(filter_fixed_controls(params,fixed=False)) + sorted(filter_fixed_controls(params,fixed=False).items()) ) - data['arguments'] = OrderedDict( - filter_fixed_controls(params,fixed=True) - ) - + data['arguments'] = { + **filter_primary_controls(params), + **filter_fixed_controls(params,fixed=True) + } + data['messages'] = {x['name']:x for x in data.pop('messages')} for n,m in data['messages'].items(): diff --git a/flucoma/doc/validate/controls.py b/flucoma/doc/validate/controls.py index bbf554c..ab55f1c 100644 --- a/flucoma/doc/validate/controls.py +++ b/flucoma/doc/validate/controls.py @@ -32,15 +32,15 @@ def render_constraints_markup(control): } special_invariants = { - 'fftFrame': '``(FFT Size / 2) + 1`` (see fft settings)', - 'maxFFTFrame': '``(max FFT Size / 2) + 1`` (see maxFFTSize)' + 'fftFrame': '(FFT Size / 2) + 1 (see fft settings)', + 'maxFFTFrame': '(max FFT Size / 2) + 1 (see maxFFTSize)' } - + resultStr = '\n**Constraints**\n\n' upperLimits = constraints.get('upper',[]) lowerLimits = constraints.get('lower',[]) - + upperLimits = [upperLimits] if not isinstance(upperLimits,list) else upperLimits lowerLimits = [lowerLimits] if not isinstance(lowerLimits,list) else lowerLimits @@ -48,17 +48,19 @@ def render_constraints_markup(control): lowerStrs = [special_invariants.get(c,f'{c}') for c in lowerLimits] if 'max' in constraints: upperStrs.append(str(constraints['max'])) - if 'min' in constraints: lowerStrs.append(str(constraints['min'])) + if 'min' in constraints: lowerStrs.append(str(constraints['min'])) + if(control.get('runtimemax',False)): + upperStrs.append(f"max{control['name']}") if len(lowerStrs) > 1: - resultStr += f"* Minimum: MAX({', '.join(lowerStrs)})\n" + resultStr += f"* Minimum: MAX(``{', '.join(lowerStrs)}``)\n" elif len(lowerStrs) == 1: - resultStr += f"* Minimum: {lowerStrs[0]}\n" + resultStr += f"* Minimum: ``{lowerStrs[0]}``\n" if len(upperStrs) > 1: - resultStr += f"* Maximum: MIN({', '.join(upperStrs)})\n" + resultStr += f"* Maximum: MIN(``{', '.join(upperStrs)}``)\n" elif len(upperStrs) == 1: - resultStr += f"* Maximum: {upperStrs[0]}\n" + resultStr += f"* Maximum: ``{upperStrs[0]}``\n" if 'snap' in constraints: resultStr += f"* Snaps to {snaps[constraints['snap']]} \n" diff --git a/include/FluidParameterDump.hpp b/include/FluidParameterDump.hpp index f4b4852..0ab5b1e 100644 --- a/include/FluidParameterDump.hpp +++ b/include/FluidParameterDump.hpp @@ -77,6 +77,17 @@ struct Constraint> } }; +template <> +struct Constraint +{ + template + static json::object_t::value_type + dump(const LongRuntimeMaxParam::RuntimeMaxConstraint&, Tuple&) + { + return {"runtimemax",-1}; + } +}; + template Constraint makeConstraint(C c, AllParams& p) { @@ -296,6 +307,11 @@ class ParameterDump return p.defaultValue; } + static index makeValue(const LongRuntimeMaxT& p) + { + return p.defaultValue(); + } + template static std::enable_if_t::value, std::string> makeValue(Param&) @@ -384,6 +400,7 @@ class ParameterDump static std::string getParamType(const FFTParamsT&) { return "fft"; } static std::string getParamType(const EnumT&) { return "enum"; } static std::string getParamType(const LongArrayT&) { return "long"; } + static std::string getParamType(const LongRuntimeMaxT&) { return "long"; } static std::string getParamType(const ChoicesT&) { return "choices"; } static std::string @@ -406,16 +423,22 @@ class ParameterDump template static json jsonify_param(P& p, Tuple& tuple, All& allParams) { - constexpr bool fixed = std::tuple_element<2, Tuple>::type::value; - json j; + using fixed_el_type = std::decay_t::type>; + constexpr bool fixed = std::is_same>::value; + constexpr bool primary = std::is_same::value; + + json j; + j["name"] = p.name; j["displayName"] = p.displayName; - // j["default"] = p.defaultValue; j["default"] = makeValue(p); j["fixed"] = fixed; j["type"] = getParamType(p); j["size"] = p.fixedSize; - + + j["runtimemax"] = std::is_same::value; + j["primary"] = primary; + // constraints auto& constraintsTuple = std::get<1>(tuple); using constraintsTupleType = std::decay_t; @@ -446,6 +469,10 @@ class ParameterDump std::copy(p.strings, p.strings + p.numOptions, strings.begin()); j["values"] = strings; j["type"] = "enum"; + + j["runtimemax"] = false; + j["primary"] = false; + return j; } diff --git a/script/dump-posttarget.cmake b/script/dump-posttarget.cmake index ffe7ed0..e8baf43 100644 --- a/script/dump-posttarget.cmake +++ b/script/dump-posttarget.cmake @@ -7,13 +7,6 @@ # (grant agreement No 725899). -target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) - -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD_REQUIRED ON - CXX_STANDARD 14 - CXX_EXTENSIONS OFF -) target_link_libraries(${PROJECT_NAME} PRIVATE FLUID_DECOMPOSITION FLUID_DUMP