* rewrote the way plugins can handle certain filetypes

* rewrote various parts of file-browser to be less redundant and more stable (closes #2071891)



git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1582 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Tobias Doerffel
2008-09-07 22:38:23 +00:00
parent 9667fecd8b
commit fa1a9f4967
23 changed files with 354 additions and 400 deletions

View File

@@ -62,7 +62,7 @@ projectJournal * engine::s_projectJournal = NULL;
ladspa2LMMS * engine::s_ladspaManager = NULL;
dummyTrackContainer * engine::s_dummyTC = NULL;
controllerRackView * engine::s_controllerRackView = NULL;
QMap<QString, QString> engine::s_sampleExtensions;
QMap<QString, QString> engine::s_pluginFileHandling;
@@ -71,7 +71,7 @@ void engine::init( const bool _has_gui )
{
s_hasGUI = _has_gui;
loadExtensions();
initPluginFileHandling();
s_projectJournal = new projectJournal;
s_mixer = new mixer;
@@ -165,7 +165,7 @@ void engine::updateFramesPerTick( void )
void engine::loadExtensions( void )
void engine::initPluginFileHandling( void )
{
QVector<plugin::descriptor> pluginDescriptors;
plugin::getDescriptorsOfAvailPlugins( pluginDescriptors );
@@ -180,7 +180,7 @@ void engine::loadExtensions( void )
for( QStringList::const_iterator itExt = ext.begin();
itExt != ext.end(); ++itExt )
{
s_sampleExtensions[*itExt] = it->name;
s_pluginFileHandling[*itExt] = it->name;
}
}
}

View File

@@ -76,7 +76,7 @@ plugin::~plugin()
void plugin::setParameter( const QString &, const QString & )
void plugin::loadFile( const QString & )
{
}

View File

@@ -105,7 +105,7 @@ previewTrackContainer * presetPreviewPlayHandle::s_previewTC;
presetPreviewPlayHandle::presetPreviewPlayHandle( const QString & _preset_file,
bool _special_preset ) :
bool _load_by_plugin ) :
playHandle( PresetPreviewHandle ),
m_previewNote( NULL )
{
@@ -120,7 +120,7 @@ presetPreviewPlayHandle::presetPreviewPlayHandle( const QString & _preset_file,
const bool j = engine::getProjectJournal()->isJournalling();
engine::getProjectJournal()->setJournalling( FALSE );
if( _special_preset )
if( _load_by_plugin )
{
instrument * i = s_previewTC->previewInstrumentTrack()->
getInstrument();
@@ -130,11 +130,11 @@ presetPreviewPlayHandle::presetPreviewPlayHandle( const QString & _preset_file,
{
i = s_previewTC->previewInstrumentTrack()->
loadInstrument(
engine::sampleExtensions()[ext] );
engine::pluginFileHandling()[ext] );
}
if( i != NULL )
{
i->setParameter( "samplefile", _preset_file );
i->loadFile( _preset_file );
}
}
else

View File

@@ -176,7 +176,7 @@ listView::listView( QWidget * _parent ) :
m_mousePressed( FALSE ),
m_pressPos(),
m_previewPlayHandle( NULL ),
m_pphMutex(),
m_pphMutex( QMutex::Recursive ),
m_contextMenuItem( NULL )
{
setColumnCount( 1 );
@@ -203,194 +203,11 @@ listView::~listView()
void listView::activateListItem( QTreeWidgetItem * _item, int _column )
{
fileItem * f = dynamic_cast<fileItem *>( _item );
if( f == NULL )
{
return;
}
if( f->type() == fileItem::SampleFile ||
f->type() == fileItem::SpecialPresetFile )
{
// samples are per default opened in bb-editor because they're
// likely drum-samples etc.
engine::getMixer()->lock();
instrumentTrack * it = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack,
engine::getBBTrackContainer() ) );
#ifdef LMMS_DEBUG
assert( it != NULL );
#endif
instrument * inst = it->loadInstrument(
engine::sampleExtensions()[f->extension()] );
if( inst != NULL )
{
inst->setParameter( "samplefile", f->fullName() );
}
engine::getMixer()->unlock();
}
else if( f->type() == fileItem::PresetFile )
{
// presets are per default opened in bb-editor
multimediaProject mmp( f->fullName() );
instrumentTrack::removeMidiPortNode( mmp );
engine::getMixer()->lock();
instrumentTrack * it = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack,
engine::getBBTrackContainer() ) );
if( it != NULL )
{
it->setSimpleSerializing();
it->loadSettings( mmp.content().toElement() );
}
engine::getMixer()->unlock();
}
else if( f->type() == fileItem::ProjectFile )
{
if( engine::getMainWindow()->mayChangeProject() )
{
engine::getSong()->loadProject( f->fullName() );
}
}
}
void listView::sendToActiveInstrumentTrack( void )
{
if( engine::getMainWindow()->workspace() == NULL )
{
return;
}
// get all windows opened in the workspace
QList<QMdiSubWindow*> pl = engine::getMainWindow()->workspace()->
subWindowList( QMdiArea::StackingOrder );
QListIterator<QMdiSubWindow *> w( pl );
w.toBack();
// now we travel through the window-list until we find an
// instrument-track
while( w.hasPrevious() )
{
instrumentTrackWindow * itw =
dynamic_cast<instrumentTrackWindow *>( w.previous()->
widget() );
if( itw != NULL && itw->isHidden() == FALSE )
{
// ok, it's an instrument-track, so we can apply the
// sample or the preset
engine::getMixer()->lock();
if( m_contextMenuItem->type() == fileItem::SampleFile ||
m_contextMenuItem->type() ==
fileItem::SpecialPresetFile )
{
QString e = m_contextMenuItem->extension();
instrument * i = itw->model()->getInstrument();
if( !i->getDescriptor()->supportsFileType( e ) )
{
i = itw->model()->loadInstrument(
engine::sampleExtensions()[e] );
}
i->setParameter( "samplefile",
m_contextMenuItem->fullName() );
}
else if( m_contextMenuItem->type() ==
fileItem::PresetFile )
{
multimediaProject mmp(
m_contextMenuItem->fullName() );
instrumentTrack::removeMidiPortNode( mmp );
itw->model()->setSimpleSerializing();
itw->model()->loadSettings(
mmp.content().toElement() );
}
engine::getMixer()->unlock();
break;
}
}
}
void listView::openInNewInstrumentTrack( trackContainer * _tc )
{
engine::getMixer()->lock();
if( m_contextMenuItem->type() == fileItem::SampleFile ||
m_contextMenuItem->type() == fileItem::SpecialPresetFile )
{
instrumentTrack * ct = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack, _tc ) );
#ifdef LMMS_DEBUG
assert( ct != NULL );
#endif
instrument * i = ct->loadInstrument(
engine::sampleExtensions()
[m_contextMenuItem
->extension()] );
if( i != NULL )
{
i->setParameter( "samplefile",
m_contextMenuItem->fullName() );
}
//ct->toggledInstrumentTrackButton( TRUE );
}
else if( m_contextMenuItem->type() == fileItem::PresetFile )
{
multimediaProject mmp( m_contextMenuItem->fullName() );
instrumentTrack::removeMidiPortNode( mmp );
track * t = track::create( track::InstrumentTrack, _tc );
instrumentTrack * it = dynamic_cast<instrumentTrack *>( t );
if( it != NULL )
{
it->setSimpleSerializing();
it->loadSettings( mmp.content().toElement() );
}
}
engine::getMixer()->unlock();
}
void listView::openInNewInstrumentTrackBBE( void )
{
openInNewInstrumentTrack( engine::getBBTrackContainer() );
}
void listView::openInNewInstrumentTrackSE( void )
{
openInNewInstrumentTrack( engine::getSong() );
}
void listView::updateDirectory( QTreeWidgetItem * _item )
{
directory * dir = dynamic_cast<directory *>( _item );
if( dir != NULL )
{
dir->update();
}
}
void listView::contextMenuEvent( QContextMenuEvent * _e )
{
fileItem * f = dynamic_cast<fileItem *>( itemAt( _e->pos() ) );
if( f != NULL && ( f->type() == fileItem::SampleFile ||
f->type() == fileItem::SpecialPresetFile ||
f->type() == fileItem::PresetFile ) )
if( f != NULL && ( f->handling() == fileItem::LoadAsPreset ||
f->handling() == fileItem::LoadByPlugin ) )
{
m_contextMenuItem = f;
QMenu contextMenu( this );
@@ -439,38 +256,39 @@ void listView::mousePressEvent( QMouseEvent * _me )
fileItem * f = dynamic_cast<fileItem *>( i );
if( f != NULL )
{
if( !m_pphMutex.tryLock() )
{
return;
}
m_pphMutex.lock();
if( m_previewPlayHandle != NULL )
{
engine::getMixer()->removePlayHandle(
m_previewPlayHandle );
m_previewPlayHandle = NULL;
}
// in special case of sample-files we do not care about
// handling() rather than directly creating a samplePlayHandle
if( f->type() == fileItem::SampleFile )
{
textFloat * tf = textFloat::displayMessage(
tr( "Loading sample" ),
tr( "Please wait, loading sample for "
"preview..." ),
embed::getIconPixmap( "sound_file",
embed::getIconPixmap( "sample_file",
24, 24 ), 0 );
qApp->processEvents( QEventLoop::AllEvents );
qApp->processEvents(
QEventLoop::ExcludeUserInputEvents );
samplePlayHandle * s = new samplePlayHandle(
f->fullName() );
s->setDoneMayReturnTrue( FALSE );
m_previewPlayHandle = s;
delete tf;
}
else if( f->type() == fileItem::PresetFile ||
f->type() == fileItem::SpecialPresetFile )
else if( f->handling() == fileItem::LoadAsPreset ||
f->handling() == fileItem::LoadByPlugin )
{
m_previewPlayHandle =
new presetPreviewPlayHandle( f->fullName(),
f->type() ==
fileItem::SpecialPresetFile );
f->handling() ==
fileItem::LoadByPlugin );
}
if( m_previewPlayHandle != NULL )
{
@@ -490,7 +308,9 @@ void listView::mouseMoveEvent( QMouseEvent * _me )
( m_pressPos - _me->pos() ).manhattanLength() >
QApplication::startDragDistance() )
{
// make sure any playback is stopped
mouseReleaseEvent( NULL );
fileItem * f = dynamic_cast<fileItem *>( itemAt( m_pressPos ) );
if( f != NULL )
{
@@ -508,7 +328,7 @@ void listView::mouseMoveEvent( QMouseEvent * _me )
new stringPairDrag( "samplefile",
f->fullName(),
embed::getIconPixmap(
"sound_file" ),
"sample_file" ),
this );
break;
@@ -532,12 +352,9 @@ void listView::mouseMoveEvent( QMouseEvent * _me )
void listView::mouseReleaseEvent( QMouseEvent * _me )
{
if( !m_pphMutex.tryLock() )
{
return;
}
m_mousePressed = FALSE;
m_pphMutex.lock();
if( m_previewPlayHandle != NULL )
{
// if there're samples shorter than 3 seconds, we don't
@@ -567,6 +384,146 @@ void listView::mouseReleaseEvent( QMouseEvent * _me )
void listView::handleFile( fileItem * f, instrumentTrack * _it )
{
engine::getMixer()->lock();
switch( f->handling() )
{
case fileItem::LoadAsProject:
if( engine::getMainWindow()->mayChangeProject() )
{
engine::getSong()->loadProject( f->fullName() );
}
break;
case fileItem::LoadByPlugin:
{
const QString e = f->extension();
instrument * i = _it->getInstrument();
if( i == NULL ||
!i->getDescriptor()->supportsFileType( e ) )
{
i = _it->loadInstrument(
engine::pluginFileHandling()[e] );
}
i->loadFile( f->fullName() );
break;
}
case fileItem::LoadAsPreset:
{
multimediaProject mmp( f->fullName() );
instrumentTrack::removeMidiPortNode( mmp );
_it->setSimpleSerializing();
_it->loadSettings( mmp.content().toElement() );
}
case fileItem::NotSupported:
default:
break;
}
engine::getMixer()->unlock();
}
void listView::activateListItem( QTreeWidgetItem * _item, int _column )
{
fileItem * f = dynamic_cast<fileItem *>( _item );
if( f == NULL )
{
return;
}
if( f->handling() == fileItem::LoadAsProject )
{
handleFile( f, NULL );
}
else
{
engine::getMixer()->lock();
instrumentTrack * it = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack,
engine::getBBTrackContainer() ) );
handleFile( f, it );
engine::getMixer()->unlock();
}
}
void listView::openInNewInstrumentTrack( trackContainer * _tc )
{
if( m_contextMenuItem->handling() == fileItem::LoadAsPreset ||
m_contextMenuItem->handling() == fileItem::LoadByPlugin )
{
engine::getMixer()->lock();
instrumentTrack * it = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack, _tc ) );
handleFile( m_contextMenuItem, it );
engine::getMixer()->unlock();
}
}
void listView::openInNewInstrumentTrackBBE( void )
{
openInNewInstrumentTrack( engine::getBBTrackContainer() );
}
void listView::openInNewInstrumentTrackSE( void )
{
openInNewInstrumentTrack( engine::getSong() );
}
void listView::sendToActiveInstrumentTrack( void )
{
// get all windows opened in the workspace
QList<QMdiSubWindow*> pl =
engine::getMainWindow()->workspace()->
subWindowList( QMdiArea::StackingOrder );
QListIterator<QMdiSubWindow *> w( pl );
w.toBack();
// now we travel through the window-list until we find an
// instrument-track
while( w.hasPrevious() )
{
instrumentTrackWindow * itw =
dynamic_cast<instrumentTrackWindow *>(
w.previous()->widget() );
if( itw != NULL && itw->isHidden() == FALSE )
{
handleFile( m_contextMenuItem, itw->model() );
break;
}
}
}
void listView::updateDirectory( QTreeWidgetItem * _item )
{
directory * dir = dynamic_cast<directory *>( _item );
if( dir != NULL )
{
dir->update();
}
}
QPixmap * directory::s_folderPixmap = NULL;
@@ -775,7 +732,7 @@ void fileItem::initPixmapStuff( void )
if( s_sampleFilePixmap == NULL )
{
s_sampleFilePixmap = new QPixmap( embed::getIconPixmap(
"sound_file", 16, 16 ) );
"sample_file", 16, 16 ) );
}
if( s_midiFilePixmap == NULL )
@@ -802,10 +759,11 @@ void fileItem::initPixmapStuff( void )
setIcon( 0, *s_projectFilePixmap );
break;
case PresetFile:
case SpecialPresetFile:
setIcon( 0, *s_presetFilePixmap );
break;
case SampleFile:
case SoundFontFile: // TODO
case PatchFile: // TODO
setIcon( 0, *s_sampleFilePixmap );
break;
case MidiFile:
@@ -826,39 +784,26 @@ void fileItem::initPixmapStuff( void )
void fileItem::determineFileType( void )
{
QString ext = extension();
m_handling = NotSupported;
const QString ext = extension();
if( ext == "mmp" || ext == "mpt" || ext == "mmpz" )
{
m_type = ProjectFile;
m_handling = LoadAsProject;
}
else if( ext == "xml" )
{
/* multimediaProject::ProjectTypes t =
multimediaProject::typeOfFile( fullName() );
if( t == multimediaProject::SongProject )
{
m_type = ProjectFile;
}
else if( t == multimediaProject::InstrumentTrackSettings )
{*/
m_type = PresetFile;
/* }
else
{
m_type = UnknownFile;
}*/
}
else if( ext == "csf" )
else if( ext == "xml" || ext == "xiz" )
{
m_type = PresetFile;
m_handling = LoadAsPreset;
}
else if( ext == "xiz" )
else if( ext == "sf2" )
{
m_type = SpecialPresetFile;
m_type = SoundFontFile;
}
else if( engine::sampleExtensions().contains( ext ) )
else if( ext == "pat" )
{
m_type = SampleFile;
m_type = PatchFile;
}
else if( ext == "mid" )
{
@@ -872,6 +817,17 @@ void fileItem::determineFileType( void )
{
m_type = UnknownFile;
}
if( !ext.isEmpty() && engine::pluginFileHandling().contains( ext ) )
{
m_handling = LoadByPlugin;
// classify as sample if not classified by anything yet but can
// be handled by a certain plugin
if( m_type == UnknownFile )
{
m_type = SampleFile;
}
}
}

View File

@@ -91,14 +91,6 @@ mainWindow::mainWindow( void ) :
QSplitter * splitter = new QSplitter( Qt::Horizontal, w );
splitter->setChildrenCollapsible( FALSE );
QString sample_filter;
QList<QString> ext_keys = engine::sampleExtensions().keys();
for( QList<QString>::iterator it = ext_keys.begin();
it != ext_keys.end(); ++it )
{
sample_filter += " *." + *it;
}
int id = 0;
QString wdir = configManager::inst()->workingDir();
side_bar->appendTab( new pluginBrowser( splitter ), ++id );
@@ -112,8 +104,8 @@ mainWindow::mainWindow( void ) :
side_bar->appendTab( new fileBrowser(
configManager::inst()->userSamplesDir() + "*" +
configManager::inst()->factorySamplesDir(),
sample_filter, tr( "My samples" ),
embed::getIconPixmap( "sound_file" ),
"*", tr( "My samples" ),
embed::getIconPixmap( "sample_file" ),
splitter ), ++id );
side_bar->appendTab( new fileBrowser(
configManager::inst()->userPresetsDir() + "*" +

View File

@@ -380,16 +380,17 @@ void trackContainerView::dropEvent( QDropEvent * _de )
//it->toggledInstrumentTrackButton( TRUE );
_de->accept();
}
else if( type == "sampledata" || type == "samplefile" )
else if( /*type == "sampledata" || */type == "samplefile" )
{
instrumentTrack * it = dynamic_cast<instrumentTrack *>(
track::create( track::InstrumentTrack,
m_tc ) );
QString iname = type == "sampledata" ? "audiofileprocessor" :
engine::sampleExtensions()[fileItem::extension(
const QString iname = /*( type == "sampledata" ) ?
"audiofileprocessor" :*/
engine::pluginFileHandling()[fileItem::extension(
value )];
instrument * i = it->loadInstrument( iname );
i->setParameter( type, value );
i->loadFile( value );
//it->toggledInstrumentTrackButton( TRUE );
_de->accept();
}