From abedca49b707bd5bced2bee2caa8bb4417dcfa51 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 11 Oct 2011 16:02:53 +0000 Subject: improved creating new notes in drum canvas --- muse2/muse/helper.cpp | 36 ++++++++++++++++++++++++++++++++++++ muse2/muse/helper.h | 8 ++++++++ muse2/muse/midiedit/dcanvas.cpp | 37 ++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 13 deletions(-) (limited to 'muse2') 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 parts_at_tick(unsigned tick) +{ + using MusEGlobal::song; + + QSet tmp; + for (iTrack it=song->tracks()->begin(); it!=song->tracks()->end(); it++) + tmp.insert(*it); + + return parts_at_tick(tick, tmp); +} + +QSet parts_at_tick(unsigned tick, Track* track) +{ + QSet tmp; + tmp.insert(track); + + return parts_at_tick(tick, tmp); +} + +QSet parts_at_tick(unsigned tick, const QSet& tracks) +{ + QSet result; + + for (QSet::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 +#include #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&, bool in_range=false); bool drummaps_almost_equal(DrumMap* one, DrumMap* two, int drummap_size=128); + +QSet parts_at_tick(unsigned tick); +QSet parts_at_tick(unsigned tick, const Track* track); +QSet parts_at_tick(unsigned tick, const QSet& 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 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); } //--------------------------------------------------------- -- cgit v1.2.3