Skip to content

Commit

Permalink
support [else/knob] as if it's a floatatom (#171)
Browse files Browse the repository at this point in the history
* support [else/knob] as if it's a floatatom

* create regular [knob] but remove it from the hvutils output

* move else/knob to its own lib-dir

* add main dir path to fall-back search and module import

* add changelog
  • Loading branch information
dromer authored Jun 21, 2024
1 parent f1f9e85 commit 7b0e22b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Next Release

* Core: parse remote/send messages
* Core: MIDI i/o added to memoryPool
* Core: support `[else/knob]` as `[float]`
* Daisy: set heavy context after hw.init()
* OWL: add Polytouchin and Polytouchout
* JS: webmidi input
Expand Down
1 change: 1 addition & 0 deletions docs/09.supported_vanilla_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ del
delay
div
exp
else/knob
f
float
floatatom
Expand Down
23 changes: 23 additions & 0 deletions hvcc/interpreters/pd2hv/PdParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
class PdParser:

# library search paths
__LIB_DIR = os.path.join(os.path.dirname(__file__), "libs")
__HVLIB_DIR = os.path.join(os.path.dirname(__file__), "libs", "heavy")
__HVLIB_CONVERTED_DIR = os.path.join(os.path.dirname(__file__), "libs", "heavy_converted")
__PDLIB_DIR = os.path.join(os.path.dirname(__file__), "libs", "pd")
__ELSELIB_DIR = os.path.join(os.path.dirname(__file__), "libs", "else")
__PDLIB_CONVERTED_DIR = os.path.join(os.path.dirname(__file__), "libs", "pd_converted")

# detect a dollar argument in a string
Expand All @@ -72,6 +74,7 @@ def get_supported_objects(cls) -> List:
""" Returns a set of all pd objects names supported by the parser.
"""
pd_objects = [os.path.splitext(f)[0] for f in os.listdir(cls.__PDLIB_DIR) if f.endswith(".pd")]
pd_objects += [f"else/{os.path.splitext(f)[0]}" for f in os.listdir(cls.__ELSELIB_DIR) if f.endswith(".pd")]
pd_objects.extend(cls.__PD_CLASSES.keys())
return pd_objects

Expand Down Expand Up @@ -416,6 +419,26 @@ def graph_from_canvas(
pos_x=int(line[2]), pos_y=int(line[3]),
is_root=False)

# is this object in lib/else?
elif os.path.isfile(os.path.join(self.__ELSELIB_DIR, f"{obj_type}.pd")):
self.obj_counter[obj_type] += 1
hvlib_path = os.path.join(self.__ELSELIB_DIR, f"{obj_type}.pd")
x = self.graph_from_file(
file_path=hvlib_path,
obj_args=obj_args,
pos_x=int(line[2]), pos_y=int(line[3]),
is_root=False)

# is this object in lib? (sub-directory)
elif os.path.isfile(os.path.join(self.__LIB_DIR, f"{obj_type}.pd")):
self.obj_counter[obj_type] += 1
hvlib_path = os.path.join(self.__LIB_DIR, f"{obj_type}.pd")
x = self.graph_from_file(
file_path=hvlib_path,
obj_args=obj_args,
pos_x=int(line[2]), pos_y=int(line[3]),
is_root=False)

# is this an object that must be programatically parsed?
elif obj_type in self.__PD_CLASSES:
self.obj_counter[obj_type] += 1
Expand Down
6 changes: 6 additions & 0 deletions hvcc/interpreters/pd2hv/libs/else/knob.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#N canvas 0 149 210 157 10;
#X obj 24 35 inlet;
#X obj 24 57 float 0;
#X obj 24 79 outlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;

0 comments on commit 7b0e22b

Please sign in to comment.