From 3bc9d3fbf2ed031ac13da1133689cb825d35ae46 Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Thu, 28 Apr 2022 12:41:13 +0100 Subject: [PATCH 1/3] CMake: Centralise C++ version and set to 17 --- CMakeLists.txt | 9 +++++++-- script/dump-posttarget.cmake | 7 ------- 2 files changed, 7 insertions(+), 9 deletions(-) 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/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 From 5d19082463d369d7f5e47cd8e841e4d96cbe3440 Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Thu, 28 Apr 2022 12:41:52 +0100 Subject: [PATCH 2/3] Wrapper: Handle new LongRuntimeMax parameter type --- include/FluidParameterDump.hpp | 38 +++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/include/FluidParameterDump.hpp b/include/FluidParameterDump.hpp index 673bd17..b3d63b5 100644 --- a/include/FluidParameterDump.hpp +++ b/include/FluidParameterDump.hpp @@ -76,6 +76,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) { @@ -287,7 +298,12 @@ 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&) @@ -376,6 +392,8 @@ 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 SharedClientRef::ParamType&) @@ -397,16 +415,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; @@ -437,6 +461,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; } From d158bf221fe5614d8b0da4e90e3e43ecda20b4e0 Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Thu, 28 Apr 2022 12:42:37 +0100 Subject: [PATCH 3/3] Doc generators: Handle new LongRuntimeMax type + rules for args in Max/PD --- flucoma/doc/cli/driver.py | 2 +- flucoma/doc/max/driver.py | 2 +- flucoma/doc/pd/driver.py | 2 +- flucoma/doc/rst/html.py | 11 ++++++++ flucoma/doc/sc/driver.py | 34 +++++++++++++++++++++--- flucoma/doc/transformers.py | 44 +++++++++++++++++++++++++++----- flucoma/doc/validate/controls.py | 20 ++++++++------- 7 files changed, 93 insertions(+), 22 deletions(-) diff --git a/flucoma/doc/cli/driver.py b/flucoma/doc/cli/driver.py index 075fe64..35be125 100644 --- a/flucoma/doc/cli/driver.py +++ b/flucoma/doc/cli/driver.py @@ -104,7 +104,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 0b62bf4..d8afba3 100644 --- a/flucoma/doc/max/driver.py +++ b/flucoma/doc/max/driver.py @@ -95,7 +95,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 766999c..bac2273 100644 --- a/flucoma/doc/pd/driver.py +++ b/flucoma/doc/pd/driver.py @@ -92,7 +92,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 641917d..f3dd903 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=[]): @@ -71,9 +72,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'] = { @@ -83,6 +88,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']: @@ -103,7 +131,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')} @@ -127,7 +155,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 5b4707b..de1b6b2 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,16 +73,32 @@ 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'] + }) + 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"