From 2aae228af4a14ae937c3e6c82dbe71665ccbba31 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 16 Jul 2009 04:34:11 -0700 Subject: [PATCH] Refactor supportedFileExts from AudioFileProcessor Refactor supported file extensions from AudioFileProcessor to sampleBuffer, where the magic really happens. Change the hard- coded MessageBox explaining supported formats to the real deal. Also added modelines and switched spaces to tabs in the files affected. --- TODO | 1 - include/plugin.h | 2 ++ include/sample_buffer.h | 7 +++- .../audio_file_processor.cpp | 10 +++--- .../audio_file_processor.h | 4 ++- src/core/lame_library.cpp | 2 +- src/core/main.cpp | 18 +++++----- src/core/sample_buffer.cpp | 34 +++++++++++++++++-- 8 files changed, 57 insertions(+), 21 deletions(-) diff --git a/TODO b/TODO index 937f4bf88..70ed927da 100644 --- a/TODO +++ b/TODO @@ -55,7 +55,6 @@ Andrew Kelley's todo: * when you press down or up while browsing the resource browser, it should play the sample * select the output file format based on what you selected in file->save as -* ability to read mp3 samples * load asdlol.mmpz. if you render it without playing it, or if you play it the first time, you hear unwanted artifacts. diff --git a/include/plugin.h b/include/plugin.h index 268573f2c..dde788a1c 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -215,3 +215,5 @@ private: #endif + +/* vim: set tw=0 noexpandtab: */ diff --git a/include/sample_buffer.h b/include/sample_buffer.h index 99453470b..c8f6b9d61 100644 --- a/include/sample_buffer.h +++ b/include/sample_buffer.h @@ -46,6 +46,11 @@ class EXPORT sampleBuffer : public QObject, public sharedObject { Q_OBJECT public: + static const char * supportedExts[]; + + QString niceListOfExts() const; + + class EXPORT handleState { public: @@ -254,4 +259,4 @@ signals: #endif -/* vim: set tw=0 expandtab: */ +/* vim: set tw=0 noexpandtab: */ diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index ceb1a612e..982e4c8ad 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -46,9 +46,6 @@ #undef SINGLE_SOURCE_COMPILE #include "embed.cpp" -static const char * __supportedExts[] = -{ "wav", "ogg", "ds", "spx", "au", "voc", "aif", "aiff", "flac", "raw", "mp3", - NULL }; extern "C" { @@ -65,7 +62,7 @@ plugin::descriptor PLUGIN_EXPORT audiofileprocessor_plugin_descriptor = 0x0100, plugin::Instrument, new pluginPixmapLoader( "logo" ), - __supportedExts, + sampleBuffer::supportedExts, NULL } ; @@ -222,8 +219,8 @@ void audioFileProcessor::setAudioFile( const QString & _audio_file, { // is current channel-name equal to previous-filename?? if( _rename && ( getInstrumentTrack()->name() == - QFileInfo( m_sampleBuffer.audioFile() ).fileName() || - m_sampleBuffer.audioFile() == "" ) ) + QFileInfo( m_sampleBuffer.audioFile() ).fileName() || + m_sampleBuffer.audioFile() == "" ) ) { // then set it to new one getInstrumentTrack()->setName( QFileInfo( _audio_file).fileName() ); @@ -503,3 +500,4 @@ plugin * PLUGIN_EXPORT lmms_plugin_main( model *, void * _data ) #include "moc_audio_file_processor.cxx" +/* vim: set tw=0 expandtab: */ diff --git a/plugins/audio_file_processor/audio_file_processor.h b/plugins/audio_file_processor/audio_file_processor.h index c7ab2507f..4c78efb4e 100644 --- a/plugins/audio_file_processor/audio_file_processor.h +++ b/plugins/audio_file_processor/audio_file_processor.h @@ -1,6 +1,6 @@ /* * audio_file_processor.h - declaration of class audioFileProcessor - * (instrument-plugin for using audio-files) + * (instrument-plugin for using audio-files) * * Copyright (c) 2004-2009 Tobias Doerffel * @@ -128,3 +128,5 @@ private: #endif + +/* vim: set tw=0 noexpandtab: */ diff --git a/src/core/lame_library.cpp b/src/core/lame_library.cpp index 431850442..6d955a977 100644 --- a/src/core/lame_library.cpp +++ b/src/core/lame_library.cpp @@ -180,4 +180,4 @@ bool LameLibrary::isLoaded() return m_lameLib != NULL; } -/* vim: set tw=0 expandtab: */ +/* vim: set tw=0 noexpandtab: */ diff --git a/src/core/main.cpp b/src/core/main.cpp index 80969fdb1..85512c4c2 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -155,10 +155,10 @@ int main( int argc, char * * argv ) printf( "\nLinux MultiMedia Studio %s\n" "Copyright (c) 2004-2008 LMMS developers.\n\n" "usage: lmms [ -r ] [ options ]\n" - " [ -u ]\n" - " [ -d ]\n" - " [ -h ]\n" - " [ ]\n\n" + " [ -u ]\n" + " [ -d ]\n" + " [ -h ]\n" + " [ ]\n\n" "-r, --render render given project file\n" "-o, --output render into \n" "-f, --output-format specify format of render-output where\n" @@ -227,10 +227,10 @@ int main( int argc, char * * argv ) eff = projectRenderer::OggFile; } #endif - else if( ext == "mp3" ) - { - eff = projectRenderer::Mp3File; - } + else if( ext == "mp3" ) + { + eff = projectRenderer::Mp3File; + } else { printf( "\nInvalid output format %s.\n\n" @@ -522,3 +522,5 @@ int main( int argc, char * * argv ) #endif + +/* vim: set tw=0 noexpandtab: */ diff --git a/src/core/sample_buffer.cpp b/src/core/sample_buffer.cpp index d74847997..065ad846f 100644 --- a/src/core/sample_buffer.cpp +++ b/src/core/sample_buffer.cpp @@ -66,6 +66,21 @@ #include "lame_library.h" +const char * sampleBuffer::supportedExts[] = { + "wav", + "ogg", + "ds", + "spx", + "au", + "voc", + "aif", + "aiff", + "flac", + "raw", + "mp3", + NULL +}; + sampleBuffer::sampleBuffer( const QString & _audio_file, bool _is_base64_data ) : m_audioFile( ( _is_base64_data == true ) ? "" : _audio_file ), @@ -260,7 +275,8 @@ void sampleBuffer::update( bool _keep_settings ) m_loopStartFrame = m_startFrame = 0; m_loopEndFrame = m_endFrame = 1; - QString decoders = tr( "wav, ogg, mp3" ); + // TODO: this list probably shouldn't be hardcoded + QString decoders = niceListOfExts(); QMessageBox::information( NULL, QObject::tr( "Unrecognized audio format" ), QObject::tr( "None of the available audio decoders " @@ -292,10 +308,22 @@ void sampleBuffer::update( bool _keep_settings ) } +QString sampleBuffer::niceListOfExts() const +{ + QString ret = ""; + for( const char * * i = supportedExts; *i; ++i ) + { + ret.append(*i); + if( *(i+1) ) + ret.append(", "); + } + + return ret; +} void sampleBuffer::normalizeSampleRate( const sample_rate_t _src_sr, - bool _keep_settings ) + bool _keep_settings ) { // do samplerate-conversion to our default-samplerate if( _src_sr != engine::getMixer()->baseSampleRate() ) @@ -1328,4 +1356,4 @@ sampleBuffer::handleState::~handleState() #endif -/* vim: set tw=0 expandtab: */ +/* vim: set tw=0 noexpandtab: */