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

Feature: Able to set startDuration & endDuration for active waveform? #43

Open
hishamsyed0 opened this issue Sep 13, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@hishamsyed0
Copy link

Hi, i need to show active waveform between two durations, it will be a helpful feature!
Thanks for the great library.

@rutvik110
Copy link
Owner

So you want to set a start and end point for active waveforms?

@rutvik110 rutvik110 added the enhancement New feature or request label Sep 26, 2023
@bdlukaa
Copy link

bdlukaa commented Jan 2, 2024

@rutvik110 Yes! And, in addition to this feature, it would be nice to have a way to define a start and end point for the waveform. This would be useful in a clipping functionality, for example.

Thank you!

@bdlukaa
Copy link

bdlukaa commented Jan 2, 2024

The output would look like this:

One waveform highlighted, other ofuscated

Currently, we need to make use of a Stack and a CustomClipper<Rect> to render two waveforms on top of each other:

Stack(children: [
  Positioned.fill(
    child: CurvedPolygonWaveform(
      height: constraints.maxHeight,
      width: constraints.maxWidth,
      samples: snapshot.data!,
      style: PaintingStyle.fill,
      inactiveColor: theme.colorScheme.primaryContainer.withOpacity(0.5),
    ),
  ),
  Positioned.fill(
    child: ClipRect(
      clipper: RectClipper(
        initialPositionFactor: start.inMilliseconds / duration.inMilliseconds,
        endPositionFactor: end.inMilliseconds / duration.inMilliseconds,
      ),
      child: CurvedPolygonWaveform(
        height: constraints.maxHeight,
        width: constraints.maxWidth,
        samples: snapshot.data!,
        style: PaintingStyle.fill,
        inactiveColor: theme.colorScheme.primary,
      ),
    ),
  ),
])

class RectClipper extends CustomClipper<Rect> {
  final double initialPositionFactor;
  final double endPositionFactor;

  const RectClipper({
    required this.initialPositionFactor,
    required this.endPositionFactor,
  });

  @override
  Rect getClip(Size size) {
    return Rect.fromLTRB(
      size.width * initialPositionFactor,
      0.0,
      size.width * endPositionFactor,
      size.height,
    );
  }

  @override
  bool shouldReclip(RectClipper oldClipper) =>
      oldClipper.endPositionFactor != endPositionFactor ||
      oldClipper.initialPositionFactor != initialPositionFactor;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants