00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2010 Dan Leinir Turthra Jensen <admin@leinir.dk> 00004 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "soundasset.h" 00022 00023 #include <core/debughelper.h> 00024 #include <audio/engine.h> 00025 00026 #include <QtCore/QMimeData> 00027 00028 REGISTER_OBJECTTYPE( GluonEngine, SoundAsset ) 00029 00030 using namespace GluonEngine; 00031 00032 class SoundAsset::SoundAssetPrivate 00033 { 00034 public: 00035 SoundAssetPrivate() 00036 { 00037 buffer = 0; 00038 } 00039 00040 GluonAudio::Buffer* buffer; 00041 }; 00042 00043 SoundAsset::SoundAsset( QObject* parent ) 00044 : Asset( parent ) 00045 , d( new SoundAssetPrivate ) 00046 { 00047 } 00048 00049 SoundAsset::~SoundAsset() 00050 { 00051 delete d; 00052 } 00053 00054 const QStringList SoundAsset::supportedMimeTypes() const 00055 { 00056 QStringList list; 00057 list.append( "audio/x-wav" ); 00058 list.append( "audio/x-vorbis+ogg" ); 00059 list.append( "application/x-ogg" ); 00060 return list; 00061 } 00062 00063 void SoundAsset::load() 00064 { 00065 d->buffer = new GluonAudio::Buffer( file().toLocalFile() ); 00066 00067 if( !d->buffer->isEmpty() ) 00068 { 00069 mimeData()->setData( "application/gluon-audio-buffer", ( QString( "%1" ).arg( d->buffer->buffer() ) ).toAscii() ); 00070 setLoaded( true ); 00071 } 00072 else 00073 { 00074 DEBUG_BLOCK 00075 DEBUG_TEXT( "Error loading sound - Buffer is empty" ); 00076 } 00077 } 00078 00079 Q_EXPORT_PLUGIN2( gluon_asset_sound, GluonEngine::SoundAsset ) 00080 00081 #include "soundasset.moc"