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

regions plugin: add regionsMinLength option #2009

Merged
merged 2 commits into from
Aug 13, 2020

Conversation

marizuccara
Copy link
Contributor

@marizuccara marizuccara commented Jul 19, 2020

Added generalMinLength parameter to control min length of regions created dragging on drawer (so not those passed on initialization in regions array), to avoid dragging regions to size 0.

NB. Maybe unify in some way minLength and generalMinLength parameters if necesssary?

Related Issues and other PRs:

PR #2002
ISSUES #2001 #2008

@coveralls
Copy link

coveralls commented Jul 19, 2020

Coverage Status

Coverage remained the same at 80.385% when pulling 28bd387 on marizuccara:master into 4eedd08 on katspaugh:master.

@thijstriemstra
Copy link
Contributor

thijstriemstra commented Jul 20, 2020

@sundayz can you also take a look? ps. I'm not a fan of the parameter name @marizuccara

@@ -614,10 +616,19 @@ export class Region {
* @param {string} direction 'start 'or 'end'
*/
onResize(delta, direction) {
let minLength = null;

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment so people know a region's minLength is used over generalMinLength if both are specified

Copy link
Contributor

Choose a reason for hiding this comment

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

@sundayz
Copy link
Contributor

sundayz commented Jul 20, 2020

Maybe regionMinLength would be a better name, but I don't mind what name is used. example/regions/index.html should be updated to show the settings that are being used in the .js file.

When I tried testing this, generalMinLength seems to always be undefined? The code looks right I don't know why it's not being passed to the plugin constructor

edit:

okay so I see generalMinLength only applies to regions created by dragging the mouse.
I think it would be better if generalMinLength applied to all regions. If you want to set a different min length for regions created via the mouse it should be done by listening to the region-created event and modifying the region after it's created. That makes more sense to me. for example:

(example code, might not work)

// first wait for the region plugin to be loaded
wavesurfer.on('plugin-added', name => {
    if (name == 'regions') {
        // now any regions created after the plugin was loaded (i.e. via mouse drag) have minlength of 1.5
        wavesurfer.on('region-created', region => region.minLength = 1.5)
    } 
})

@marizuccara
Copy link
Contributor Author

Maybe regionMinLength would be a better name, but I don't mind what name is used. example/regions/index.html should be updated to show the settings that are being used in the .js file.

When I tried testing this, generalMinLength seems to always be undefined? The code looks right I don't know why it's not being passed to the plugin constructor

edit:

okay so I see generalMinLength only applies to regions created by dragging the mouse.
I think it would be better if generalMinLength applied to all regions. If you want to set a different min length for regions created via the mouse it should be done by listening to the region-created event and modifying the region after it's created. That makes more sense to me. for example:

(example code, might not work)

// first wait for the region plugin to be loaded
wavesurfer.on('plugin-added', name => {
    if (name == 'regions') {
        // now any regions created after the plugin was loaded (i.e. via mouse drag) have minlength of 1.5
        wavesurfer.on('region-created', region => region.minLength = 1.5)
    } 
})

I'm agree, thanks. Later fix

@marizuccara
Copy link
Contributor Author

So sorry for the absence :(
If you approve these changes, I'll update changelog end regions/index.html example

@thijstriemstra
Copy link
Contributor

@marizuccara there are many old, unrelated changes in this PR, can you take a look at that?

@marizuccara
Copy link
Contributor Author

marizuccara commented Aug 5, 2020

@sundayz have you take a look at this PR if you'll have time?

example/regions/app.js Show resolved Hide resolved
@sundayz
Copy link
Contributor

sundayz commented Aug 11, 2020

I tested the change and it works as intended:

  • When setting minLength AND regionsMinLength, minLength is used
  • When setting only minLength and no regionsMinLength, minLength is used
  • When setting only regionsMinLength and no minLength, regionsMinLength is used

Works well, just need to update HTML for the examples page

@thijstriemstra thijstriemstra changed the title Regions plugin: generalMinLength parameter regions plugin: add regionsMinLength option Aug 13, 2020
Copy link
Contributor

@thijstriemstra thijstriemstra left a comment

Choose a reason for hiding this comment

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

see inline comment and there's a merge conflict with this branch.

@marizuccara marizuccara reopened this Aug 13, 2020
@thijstriemstra thijstriemstra merged commit 97ec876 into katspaugh:master Aug 13, 2020
sandiz pushed a commit to sandiz/wavesurfer.js that referenced this pull request Sep 1, 2021
* rebased fork

* added comment to minLength param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants