Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noise effect, will add soap later #886

Merged
merged 8 commits into from
Apr 5, 2024
Merged

Conversation

bigredfrog
Copy link
Contributor

@bigredfrog bigredfrog commented Apr 4, 2024

New PR to fix prior poetry process stumbles

Summary by CodeRabbit

  • New Features
    • Enhanced the Soap2d effect with noise generation and configurable parameters for speed, intensity, stretch, zoom, impulse decay, and audio injection multiplier.
    • Improved Soap2d effect to support soap smear, dynamic visualizations reacting to audio input, and color gradient mapping for visual output.
    • Added new presets "acid," "blood," and "rgb" under the "soap2d" category with unique configurations for gradient colors, intensity, and zoom.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Warning

Rate Limit Exceeded

@bigredfrog has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 8 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 825a996 and c2f0a74.

Walkthrough

The update enhances the Soap2d effect in the ledfx/effects module, introducing advanced noise generation capabilities with customizable parameters like speed, intensity, stretch, zoom, impulse decay, and audio injection multiplier. This effect now supports features such as soap smear, dynamic audio-reactive visualizations, and mapping the transformed 2D noise plane to a color gradient for visually striking outputs.

Changes

File Change Summary
ledfx/effects/soap2d.py Updated Soap2d effect to include noise generation, configurable parameters for speed, intensity, stretch, zoom, impulse decay, and audio injection multiplier. Added support for soap smear, audio reactivity, and color gradient mapping.
ledfx/presets.py Added new presets "acid", "blood", and "rgb" under the "soap2d" category in ledfx/presets.py with specific configurations for gradient colors, intensity, zoom, etc.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@bigredfrog bigredfrog marked this pull request as draft April 4, 2024 21:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d89890a and 9f8c9be.
Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
Files selected for processing (1)
  • ledfx/effects/soap2d.py (1 hunks)
Additional comments not posted (2)
ledfx/effects/soap2d.py (2)

25-62: Ensure the default values for the configuration parameters are well-justified and align with the intended user experience. For example, the default speed of 1 and intensity of 128 should provide a balanced starting point for users. However, consider if other defaults, such as zoom with a default of 5, are optimal for most use cases or if they should be adjusted based on user feedback or testing.


83-96: The initialization of noise-related variables in do_once method is clear and well-structured. However, consider adding comments to explain the rationale behind the initial random values for noise_x, noise_y, and noise_z, and how they contribute to the effect's visual appearance.

Comment on lines 18 to 24
class Soap2d(Twod, GradientEffect):
NAME = "Noise"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
ADVANCED_KEYS = Twod.ADVANCED_KEYS + []

Copy link
Contributor

@coderabbitai coderabbitai bot Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a more descriptive name for the Soap2d effect in the NAME attribute to reflect its unique characteristics, rather than just "Noise".

-    NAME = "Noise"
+    NAME = "Soap2d"

This change will help users better understand the effect's purpose and distinguish it from other noise-based effects.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
class Soap2d(Twod, GradientEffect):
NAME = "Noise"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
ADVANCED_KEYS = Twod.ADVANCED_KEYS + []
class Soap2d(Twod, GradientEffect):
NAME = "Soap2d"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
ADVANCED_KEYS = Twod.ADVANCED_KEYS + []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soap will be an additional configuration on top of noise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigredfrog, thank you for the clarification. Given that the Soap2d effect builds upon a noise base with additional soap-like configurations, a name that reflects both aspects could be more descriptive. How about "SoapNoise" or "NoiseSoap"? This naming convention would highlight the effect's unique characteristics while acknowledging its foundation in noise generation. Would one of these names align better with your vision for the effect?

NAME = "Noise"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the necessity of hiding the soap key in HIDDEN_KEYS. Given that soap is a distinctive feature of the Soap2d effect, consider making it visible in the UI for easier access and configuration by users.

-    HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
+    HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity"]

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity", "soap"]
HIDDEN_KEYS = Twod.HIDDEN_KEYS + ["background_color", "gradient_roll", "intensity"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are hidden for further development

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigredfrog, thank you for clarifying the reason behind hiding certain keys, including soap, for further development. It's essential to ensure that features are fully developed and tested before making them accessible for configuration. If there are any other aspects of the development process or specific features you'd like to discuss or need assistance with in the future, please feel free to reach out.

Comment on lines 78 to 81
self.lows_impulse_filter = self.create_filter(
alpha_decay=self._config["impulse_decay"], alpha_rise=0.99
)
self.lows_impulse = 0
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The creation of the lows_impulse_filter uses hardcoded values for alpha_decay and alpha_rise. Consider making these values configurable to allow for more flexibility in adjusting the filter behavior based on different audio inputs or user preferences.

-        self.lows_impulse_filter = self.create_filter(
-            alpha_decay=self._config["impulse_decay"], alpha_rise=0.99
-        )
+        self.lows_impulse_filter = self.create_filter(**self._config["lows_impulse_filter"])

And update the CONFIG_SCHEMA to include the lows_impulse_filter configuration.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
self.lows_impulse_filter = self.create_filter(
alpha_decay=self._config["impulse_decay"], alpha_rise=0.99
)
self.lows_impulse = 0
self.lows_impulse_filter = self.create_filter(**self._config["lows_impulse_filter"])
self.lows_impulse = 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intentional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigredfrog, understood. It's clear that you have specific reasons for choosing to use hardcoded values for alpha_decay and alpha_rise in the lows_impulse_filter. If there are any other aspects of the Soap2d effect's configuration or functionality you'd like to discuss or get feedback on, please feel free to let me know. I'm here to help!

Comment on lines 117 to 184
# temp logging switching, will all be removed in due course
log = False

# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
if log:
start = timeit.default_timer()

bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse

scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y

noise_x = self.noise_x - ( scale_x * self.r_height / 2)
noise_y = self.noise_y - ( scale_y * self.r_width / 2)

x_array = np.linspace(noise_x, noise_x + scale_x * self.r_height, self.r_height)
y_array = np.linspace(noise_y, noise_y + scale_y * self.r_width, self.r_width)
z_array = np.array([self.noise_z])
if log:
next1 = timeit.default_timer()
_LOGGER.info(f"array generation time: {next1 - start}")

###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(x_array, y_array, z_array, grid_mode=True)

if log:
next2 = timeit.default_timer()
_LOGGER.info(f"simple noise time: {next2 - next1}")

# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2

if log:
next3 = timeit.default_timer()
_LOGGER.info(f"simple squeeze time: {next3 - next2}")

# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")

# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(self.noise_normalised).astype(np.uint8)

if log:
next4 = timeit.default_timer()
_LOGGER.info(f"color array time: {next4 - next3}")

# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")

if log:
next5 = timeit.default_timer()
_LOGGER.info(f"image from array time: {next5 - next4}")
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the temporary logging mechanism before finalizing the PR. If logging is necessary for debugging or monitoring, implement a more permanent and configurable logging strategy that can be enabled or disabled based on the environment or user settings.

-        # temp logging switching, will all be removed in due course
-        log = False
-        if log:
-            start = timeit.default_timer()
-        ...
-        if log:
-            next5 = timeit.default_timer()
-            _LOGGER.info(f"image from array time: {next5 - next4}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
# temp logging switching, will all be removed in due course
log = False
# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
if log:
start = timeit.default_timer()
bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse
scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y
noise_x = self.noise_x - ( scale_x * self.r_height / 2)
noise_y = self.noise_y - ( scale_y * self.r_width / 2)
x_array = np.linspace(noise_x, noise_x + scale_x * self.r_height, self.r_height)
y_array = np.linspace(noise_y, noise_y + scale_y * self.r_width, self.r_width)
z_array = np.array([self.noise_z])
if log:
next1 = timeit.default_timer()
_LOGGER.info(f"array generation time: {next1 - start}")
###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(x_array, y_array, z_array, grid_mode=True)
if log:
next2 = timeit.default_timer()
_LOGGER.info(f"simple noise time: {next2 - next1}")
# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2
if log:
next3 = timeit.default_timer()
_LOGGER.info(f"simple squeeze time: {next3 - next2}")
# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")
# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(self.noise_normalised).astype(np.uint8)
if log:
next4 = timeit.default_timer()
_LOGGER.info(f"color array time: {next4 - next3}")
# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")
if log:
next5 = timeit.default_timer()
_LOGGER.info(f"image from array time: {next5 - next4}")
# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse
scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y
noise_x = self.noise_x - ( scale_x * self.r_height / 2)
noise_y = self.noise_y - ( scale_y * self.r_width / 2)
x_array = np.linspace(noise_x, noise_x + scale_x * self.r_height, self.r_height)
y_array = np.linspace(noise_y, noise_y + scale_y * self.r_width, self.r_width)
z_array = np.array([self.noise_z])
###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(x_array, y_array, z_array, grid_mode=True)
# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2
# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")
# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(self.noise_normalised).astype(np.uint8)
# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logging will be pulled out in the next phase

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigredfrog, understood! It's great to have a plan for refining the logging mechanism in the next phase. Just a friendly reminder to ensure this task is tracked appropriately, so it doesn't get overlooked before the final release. If you think it would be helpful, would you like me to open a GitHub issue as a reminder for this task?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9f8c9be and 8bea27e.
Files selected for processing (1)
  • ledfx/effects/soap2d.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ledfx/effects/soap2d.py

@bigredfrog bigredfrog marked this pull request as ready for review April 4, 2024 22:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8bea27e and 6de2ddf.
Files selected for processing (2)
  • ledfx/effects/soap2d.py (1 hunks)
  • ledfx/presets.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ledfx/effects/soap2d.py
Additional comments not posted (3)
ledfx/presets.py (3)

9-30: Ensure all configuration values match their expected types and ranges. For example, "brightness" and "background_brightness" should be floats between 0.0 and 1.0, and boolean values should be either True or False.

-                "background_brightness": 1.0,
+                "background_brightness": 0.8, # Ensure this is within the expected range
-                "brightness": 1.0,
+                "brightness": 0.9, # Adjust if necessary to match effect requirements

26-26: Verify that the "soap" configuration is applicable and correctly used within the "acid" preset for the soap2d effect category.

-                "soap": False,
+                # If "soap" is not applicable to this effect, consider removing this line.

19-19: Ensure the gradient configuration is correctly formatted and visually appropriate for the "acid" preset.

-                "gradient": "linear-gradient(90deg, #000000 45.00%,#1aff00 57.00%,#000000 70.00%)",
+                # Confirm that this gradient produces the desired visual effect for the "acid" preset.

ledfx/presets.py Outdated
Comment on lines 6 to 88
"soap2d": {
"acid": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 45.00%,#1aff00 57.00%,#000000 70.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "acid",
},
"blood": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#ff2800 41.00%,#000000 68.00%,#ff0000 100.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "blood",
},
"rgb": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#0016ff 31.00%,#000000 43.00%,#f60202 55.00%,#000000 66.00%,#1afc01 77.00%,#000000 87.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "RGB",
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a brief description comment for each preset category and individual preset to improve maintainability and understandability of the presets.

+    # soap2d presets for soap-like visual effects
        "acid": {
+           # Preset for acid-like visual appearance

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"soap2d": {
"acid": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 45.00%,#1aff00 57.00%,#000000 70.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "acid",
},
"blood": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#ff2800 41.00%,#000000 68.00%,#ff0000 100.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "blood",
},
"rgb": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#0016ff 31.00%,#000000 43.00%,#f60202 55.00%,#000000 66.00%,#1afc01 77.00%,#000000 87.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "RGB",
},
},
# soap2d presets for soap-like visual effects
"soap2d": {
"acid": {
# Preset for acid-like visual appearance
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 45.00%,#1aff00 57.00%,#000000 70.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "acid",
},
"blood": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#ff2800 41.00%,#000000 68.00%,#ff0000 100.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "blood",
},
"rgb": {
"config": {
"advanced": False,
"background_brightness": 1.0,
"background_color": "#000000",
"blur": 0.0,
"brightness": 1.0,
"diag": False,
"dump": False,
"flip": False,
"flip_horizontal": False,
"flip_vertical": False,
"gradient": "linear-gradient(90deg, #000000 20.00%,#0016ff 31.00%,#000000 43.00%,#f60202 55.00%,#000000 66.00%,#1afc01 77.00%,#000000 87.00%)",
"gradient_roll": 0.0,
"impulse_decay": 0.06,
"intensity": 128,
"mirror": False,
"multiplier": 2.0,
"rotate": 0,
"soap": False,
"speed": 1.0,
"stretch": 1.5,
"test": False,
"zoom": 2.0,
},
"name": "RGB",
},
},

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6de2ddf and 825a996.
Files selected for processing (1)
  • ledfx/effects/noise2d.py (1 hunks)
