3131using namespace mu ;
3232
3333namespace mu ::engraving {
34- // ---------------------------------------------------------
35- // TEvent
36- // ---------------------------------------------------------
37-
38- TEvent::TEvent ()
39- {
40- type = TempoType::INVALID;
41- tempo = 0.0 ;
42- pause = 0.0 ;
43- time = 0.0 ;
44- }
45-
46- TEvent::TEvent (const TEvent& e)
47- {
48- type = e.type ;
49- tempo = e.tempo ;
50- pause = e.pause ;
51- time = e.time ;
52- }
53-
54- TEvent::TEvent (BeatsPerSecond t, double p, TempoType tp)
34+ TEvent::TEvent (const BeatsPerSecond t, const double p, const TempoType tp)
35+ : type(tp), tempo(t), pause(p)
5536{
56- type = tp;
57- tempo = t;
58- pause = p;
59- time = 0.0 ;
6037}
6138
6239bool TEvent::valid () const
6340{
6441 return !(!type);
6542}
6643
67- // ---------------------------------------------------------
68- // TempoMap
69- // ---------------------------------------------------------
70-
71- TempoMap::TempoMap ()
72- {
73- m_tempo = 2.0 ; // default fixed tempo in beat per second
74- m_tempoSN = 1 ;
75- m_tempoMultiplier = 1.0 ;
76- }
77-
7844// ---------------------------------------------------------
7945// setPause
8046// ---------------------------------------------------------
@@ -135,7 +101,6 @@ void TempoMap::normalize()
135101 tick = e->first ;
136102 tempo = e->second .tempo .val ;
137103 }
138- ++m_tempoSN;
139104}
140105
141106// ---------------------------------------------------------
@@ -159,7 +124,6 @@ void TempoMap::clear()
159124{
160125 std::map<int , TEvent>::clear ();
161126 m_pauses.clear ();
162- ++m_tempoSN;
163127}
164128
165129// ---------------------------------------------------------
@@ -183,7 +147,6 @@ void TempoMap::clearRange(int tick1, int tick2)
183147 }
184148
185149 erase (first, last);
186- ++m_tempoSN;
187150}
188151
189152// ---------------------------------------------------------
@@ -224,27 +187,6 @@ double TempoMap::pauseSecs(int tick) const
224187 return muse::value (m_pauses, tick, 0.0 );
225188}
226189
227- // ---------------------------------------------------------
228- // del
229- // ---------------------------------------------------------
230-
231- void TempoMap::del (int tick)
232- {
233- auto e = find (tick);
234- if (e == end ()) {
235- LOGD (" TempoMap::del event at (%d): not found" , tick);
236- // abort();
237- return ;
238- }
239- // don't delete event if still being used for pause
240- if (e->second .type & TempoType::PAUSE) {
241- e->second .type = TempoType::PAUSE;
242- } else {
243- erase (e);
244- }
245- normalize ();
246- }
247-
248190BeatsPerSecond TempoMap::tempoMultiplier () const
249191{
250192 return m_tempoMultiplier;
@@ -272,34 +214,22 @@ bool TempoMap::setTempoMultiplier(BeatsPerSecond val)
272214
273215void TempoMap::delTempo (int tick)
274216{
275- del (tick);
276- ++m_tempoSN;
277- }
278-
279- // ---------------------------------------------------------
280- // tick2time
281- // ---------------------------------------------------------
282-
283- double TempoMap::tick2time (int tick, double time, int * sn) const
284- {
285- return (*sn == m_tempoSN) ? time : tick2time (tick, sn);
286- }
287-
288- // ---------------------------------------------------------
289- // time2tick
290- // return cached value t if list did not change
291- // ---------------------------------------------------------
292-
293- int TempoMap::time2tick (double time, int t, int * sn) const
294- {
295- return (*sn == m_tempoSN) ? t : time2tick (time, sn);
217+ auto e = find (tick);
218+ if (e == end ()) {
219+ LOGD (" TempoMap::del event at (%d): not found" , tick);
220+ // abort();
221+ return ;
222+ }
223+ // don't delete event if still being used for pause
224+ if (e->second .type & TempoType::PAUSE) {
225+ e->second .type = TempoType::PAUSE;
226+ } else {
227+ erase (e);
228+ }
229+ normalize ();
296230}
297231
298- // ---------------------------------------------------------
299- // tick2time
300- // ---------------------------------------------------------
301-
302- double TempoMap::tick2time (int tick, int * sn) const
232+ double TempoMap::tick2time (int tick) const
303233{
304234 double time = 0.0 ;
305235 double delta = double (tick);
@@ -329,9 +259,7 @@ double TempoMap::tick2time(int tick, int* sn) const
329259 } else {
330260 LOGD (" TempoMap: empty" );
331261 }
332- if (sn) {
333- *sn = m_tempoSN;
334- }
262+
335263 time += delta / (Constants::DIVISION * tempo.val * m_tempoMultiplier.val );
336264 return time;
337265}
@@ -340,7 +268,7 @@ double TempoMap::tick2time(int tick, int* sn) const
340268// time2tick
341269// ---------------------------------------------------------
342270
343- int TempoMap::time2tick (double time, int * sn ) const
271+ int TempoMap::time2tick (double time) const
344272{
345273 int tick = 0 ;
346274 double delta = time;
@@ -363,9 +291,7 @@ int TempoMap::time2tick(double time, int* sn) const
363291 }
364292 delta = time - delta;
365293 tick += lrint (delta * m_tempoMultiplier.val * Constants::DIVISION * tempo.val );
366- if (sn) {
367- *sn = m_tempoSN;
368- }
294+
369295 return tick;
370296}
371297}
0 commit comments