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

Expose Melbank and Audio Analysis configurations via API #743

Merged
merged 61 commits into from
Feb 23, 2024

Conversation

shauneccles
Copy link
Member

@shauneccles shauneccles commented Feb 14, 2024

Exposes melbank configurations to /api/config, /api/schema and a new /api/melbanks that shows the melbank config and schema

Loooots of changes in here but mostly to make things work and some tidying.

Still lots of potholes - it blows up when changing some things but this is something to start with.

To test:

hit /api/config with a json payload such as

{
"melbanks": {
"peak_isolation" : 0.0
}
}

Summary by CodeRabbit

  • New Features
    • Introduced a new REST endpoint for querying melbank configurations and schemas.
    • Added new optional field melbank_collection to configuration settings, enhancing audio effect configurability.
  • Enhancements
    • Improved response flexibility in API by allowing additional data in successful responses.
    • Enhanced error handling clarity in API configuration updates.
    • Updated melbank configuration and processing logic for better audio effect customization.
    • Adjusted formula for converting frequency values to Mel-frequency, improving audio analysis accuracy.
  • Refactor
    • Refactored code related to melbanks configuration and pre-emphasis settings in audio effects for clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2024

Walkthrough

The recent updates to the LedFx project aim to enhance API flexibility, improve error handling clarity, and refine melbank configuration management. These changes include enabling the inclusion of additional data in API success responses, enhancing error messaging structure, introducing a new REST endpoint for melbank configurations, and updating melbank configuration and collection handling for improved audio processing capabilities.

Changes

Files Change Summary
ledfx/api/config.py Updated error handling by passing type and message as named arguments in the put method's internal_error.
ledfx/api/schema.py, ledfx/api/utils.py Added Melbank and AudioAnalysisSource imports. Added schemas for melbank_collection and related logic.
ledfx/api/utils.py Added new fields to tuples: "pitch_method", "onset_method", "pitch_tolerance", "peak_isolation", "coeffs_type", "samples", "name", and "max_frequency". Added "melbank_collection" to the "core" dictionary.
ledfx/effects/audio.py Implemented conditional block for pre-emphasis values based on coefficients. Improved pre-emphasis settings handling, assertion updates, and logging.
ledfx/effects/audio.py, ledfx/effects/mel.py, ledfx/effects/melbank.py Refactored code for melbanks configuration, pre-emphasis settings, and frequency conversion calculations.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1d2a0e7 and eb2d775.
Files selected for processing (9)
  • ledfx/api/init.py (2 hunks)
  • ledfx/api/config.py (1 hunks)
  • ledfx/api/melbanks.py (1 hunks)
  • ledfx/api/schema.py (4 hunks)
  • ledfx/api/utils.py (2 hunks)
  • ledfx/config.py (1 hunks)
  • ledfx/effects/audio.py (4 hunks)
  • ledfx/effects/mel.py (1 hunks)
  • ledfx/effects/melbank.py (6 hunks)
Files skipped from review due to trivial changes (1)
  • ledfx/api/config.py
Additional comments: 14
ledfx/api/utils.py (1)
  • 22-35: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [24-47]

The addition of new keys "peak_isolation", "coeffs_type", and "samples" to the "melbanks" tuple, and "name" and "max_frequency" to the "melbank_collection" tuple in PERMITTED_KEYS is correct and aligns with the PR objectives. Ensure that these keys are properly documented and validated elsewhere in the codebase.

ledfx/api/schema.py (2)
  • 10-10: Importing Melbank alongside Melbanks is correct and necessary for defining the melbank_collection schema.
  • 141-154: The addition of the melbank_collection schema is correctly implemented, aligning with the PR objectives to expose melbank configurations. Ensure the schema definitions in Melbank.CONFIG_SCHEMA are comprehensive and accurately reflect the configuration options available.
ledfx/api/__init__.py (1)
  • 161-168: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [138-165]

The enhancement to the request_success method, allowing for an optional data parameter, is correctly implemented and increases the method's flexibility. This change supports the PR's objective of enhancing API response structures. Ensure that all calls to request_success throughout the API correctly handle the inclusion or omission of the data parameter.

ledfx/effects/mel.py (1)
  • 52-52: The updated formula in the hertz_to_mel function is correctly implemented to adjust the conversion from Hz to Mel-frequency values. Ensure this new formula is validated against expected outcomes and is consistent with the latest research or standards in the field.
ledfx/effects/melbank.py (7)
  • 17-17: Import of generate_id is added. Ensure it's used appropriately within the file.
  • 84-84: MELBANK_CONFIG_SCHEMA is renamed to CONFIG_SCHEMA. Verify that all references to this constant are updated accordingly.
Verification successful

The search for occurrences of MELBANK_CONFIG_SCHEMA within the project's Python files did not yield any results. This indicates that all references to this constant have likely been updated to CONFIG_SCHEMA as intended. No issues were found regarding the renaming process based on the provided context and the results of the executed script.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for old constant name usage in the project
rg --type py 'MELBANK_CONFIG_SCHEMA'

Length of output: 36

* 100-100: The configuration is validated against `CONFIG_SCHEMA` upon initialization of a `Melbank` instance. This is a good practice for ensuring the configuration's integrity. * 423-429: The `CONFIG_SCHEMA` in the `Melbanks` class includes a default value for `coeffs_type` as `"matt_mel"`. Confirm that this default value is appropriate and consistent with the rest of the application's logic and settings.
Verification successful

The search results indicate that the default value "matt_mel" for "coeffs_type" is used consistently within the application, particularly within the Melbanks effect configuration and its usage in audio processing logic. There is no evidence of contradictory defaults or settings that would suggest inconsistency with the rest of the application's logic and settings. Therefore, the default value appears to be appropriate and consistent with the application's logic.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for consistency of default `coeffs_type` across the project
rg --type py '"coeffs_type"'

Length of output: 1465

* 440-440: `DEFAULT_MELBANK_CONFIG` is derived from `Melbank.CONFIG_SCHEMA({})`. This approach ensures that the default configuration adheres to the schema. However, verify that the empty configuration passed to `CONFIG_SCHEMA` generates a meaningful default configuration. * 473-478: `generate_id` is used to create a unique ID for each melbank based on its name. This is a good use of the imported function, ensuring that each melbank can be uniquely identified. * 498-514: Global settings are removed from individual melbank configurations in `cleaned_melbank_collection`. This is a good practice for separating global settings from individual configurations. However, ensure that this cleaned configuration is appropriately used wherever individual melbank configurations are needed.
Verification successful

The verification process has revealed that self._ledfx.config["melbank_collection"], which is assigned the cleaned_melbank_collection, is indeed utilized within the project. Specifically, it is referenced in two places within the codebase:

  1. In ledfx/effects/melbank.py, where the cleaned configuration is assigned to self._ledfx.config["melbank_collection"].
  2. In ledfx/api/melbanks.py, where self._ledfx.config["melbank_collection"] is accessed, indicating that the cleaned configurations are being used, potentially in API responses or internal logic.

This confirms that the cleaned configuration is not only created but also utilized, aligning with the intent expressed in the review comment to ensure that the cleaned configuration is appropriately used wherever individual melbank configurations are needed. Therefore, the review comment's concern has been addressed by the current implementation in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for usage of `cleaned_melbank_collection` in the project
rg --type py 'cleaned_melbank_collection'

Length of output: 179



Script:

#!/bin/bash
# Check for usage of `self._ledfx.config["melbank_collection"]` in the project to understand how the cleaned configurations are utilized
rg --type py '_ledfx.config\[\"melbank_collection\"\]'

Length of output: 177



Script:

#!/bin/bash
# Correcting the search pattern to avoid regex parse errors and check for usage of `self._ledfx.config["melbank_collection"]` in the project
rg --type py 'self\._ledfx\.config\["melbank_collection"\]'

Length of output: 225

ledfx/config.py (1)
  • 98-98: The addition of melbank_collection as an optional field in CORE_CONFIG_SCHEMA is consistent with the PR's objective to expose melbank configurations via the API. Ensure that the default value [] is appropriate and that the application logic correctly handles this new field.
ledfx/effects/audio.py (1)
  • 199-215: The conditional logic for setting pre-emphasis values based on coeffs_type is clear and follows the stated objectives. However, ensure that self._ledfx.config["melbanks"]["coeffs_type"] is always defined and has a default value to avoid potential KeyError.

@@ -534,7 +510,7 @@ def initialise_analysis(self):
self.freq_mel_indexes = []

for freq in self.freq_max_mels:
assert self.melbanks._config["max_frequencies"][2] >= freq
assert self.melbanks.melbanks_config["max_frequencies"][2] >= freq
Copy link
Contributor

Choose a reason for hiding this comment

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

Using an assertion to check if self.melbanks.melbanks_config["max_frequencies"][2] is greater than or equal to freq is a direct way to validate the configuration. However, consider handling this condition more gracefully to provide a clearer error message to the user if the configuration is invalid.

- assert self.melbanks.melbanks_config["max_frequencies"][2] >= freq
+ if self.melbanks.melbanks_config["max_frequencies"][2] < freq:
+     raise ValueError("Configuration error: max_frequencies[2] is less than required frequency.")

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
assert self.melbanks.melbanks_config["max_frequencies"][2] >= freq
if self.melbanks.melbanks_config["max_frequencies"][2] < freq:
raise ValueError("Configuration error: max_frequencies[2] is less than required frequency.")

Comment on lines 12 to 44
class ScenesEndpoint(RestEndpoint):
"""REST end-point for querying config and schema melbanks"""

ENDPOINT_PATH = "/api/melbanks"