Additional comments not posted (2)
ledfx/effects/noise2d.py (2)

84-86: Consider adding a brief comment explaining the purpose of create_filter and how it relates to the lows_impulse_filter, as it might not be immediately clear to someone unfamiliar with the codebase.


89-96: The initialization of noise_x, noise_y, and noise_z with random values might lead to non-deterministic behavior in the effect, which could complicate debugging. If deterministic behavior is desired for testing or reproducibility, consider allowing these values to be set via configuration or using a fixed seed for the random number generator.

Comment on lines +19 to +28
class Soap2d(Twod, GradientEffect):
NAME = "Noise"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + [
"background_color",
"gradient_roll",
"intensity",
"soap",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the NAME property to "Soap2d" to accurately reflect the effect's purpose and to avoid confusion with other potential noise effects.

-    NAME = "Noise"
+    NAME = "Soap2d"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
class Soap2d(Twod, GradientEffect):
NAME = "Noise"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + [
"background_color",
"gradient_roll",
"intensity",
"soap",
]
class Soap2d(Twod, GradientEffect):
NAME = "Soap2d"
CATEGORY = "Matrix"
# add keys you want hidden or in advanced here
HIDDEN_KEYS = Twod.HIDDEN_KEYS + [
"background_color",
"gradient_roll",
"intensity",
"soap",
]

Comment on lines +31 to +67
CONFIG_SCHEMA = vol.Schema(
{
vol.Optional(
"speed",
description="Speed of the effect",
default=1,
): vol.All(vol.Coerce(float), vol.Range(min=0, max=5)),
vol.Optional(
"intensity",
description="intensity of the effect",
default=128,
): vol.All(vol.Coerce(int), vol.Range(min=0, max=255)),
vol.Optional(
"stretch",
description="Stretch of the effect",
default=1.5,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=1.5)),
vol.Optional(
"zoom",
description="zoom density",
default=2,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=20)),
vol.Optional(
"impulse_decay",
description="Decay filter applied to the impulse for development",
default=0.06,
): vol.All(vol.Coerce(float), vol.Range(min=0.01, max=0.3)),
vol.Optional(
"multiplier",
description="audio injection multiplier, 0 is none",
default=2.0,
): vol.All(vol.Coerce(float), vol.Range(min=0.0, max=4.0)),
vol.Optional(
"soap",
description="Add soap smear to noise",
default=False,
): bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the CONFIG_SCHEMA descriptions are consistent in terms of capitalization and punctuation for better readability and professionalism.

-                description="Speed of the effect",
+                description="Speed of the effect.",
-                description="intensity of the effect",
+                description="Intensity of the effect.",
-                description="zoom density",
+                description="Zoom density.",
-                description="Decay filter applied to the impulse for development",
+                description="Decay filter applied to the impulse for development.",
-                description="audio injection multiplier, 0 is none",
+                description="Audio injection multiplier, 0 is none.",
-                description="Add soap smear to noise",
+                description="Add soap smear to noise.",

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
CONFIG_SCHEMA = vol.Schema(
{
vol.Optional(
"speed",
description="Speed of the effect",
default=1,
): vol.All(vol.Coerce(float), vol.Range(min=0, max=5)),
vol.Optional(
"intensity",
description="intensity of the effect",
default=128,
): vol.All(vol.Coerce(int), vol.Range(min=0, max=255)),
vol.Optional(
"stretch",
description="Stretch of the effect",
default=1.5,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=1.5)),
vol.Optional(
"zoom",
description="zoom density",
default=2,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=20)),
vol.Optional(
"impulse_decay",
description="Decay filter applied to the impulse for development",
default=0.06,
): vol.All(vol.Coerce(float), vol.Range(min=0.01, max=0.3)),
vol.Optional(
"multiplier",
description="audio injection multiplier, 0 is none",
default=2.0,
): vol.All(vol.Coerce(float), vol.Range(min=0.0, max=4.0)),
vol.Optional(
"soap",
description="Add soap smear to noise",
default=False,
): bool,
CONFIG_SCHEMA = vol.Schema(
{
vol.Optional(
"speed",
description="Speed of the effect.",
default=1,
): vol.All(vol.Coerce(float), vol.Range(min=0, max=5)),
vol.Optional(
"intensity",
description="Intensity of the effect.",
default=128,
): vol.All(vol.Coerce(int), vol.Range(min=0, max=255)),
vol.Optional(
"stretch",
description="Stretch of the effect",
default=1.5,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=1.5)),
vol.Optional(
"zoom",
description="Zoom density.",
default=2,
): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=20)),
vol.Optional(
"impulse_decay",
description="Decay filter applied to the impulse for development.",
default=0.06,
): vol.All(vol.Coerce(float), vol.Range(min=0.01, max=0.3)),
vol.Optional(
"multiplier",
description="Audio injection multiplier, 0 is none.",
default=2.0,
): vol.All(vol.Coerce(float), vol.Range(min=0.0, max=4.0)),
vol.Optional(
"soap",
description="Add soap smear to noise.",
default=False,
): bool,

