Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ class smfMidiChannel
p( NULL ),
it_inst( NULL ),
isSF2( false ),
hasNotes( false ),
lastEnd( 0 )
hasNotes( false )
{ }

InstrumentTrack * it;
Pattern* p;
Instrument * it_inst;
bool isSF2;
bool hasNotes;
MidiTime lastEnd;
QString trackName;

smfMidiChannel * create( TrackContainer* tc, QString tn )
Expand Down Expand Up @@ -255,26 +253,49 @@ class smfMidiChannel
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;
}


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;
}

};
Expand Down Expand Up @@ -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?
Expand Down