From 728839fb3581904c2a464c73419126da04c250ee Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Wed, 18 May 2011 15:07:22 +0000 Subject: removed the silly and slow loop in importmidi.cpp caution: this may have introduced bugs like infinite loops or wrong file reading (but shouldn't). test it well! --- muse2/muse/importmidi.cpp | 60 ++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/importmidi.cpp b/muse2/muse/importmidi.cpp index 6917a0fd..3e4e641e 100644 --- a/muse2/muse/importmidi.cpp +++ b/muse2/muse/importmidi.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + #include #include "app.h" @@ -32,6 +35,9 @@ #include "audio.h" #include "gconfig.h" +using std::set; +using std::pair; + //--------------------------------------------------------- // importMidi //--------------------------------------------------------- @@ -137,26 +143,27 @@ bool MusE::importMidi(const QString name, bool merge) // the first target track bool first = true; - // somewhat silly and slooow: - for (int port = 0; port < MIDI_PORTS; ++port) { - for (int channel = 0; channel < MIDI_CHANNELS; ++channel) { - // - // check if there are any events for port/channel in track: - // - iMPEvent i; - for (i = el->begin(); i != el->end(); ++i) { - MidiPlayEvent ev = *i; - if (ev.type() != ME_SYSEX && ev.type() != ME_META - && ev.channel() == channel && ev.port() == port) - break; - } - if (i == el->end()) - continue; + + // vastly changed by flo: replaced that silly loop + // with that already_processed-set-check. + // this makes stuff really fast :) + + iMPEvent ev; + set< pair > already_processed; + for (ev = el->begin(); ev != el->end(); ++ev) + { + if (ev->type() != ME_SYSEX && ev->type() != ME_META) + { + int channel=ev->channel(); + int port=ev->port(); + + if (already_processed.find(pair(channel, port)) == already_processed.end()) + { + already_processed.insert(pair(channel, port)); + MidiTrack* track = new MidiTrack(); if ((*t)->isDrumTrack) - { track->setType(Track::DRUM); - } track->setOutChannel(channel); track->setOutPort(port); @@ -171,15 +178,6 @@ bool MusE::importMidi(const QString name, bool merge) buildMidiEventList(mel, el, track, division, first, false); first = false; - // Removed by T356. Handled by addPortCtrlEvents() below. - //for (iEvent i = mel->begin(); i != mel->end(); ++i) { - // Event event = i->second; - // if (event.type() == Controller) { - // importController(channel, mport, event.dataA()); - // midiPorts[track->outPort()].setCtrl(channel, event.tick(), event.dataA(), event.dataB()); - // } - // } - // Comment Added by T356. // Hmm. buildMidiEventList already takes care of this. // But it seems to work. How? Must test. @@ -208,13 +206,11 @@ bool MusE::importMidi(const QString name, bool merge) processTrack(track); - // Added by T356. Send all controller values to the port's controller value list. - // No, done in song->insertTrack2() now. - //track->addPortCtrlEvents(); - song->insertTrack0(track, -1); - } - } + } + } + } + if (first) { // // track does only contain non-channel messages -- cgit v1.2.3