-
Notifications
You must be signed in to change notification settings - Fork 157
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
Expose Melbank and Audio Analysis configurations via API #743
Conversation
WalkthroughThe 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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
alongsideMelbanks
is correct and necessary for defining themelbank_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 inMelbank.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 optionaldata
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 torequest_success
throughout the API correctly handle the inclusion or omission of thedata
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 toCONFIG_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 toCONFIG_SCHEMA
as intended. No issues were found regarding the renaming process based on the provided context and the results of the executed script.* 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.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
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.* 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.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
Verification successful
The verification process has revealed that
self._ledfx.config["melbank_collection"]
, which is assigned thecleaned_melbank_collection
, is indeed utilized within the project. Specifically, it is referenced in two places within the codebase:
- In
ledfx/effects/melbank.py
, where the cleaned configuration is assigned toself._ledfx.config["melbank_collection"]
.- In
ledfx/api/melbanks.py
, whereself._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 inCORE_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 thatself._ledfx.config["melbanks"]["coeffs_type"]
is always defined and has a default value to avoid potentialKeyError
.
@@ -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 |
There was a problem hiding this comment.
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.
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.") |
ledfx/api/melbanks.py
Outdated
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) |
There was a problem hiding this comment.
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.
ledfx/api/melbanks.py
Outdated
async def get(self) -> web.Response: | ||
""" | ||
Get all melbank configuration and permitted values. | ||
|
||
Returns: | ||
web.Response: The response containing the scenes. | ||
""" |
There was a problem hiding this comment.
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.
ledfx/api/melbanks.py
Outdated
}, | ||
} | ||
|
||
return await self.request_success(type=None, message=None, data=data) |
There was a problem hiding this comment.
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.
self.melbanks_config = config | ||
if not self.melbanks_config: | ||
self.melbanks_config = self.CONFIG_SCHEMA(config) | ||
self.melbank_collection = self._ledfx.config.get( |
There was a problem hiding this comment.
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.
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( |
There was a problem hiding this 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
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
There was a problem hiding this 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
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
… sha and release to info.py
* 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
for more information, see https://pre-commit.ci
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
/> | ||
) : name.startsWith('https://') ? ( | ||
<img | ||
src={name.replaceAll('#000000', 'currentColor')} |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
DOM text
There was a problem hiding this 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
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
withs.id === 'audio_device'
. This change simplifies the condition for identifying theaudio_device
field within the schema. However, ensure that this change does not inadvertently affect other parts of the form whereaudio_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 |
There was a problem hiding this comment.
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.
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
melbank_collection
to configuration settings, enhancing audio effect configurability.