Comment on lines +126 to +201
# temp logging switching, will all be removed in due course
log = False

# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
if log:
start = timeit.default_timer()

bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse

scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y

noise_x = self.noise_x - (scale_x * self.r_height / 2)
noise_y = self.noise_y - (scale_y * self.r_width / 2)

x_array = np.linspace(
noise_x, noise_x + scale_x * self.r_height, self.r_height
)
y_array = np.linspace(
noise_y, noise_y + scale_y * self.r_width, self.r_width
)
z_array = np.array([self.noise_z])
if log:
next1 = timeit.default_timer()
_LOGGER.info(f"array generation time: {next1 - start}")

###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(
x_array, y_array, z_array, grid_mode=True
)

if log:
next2 = timeit.default_timer()
_LOGGER.info(f"simple noise time: {next2 - next1}")

# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2

if log:
next3 = timeit.default_timer()
_LOGGER.info(f"simple squeeze time: {next3 - next2}")

# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")

# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(
self.noise_normalised
).astype(np.uint8)

if log:
next4 = timeit.default_timer()
_LOGGER.info(f"color array time: {next4 - next3}")

# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")

if log:
next5 = timeit.default_timer()
_LOGGER.info(f"image from array time: {next5 - next4}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the temporary logging code before merging to maintain code cleanliness and reduce clutter. If logging is necessary for future debugging, consider implementing a more permanent and configurable logging solution.

-        # temp logging switching, will all be removed in due course
-        log = False
-        ...
-        if log:
-            start = timeit.default_timer()
-        ...
-        if log:
-            next1 = timeit.default_timer()
-            _LOGGER.info(f"array generation time: {next1 - start}")
-        ...
-        if log:
-            next2 = timeit.default_timer()
-            _LOGGER.info(f"simple noise time: {next2 - next1}")
-        ...
-        if log:
-            next3 = timeit.default_timer()
-            _LOGGER.info(f"simple squeeze time: {next3 - next2}")
-        ...
-        if log:
-            next4 = timeit.default_timer()
-            _LOGGER.info(f"color array time: {next4 - next3}")
-        ...
-        if log:
-            next5 = timeit.default_timer()
-            _LOGGER.info(f"image from array time: {next5 - next4}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
# temp logging switching, will all be removed in due course
log = False
# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
if log:
start = timeit.default_timer()
bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse
scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y
noise_x = self.noise_x - (scale_x * self.r_height / 2)
noise_y = self.noise_y - (scale_y * self.r_width / 2)
x_array = np.linspace(
noise_x, noise_x + scale_x * self.r_height, self.r_height
)
y_array = np.linspace(
noise_y, noise_y + scale_y * self.r_width, self.r_width
)
z_array = np.array([self.noise_z])
if log:
next1 = timeit.default_timer()
_LOGGER.info(f"array generation time: {next1 - start}")
###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(
x_array, y_array, z_array, grid_mode=True
)
if log:
next2 = timeit.default_timer()
_LOGGER.info(f"simple noise time: {next2 - next1}")
# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2
if log:
next3 = timeit.default_timer()
_LOGGER.info(f"simple squeeze time: {next3 - next2}")
# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")
# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(
self.noise_normalised
).astype(np.uint8)
if log:
next4 = timeit.default_timer()
_LOGGER.info(f"color array time: {next4 - next3}")
# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")
if log:
next5 = timeit.default_timer()
_LOGGER.info(f"image from array time: {next5 - next4}")
# generate arrays of the X adn Y axis of our plane, with a singular Z
# this should allow libs to use any internal acceleration for unrolling across all points
bass_x = self.scale_x * self.lows_impulse
bass_y = self.scale_y * self.lows_impulse
scale_x = self.scale_x + bass_x
scale_y = self.scale_y + bass_y
noise_x = self.noise_x - (scale_x * self.r_height / 2)
noise_y = self.noise_y - (scale_y * self.r_width / 2)
x_array = np.linspace(
noise_x, noise_x + scale_x * self.r_height, self.r_height
)
y_array = np.linspace(
noise_y, noise_y + scale_y * self.r_width, self.r_width
)
z_array = np.array([self.noise_z])
###################################################################################
# This is where the magic happens, calling the lib of choice to get the noise plane
###################################################################################
# opensimplex at 128x128 on dev machine is 200 ms per frame - Unusable
# self.noise_3d = opensimplex.noise3array(x_array, y_array, z_array)
# vnoise at 128x128 on dev machine is 2.5 ms per frame - Current best candidate
self.noise_3d = self.noise.noise3(
x_array, y_array, z_array, grid_mode=True
)
# if the lib happens to return in a 3 dimensionsal, even though Z is depth of 1, then squeeze it down
self.noise_squeezed = np.squeeze(self.noise_3d)
# apply the stetch param to expand the range of the color space, as noise is likely not full -1 to 1
# TODO: look at what color mapping does with out of range values, do we need to cap here
self.noise_stretched = self.noise_squeezed * self.stretch
# normalise the noise from -1,1 range to 0,1
self.noise_normalised = (self.noise_stretched + 1) / 2
# _LOGGER.info(f"x_array: {x_array}")
# _LOGGER.info(f"y_array: {y_array}")
# _LOGGER.info(f"z_array: {z_array}")
# _LOGGER.info(f"simple_noise3d: {self.simple_n3d}")
# _LOGGER.info(f"shape: {self.simple_n3d.shape}")
# _LOGGER.info(f"min {np.min(self.simple_n3d)}, max {np.max(self.simple_n3d)}")
# map from 0,1 space into the gradient color space via our nicely vecotrised function
self.color_array = self.get_gradient_color_vectorized2d(
self.noise_normalised
).astype(np.uint8)
# transform the numpy array into a PIL image in one easy step
self.matrix = Image.fromarray(self.color_array, "RGB")

@bigredfrog bigredfrog merged commit b926820 into LedFx:main Apr 5, 2024
20 checks passed
@bigredfrog bigredfrog deleted the soap2 branch April 8, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant