MidiImport: adapted to resource framework

Adapted MidiImport plugin to new resource framework support in plugin
base class. Files for PatMan or soundfonts for Sf2Player are now
relocated using resources framework.

Furthermore some coding style improvements.

Signed-off-by: Tobias Doerffel <tobias.doerffel@gmail.com>
This commit is contained in:
Tobias Doerffel
2009-06-29 23:27:22 +02:00
parent ac4ef21ab7
commit 6ebe8df65a
2 changed files with 36 additions and 29 deletions

View File

@@ -1,10 +1,10 @@
/*
* midi_import.cpp - support for importing MIDI-files
* midi_import.cpp - support for importing MIDI files
*
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
@@ -22,13 +22,15 @@
*
*/
#include <QtXml/QDomDocument>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QProgressDialog>
#include "LocalResourceProvider.h"
#include "ResourceDB.h"
#include "midi_import.h"
#include "track_container.h"
#include "instrument_track.h"
@@ -96,7 +98,7 @@ bool midiImport::tryImport( trackContainer * _tc )
#ifdef LMMS_HAVE_FLUIDSYNTH
if( engine::hasGUI() &&
configManager::inst()->defaultSoundfont().isEmpty() )
configManager::inst()->defaultSoundfont() == NULL )
{
QMessageBox::information( engine::getMainWindow(),
tr( "Setup incomplete" ),
@@ -227,14 +229,16 @@ public:
if( it_inst )
{
isSF2 = true;
it_inst->loadFile( configManager::inst()->defaultSoundfont() );
it_inst->loadResource(
configManager::inst()->
defaultSoundfont() );
it_inst->getChildModel( "bank" )->setValue( 0 );
it_inst->getChildModel( "patch" )->setValue( 0 );
}
else
{
it_inst = it->loadInstrument( "patman" );
}
}
#else
it_inst = it->loadInstrument( "patman" );
#endif
@@ -350,6 +354,10 @@ bool midiImport::readSMF( trackContainer * _tc )
}
}
// create a LocalResourceProvider for accessing pat files later
LocalResourceProvider midiPatterns( ResourceItem::BaseRoot,
"/usr/share/midi/freepats/" );
// Tracks
for( int t = 0; t < seq->tracks(); ++t )
{
@@ -402,17 +410,16 @@ bool midiImport::readSMF( trackContainer * _tc )
ch->it_inst->getChildModel( "bank" )->setValue( 0 );
ch->it_inst->getChildModel( "patch" )->setValue( prog );
}
else {
const QString num = QString::number( prog );
const QString filter = QString().fill( '0', 3 - num.length() ) + num + "*.pat";
const QString dir = "/usr/share/midi/"
"freepats/Tone_000/";
const QStringList files = QDir( dir ).
entryList( QStringList( filter ) );
if( ch->it_inst && !files.empty() )
{
ch->it_inst->loadFile( dir+files.front() );
}
else
{
const QString num = QString::number( prog );
const QString filter = QString().fill( '0', 3-num.length() ) + num;
const ResourceItemList items = midiPatterns.database()->
matchItems( QStringList() << filter );
if( ch->it_inst && !items.empty() )
{
ch->it_inst->loadResource( items.first() );
}
}
}
else if( update == "tracknames" )

View File

@@ -1,7 +1,7 @@
/*
* midi_import.h - support for importing MIDI-files
*
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -42,7 +42,7 @@ public:
virtual pluginView * instantiateView( QWidget * )
{
return( NULL );
return NULL;
}
@@ -53,7 +53,7 @@ private:
bool readRIFF( trackContainer * _tc );
bool readTrack( int _track_end, QString & _track_name );
void error( void );
void error();
inline int readInt( int _bytes )
@@ -64,21 +64,21 @@ private:
c = readByte();
if( c == -1 )
{
return( -1 );
return -1;
}
value = ( value << 8 ) | c;
} while( --_bytes );
return( value );
return value;
}
inline Sint32 read32LE( void )
inline Sint32 read32LE()
{
int value = readByte();
value |= readByte() << 8;
value |= readByte() << 16;
value |= readByte() << 24;
return( value );
return value;
}
inline int readVar( void )
inline int readVar()
{
int c = readByte();
int value = c & 0x7f;
@@ -100,13 +100,13 @@ private:
}
}
}
}
return( !file().atEnd() ? value : -1 );
}
return ( !file().atEnd() ? value : -1 );
}
inline Sint32 readID( void )
inline Sint32 readID()
{
return( read32LE() );
return read32LE();
}
inline void skip( int _bytes )
{