Skip to content

Commit

Permalink
Merge branch 'master' of github.com:musescore/MuseScore
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jan 3, 2014
2 parents b1e03fd + 4a1d692 commit 30e0623
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 108 deletions.
43 changes: 42 additions & 1 deletion mscore/importmidi.cpp
Expand Up @@ -852,6 +852,40 @@ QList<TrackMeta> getTracksMeta(const QList<MTrack> &tracks,
return tracksMeta;
}


#ifdef QT_DEBUG

bool doNotesOverlap(const std::multimap<int, MTrack> &tracks)
{
for (const auto &track: tracks) {
const auto &chords = track.second.chords;
for (auto it = chords.begin(); it != chords.end(); ++it) {
const auto &firstChord = it->second;
const auto &firstOnTime = it->first;
for (const auto &note1: firstChord.notes) {
auto ii = std::next(it);
for (; ii != chords.end(); ++ii) {
const auto &secondChord = ii->second;
if (firstChord.voice != secondChord.voice)
continue;
const auto &secondOnTime = ii->first;
for (const auto &note2: secondChord.notes) {
if (note2.pitch != note1.pitch)
continue;
if (secondOnTime >= (firstOnTime + note1.len))
continue;
return true;
}
}
}
}
}
return false;
}

#endif


void convertMidi(Score *score, const MidiFile *mf)
{
ReducedFraction lastTick;
Expand All @@ -861,8 +895,15 @@ void convertMidi(Score *score, const MidiFile *mf)
cleanUpMidiEvents(tracks);
MChord::collectChords(tracks);
MChord::removeOverlappingNotes(tracks);

Q_ASSERT_X(!doNotesOverlap(tracks),
"convertMidi:", "There are overlapping notes of the same voice that is incorrect");

quantizeAllTracks(tracks, sigmap, lastTick);
MChord::removeOverlappingNotes(tracks);

Q_ASSERT_X(!doNotesOverlap(tracks),
"convertMidi:", "There are overlapping notes of the same voice that is incorrect");

MChord::mergeChordsWithEqualOnTimeAndVoice(tracks);
LRHand::splitIntoLeftRightHands(tracks);
MidiDrum::splitDrumVoices(tracks);
Expand Down
7 changes: 4 additions & 3 deletions mscore/importmidi_chord.cpp
Expand Up @@ -90,8 +90,8 @@ void removeOverlappingNotes(std::multimap<int, MTrack> &tracks)
}
}

//----------------------------------------------------------------------------------------
// DEBUG function

#ifdef QT_DEBUG

bool areOnTimeValuesDifferent(const std::multimap<ReducedFraction, MidiChord> &chords)
{
Expand All @@ -105,7 +105,8 @@ bool areOnTimeValuesDifferent(const std::multimap<ReducedFraction, MidiChord> &c
return true;
}

//----------------------------------------------------------------------------------------
#endif


// based on quickthresh algorithm
//
Expand Down
7 changes: 4 additions & 3 deletions mscore/importmidi_drum.cpp
Expand Up @@ -16,8 +16,8 @@ extern Preferences preferences;

namespace MidiDrum {

//----------------------------------------------------------------------------------------
// DEBUG functions

#ifdef QT_DEBUG

bool areOnTimeValuesDifferent(const std::multimap<ReducedFraction, MidiChord> &chords)
{
Expand All @@ -40,7 +40,8 @@ bool areVoicesNonZero(const std::multimap<ReducedFraction, MidiChord> &chords)
return true;
}

//----------------------------------------------------------------------------------------
#endif


void splitDrumVoices(std::multimap<int, MTrack> &tracks)
{
Expand Down
9 changes: 6 additions & 3 deletions mscore/importmidi_operations.cpp
Expand Up @@ -55,11 +55,14 @@ QString MidiImportOperations::charset() const
void MidiImportOperations::adaptForPercussion(int trackIndex, bool isDrumTrack)
{
// small hack: don't use multiple voices for tuplets in percussion tracks
if (isValidIndex(trackIndex))
operations_[trackIndex].useMultipleVoices = !isDrumTrack;
else
if (isValidIndex(trackIndex)) {
if (isDrumTrack)
operations_[trackIndex].useMultipleVoices = false;
}
else {
defaultOpers.useMultipleVoices = isDrumTrack
? false : TrackOperations().useMultipleVoices;
}
}

void MidiImportOperations::addTrackLyrics(const std::multimap<ReducedFraction, std::string> &trackLyrics)
Expand Down

0 comments on commit 30e0623

Please sign in to comment.