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

How to get bars width ? #155

Closed
lc-thomas opened this issue Jul 31, 2017 · 9 comments
Closed

How to get bars width ? #155

lc-thomas opened this issue Jul 31, 2017 · 9 comments

Comments

@lc-thomas
Copy link

Your environment

  • Version used: (master branch)
  • Platform used: C#
  • Rendering engine used: GDI
  • Operating System and version (desktop or mobile): Linux CentOS 7

Expected Results

I'm using Samples.PngDump to generate images from tablatures.
I'd like to be able to get the size of each bar drawn.

Observed Results

Currently the Bar model doesn't seem to have a "width" attribute.

@Danielku15
Copy link
Member

The model is independent from the whole rendering part; that's why you won't find any graphical details in the model classes.

During rendering there a AlphaTab.Rendering.Utils.BoundsLookup filled with all details about where the individual bars and beats are located. This lookup is used also by the player feature (HTML5) to place the cursor. The lookup is currently based on Beats not Bars but passing in any beat of the bar allows you to access also the bars.

renderer.Render(track);

var boundsLookup = renderer.BoundsLookup;
var beatBounds = boundsLookup.FindBeat( track.Staves[0].Bars[0].Voices[0].Beats[0] ); // 
var barBounds = beatPosition.BarBounds;

Does this help you?

@Danielku15 Danielku15 self-assigned this Aug 1, 2017
@Danielku15 Danielku15 added state-accepted This is a valid topic to work on. state-needs-discussion 💬 labels Aug 1, 2017
@lc-thomas
Copy link
Author

It works great thank you !
Is there any chance I could get each note position as well ?

@Danielku15
Copy link
Member

Currently the note and rest positions are not part of the lookup cache. Mostly because I did not see any need for it yet but it is also not clear what bounds exactly to provide. The note head is the most obvious rectangle, but also the effects might be of interest (e.g. dots). It would be interesting ot hear what you are exactly planning to implement, then I rather able to provide a proper solution. All the information is available internally.

I also have some performance worries of collecting all those details. I will run some tests where I collect also the note and rests. I could add a setting which allows to control whether the note bounds are included.

@lc-thomas
Copy link
Author

lc-thomas commented Aug 5, 2017

I'm building videos out of tablatures.
I generate PNGs with alphatab, then I move them to create the video.

http://puu.sh/x2bIV/9b33162032.jpg

Using bars boundaries I can highlight the current bar, and I'd love to be able to highlight the notes currenlty playing as well.

BTW I'm sorry I moved the copyright, but I can't keep it in this form, otherwise each track is too large.
I was thinking of placing the credit to AlphaTab in intro / outro of the videos + in the video description.
What do you think ?

@Danielku15
Copy link
Member

If you have a proper replacement for the existing alphaTab notice I'm fine with it.

Regarding your sceenshot it seems that you are rendering all tracks individually. In this case the tracks are not aligned properly to their timeline. You should use the multi-track rendering to overcome this problem. To render all tracks into PNGs (chunked to have a usable image size) you can do something like:

// load score
var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0]));

// render score with svg engine and desired rendering width
var settings = Settings.Defaults;
settings.Engine = "gdi";
settings.Layout.Mode = "horizontal";
settings.Staves.Id = "tab";
var renderer = new ScoreRenderer(settings);

var chunk = 0;
var info = new FileInfo(args[0]);
renderer.PartialRenderFinished += r =>
{
    var path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "_" + chunk + ".png");
    chunk++;
    ((Image) r.RenderResult).Save(path, ImageFormat.Png);
};
renderer.Render(score, score.Tracks.Select(t => t.Index).ToArray());

@lc-thomas
Copy link
Author

lc-thomas commented Aug 5, 2017

Wow man ! I wish I've talked to you about this earlier I'd have spared a lot of time!

Though it works not too bad, tracks are somewhat aligned, see :
http://91.121.5.186:8008/listing/out/e15fb87d63d6e5b75a7733a92c09fff9520831b4450ff0d1855527d0/final.mp4
What do you think ?

I have this tempo issue I'm working on, and a few minor bugs.
Also a good thing would be to remove that red bar, and highlight the current note instead a switch would be great to not destroy performances for those who don't need it, I agree with you.

@Danielku15
Copy link
Member

That's a very interesting way of animating the playback, it looks very fancy. But for playing along the song with the guitar, it is quite hard to read the tablature this way. What are you using for playback? Sounds a lot like the audio exported from Guitar Pro 6.

@lc-thomas
Copy link
Author

That's GP6 right.
And yes, sadly it's a bit hard to read, this song is relatively fast though, and I can make the readability a bit better.
That's 32 FPS for testing purposes, it's a bit low, so it looks laggy.
Also there is something I wished to report to you as a minor bug later.
See in front of the numbers there is a white space, but not behind them : http://puu.sh/x2ijN/ec1ec8f4bd.png
When there is also a slide like in the pic it reduces the readability.
Though if I get notes positions I can clear that with a basic vertical white line.

@Danielku15 Danielku15 removed the state-accepted This is a valid topic to work on. label Aug 19, 2018
@Danielku15
Copy link
Member

I'm closing this issue in favor of #187. The only open topic here is the individual note position which is handled there.

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

No branches or pull requests

2 participants