Skip to content

Commit

Permalink
Support for documenting arguments for all inputs / distribute modes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHarker committed Mar 24, 2022
1 parent 45af28d commit 27b2e52
Show file tree
Hide file tree
Showing 167 changed files with 4,885 additions and 48 deletions.
68 changes: 60 additions & 8 deletions Documentation/Max Documentation/Build_Max_Docs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string escape_xml(std::string str)
return str;
}

bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName)
bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName, MaxObjectArgsMode argsMode)
{
std::string fileName(__FILE__);
std::string dirPath = dirname(const_cast<char *>(fileName.c_str()));
Expand All @@ -81,6 +81,12 @@ bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName)

const FrameLib_Parameters *params = frameLibObject->getParameters();

auto to_lower = [](std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c){ return std::tolower(c); });
return s;
};

auto write_attribute = [&](const char *name, const char *type, const char *digest, const char *description, const char *label)
{
myfile << tab_2 + "<attribute name='" + name + "' get='1' set='1' type='"+ type + "' size='1'> \n";
Expand All @@ -97,13 +103,13 @@ bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName)
myfile << tab_2 + "</attribute> \n";
};

auto write_argument = [&](int idx)
auto write_argument = [&](unsigned long idx)
{
int pIdx = -1;
long pIdx = -1;

for (int i = 0; params && i < params->size(); i++)
for (unsigned long i = 0; params && i < params->size(); i++)
if (params->getArgumentIdx(i) == idx)
pIdx = i;
pIdx = static_cast<long>(i);

if (pIdx == -1)
{
Expand Down Expand Up @@ -143,6 +149,39 @@ bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName)
return true;
};

auto write_arguments_all_inputs = [&]()
{
myfile << tab_1 + "<objarglist> \n";
myfile << tab_2 + "<objarg name='default-input' optional='1' type='list'> \n";
myfile << tab_3 + "<digest> \n";
myfile << tab_4 + "The input vector to use for any disconnected inputs \n";
myfile << tab_3 + "</digest> \n";
myfile << tab_3 + "<description> \n";
myfile << tab_4 + "Values typed as arguments will be used as a vector for any inputs that are not connected. Either single values or multi-valued vectors can be entered. The behaviour is similar to that for arguments to standard objects such as +~, *~ or zl.reg. \n";
myfile << tab_3 + "</description> \n";
myfile << tab_2 + "</objarg> \n";
myfile << tab_1 + "</objarglist> \n \n";
};

auto write_arguments_distributed = [&]()
{
myfile << tab_1 + "<objarglist> \n";

for (unsigned long i = 1; i < frameLibObject->getNumIns(); i++)
{
myfile << tab_2 + "<objarg name='default-input' optional='1' type='number'> \n";
myfile << tab_3 + "<digest> \n";
myfile << tab_4 + "The value to use for input " + std::to_string(i + 1) + " if it is disconnected \n";
myfile << tab_3 + "</digest> \n";
myfile << tab_3 + "<description> \n";
myfile << tab_4 + "Sets a single value for " + to_lower(frameLibObject->inputInfo(i)) +" \n";
myfile << tab_3 + "</description> \n";
myfile << tab_2 + "</objarg> \n";
}

myfile << tab_1 + "</objarglist> \n \n";
};

auto write_message = [&](const char *name, const char *digest, const char *description)
{
myfile << tab_2 + "<method name='" + name + "'> \n";
Expand Down Expand Up @@ -259,8 +298,21 @@ bool write_info(FrameLib_Multistream* frameLibObject, std::string inputName)

// Arguments //
myfile << tab_1 + "<!--ARGUMENTS-->\n";
for (int i = 0; write_argument(i); i++);

switch (argsMode)
{
case kAsParams:
for (unsigned long i = 0; write_argument(i); i++);
break;

case kAllInputs:
write_arguments_all_inputs();
break;

case kDistribute:
write_arguments_distributed();
break;
}

// Messages //
myfile << tab_1 + "<!--MESSAGES-->\n";
myfile << tab_1 + "<methodlist> \n";
Expand Down Expand Up @@ -310,7 +362,7 @@ struct DocumentationGenerator
{
T obj(context, parameters, proxy, 1);

if (!write_info(&obj, FrameLib_ObjectName<T>().name()))
if (!write_info(&obj, FrameLib_ObjectInfo<T>().name(), FrameLib_ObjectInfo<T>().template option<MaxObjectArgsMode, 0>()))
*success = false;
}
};
Expand Down
62 changes: 55 additions & 7 deletions Documentation/Max Documentation/generate_max_object_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
docs = Documentation()
op = open(docs.max_docs_dir / "Max_Object_List.h", "w+")


def write_comma(counter: int, ceiling: int) -> None:
if counter < ceiling - 1:
op.write(",")
Expand Down Expand Up @@ -34,6 +33,8 @@ def name_sanitisation(name: str) -> str:
def main(docs: Documentation):
# Create the Max_Object_list.h and add skeleton
op.write('#include "FrameLib_TypeList.h"\n\n')
op.write("enum MaxObjectArgsMode { kAsParams, kAllInputs, kDistribute };\n\n")

op.write("using FrameLib_DSPList = detail::FrameLib_Typelist<\n\n")

# Directory formation
Expand All @@ -47,7 +48,7 @@ def main(docs: Documentation):
if name.stem not in ignored_objects:
source_file_list.append([category, name])

# TODO - lookwithin and reaise this is not okay
# TODO - lookwithin and realise this is not okay
# Recreate full paths to open and parse for type cases
for counter, (category_folder, name) in enumerate(source_file_list):
with open((Path(category_folder) / name), "r") as cpp:
Expand All @@ -70,9 +71,9 @@ def main(docs: Documentation):
write_comma(counter, len(source_file_list))

## Demarcate end of this section
op.write("\n\n>;\n\n")
op.write(">;\n\n")

## Start const bit
## Start const char bit
for category_folder, name in source_file_list:
with open(Path(category_folder) / name, "r") as cpp:

