summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--muse2/muse/event.cpp4
-rw-r--r--muse2/muse/event.h3
-rw-r--r--muse2/muse/eventbase.h2
-rw-r--r--muse2/muse/eventlist.cpp23
-rw-r--r--muse2/muse/midievent.cpp15
-rw-r--r--muse2/muse/midievent.h2
-rw-r--r--muse2/muse/waveevent.cpp9
-rw-r--r--muse2/muse/waveevent.h2
8 files changed, 60 insertions, 0 deletions
diff --git a/muse2/muse/event.cpp b/muse2/muse/event.cpp
index 065a49cf..32b72277 100644
--- a/muse2/muse/event.cpp
+++ b/muse2/muse/event.cpp
@@ -179,6 +179,10 @@ Event& Event::operator=(const Event& e) {
bool Event::operator==(const Event& e) const {
return ev == e.ev;
}
+bool Event::isSimilarTo(const Event& other) const
+{
+ return ev->isSimilarTo(*other.ev);
+}
int Event::getRefCount() const { return ev->getRefCount(); }
bool Event::selected() const { return ev->_selected; }
diff --git a/muse2/muse/event.h b/muse2/muse/event.h
index e512e03d..b2f5a50a 100644
--- a/muse2/muse/event.h
+++ b/muse2/muse/event.h
@@ -64,6 +64,7 @@ class Event {
void setType(EventType t);
Event& operator=(const Event& e);
bool operator==(const Event& e) const;
+ bool isSimilarTo(const Event& other) const;
int getRefCount() const;
bool selected() const;
@@ -137,6 +138,8 @@ class EventList : public EL {
public:
ciEvent find(const Event&) const;
iEvent find(const Event&);
+ ciEvent findSimilar(const Event&) const;
+ iEvent findSimilar(const Event&);
iEvent add(Event event);
void move(Event& event, unsigned tick);
void dump() const;
diff --git a/muse2/muse/eventbase.h b/muse2/muse/eventbase.h
index adf7da97..92e91761 100644
--- a/muse2/muse/eventbase.h
+++ b/muse2/muse/eventbase.h
@@ -56,6 +56,8 @@ class EventBase : public PosLen {
void setSelected(bool val) { _selected = val; }
void move(int offset);
+
+ virtual bool isSimilarTo(const EventBase& other) const = 0;
virtual void read(Xml&) = 0;
virtual void write(int, Xml&, const Pos& offset, bool forcePath = false) const = 0;
diff --git a/muse2/muse/eventlist.cpp b/muse2/muse/eventlist.cpp
index ecc7f452..80180ab7 100644
--- a/muse2/muse/eventlist.cpp
+++ b/muse2/muse/eventlist.cpp
@@ -151,6 +151,29 @@ ciEvent EventList::find(const Event& event) const
return end();
}
+iEvent EventList::findSimilar(const Event& event)
+{
+ std::pair<iEvent,iEvent> range = equal_range(event.type() == Wave ? event.frame() : event.tick());
+
+ for (iEvent i = range.first; i != range.second; ++i) {
+ if (i->second.isSimilarTo(event))
+ return i;
+ }
+ return end();
+}
+
+ciEvent EventList::findSimilar(const Event& event) const
+ {
+ EventRange range = equal_range(event.type() == Wave ? event.frame() : event.tick());
+
+
+ for (ciEvent i = range.first; i != range.second; ++i) {
+ if (i->second.isSimilarTo(event))
+ return i;
+ }
+ return end();
+ }
+
//---------------------------------------------------------
// dump
//---------------------------------------------------------
diff --git a/muse2/muse/midievent.cpp b/muse2/muse/midievent.cpp
index 5330b518..fb6517cd 100644
--- a/muse2/muse/midievent.cpp
+++ b/muse2/muse/midievent.cpp
@@ -41,6 +41,21 @@ MidiEventBase::MidiEventBase(EventType t)
c = 0;
}
+bool MidiEventBase::isSimilarTo(const EventBase& other_) const
+{
+ const MidiEventBase* other = dynamic_cast<const MidiEventBase*>(&other_);
+ if (other==NULL) // dynamic cast hsa failed: "other_" is not of type MidiEventBase.
+ return false;
+
+ if ((a==other->a && b==other->b && c==other->c && edata.dataLen==other->edata.dataLen && this->PosLen::operator==(*other)) == false)
+ return false;
+
+ if (edata.dataLen > 0)
+ return (memcmp(edata.data, other->edata.data, edata.dataLen) == 0);
+ else
+ return true; // no data equals no data.
+}
+
//---------------------------------------------------------
// MidiEventBase::mid
//---------------------------------------------------------
diff --git a/muse2/muse/midievent.h b/muse2/muse/midievent.h
index 8aa38f0e..dba2d727 100644
--- a/muse2/muse/midievent.h
+++ b/muse2/muse/midievent.h
@@ -41,6 +41,8 @@ class MidiEventBase : public EventBase {
public:
MidiEventBase(EventType t);
virtual ~MidiEventBase() {}
+
+ virtual bool isSimilarTo(const EventBase& other) const;
virtual bool isNote() const { return type() == Note; }
virtual bool isNoteOff() const;
diff --git a/muse2/muse/waveevent.cpp b/muse2/muse/waveevent.cpp
index 842e40b9..24be2d01 100644
--- a/muse2/muse/waveevent.cpp
+++ b/muse2/muse/waveevent.cpp
@@ -58,6 +58,15 @@ EventBase* WaveEventBase::clone() const
return new WaveEventBase(*this);
}
+bool WaveEventBase::isSimilarTo(const EventBase& other_) const
+{
+ const WaveEventBase* other = dynamic_cast<const WaveEventBase*>(&other_);
+ if (other==NULL) // dynamic cast hsa failed: "other_" is not of type WaveEventBase.
+ return false;
+
+ return f.dirPath()==other->f.dirPath() && _spos==other->_spos && this->PosLen::operator==(*other);
+}
+
//---------------------------------------------------------
// WaveEvent::mid
//---------------------------------------------------------
diff --git a/muse2/muse/waveevent.h b/muse2/muse/waveevent.h
index 4174e3f5..d11803c7 100644
--- a/muse2/muse/waveevent.h
+++ b/muse2/muse/waveevent.h
@@ -49,6 +49,8 @@ class WaveEventBase : public EventBase {
public:
WaveEventBase(EventType t);
virtual ~WaveEventBase() {}
+
+ virtual bool isSimilarTo(const EventBase& other) const;
virtual void read(Xml&);
virtual void write(int, Xml&, const Pos& offset, bool forcePath = false) const;