async def get(self) -> web.Response:
"""
Get all melbank configuration and permitted values.

Returns:
web.Response: The response containing the scenes.
"""
data = {}
data["melbanks"] = {
"config": self._ledfx.config["melbanks"],
"schema": {
**convertToJsonSchema(
Melbanks.CONFIG_SCHEMA,
),
**{"permitted_keys": PERMITTED_KEYS["melbanks"]},
},
}
data["melbank_collection"] = {
"config": self._ledfx.config["melbank_collection"],
"schema": {
**convertToJsonSchema(
Melbank.CONFIG_SCHEMA,
),
**{"permitted_keys": PERMITTED_KEYS["melbank_collection"]},
},
}

return await self.request_success(type=None, message=None, data=data)
Copy link
Contributor

Choose a reason for hiding this comment

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

The class name ScenesEndpoint does not accurately reflect its purpose, which is to handle melbank configurations, not scenes. Consider renaming it to MelbanksEndpoint or similar to improve clarity.

Comment on lines 17 to 23
async def get(self) -> web.Response:
"""
Get all melbank configuration and permitted values.

Returns:
web.Response: The response containing the scenes.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring for the get method inaccurately describes the return value as "The response containing the scenes." It should be updated to reflect that it returns melbank configurations and schemas.

},
}

return await self.request_success(type=None, message=None, data=data)
Copy link
Contributor

Choose a reason for hiding this comment

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

The request_success method is called without specifying the type and message parameters, which could be utilized to provide more informative responses. Consider adding a success type and message for better user feedback.

Comment on lines +450 to +453
self.melbanks_config = config
if not self.melbanks_config:
self.melbanks_config = self.CONFIG_SCHEMA(config)
self.melbank_collection = self._ledfx.config.get(
Copy link
Contributor

Choose a reason for hiding this comment

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

The method update_config in the Melbanks class directly assigns the provided configuration to self.melbanks_config without validation. It should validate the configuration against CONFIG_SCHEMA before assignment.

- self.melbanks_config = config
+ self.melbanks_config = self.CONFIG_SCHEMA(config)

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.melbanks_config = config
if not self.melbanks_config:
self.melbanks_config = self.CONFIG_SCHEMA(config)
self.melbank_collection = self._ledfx.config.get(
self.melbanks_config = self.CONFIG_SCHEMA(config)
if not self.melbanks_config:
self.melbanks_config = self.CONFIG_SCHEMA(config)
self.melbank_collection = self._ledfx.config.get(

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between eb2d775 and 3ffb12e.
Files selected for processing (1)
  • ledfx/effects/melbank.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ledfx/effects/melbank.py

@shauneccles shauneccles changed the title Expose melbank configurations via API Expose Melbank and Audio Analysis configurations via API Feb 21, 2024
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3ffb12e and c6219cd.
Files selected for processing (4)
  • ledfx/api/config.py (3 hunks)
  • ledfx/api/schema.py (4 hunks)
  • ledfx/api/utils.py (2 hunks)
  • ledfx/effects/audio.py (6 hunks)
Files skipped from review as they are similar to previous changes (4)
  • ledfx/api/config.py
  • ledfx/api/schema.py
  • ledfx/api/utils.py
  • ledfx/effects/audio.py

bigredfrog and others added 22 commits February 23, 2024 14:27
* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls
transform: card ? 'unset' : scene ? 'scale(1)' : 'scale(0.012)',
marginTop: '3px'
}}
dangerouslySetInnerHTML={{ __html: name }}

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
/>
) : name.startsWith('https://') ? (
<img
src={name.replaceAll('#000000', 'currentColor')}

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
@shauneccles shauneccles merged commit 9c416cc into LedFx:main Feb 23, 2024
16 checks passed
@shauneccles shauneccles deleted the feat/expose_audio_analysis_options branch February 23, 2024 04:58
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c6219cd and 696d6ef.
Files selected for processing (2)
  • frontend/.eslintrc (2 hunks)
  • frontend/src/components/SchemaForm/SchemaForm/SchemaForm.tsx (1 hunks)
Additional comments: 1
frontend/src/components/SchemaForm/SchemaForm/SchemaForm.tsx (1)
  • 112-112: The logic for handling audio devices has been altered by replacing a check on schema?.properties?.audio_device?.enum with s.id === 'audio_device'. This change simplifies the condition for identifying the audio_device field within the schema. However, ensure that this change does not inadvertently affect other parts of the form where audio_device properties are used or expected. It's also important to verify that this change aligns with the overall objectives of exposing melbank configurations and audio analysis settings via the API, as mentioned in the PR objectives. Testing this specific part of the form with various schema configurations would be beneficial to ensure that the new logic behaves as expected.

@@ -92,6 +88,6 @@
"argsIgnorePattern": "^_"
}
],
"jsx-a11y/label-has-associated-control": 0,
"jsx-a11y/label-has-associated-control": 0
Copy link
Contributor

Choose a reason for hiding this comment

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

The jsx-a11y/label-has-associated-control rule is set to 0, effectively disabling it. This rule ensures that form labels have a corresponding control, which is crucial for accessibility. Consider the impact of disabling this rule on the accessibility of your application. If the decision to disable it is intentional and based on specific requirements, it might be helpful to document the rationale behind this choice directly in the .eslintrc file or in your project's documentation to maintain clarity for future developers.

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

3 participants