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

Saving measures' BPM and fix #557 #558

Merged
merged 4 commits into from Aug 19, 2019
Merged

Saving measures' BPM and fix #557 #558

merged 4 commits into from Aug 19, 2019

Conversation

praisethemoon
Copy link
Collaborator

praisethemoon strikes once again with another PR. I personally needed such API to capture measure's tempo.

Does this deprecate this.osmd.sheet.userStartTempoInBPM? Right now it has a different value (100) and I think it either must be deprecated, or inherits its value from BPM of the first measure.

Any thoughts? 🎵

Copy link
Collaborator

@bneumann bneumann left a comment

Choose a reason for hiding this comment

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

LGTM! but consider changing the default value from 0 to 120 because the sound tag is optional and having a player wanting to play the sheet might result in a stuck

@@ -142,6 +142,7 @@ export class ExpressionReader {
if (tempoAttr) {
const match: string[] = tempoAttr.value.match(/\d+/);
this.soundTempo = match !== undefined ? parseInt(match[0], 10) : 100;
currentMeasure.TempoInBPM = this.soundTempo;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sound is an optional attribute. So your tempo might always be 0.
If somebody implementing a midi player wants to use this it might come in handy to set the tempo to 120 as a default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should introduce a flag, to tell the user if the bpm was ever set in the sheet, or its value was not specified

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea

@@ -32,6 +32,7 @@ export class SourceMeasure {
this.endingBarStyle = "";
this.firstInstructionsStaffEntries = new Array(completeNumberOfStaves);
this.lastInstructionsStaffEntries = new Array(completeNumberOfStaves);
this.TempoInBPM = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yeah here is the 0. Maybe make it! = 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gonna update this to 120

@@ -505,6 +505,10 @@ export class InstrumentReader {
}
}
}

if (currentMeasure.TempoInBPM === 0) {
this.currentMeasure.TempoInBPM = this.previousMeasure.TempoInBPM;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If having a fix value for the tempo this is unnecessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do I distinguish between fix and dynamic BPM? What I have in mind is upon playing each measure I would do something like setAudioPlayBackBPM(currentMeasure.TempoInBPM) be it a fix or dynamic value

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, having thought about that. My comment was about the initial value. So in your case that is correct.

@bneumann
Copy link
Collaborator

The field you are referring to might be from our old implementation which we ported to JS. Maybe reuse it as a default for your implementation, see PR comments

@praisethemoon
Copy link
Collaborator Author

@bneumann what about this.osmd.sheet.userStartTempoInBPM

@praisethemoon
Copy link
Collaborator Author

praisethemoon commented Aug 10, 2019

Test 1 :

No bpm mentioned in the sheet (I know cause I made it)
image

Test 2

Varying BPM
image

Test 3

userStartTempoInBPM
image

@matt-uib
Copy link
Collaborator

Hi! Just to clarify the original idea of the code and the variables:
As there are possibly many tempo instructions and dynamic tempo changes, we read them all in and use the first instantaneous for the defaultTempoInBpm. This bpm value gets also copied into the userTempoInBpm, but this can later be set by the user to scale up or down the whole "tempo curve" of the piece. And with defaultTempoInBpm the user can reset back to the original tempo curve given in xml.

@praisethemoon
Copy link
Collaborator Author

@matt-uib thank you very much for the clarification, in that case, maybe I should set defaultTempoInBpm to the first measure's bpm instead of userStartTempoInBPM?

@matt-uib
Copy link
Collaborator

Yes that would make sense. And then, if userStartTempoInBPM has not been set by the user (e.g. =0) , which will currently be always the case, set it as well by copying the value from defaultTempoInBpm. defaultTempoInBpm shall then never be changed and userStartTempoInBPM can be changed by the user.

@praisethemoon
Copy link
Collaborator Author

@matt-uib something like this?
MusicSheetReader.ts

this.musicSheet.DefaultStartTempoInBpm = this.musicSheet.SourceMeasures[0].TempoInBPM;
this.musicSheet.userStartTempoInBPM = this.musicSheet.userStartTempoInBPM || this.musicSheet.DefaultStartTempoInBpm;

@praisethemoon
Copy link
Collaborator Author

The last commit improves reading tempo that appears inside of metronome instead of sound

@sschmidTU
Copy link
Contributor

LGTM. seems like all suggestions were implemented, anything else can be changed later.

@sschmidTU sschmidTU merged commit cf199ad into opensheetmusicdisplay:develop Aug 19, 2019
@praisethemoon praisethemoon mentioned this pull request Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants