MIDI import: fix putting notes before the beginning of a pattern (#5343)

This commit is contained in:
Hyunjin Song
2019-12-23 17:33:46 +09:00
committed by GitHub
parent 578a9475ec
commit 4bfcc30a71

View File

@@ -215,8 +215,7 @@ public:
p( NULL ),
it_inst( NULL ),
isSF2( false ),
hasNotes( false ),
lastEnd( 0 )
hasNotes( false )
{ }
InstrumentTrack * it;
@@ -224,7 +223,6 @@ public:
Instrument * it_inst;
bool isSF2;
bool hasNotes;
MidiTime lastEnd;
QString trackName;
smfMidiChannel * create( TrackContainer* tc, QString tn )
@@ -255,9 +253,11 @@ public:
if( trackName != "") {
it->setName( tn );
}
lastEnd = 0;
// General MIDI default
it->pitchRangeModel()->setInitValue( 2 );
// Create a default pattern
p = dynamic_cast<Pattern*>(it->createTCO(0));
}
return this;
}
@@ -265,16 +265,37 @@ public:
void addNote( Note & n )
{
if( !p || n.pos() > lastEnd + DefaultTicksPerTact )
if (!p)
{
MidiTime pPos = MidiTime( n.pos().getTact(), 0 );
p = dynamic_cast<Pattern*>( it->createTCO( 0 ) );
p->movePosition( pPos );
p = dynamic_cast<Pattern*>(it->createTCO(0));
}
p->addNote(n, false);
hasNotes = true;
lastEnd = n.pos() + n.length();
n.setPos( n.pos( p->startPosition() ) );
p->addNote( n, false );
}
void splitPatterns()
{
Pattern * newPattern = nullptr;
MidiTime lastEnd(0);
p->rearrangeAllNotes();
for (auto n : p->notes())
{
if (!newPattern || n->pos() > lastEnd + DefaultTicksPerTact)
{
MidiTime pPos = MidiTime(n->pos().getTact(), 0);
newPattern = dynamic_cast<Pattern*>(it->createTCO(0));
newPattern->movePosition(pPos);
}
lastEnd = n->pos() + n->length();
Note newNote(*n);
newNote.setPos(n->pos(newPattern->startPosition()));
newPattern->addNote(newNote, false);
}
delete p;
p = nullptr;
}
};
@@ -534,7 +555,11 @@ bool MidiImport::readSMF( TrackContainer* tc )
for( int c=0; c < 256; ++c )
{
if( !chs[c].hasNotes && chs[c].it )
if (chs[c].hasNotes)
{
chs[c].splitPatterns();
}
else if (chs[c].it)
{
printf(" Should remove empty track\n");
// must delete trackView first - but where is it?