Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Midi import: various small improvements #2006

Merged
merged 7 commits into from
Jun 17, 2015
35 changes: 27 additions & 8 deletions plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,19 @@ class smfMidiCC
AutomationPattern * ap;
MidiTime lastPos;

smfMidiCC & create( TrackContainer* tc )
smfMidiCC & create( TrackContainer* tc, QString tn )
{
if( !at )
{
// Keep LMMS responsive, for now the import runs
// in the main thread. This should probably be
// removed if that ever changes.
qApp->processEvents();
at = dynamic_cast<AutomationTrack *>( Track::create( Track::AutomationTrack, tc ) );
}
if( tn != "") {
at->setName( tn );
}
return *this;
}

Expand All @@ -182,8 +189,8 @@ class smfMidiCC
ap = dynamic_cast<AutomationPattern*>(
at->createTCO(0) );
ap->movePosition( pPos );
ap->addObject( objModel );
}
ap->addObject( objModel );

lastPos = time;
time = time - ap->startPosition();
Expand Down Expand Up @@ -220,6 +227,8 @@ class smfMidiChannel
smfMidiChannel * create( TrackContainer* tc, QString tn )
{
if( !it ) {
// Keep LMMS responsive
qApp->processEvents();
it = dynamic_cast<InstrumentTrack *>( Track::create( Track::InstrumentTrack, tc ) );

#ifdef LMMS_HAVE_FLUIDSYNTH
Expand All @@ -244,6 +253,8 @@ class smfMidiChannel
it->setName( tn );
}
lastEnd = 0;
// General MIDI default
it->pitchRangeModel()->setInitValue( 2 );
}
return this;
}
Expand Down Expand Up @@ -357,7 +368,7 @@ bool MidiImport::readSMF( TrackContainer* tc )
// Tracks
for( int t = 0; t < seq->tracks(); ++t )
{
QString trackName = "";
QString trackName = QString( tr( "Track" ) + " %1" ).arg( t );
Alg_track_ptr trk = seq->track( t );
pd.setValue( t + preTrackSteps );

Expand All @@ -377,8 +388,8 @@ bool MidiImport::readSMF( TrackContainer* tc )
if( evt->is_update() )
{
QString attr = evt->get_attribute();
if( attr == "tracknames" && evt->get_update_type() == 'a' ) {
trackName = evt->get_atom_value();
if( attr == "tracknames" && evt->get_update_type() == 's' ) {
trackName = evt->get_string_value();
handled = true;
}
}
Expand All @@ -402,8 +413,8 @@ bool MidiImport::readSMF( TrackContainer* tc )
{
smfMidiChannel * ch = chs[evt->chan].create( tc, trackName );
Alg_note_ptr noteEvt = dynamic_cast<Alg_note_ptr>( evt );

Note n( noteEvt->get_duration() * ticksPerBeat,
int ticks = noteEvt->get_duration() * ticksPerBeat;
Note n( (ticks < 1 ? 1 : ticks ),
noteEvt->get_start_time() * ticksPerBeat,
noteEvt->get_identifier() - 12,
noteEvt->get_loud());
Expand Down Expand Up @@ -477,6 +488,9 @@ bool MidiImport::readSMF( TrackContainer* tc )
objModel = ch->it->pitchModel();
cc = cc * 100.0f;
break;
default:
//TODO: something useful for other CCs
break;
}

if( objModel )
Expand All @@ -487,7 +501,12 @@ bool MidiImport::readSMF( TrackContainer* tc )
}
else
{
ccs[ccid].create( tc );
if( ccs[ccid].at == NULL ) {
ccs[ccid].create( tc, trackName + " > " + (
objModel != NULL ?
objModel->displayName() :
QString("CC %1").arg(ccid) ) );
}
ccs[ccid].putValue( time, objModel, cc );
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/MidiImport/portsmf/allegro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ char *Alg_event::get_string_value()
assert(is_update());
Alg_update* update = (Alg_update *) this;
assert(get_update_type() == 's');
return update->parameter.attr_name();
return update->parameter.a;
}


Expand Down