Tempo changes and the TempoMap / TempoMap::tick2time()

• Oct 26, 2015 - 19:39

I am attempting to convert ChordRest.tick() into elapsed milliseconds (for the score, the number of milliseconds up to the point where the current ChordRest starts playback). First, I am not getting the results I expect when using TempoMap::tick2time(), and I'm not understanding the inner workings of its various overloaded flavors. Basically, I am not fully grasping how to use the Score's TempoMap (_tempomap internally).

Here is what I think I understand:
- I see that in the TempoMap: key = tick, value = TEvent.
- Tempo is in Beats per Second (BMP/60)
- I imagine that in practical terms, the most granular level at which a user will apply a tempo change is a ChordRest. But the map is by tick, so a tempo change might occur at any tick in the score.
- I imagine that, given tempo changes anywhere, correctly calculating elapsed time involves an incrementing counter, incrementing for each new ChordRest.tick() (the starting tick for the ChordRest), keeping track of the elapsed time prior to the current ChordRest. This requires iterating over all the ChordRests in the score in playback order, from the beginning of the score.

Here are some of my questions:
- Do I need to do a whole separate loop where I iterate over the TEvents in the score's TempoMap from start to end? Or can I rely on tempo changes only occurring on the same tick as a ChordRest, and check the tempo map at each of my ChordRest.tick() values?
- If a ChordRest's start tick is delayed in playback because of Swing, is the tempo change applied to that ChordRest also delayed the same number of ticks?

I think that's it. If TempoMap::tick2time() really provides the elapsed time value I'm looking for (I can convert from qreal to int and seconds to milliseconds), please let me know how to use it properly.

Thanks in advance...


Comments

OK, nevermind. I got TempoMap.tick2time() to work. I will continue testing it to make sure it works - I'm still curious about the swing-related question above, for example, and also if tempo changes can occur at non-note-start-time-related ticks via midi file imports where the tempo changes can be anywhere.

I also now understand how tick2time() works and would simply like to highlight the fact that the TempoMap class is inherited from STL map, not QMap. Both std::map and QMap are used throughout the project, and they're different. Just something to watch out for as you're trying to understand/modify the code. In writing my custom code so far I had only encountered QMap, so I was expecting TempoMap to inherit from QMap. My STL is rusty, and it threw me off track initially in my ability to undersand tick2time().

In reply to by Marc Sabatella

If you are correct, then a tempo change might occur at a tick that does not coincide with a ChordRest's start tick, in spite of the fact that the user selected a specific note or rest when inserting that tempo change. Nothing catastrophic, but mildly disconnected - I'm more curious than worried. The "import midi" scenario offers another situation in which it might occur. I need to test my stuff against tempo changes, so I'll get around to testing these scenarios, eventually... I'll post any results here.

In reply to by Marc Sabatella

For the swing issue, it matters to the extent that you are fussy about the precision of your score's playback. I think that because swing factors only affect offbeat notes, you'd have to be pretty fussy. Unless there was a cumulative effect over the course of a long score. But it's generally unlikely that there would be tempo changes on offbeats.

For the midi import, it might matter if it causes difficulties editing the tempo changes. Imagine a gradual midi tempo change (made up of lots of specific tempo changes) granular enough that it creates multiple tempo changes within the span of any single note. Will the user be able to access all of those tempo changes in MuseScore, more than one per note? Pro Tools, for example, creates absurdly granular gradual tempo changes by default. I'm not familiar with midi import, yet, but I might have to be in the future.

Do you still have an unanswered question? Please log in first to post your question.