From fa1a9f4967ea724beb6d181bed72be57c5a43b1b Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 7 Sep 2008 22:38:23 +0000 Subject: [PATCH] * 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 --- ChangeLog | 36 ++ include/engine.h | 8 +- include/file_browser.h | 55 ++- include/plugin.h | 7 +- include/preset_preview_play_handle.h | 4 +- include/remote_plugin.h | 2 +- include/sample_play_handle.h | 2 - .../audio_file_processor.cpp | 12 +- .../audio_file_processor.h | 3 +- plugins/flp_import/flp_import.cpp | 20 +- plugins/midi_import/midi_import.cpp | 5 +- plugins/sf2_player/sf2_player.cpp | 13 +- plugins/sf2_player/sf2_player.h | 3 +- .../triple_oscillator/triple_oscillator.cpp | 15 - plugins/triple_oscillator/triple_oscillator.h | 3 - plugins/vestige/vestige.cpp | 114 ++--- plugins/vestige/vestige.h | 3 +- src/core/engine.cpp | 8 +- src/core/plugin.cpp | 2 +- src/core/preset_preview_play_handle.cpp | 8 +- src/gui/file_browser.cpp | 410 ++++++++---------- src/gui/main_window.cpp | 12 +- src/gui/track_container_view.cpp | 9 +- 23 files changed, 354 insertions(+), 400 deletions(-) diff --git a/ChangeLog b/ChangeLog index bfdfacfe3..24f8ef028 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,41 @@ 2008-09-07 Tobias Doerffel + * plugins/patman/patman.cpp: + * plugins/patman/patman.h: + - apply release of 128 frames + - enable loop mode per default + + * plugins/patman/patman.cpp: + * plugins/patman/patman.h: + * plugins/triple_oscillator/triple_oscillator.h: + * plugins/triple_oscillator/triple_oscillator.cpp: + * plugins/audio_file_processor/audio_file_processor.cpp: + * plugins/audio_file_processor/audio_file_processor.h: + * plugins/sf2_player/sf2_player.cpp: + * plugins/sf2_player/sf2_player.h: + * plugins/vestige/vestige.cpp: + * plugins/vestige/vestige.h: + * plugins/flp_import/flp_import.cpp: + * plugins/midi_import/midi_import.cpp: + * include/engine.h: + * include/file_browser.h: + * include/preset_preview_play_handle.h: + * include/plugin.h: + * include/remote_plugin.h: + * include/sample_play_handle.h: + * src/core/engine.cpp: + * src/core/plugin.cpp: + * src/core/preset_preview_play_handle.cpp: + * src/gui/file_browser.cpp: + * src/gui/main_window.cpp: + * src/gui/track_container_view.cpp: + - rewrote the way plugins can handle certain filetypes + - rewrote various parts of file-browser to be less redundant and + more stable (closes #2071891) + + * data/themes/default/sample_file.png: + renamed from sound_file.png + * include/midi.h: * src/core/midi/midi_client.cpp: * src/core/midi/midi_port.cpp: diff --git a/include/engine.h b/include/engine.h index cb8772660..638abdd2e 100644 --- a/include/engine.h +++ b/include/engine.h @@ -143,9 +143,9 @@ public: } static void updateFramesPerTick( void ); - static const QMap & sampleExtensions( void ) + static const QMap & pluginFileHandling( void ) { - return( s_sampleExtensions ); + return( s_pluginFileHandling ); } @@ -172,9 +172,9 @@ private: static projectNotes * s_projectNotes; static ladspa2LMMS * s_ladspaManager; - static QMap s_sampleExtensions; + static QMap s_pluginFileHandling; - static void loadExtensions( void ); + static void initPluginFileHandling( void ); } ; diff --git a/include/file_browser.h b/include/file_browser.h index 99f74848a..2619e8219 100644 --- a/include/file_browser.h +++ b/include/file_browser.h @@ -1,7 +1,7 @@ /* * file_browser.h - include file for fileBrowser * - * Copyright (c) 2004-2007 Tobias Doerffel + * Copyright (c) 2004-2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -38,6 +38,7 @@ class QColorGroup; class QPixmap; class fileItem; +class instrumentTrack; class listView; class playHandle; class trackContainer; @@ -90,6 +91,10 @@ protected: private: + void handleFile( fileItem * _fi, instrumentTrack * _it ); + void openInNewInstrumentTrack( trackContainer * _tc ); + + bool m_mousePressed; QPoint m_pressPos; @@ -98,8 +103,6 @@ private: fileItem * m_contextMenuItem; - void openInNewInstrumentTrack( trackContainer * _tc ); - private slots: void activateListItem( QTreeWidgetItem * _item, int _column ); @@ -159,6 +162,28 @@ private: class fileItem : public QTreeWidgetItem { public: + enum FileTypes + { + ProjectFile, + PresetFile, + SampleFile, + SoundFontFile, + PatchFile, + MidiFile, + FlpFile, + UnknownFile, + NumFileTypes + } ; + + enum FileHandling + { + NotSupported, + LoadAsProject, + LoadAsPreset, + LoadByPlugin + } ; + + fileItem( QTreeWidget * _parent, const QString & _name, const QString & _path ); fileItem( QTreeWidgetItem * _parent, const QString & _name, @@ -170,23 +195,16 @@ public: text( 0 ) ); } - enum FileTypes - { - ProjectFile, - PresetFile, - SpecialPresetFile, - SampleFile, - MidiFile, - FlpFile, - UnknownFile, - NumFileTypes - } ; - - inline FileTypes type( void ) + inline FileTypes type( void ) const { return( m_type ); } + inline FileHandling handling( void ) const + { + return( m_handling ); + } + QString extension( void ); static QString extension( const QString & _file ); @@ -201,11 +219,12 @@ private: static QPixmap * s_midiFilePixmap; static QPixmap * s_flpFilePixmap; static QPixmap * s_unknownFilePixmap; - + QString m_path; FileTypes m_type; + FileHandling m_handling; + } ; - #endif diff --git a/include/plugin.h b/include/plugin.h index 1eeaeff4e..91c754350 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -167,10 +167,9 @@ public: return( m_descriptor ); } - // plugins can overload this for making other classes able to change - // settings of the plugin without knowing the actual class - virtual void setParameter( const QString & _param, - const QString & _value ); + // can be called if a file matching supportedFileTypes should be + // loaded/processed with the help of this plugin + virtual void loadFile( const QString & _file ); // plugins can overload this for making other classes able to query // settings of the plugin without knowing the actual class diff --git a/include/preset_preview_play_handle.h b/include/preset_preview_play_handle.h index a75d5f2a7..33f7f9c04 100644 --- a/include/preset_preview_play_handle.h +++ b/include/preset_preview_play_handle.h @@ -1,6 +1,6 @@ /* * preset_preview_play_handle.h - play-handle for playing a short preview-sound - * of a preset + * of a preset or a file processed by a plugin * * Copyright (c) 2005-2008 Tobias Doerffel * @@ -38,7 +38,7 @@ class presetPreviewPlayHandle : public playHandle { public: presetPreviewPlayHandle( const QString & _preset_file, - bool _special_preset = false ); + bool _load_by_plugin = false ); virtual ~presetPreviewPlayHandle(); virtual void play( bool _try_parallelizing, diff --git a/include/remote_plugin.h b/include/remote_plugin.h index e6e4966ac..a6c10e5f6 100755 --- a/include/remote_plugin.h +++ b/include/remote_plugin.h @@ -850,7 +850,7 @@ remotePluginBase::message remotePluginBase::waitForMessage( if( _busy_waiting && !messagesLeft() ) { QCoreApplication::processEvents( - QEventLoop::AllEvents, 50 ); + QEventLoop::ExcludeUserInputEvents, 50 ); continue; } #endif diff --git a/include/sample_play_handle.h b/include/sample_play_handle.h index 27664944d..5bcea1d26 100644 --- a/include/sample_play_handle.h +++ b/include/sample_play_handle.h @@ -26,8 +26,6 @@ #ifndef _SAMPLE_PLAY_HANDLE_H #define _SAMPLE_PLAY_HANDLE_H -#include - #include "mixer.h" #include "sample_buffer.h" #include "automatable_model.h" diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 1217422c0..462535be7 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -173,17 +173,9 @@ void audioFileProcessor::loadSettings( const QDomElement & _this ) -void audioFileProcessor::setParameter( const QString & _param, - const QString & _value ) +void audioFileProcessor::loadFile( const QString & _file ) { - if( _param == "samplefile" ) - { - setAudioFile( _value ); - } - else if( _param == "sampledata" ) - { - m_sampleBuffer.loadFromBase64( _value ); - } + setAudioFile( _file ); } diff --git a/plugins/audio_file_processor/audio_file_processor.h b/plugins/audio_file_processor/audio_file_processor.h index b93907462..94d362a8a 100644 --- a/plugins/audio_file_processor/audio_file_processor.h +++ b/plugins/audio_file_processor/audio_file_processor.h @@ -52,8 +52,7 @@ public: QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); - virtual void setParameter( const QString & _param, - const QString & _value ); + virtual void loadFile( const QString & _file ); virtual QString nodeName( void ) const; diff --git a/plugins/flp_import/flp_import.cpp b/plugins/flp_import/flp_import.cpp index ed02defa2..c8e281b8a 100644 --- a/plugins/flp_import/flp_import.cpp +++ b/plugins/flp_import/flp_import.cpp @@ -519,26 +519,26 @@ bool flpImport::tryImport( trackContainer * _tc ) "created so far\n" ); break; } - QString dir = text; -/* if( dir.mid( 1, 11 ) == "Instruments" ) + QString f = text; +/* if( f.mid( 1, 11 ) == "Instruments" ) { - dir = "\\Patches\\Packs" + - dir.mid( 12 ); + f = "\\Patches\\Packs" + + f.mid( 12 ); }*/ - dir.replace( '\\', QDir::separator() ); + f.replace( '\\', QDir::separator() ); if( QFileInfo( configManager::inst()->flDir() + "/Data/" ).exists() ) { - dir = configManager::inst()->flDir() + - "/Data/" + dir; + f = configManager::inst()->flDir() + + "/Data/" + f; } else { // FL 3 compat - dir = configManager::inst()->flDir() + - "/Samples/" + dir; + f = configManager::inst()->flDir() + + "/Samples/" + f; } - it_inst->setParameter( "samplefile", dir ); + it_inst->loadFile( f ); break; } diff --git a/plugins/midi_import/midi_import.cpp b/plugins/midi_import/midi_import.cpp index d737454b0..eecb33825 100644 --- a/plugins/midi_import/midi_import.cpp +++ b/plugins/midi_import/midi_import.cpp @@ -337,10 +337,9 @@ invalid_format: const QStringList files = QDir( dir ). entryList( QStringList( filter ) ); - if( !files.empty() && !sample_loaded ) + if( it_inst && !files.empty() && !sample_loaded ) { - it_inst->setParameter( "samplefile", - dir+files.front() ); + it_inst->loadFile( dir+files.front() ); sample_loaded = TRUE; } break; diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index e3d7d6e3f..846858ba5 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -238,13 +238,14 @@ void sf2Instrument::loadSettings( const QDomElement & _this ) -void sf2Instrument::setParameter( const QString & _param, - const QString & _value ) +void sf2Instrument::loadFile( const QString & _file ) { - if( _param == "samplefile" ) - { - openFile( _value ); - } + openFile( _file ); + updatePatch(); + + // for some reason we've to call that, otherwise preview of a + // soundfont for the first time fails + updateSampleRate(); } diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index 829392a61..75d9d0e53 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -62,8 +62,7 @@ public: virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); - virtual void setParameter( const QString & _param, - const QString & _value ); + virtual void loadFile( const QString & _file ); virtual QString nodeName( void ) const; diff --git a/plugins/triple_oscillator/triple_oscillator.cpp b/plugins/triple_oscillator/triple_oscillator.cpp index 58afdd688..eb227c4d5 100644 --- a/plugins/triple_oscillator/triple_oscillator.cpp +++ b/plugins/triple_oscillator/triple_oscillator.cpp @@ -289,21 +289,6 @@ void tripleOscillator::loadSettings( const QDomElement & _this ) -void tripleOscillator::setParameter( const QString & _param, - const QString & _value ) -{ - if( _param == "samplefile" ) - { - for( int i = 0; i < NUM_OF_OSCILLATORS; ++i ) - { - m_osc[i]->m_sampleBuffer->setAudioFile( _value ); - } - } -} - - - - QString tripleOscillator::nodeName( void ) const { return( tripleoscillator_plugin_descriptor.name ); diff --git a/plugins/triple_oscillator/triple_oscillator.h b/plugins/triple_oscillator/triple_oscillator.h index a07531a7f..0061458f4 100644 --- a/plugins/triple_oscillator/triple_oscillator.h +++ b/plugins/triple_oscillator/triple_oscillator.h @@ -105,9 +105,6 @@ public: virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); - virtual void setParameter( const QString & _param, - const QString & _value ); - virtual QString nodeName( void ) const; virtual f_cnt_t desiredReleaseFrames( void ) const diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index aa6fd2afa..af168a4bd 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -92,7 +92,7 @@ vestigeInstrument::~vestigeInstrument() void vestigeInstrument::loadSettings( const QDomElement & _this ) { - setParameter( "plugin", _this.attribute( "plugin" ) ); + loadFile( _this.attribute( "plugin" ) ); m_pluginMutex.lock(); if( m_plugin != NULL ) { @@ -126,76 +126,58 @@ QString vestigeInstrument::nodeName( void ) const -void vestigeInstrument::setParameter( const QString & _param, - const QString & _value ) +void vestigeInstrument::loadFile( const QString & _file ) { - if( _param == "plugin" && _value != "" ) + m_pluginMutex.lock(); + const bool set_ch_name = ( m_plugin != NULL && + getInstrumentTrack()->name() == m_plugin->name() ) || + getInstrumentTrack()->name() == + instrumentTrack::tr( "Default preset" ); + m_pluginMutex.unlock(); + + closePlugin(); + + m_pluginDLL = _file; + textFloat * tf = textFloat::displayMessage( + tr( "Loading plugin" ), + tr( "Please wait while loading VST-plugin..." ), + PLUGIN_NAME::getIconPixmap( "logo", 24, 24 ), 0 ); + + m_pluginMutex.lock(); + m_plugin = new vstPlugin( m_pluginDLL ); + if( m_plugin->failed() ) { - m_pluginMutex.lock(); - const bool set_ch_name = ( m_plugin != NULL && - getInstrumentTrack()->name() == m_plugin->name() ) || - getInstrumentTrack()->name() == - instrumentTrack::tr( "Default" ); m_pluginMutex.unlock(); - closePlugin(); - - m_pluginDLL = _value; - textFloat * tf = textFloat::displayMessage( - tr( "Loading plugin" ), - tr( "Please wait while loading VST-plugin..." ), - PLUGIN_NAME::getIconPixmap( "logo", 24, 24 ), - 0 ); - m_pluginMutex.lock(); - m_plugin = new vstPlugin( m_pluginDLL ); - if( m_plugin->failed() ) - { - m_pluginMutex.unlock(); - closePlugin(); - delete tf; - QMessageBox::information( 0, - tr( "Failed loading VST-plugin" ), - tr( "The VST-plugin %1 could not " - "be loaded for some reason.\n" - "If it runs with other VST-" - "software under Linux, please " - "contact an LMMS-developer!" - ).arg( m_pluginDLL ), - QMessageBox::Ok ); - return; - } -/* if( m_plugin->vstVersion() < 2000 ) - { - QMessageBox::information( this, - tr( "VST-plugin too old" ), - tr( "The version of VST-plugin %1 " - "is smaller than 2, which " - "isn't supported." ).arg( - m_pluginDLL ), - QMessageBox::Ok ); - closePlugin(); - return; - }*/ - m_plugin->showEditor(); - connect( engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), - m_plugin, SLOT( setTempo( bpm_t ) ) ); - m_plugin->setTempo( engine::getSong()->getTempo() ); - connect( engine::getMixer(), SIGNAL( sampleRateChanged() ), - m_plugin, SLOT( updateSampleRate() ) ); - if( set_ch_name == TRUE ) - { - getInstrumentTrack()->setName( m_plugin->name() ); - } - if( m_plugin->pluginWidget() != NULL ) - { -/* m_plugin->pluginWidget()->setWindowIcon( - getInstrumentTrack()->windowIcon() );*/ - } - m_pluginMutex.unlock(); -// update(); - emit dataChanged(); delete tf; + QMessageBox::information( 0, + tr( "Failed loading VST-plugin" ), + tr( "The VST-plugin %1 could not " + "be loaded for some reason.\n" + "If it runs with other VST-" + "software under Linux, please " + "contact an LMMS-developer!" + ).arg( m_pluginDLL ), + QMessageBox::Ok ); + return; } + + m_plugin->showEditor(); + connect( engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), + m_plugin, SLOT( setTempo( bpm_t ) ) ); + m_plugin->setTempo( engine::getSong()->getTempo() ); + connect( engine::getMixer(), SIGNAL( sampleRateChanged() ), + m_plugin, SLOT( updateSampleRate() ) ); + if( set_ch_name ) + { + getInstrumentTrack()->setName( m_plugin->name() ); + } + + m_pluginMutex.unlock(); + + emit dataChanged(); + + delete tf; } @@ -385,7 +367,7 @@ void vestigeInstrumentView::openPlugin( void ) return; } engine::getMixer()->lock(); - m_vi->setParameter( "plugin", ofd.selectedFiles()[0] ); + m_vi->loadFile( ofd.selectedFiles()[0] ); engine::getMixer()->unlock(); } } diff --git a/plugins/vestige/vestige.h b/plugins/vestige/vestige.h index 62b18a0be..f797692af 100644 --- a/plugins/vestige/vestige.h +++ b/plugins/vestige/vestige.h @@ -58,8 +58,7 @@ public: virtual QString nodeName( void ) const; - virtual void setParameter( const QString & _param, - const QString & _value ); + virtual void loadFile( const QString & _file ); virtual bool supportsParallelizing( void ) const { diff --git a/src/core/engine.cpp b/src/core/engine.cpp index f7967ebae..7d0597a04 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -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 engine::s_sampleExtensions; +QMap 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 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; } } } diff --git a/src/core/plugin.cpp b/src/core/plugin.cpp index 0e2b68fc6..5c51d1104 100644 --- a/src/core/plugin.cpp +++ b/src/core/plugin.cpp @@ -76,7 +76,7 @@ plugin::~plugin() -void plugin::setParameter( const QString &, const QString & ) +void plugin::loadFile( const QString & ) { } diff --git a/src/core/preset_preview_play_handle.cpp b/src/core/preset_preview_play_handle.cpp index 98048dc84..2d2f2d2b8 100644 --- a/src/core/preset_preview_play_handle.cpp +++ b/src/core/preset_preview_play_handle.cpp @@ -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 diff --git a/src/gui/file_browser.cpp b/src/gui/file_browser.cpp index d943d90fd..03aac8c4a 100644 --- a/src/gui/file_browser.cpp +++ b/src/gui/file_browser.cpp @@ -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( _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( - 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( - 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 pl = engine::getMainWindow()->workspace()-> - subWindowList( QMdiArea::StackingOrder ); - QListIterator w( pl ); - w.toBack(); - // now we travel through the window-list until we find an - // instrument-track - while( w.hasPrevious() ) - { - instrumentTrackWindow * itw = - dynamic_cast( 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( - 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( 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( _item ); - if( dir != NULL ) - { - dir->update(); - } -} - - - - void listView::contextMenuEvent( QContextMenuEvent * _e ) { fileItem * f = dynamic_cast( 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( 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( 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( _item ); + if( f == NULL ) + { + return; + } + + if( f->handling() == fileItem::LoadAsProject ) + { + handleFile( f, NULL ); + } + else + { + engine::getMixer()->lock(); + instrumentTrack * it = dynamic_cast( + 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( + 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 pl = + engine::getMainWindow()->workspace()-> + subWindowList( QMdiArea::StackingOrder ); + QListIterator w( pl ); + w.toBack(); + // now we travel through the window-list until we find an + // instrument-track + while( w.hasPrevious() ) + { + instrumentTrackWindow * itw = + dynamic_cast( + w.previous()->widget() ); + if( itw != NULL && itw->isHidden() == FALSE ) + { + handleFile( m_contextMenuItem, itw->model() ); + break; + } + } +} + + + + +void listView::updateDirectory( QTreeWidgetItem * _item ) +{ + directory * dir = dynamic_cast( _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; + } + } } diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp index b7966a90d..aa228fbbf 100644 --- a/src/gui/main_window.cpp +++ b/src/gui/main_window.cpp @@ -91,14 +91,6 @@ mainWindow::mainWindow( void ) : QSplitter * splitter = new QSplitter( Qt::Horizontal, w ); splitter->setChildrenCollapsible( FALSE ); - QString sample_filter; - QList ext_keys = engine::sampleExtensions().keys(); - for( QList::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() + "*" + diff --git a/src/gui/track_container_view.cpp b/src/gui/track_container_view.cpp index 1e4324b89..148dd4883 100644 --- a/src/gui/track_container_view.cpp +++ b/src/gui/track_container_view.cpp @@ -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( 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(); }