tomoyu719 / simple_sheet_music

A Flutter package for rendering sheet music on canvas.
https://pub.dev/packages/simple_sheet_music
MIT License
6 stars 3 forks source link

Stave doesn't render dead-center #6

Open heyaphra opened 1 week ago

heyaphra commented 1 week ago

Summary

While the widget is behaving as expected (the bottom staff line renders at (0, 0) in the coordinate system), this causes issues when centering the widget within a container. Rendering dead-center would be useful for displaying figures for music theory education.

Example of the issue:

Screenshot 2024-06-23 at 12 34 09 PM

Example code:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Simple Sheet Music Example')),
      body: Center(
        child: Container(
          decoration: BoxDecoration(border: Border.all()),
          width: 200.0,
          height: 200.0,
          child: Align(
            alignment: Alignment.center,
            child: SimpleSheetMusic(
              initialClef: initialClef,
              height: 100,
              width: 100,
              staffs: [staff],
            ),
          ),
        ),
      ),
    );
  }
}
heyaphra commented 1 week ago

Update: I was able to "fix" this problem by changing the staffLineCenterY in built_staff.dart:

final measureOnCanvas = measure.placeOnCanvas(
    staffLineCenterY + staffLineCenterY / 2),
    currentX,
);

Not sure if this would break any other intended use cases.

tomoyu719 commented 1 week ago

Thank you for the Issue and kind example. We will address this issue as soon as possible. Incidentally, how about using the uppermost part as the origin of the Y-coordinate? (in this case, the topmost part of the G clef)

heyaphra commented 1 week ago

I'm concerned that if the uppermost part were used as the origin then the staff would be off-center inside of its container. Are there any benefits conferred by that approach that I'm not seeing?

Here's a picture to go along with the code example that I modified:

Screenshot 2024-06-24 at 2 57 03 PM
tomoyu719 commented 1 week ago

I was a little mistaken. I thought it would cause problems with rendering multi-stage Stave, but your method will work. I will put out a revised version in a few more days.