summaryrefslogtreecommitdiff
path: root/muse2/muse/tempo.cpp
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2012-07-01 16:42:16 +0000
committerFlorian Jung <flo@windfisch.org>2012-07-01 16:42:16 +0000
commit9c4664d162c537ba4dd4fd8220971c0fb727103a (patch)
tree37a28b7cd4e4d8984ad4934a4884cd7b4da0505c /muse2/muse/tempo.cpp
parente87fedf1be804f7ec774071d844b1f163be30b96 (diff)
final merge
Diffstat (limited to 'muse2/muse/tempo.cpp')
-rw-r--r--muse2/muse/tempo.cpp86
1 files changed, 82 insertions, 4 deletions
diff --git a/muse2/muse/tempo.cpp b/muse2/muse/tempo.cpp
index 1147fd78..d339f516 100644
--- a/muse2/muse/tempo.cpp
+++ b/muse2/muse/tempo.cpp
@@ -32,6 +32,7 @@
namespace MusEGlobal {
MusECore::TempoList tempomap;
+MusECore::TempoRecList tempo_rec_list;
}
namespace MusECore {
@@ -59,7 +60,7 @@ TempoList::~TempoList()
// add
//---------------------------------------------------------
-void TempoList::add(unsigned tick, int tempo)
+void TempoList::add(unsigned tick, int tempo, bool do_normalize)
{
if (tick > MAX_TICK)
tick = MAX_TICK;
@@ -74,7 +75,8 @@ void TempoList::add(unsigned tick, int tempo)
ne->tick = tick;
insert(std::pair<const unsigned, TEvent*> (tick, ev));
}
- normalize();
+ if(do_normalize)
+ normalize();
}
//---------------------------------------------------------
@@ -120,6 +122,33 @@ void TempoList::clear()
}
//---------------------------------------------------------
+// eraseRange
+//---------------------------------------------------------
+
+void TempoList::eraseRange(unsigned stick, unsigned etick)
+{
+ if(stick >= etick || stick > MAX_TICK)
+ return;
+ if(etick > MAX_TICK)
+ etick = MAX_TICK;
+
+ iTEvent se = MusEGlobal::tempomap.upper_bound(stick);
+ if(se == end() || (se->first == MAX_TICK+1))
+ return;
+
+ iTEvent ee = MusEGlobal::tempomap.upper_bound(etick);
+
+ ee->second->tempo = se->second->tempo;
+ ee->second->tick = se->second->tick;
+
+ for(iTEvent ite = se; ite != ee; ++ite)
+ delete ite->second;
+ erase(se, ee); // Erase range does NOT include the last element.
+ normalize();
+ ++_tempoSN;
+}
+
+//---------------------------------------------------------
// tempo
//---------------------------------------------------------
@@ -224,9 +253,9 @@ void TempoList::setGlobalTempo(int val)
// addTempo
//---------------------------------------------------------
-void TempoList::addTempo(unsigned t, int tempo)
+void TempoList::addTempo(unsigned t, int tempo, bool do_normalize)
{
- add(t, tempo);
+ add(t, tempo, do_normalize);
++_tempoSN;
}
@@ -538,5 +567,54 @@ int TEvent::read(Xml& xml)
return 0;
}
+//---------------------------------------------------------
+// put
+// return true on fifo overflow
+//---------------------------------------------------------
+
+bool TempoFifo::put(const TempoRecEvent& event)
+ {
+ if (size < TEMPO_FIFO_SIZE) {
+ fifo[wIndex] = event;
+ wIndex = (wIndex + 1) % TEMPO_FIFO_SIZE;
+ // q_atomic_increment(&size);
+ ++size;
+ return false;
+ }
+ return true;
+ }
+
+//---------------------------------------------------------
+// get
+//---------------------------------------------------------
+
+TempoRecEvent TempoFifo::get()
+ {
+ TempoRecEvent event(fifo[rIndex]);
+ rIndex = (rIndex + 1) % TEMPO_FIFO_SIZE;
+ --size;
+ return event;
+ }
+
+//---------------------------------------------------------
+// peek
+//---------------------------------------------------------
+
+const TempoRecEvent& TempoFifo::peek(int n)
+ {
+ int idx = (rIndex + n) % TEMPO_FIFO_SIZE;
+ return fifo[idx];
+ }
+
+//---------------------------------------------------------
+// remove
+//---------------------------------------------------------
+
+void TempoFifo::remove()
+ {
+ rIndex = (rIndex + 1) % TEMPO_FIFO_SIZE;
+ --size;
+ }
+
} // namespace MusECore