summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--muse2/muse/helper.cpp36
-rw-r--r--muse2/muse/helper.h8
-rw-r--r--muse2/muse/midiedit/dcanvas.cpp37
3 files changed, 68 insertions, 13 deletions
diff --git a/muse2/muse/helper.cpp b/muse2/muse/helper.cpp
index e3cdee7e..1298b2d2 100644
--- a/muse2/muse/helper.cpp
+++ b/muse2/muse/helper.cpp
@@ -111,6 +111,42 @@ bool drummaps_almost_equal(DrumMap* one, DrumMap* two, int len)
}
+QSet<Part*> parts_at_tick(unsigned tick)
+{
+ using MusEGlobal::song;
+
+ QSet<Track*> tmp;
+ for (iTrack it=song->tracks()->begin(); it!=song->tracks()->end(); it++)
+ tmp.insert(*it);
+
+ return parts_at_tick(tick, tmp);
+}
+
+QSet<Part*> parts_at_tick(unsigned tick, Track* track)
+{
+ QSet<Track*> tmp;
+ tmp.insert(track);
+
+ return parts_at_tick(tick, tmp);
+}
+
+QSet<Part*> parts_at_tick(unsigned tick, const QSet<Track*>& tracks)
+{
+ QSet<Part*> result;
+
+ for (QSet<Track*>::const_iterator it=tracks.begin(); it!=tracks.end(); it++)
+ {
+ Track* track=*it;
+
+ for (iPart p_it=track->parts()->begin(); p_it!=track->parts()->end(); p_it++)
+ if (tick >= p_it->second->tick() && tick <= p_it->second->endTick())
+ result.insert(p_it->second);
+ }
+
+ return result;
+}
+
+
} // namespace MusECore
namespace MusEGui {
diff --git a/muse2/muse/helper.h b/muse2/muse/helper.h
index f014ee1e..a051cd15 100644
--- a/muse2/muse/helper.h
+++ b/muse2/muse/helper.h
@@ -24,6 +24,7 @@
#define __HELPER_H__
#include <set>
+#include <QSet>
#include "drummap.h"
@@ -35,11 +36,18 @@ class QWidget;
namespace MusECore {
class Part;
+class Track;
+
+
QString pitch2string(int v);
Part* partFromSerialNumber(int serial);
bool any_event_selected(const std::set<Part*>&, bool in_range=false);
bool drummaps_almost_equal(DrumMap* one, DrumMap* two, int drummap_size=128);
+
+QSet<Part*> parts_at_tick(unsigned tick);
+QSet<Part*> parts_at_tick(unsigned tick, const Track* track);
+QSet<Part*> parts_at_tick(unsigned tick, const QSet<Track*>& tracks);
}
namespace MusEGui {
diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp
index 03d38fbf..0d2f7640 100644
--- a/muse2/muse/midiedit/dcanvas.cpp
+++ b/muse2/muse/midiedit/dcanvas.cpp
@@ -380,20 +380,31 @@ CItem* DrumCanvas::newItem(int tick, int instrument, int velocity)
{
if (!old_style_drummap_mode && !instrument_map[instrument].tracks.contains(curPart->track()))
{
- printf("FINDMICH: tried to create a new Item which cannot be inside the current track. returning NULL\n");
- return NULL;
- }
- else
- {
- tick -= curPart->tick();
- MusECore::Event e(MusECore::Note);
- e.setTick(tick);
- e.setPitch(instrument_map[instrument].pitch);
- e.setVelo(velocity);
- e.setLenTick(ourDrumMap[instrument].len);
-
- return new DEvent(e, curPart, instrument);
+ if (debugMsg)
+ printf("tried to create a new Item which cannot be inside the current track. looking for destination part...\n");
+
+ QSet<MusECore::Part*> parts = parts_at_tick(tick, instrument_map[instrument].tracks);
+
+ if (parts.count() != 1)
+ {
+ QMessageBox::warning(this, tr("Creating event failed"), tr("Couldn't create the event, because the currently selected part isn't the same track, and the selected instrument could be either on no or on multiple parts, which is ambiguous.\nSelect the destination part, then try again."));
+ return NULL;
+ }
+ else
+ {
+ setCurrentPart(*parts.begin());
+ }
}
+ // else or if we found an alternative part (which has now been set as curPart)
+
+ tick -= curPart->tick();
+ MusECore::Event e(MusECore::Note);
+ e.setTick(tick);
+ e.setPitch(instrument_map[instrument].pitch);
+ e.setVelo(velocity);
+ e.setLenTick(ourDrumMap[instrument].len);
+
+ return new DEvent(e, curPart, instrument);
}
//---------------------------------------------------------