Skip to content

Commit

Permalink
add grainer library
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesneimog committed Oct 10, 2023
1 parent f1976bc commit 322b0d7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
16 changes: 16 additions & 0 deletions docs/libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,39 @@ This table presents an overview of all PureData externals supported by <code>pd4
<th>Library Name</th>
<th>Not Supported Objects</th>
<th>Numbers of Objects</th>
<th>Main Dev</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://github.com/porres/pd-else">pd-else</a></td>
<td><code>sfz~</code>, <code>sfont~</code></td>
<td>509</td>
<td>Alexandre Porres</th>
</tr>
</tbody>
<tbody>
<tr>
<td><a href="https://github.com/porres/pd-cyclone">pd-cyclone</a></td>
<td> <code>coll</code> </td>
<td>244</td>
<td>Alexandre Porres</th>
</tr>
</tbody>
<tbody>
<tr>
<td><a href="https://github.com/pd-externals/earplug/">earplug</a></td>
<td> - </td>
<td>1</td>
<td>Dan Wilcox</th>
</tr>
</tbody>
<tbody>
<tr>
<td><a href="https://github.com/wbrent/convolve_tilde/">convolve~</a></td>
<td> - </td>
<td>1</td>
<td>Willian Brent</td>
</tr>
</tbody>

Expand All @@ -54,6 +59,7 @@ This table presents an overview of all PureData externals supported by <code>pd4
<td><a href="https://github.com/wbrent/timbreIDLib/">timbreIDLib</a></td>
<td> - </td>
<td>110</td>
<td>Willian Brent</td>
</tr>
</tbody>

Expand All @@ -62,6 +68,16 @@ This table presents an overview of all PureData externals supported by <code>pd4
<td><a href=" https://github.com/avilleret/pd-pmpd">pmpd</a></td>
<td> - </td>
<td>30</td>
<td>Cyrille Henry</td>
</tr>
</tbody>

<tbody>
<tr>
<td><a href=" https://github.com/charlesneimog/grainer_tilde">grainer~</a></td>
<td> - </td>
<td>1</td>
<td>Pablo Di Liscia</td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions pd4web/externals/Externals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ SupportedLibraries:
repoUser: avilleret
repoName: pd-pmpd
extraFunction: pmpd_extra

- name: grainer~
downloadSrc: GITHUB_TAGS
repoUser: charlesneimog
repoName: grainer_tilde
singleObject: true

20 changes: 14 additions & 6 deletions pd4web/helpers/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import platform

def myprint(text, color=None, bright=False, type=None):
def myprint(text, color=None, bright=False):
if color is None:
color_code = ''
else:
Expand All @@ -28,13 +28,21 @@ def myprint(text, color=None, bright=False, type=None):
reset_code = '\033[0m'

tab = " " * 4
if type == "error":
print(tab + color_code + "ERROR: " + text + reset_code)
elif type == "warning":
print(tab + color_code + "WARNING: " + text + reset_code)
if color == "red":
print(tab + color_code + "🔴️ ERROR: " + text + reset_code)
elif color == "yellow":
print(tab + color_code + "🟡️ WARNING: " + text + reset_code)

elif color == "green":
print(tab + color_code + "🟢️ " + text + reset_code)
elif color == "blue":
print(tab + color_code + "🔵️ " + text + reset_code)
elif color == "magenta":
print(tab + color_code + "🟣️ " + text + reset_code)
else:
print(tab + color_code + text + reset_code)




def fixPaths(path):
Expand Down Expand Up @@ -65,7 +73,7 @@ def __init__(self):
self.make = PdWebCompilerPath + '/emsdk/upstream/emscripten/emmake make '
self.emcc = PdWebCompilerPath + '/emsdk/upstream/emscripten/emcc '
self.emsdk = PdWebCompilerPath + '/emsdk/emsdk '
self.emsdk_env = PdWebCompilerPath + '/emsdk/emsdk_env.sh '
self.emsdk_env = "source " + PdWebCompilerPath + '/emsdk/emsdk_env.sh '



Expand Down
43 changes: 26 additions & 17 deletions pd4web/pd4web.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ def __init__(self, sourcefile="src/template.c", pdpatch=None,
# get this folder directory
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter, description="Check the complete docs in https://charlesneimog.github.io/pd4web")
parser.add_argument('--patch', required=True,
parser.add_argument('--patch', required=False,
help='Patch file (.pd) to compile')
parser.add_argument('--html', required=False,
help='HTML used to load and render the Web Page. If not defined, we use the default one')
parser.add_argument('--page-folder', required=False,
help='Folder with html, css, js and all others files to be used in the Web Page. If not defined, we use the default one')
parser.add_argument('--no_browser', action='store_true', help='Set the flag to True')
parser.add_argument('--compile-all', action='store_true', help='Set the flag to True')
parser.add_argument('--active-emcc', action='store_true', help='Set the flag to True')
parser.add_argument('--confirm', action='store_true',
help='There is some automatic way check if the external is correct, but it is not always accurate. If you want to confirm if the external is correct, use this flag')
parser.add_argument('--clearTmpFiles', required=False,
Expand All @@ -60,6 +61,9 @@ def __init__(self, sourcefile="src/template.c", pdpatch=None,
parser.add_argument('--version', action='version',
version='%(prog)s 1.2.0')
self.args = parser.parse_args()
if self.args.active_emcc:
self.activeEmcc()
sys.exit(0)
if pdpatch is not None:
self.args.patch = pdpatch
if not os.path.isabs(self.args.patch) and not insideaddAbstractions:
Expand Down Expand Up @@ -136,7 +140,7 @@ def main(self, pdpatch=None, insideaddAbstractions=False):
else:
self.patch = self.args.patch
patchFileName = os.path.basename(self.patch)
myprint("Patch => " + patchFileName, color='blue')
myprint("Patch => " + patchFileName, color='blue')
if self.args.html is not None:
if not os.path.isabs(self.args.html) and not insideaddAbstractions:
self.html = os.getcwd() + "/" + self.args.html
Expand All @@ -147,14 +151,14 @@ def main(self, pdpatch=None, insideaddAbstractions=False):
self.html = self.PdWebCompilerPath + "/src/index.html"
if "index.html" not in str(self.html) and not insideaddAbstractions:
myprint("The name of your html is not index.html, we will copy one index.html for webpatch!",
color="yellow", type='warning')
color="yellow")
if not os.path.exists(self.PROJECT_ROOT + "/.backup"):
os.mkdir(self.PROJECT_ROOT + "/.backup")
if not insideaddAbstractions:
if os.path.exists(self.PROJECT_ROOT + "index.html"):
myprint("index.html already exists in the root folder, " \
"please change his name or delete it, making backup and deleting it.",
color="yellow", type='warning')
color="yellow")
shutil.copy(self.PROJECT_ROOT + "index.html", self.PROJECT_ROOT + ".backup/index.html")
else:
with open(self.PROJECT_ROOT + "/index.html", "w") as file:
Expand Down Expand Up @@ -286,6 +290,10 @@ def activeEmcc(self):
os.system(f"{self.emcc.emsdk} install latest")
os.system(f"{self.emcc.emsdk} activate latest")
os.system(f"chmod +x {self.emcc.emsdk_env}")
if self.args.active_emcc:
# os.system(f"{self.emcc.emsdk} activate latest")
os.system(f"{self.emcc.emsdk_env}")
sys.exit(0)


def importExternalObjs(self):
Expand Down Expand Up @@ -763,24 +771,25 @@ def searchCFunction(self, lineInfo, root, file):
self.regexSearch(lineInfo, functionName, os.path.join(root, file))


def regexSearch(self, lineInfo, functionName, file):
def regexSearch(self, lineInfo: PatchLine, functionName, file):
'''
This search for the setup function using regex.
'''
with open(file, "r") as C_file:
file_contents = C_file.read()
pattern = r'void\s*{}\s*\(\s*void\s*\)'.format(
re.escape(functionName))
matches = re.finditer(pattern, file_contents, re.DOTALL)
listMatches = list(matches)
if len(listMatches) > 0:
shutil.copy(C_file.name, self.PROJECT_ROOT + "webpatch/externals")
lineInfo.objFound = True
lineInfo.functionName = functionName
if lineInfo.library not in self.externalsDict:
self.externalsDict[lineInfo.library] = [C_file.name]
else:
self.externalsDict[lineInfo.library].append(C_file.name)
patterns = [r'void\s*{}\s*\(\s*void\s*\)', r'void\s+{}\s*\(\s*\)']
for pattern in patterns:
pattern = pattern.format(re.escape(functionName))
matches = re.finditer(pattern, file_contents, re.DOTALL)
listMatches = list(matches)
if len(listMatches) > 0:
shutil.copy(C_file.name, self.PROJECT_ROOT + "webpatch/externals")
lineInfo.objFound = True
lineInfo.functionName = functionName
if lineInfo.library not in self.externalsDict:
self.externalsDict[lineInfo.library] = [C_file.name]
else:
self.externalsDict[lineInfo.library].append(C_file.name)


def addObjSetup(self):
Expand Down

0 comments on commit 322b0d7

Please sign in to comment.