~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/tempo.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-07-18 16:07:06 UTC
  • mfrom: (1.1.12) (10.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120718160706-qy1lydijykeiqqmg
Tags: 2.0-1
* New stable release.
* debian/rules: Exclude muse/widgets/arrangercolumns.{cpp,h}~ from being
  deleted by dh_clean.
* Drop 0002-gcc_hardening.patch, applied upstream.
* Drop 0003-ftbfs_gcc47.patch, applied upstream.
* Refresh 1001-buildsystem.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
namespace MusEGlobal {
34
34
MusECore::TempoList tempomap;
 
35
MusECore::TempoRecList tempo_rec_list;
35
36
}
36
37
 
37
38
namespace MusECore {
59
60
//   add
60
61
//---------------------------------------------------------
61
62
 
62
 
void TempoList::add(unsigned tick, int tempo)
 
63
void TempoList::add(unsigned tick, int tempo, bool do_normalize)
63
64
      {
64
65
      if (tick > MAX_TICK)
65
66
            tick = MAX_TICK;
74
75
            ne->tick   = tick;
75
76
            insert(std::pair<const unsigned, TEvent*> (tick, ev));
76
77
            }
77
 
      normalize();
 
78
      if(do_normalize)      
 
79
        normalize();
78
80
      }
79
81
 
80
82
//---------------------------------------------------------
120
122
      }
121
123
 
122
124
//---------------------------------------------------------
 
125
//   eraseRange
 
126
//---------------------------------------------------------
 
127
 
 
128
void TempoList::eraseRange(unsigned stick, unsigned etick)
 
129
{
 
130
    if(stick >= etick || stick > MAX_TICK)
 
131
      return;
 
132
    if(etick > MAX_TICK)
 
133
      etick = MAX_TICK;
 
134
    
 
135
    iTEvent se = MusEGlobal::tempomap.upper_bound(stick);
 
136
    if(se == end() || (se->first == MAX_TICK+1))
 
137
      return;
 
138
 
 
139
    iTEvent ee = MusEGlobal::tempomap.upper_bound(etick);
 
140
 
 
141
    ee->second->tempo = se->second->tempo;
 
142
    ee->second->tick = se->second->tick;
 
143
 
 
144
    for(iTEvent ite = se; ite != ee; ++ite)
 
145
      delete ite->second;
 
146
    erase(se, ee); // Erase range does NOT include the last element.
 
147
    normalize();
 
148
    ++_tempoSN;
 
149
}
 
150
      
 
151
//---------------------------------------------------------
123
152
//   tempo
124
153
//---------------------------------------------------------
125
154
 
138
167
      }
139
168
 
140
169
//---------------------------------------------------------
 
170
//   tempo
 
171
//   Bypass the useList flag and read from the list
 
172
//---------------------------------------------------------
 
173
 
 
174
int TempoList::tempoAt(unsigned tick) const
 
175
      {
 
176
            ciTEvent i = upper_bound(tick);
 
177
            if (i == end()) {
 
178
                  printf("tempoAt: no TEMPO at tick %d,0x%x\n", tick, tick);
 
179
                  return 1000;
 
180
                  }
 
181
            return i->second->tempo;
 
182
      }
 
183
 
 
184
//---------------------------------------------------------
141
185
//   del
142
186
//---------------------------------------------------------
143
187
 
144
188
void TempoList::del(unsigned tick)
145
189
      {
146
 
// printf("TempoList::del(%d)\n", tick);
147
190
      iTEvent e = find(tick);
148
191
      if (e == end()) {
149
192
            printf("TempoList::del(%d): not found\n", tick);
210
253
//   addTempo
211
254
//---------------------------------------------------------
212
255
 
213
 
void TempoList::addTempo(unsigned t, int tempo)
 
256
void TempoList::addTempo(unsigned t, int tempo, bool do_normalize)
214
257
      {
215
 
      add(t, tempo);
 
258
      add(t, tempo, do_normalize);
216
259
      ++_tempoSN;
217
260
      }
218
261
 
270
313
            ciTEvent i = upper_bound(tick);
271
314
            if (i == end()) {
272
315
                  printf("tick2frame(%d,0x%x): not found\n", tick, tick);
273
 
                  // abort();
274
316
                  return 0;
275
317
                  }
276
318
            unsigned dtick = tick - i->second->tick;
525
567
      return 0;
526
568
      }
527
569
 
 
570
//---------------------------------------------------------
 
571
//   put
 
572
//    return true on fifo overflow
 
573
//---------------------------------------------------------
 
574
 
 
575
bool TempoFifo::put(const TempoRecEvent& event)
 
576
      {
 
577
      if (size < TEMPO_FIFO_SIZE) {
 
578
            fifo[wIndex] = event;
 
579
            wIndex = (wIndex + 1) % TEMPO_FIFO_SIZE;
 
580
            // q_atomic_increment(&size);
 
581
            ++size;
 
582
            return false;
 
583
            }
 
584
      return true;
 
585
      }
 
586
 
 
587
//---------------------------------------------------------
 
588
//   get
 
589
//---------------------------------------------------------
 
590
 
 
591
TempoRecEvent TempoFifo::get()
 
592
      {
 
593
      TempoRecEvent event(fifo[rIndex]);
 
594
      rIndex = (rIndex + 1) % TEMPO_FIFO_SIZE;
 
595
      --size;
 
596
      return event;
 
597
      }
 
598
 
 
599
//---------------------------------------------------------
 
600
//   peek
 
601
//---------------------------------------------------------
 
602
 
 
603
const TempoRecEvent& TempoFifo::peek(int n)
 
604
      {
 
605
      int idx = (rIndex + n) % TEMPO_FIFO_SIZE;
 
606
      return fifo[idx];
 
607
      }
 
608
 
 
609
//---------------------------------------------------------
 
610
//   remove
 
611
//---------------------------------------------------------
 
612
 
 
613
void TempoFifo::remove()
 
614
      {
 
615
      rIndex = (rIndex + 1) % TEMPO_FIFO_SIZE;
 
616
      --size;
 
617
      }
 
618
      
528
619
} // namespace MusECore
529
620