Expand All @@ -86,7 +87,7 @@ def main(docs: Documentation):
op.write("template<>\n")
if "_Expand" in search_area:
op.write(
"const char* FrameLib_ObjectName<FrameLib_Expand<"
"const char* FrameLib_ObjectInfo<FrameLib_Expand<"
+ fl_object_name
+ '>>::name()\n{ return "'
+ name.stem
Expand All @@ -95,7 +96,7 @@ def main(docs: Documentation):

elif "_Expand" not in search_area and "makeClass" in search_area:
op.write(
"const char* FrameLib_ObjectName<FrameLib_Expand<"
"const char* FrameLib_ObjectInfo<FrameLib_Expand<"
+ fl_object_name
+ '>>::name()\n{ return "'
+ name.stem
Expand All @@ -104,13 +105,60 @@ def main(docs: Documentation):

elif "_Expand" not in search_area and "makeClass" not in search_area:
op.write(
"const char* FrameLib_ObjectName<"
"const char* FrameLib_ObjectInfo<"
+ fl_object_name
+ '>::name()\n{ return "'
+ name.stem
+ '"; }\n'
)
op.write("\n")

## Start argument type bit
for category_folder, name in source_file_list:
with open(Path(category_folder) / name, "r") as cpp:

source_file = cpp.read().replace("\n", "").replace(" ", "") # flatten it with no spaces whatsoever
search_area = source_file.split('extern"C"intC74_EXPORTmain(void){')[1]

fl_object_name = name_sanitisation(search_area.split("<")[1])
arg_type = "kAsParams"

if "kAllInputs" in source_file:
arg_type = "kAllInputs"
elif "kDistribute" in source_file:
arg_type = "kDistribute"

search_area = search_area.split("<")[0]
# infer type with brutal checking by looking at text in the extern bit (search area)
op.write("template<> template<> \n")
if "_Expand" in search_area:
op.write(
"MaxObjectArgsMode FrameLib_ObjectInfo<FrameLib_Expand<"
+ fl_object_name
+ ">>::option<MaxObjectArgsMode, 0>()\n{ return "
+ arg_type
+ "; }\n"
)

elif "_Expand" not in search_area and "makeClass" in search_area:
op.write(
"MaxObjectArgsMode FrameLib_ObjectInfo<FrameLib_Expand<"
+ fl_object_name
+ ">>::option<MaxObjectArgsMode, 0>()\n{ return "
+ arg_type
+ "; }\n"
)

elif "_Expand" not in search_area and "makeClass" not in search_area:
op.write(
"MaxObjectArgsMode FrameLib_ObjectInfo<"
+ fl_object_name
+ ">::option<MaxObjectArgsMode, 0>()\n{ return "
+ arg_type
+ "; }\n"
)
op.write("\n")

op.close()

if __name__ == "__main__":
Expand Down
8 changes: 7 additions & 1 deletion FrameLib_Exports/FrameLib_TypeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ namespace detail
}

template<typename T>
struct FrameLib_ObjectName
struct FrameLib_ObjectInfo
{
const char *name() { return "unknown"; }

template <typename U, size_t Idx>
static U option()
{
return U();
}
};

using FrameLib_ObjectList = detail::FrameLib_Typelist<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,42 @@
<metadata name="tag">FrameLib</metadata>
<metadata name="tag">FrameLib Binary</metadata>
</metadatalist>
<objarglist />
<objarglist>
<objarg name="default-input" optional="1" type="list">
<digest>
The input vector to use for any disconnected inputs
</digest>
<description>
Values typed as arguments will be used as a vector for any inputs that are not connected. Either single values or multi-valued vectors can be entered. The behaviour is similar to that for arguments to standard objects such as +~, *~ or zl.reg.
</description>
</objarg>
</objarglist>
<methodlist>
<method name="info">
<digest>
Get Object Info
</digest>
<description>
--detail--
</description>
</method>
<method name="frame">
<digest>
Connect FrameLib objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
<method name="sync">
<digest>
Synchronise FrameLib audio objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
</methodlist>
<attributelist>
<attribute name="rt" get="1" set="1" type="int" size="1">
<digest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,42 @@
<metadata name="tag">FrameLib</metadata>
<metadata name="tag">FrameLib Binary</metadata>
</metadatalist>
<objarglist />
<objarglist>
<objarg name="default-input" optional="1" type="list">
<digest>
The input vector to use for any disconnected inputs
</digest>
<description>
Values typed as arguments will be used as a vector for any inputs that are not connected. Either single values or multi-valued vectors can be entered. The behaviour is similar to that for arguments to standard objects such as +~, *~ or zl.reg.
</description>
</objarg>
</objarglist>
<methodlist>
<method name="info">
<digest>
Get Object Info
</digest>
<description>
--detail--
</description>
</method>
<method name="frame">
<digest>
Connect FrameLib objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
<method name="sync">
<digest>
Synchronise FrameLib audio objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
</methodlist>
<attributelist>
<attribute name="rt" get="1" set="1" type="int" size="1">
<digest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,42 @@
<metadata name="tag">FrameLib</metadata>
<metadata name="tag">FrameLib Binary</metadata>
</metadatalist>
<objarglist />
<objarglist>
<objarg name="default-input" optional="1" type="list">
<digest>
The input vector to use for any disconnected inputs
</digest>
<description>
Values typed as arguments will be used as a vector for any inputs that are not connected. Either single values or multi-valued vectors can be entered. The behaviour is similar to that for arguments to standard objects such as +~, *~ or zl.reg.
</description>
</objarg>
</objarglist>
<methodlist>
<method name="info">
<digest>
Get Object Info
</digest>
<description>
--detail--
</description>
</method>
<method name="frame">
<digest>
Connect FrameLib objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
<method name="sync">
<digest>
Synchronise FrameLib audio objects
</digest>
<description>
Used internally by FrameLib connection routines. User messages have no effect
</description>
</method>
</methodlist>
<attributelist>
<attribute name="rt" get="1" set="1" type="int" size="1">
<digest>
Expand Down
Loading

0 comments on commit 27b2e52

Please sign in to comment.