Skip to content

Commit

Permalink
Code format and cleanup
Browse files Browse the repository at this point in the history
And read track name from file
  • Loading branch information
liushuyu committed Jan 11, 2017
1 parent 1e39d12 commit a9d5653
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 419 deletions.
24 changes: 13 additions & 11 deletions data/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ If you're interested in translating LMMS in another language or want to imp
<source>The JACK server seems to have been shutdown and starting a new instance failed. Therefore LMMS is unable to proceed. You should save your project and restart JACK and LMMS.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AudioJack::setupWidget</name>
<message>
<source>CLIENT-NAME</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -2248,9 +2245,6 @@ You can remove and move FX channels in the context menu, which is accessed by ri
<source>FX-Mixer</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FxMixerView::FxChannelView</name>
<message>
<source>FX Fader %1</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -5805,6 +5799,13 @@ Reason: &quot;%2&quot;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QGuiApplication</name>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QWidget</name>
<message>
Expand Down Expand Up @@ -6721,11 +6722,12 @@ Please make sure you have read-permission to the file and the directory containi
<source>Please wait...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>TrackContainer::TrackContainer</name>
<message>
<source>Cancel</source>
<source>Track</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Track %1</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down Expand Up @@ -7744,7 +7746,7 @@ Please make sure you have read-permission to the file and the directory containi
<context>
<name>commonReader</name>
<message>
<source>Track</source>
<source>Importing %1 file...</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
1 change: 1 addition & 0 deletions include/SmfMidiChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SmfMidiChannel
SmfMidiChannel * create( TrackContainer* tc, QString tn );

void addNote( Note & n );
void setName(QString tn );

};

Expand Down
17 changes: 9 additions & 8 deletions plugins/SmfImport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Importer for SMF-like file format, such as .mid, .ove, .wrk

INCLUDE(BuildPlugin)

# check for drumstick-file
PKG_CHECK_MODULES(DRUMSTICK_FILE REQUIRED drumstick-file>=0.5.0)
IF(NOT DRUMSTICK_FILE_FOUND)
MESSAGE(FATAL_ERROR "LMMS requires libdrumstick-file and drumstick-dev >= 0.5.0 - please install, remove CMakeCache.txt and try again!")
ENDIF(NOT DRUMSTICK_FILE_FUND)
MESSAGE(FATAL_ERROR "LMMS requires libdrumstick-file and drumstick-dev >= 0.5.0 - please install, remove CMakeCache.txt and try again!")
ENDIF(NOT DRUMSTICK_FILE_FOUND)

IF(LMMS_BUILD_APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
ENDIF(LMMS_BUILD_APPLE)
INCLUDE(BuildPlugin)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -ldrumstick-file -Wno-reorder")
LINK_DIRECTORIES(${DRUMSTICK_FILE_LIBDIR})
INCLUDE_DIRECTORIES(${DRUMSTICK_FILE_INCLUDEDIR})

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")

BUILD_PLUGIN(smfimport SmfImport.cpp commonReader.cpp midiReader.cpp oveReader.cpp wrkReader.cpp
MOCFILES SmfImport.h commonReader.h midiReader.h oveReader.h wrkReader.h )

TARGET_LINK_LIBRARIES(smfimport ${DRUMSTICK_LIBRARIES})
122 changes: 65 additions & 57 deletions plugins/SmfImport/SmfImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@
extern "C"
{

Plugin::Descriptor PLUGIN_EXPORT smfimport_plugin_descriptor =
{
STRINGIFY( PLUGIN_NAME ),
"SMF Import",
QT_TRANSLATE_NOOP( "pluginBrowser",
"Filter for importing MIDI-like files into LMMS" ),
"Tony Chyi <tonychee1989/at/gmail/dot/com>",
0x0100,
Plugin::ImportFilter,
NULL,
NULL,
NULL
} ;
Plugin::Descriptor PLUGIN_EXPORT smfimport_plugin_descriptor =
{
STRINGIFY( PLUGIN_NAME ),
"SMF Import",
QT_TRANSLATE_NOOP( "pluginBrowser",
"Filter for importing MIDI-like files into LMMS" ),
"Tony Chyi <tonychee1989/at/gmail/dot/com>",
0x0100,
Plugin::ImportFilter,
NULL,
NULL,
NULL
} ;

}



SmfImport::SmfImport(const QString &_file):
ImportFilter(_file, &smfimport_plugin_descriptor)
SmfImport::SmfImport( const QString &_file ):
ImportFilter( _file, &smfimport_plugin_descriptor )
{

}
Expand All @@ -79,37 +79,40 @@ SmfImport::~SmfImport()
closeFile();
}

bool SmfImport::tryImport(TrackContainer *tc)
bool SmfImport::tryImport( TrackContainer *tc )
{

#ifdef LMMS_HAVE_FLUIDSYNTH

if( gui != NULL && ConfigManager::inst()->defaultSoundfont().isEmpty() )
{
QMessageBox::information( gui->mainWindow(),
tr( "Setup incomplete" ),
tr( "You do not have set up a default soundfont in "
"the settings dialog (Edit->Settings). "
"Therefore no sound will be played back after "
"importing this MIDI file. You should download "
"a General MIDI soundfont, specify it in "
"settings dialog and try again." ) );
tr( "Setup incomplete" ),
tr( "You do not have set up a default soundfont in "
"the settings dialog (Edit->Settings). "
"Therefore no sound will be played back after "
"importing this MIDI file. You should download "
"a General MIDI soundfont, specify it in "
"settings dialog and try again." ) );
}

#else

if( gui )
{
QMessageBox::information( gui->mainWindow(),
tr( "Setup incomplete" ),
tr( "You did not compile LMMS with support for "
"SoundFont2 player, which is used to add default "
"sound to imported MIDI files. "
"Therefore no sound will be played back after "
"importing this MIDI file." ) );
tr( "Setup incomplete" ),
tr( "You did not compile LMMS with support for "
"SoundFont2 player, which is used to add default "
"sound to imported MIDI files. "
"Therefore no sound will be played back after "
"importing this MIDI file." ) );
}

return false;
#endif
return true;

if( openFile() == false )
if( !openFile() )
{
return false;
}
Expand All @@ -119,47 +122,47 @@ bool SmfImport::tryImport(TrackContainer *tc)
switch( readID() )
{
case makeID( 'M', 'T', 'h', 'd' ):
printf( "SmfImport::tryImport(): found MThd\n");
printf( "SmfImport::tryImport(): found MThd\n" );
return readSMF( tc );

case makeID( 'R', 'I', 'F', 'F' ):
printf( "SmfImport::tryImport(): found RIFF\n");
printf( "SmfImport::tryImport(): found RIFF\n" );
return readRIFF( tc );

case makeID( 'O', 'V', 'S', 'C' ):
printf("SmfImport::tryImport(): found OVSC\n");
printf( "SmfImport::tryImport(): found OVSC\n" );
return readOve( tc );

case makeID( 'C', 'A', 'K', 'E'):
printf("SmfImport::tryImport(): found CAKEWALK\n");
case makeID( 'C', 'A', 'K', 'E' ):
printf( "SmfImport::tryImport(): found CAKEWALK\n" );
return readWrk( tc );

default:
printf( "MidiImport::tryImport(): not a Standard MIDI "
"file\n" );
"file\n" );
return false;
}

}

bool SmfImport::readWrk(TrackContainer *tc)
bool SmfImport::readWrk( TrackContainer *tc )
{
wrkReader mr(tc);
mr.read(filename);
wrkReader mr( tc );
mr.read( filename );
return true;
}

bool SmfImport::readOve( TrackContainer *tc)
bool SmfImport::readOve( TrackContainer *tc )
{
oveReader mr(tc);
mr.read(filename);
oveReader mr( tc );
mr.read( filename );
return true;
}

bool SmfImport::readSMF( TrackContainer *tc)
bool SmfImport::readSMF( TrackContainer *tc )
{
midiReader mr(tc);
mr.read(filename);
midiReader mr( tc );
mr.read( filename );
return true;
}

Expand All @@ -172,29 +175,33 @@ bool SmfImport::readRIFF( TrackContainer* tc )
if( readID() != makeID( 'R', 'M', 'I', 'D' ) )
{
invalid_format:
qWarning( "MidiImport::readRIFF(): invalid file format" );
return false;
qWarning( "MidiImport::readRIFF(): invalid file format" );
return false;
}

// search for "data" chunk
while( 1 )
{
const int id = readID();
const int len = read32LE();

if( file().atEnd() )
{
data_not_found:
qWarning( "MidiImport::readRIFF(): data chunk not found" );
return false;
qWarning( "MidiImport::readRIFF(): data chunk not found" );
return false;
}

if( id == makeID( 'd', 'a', 't', 'a' ) )
{
break;
break;
}

if( len < 0 )
{
goto data_not_found;
goto data_not_found;
}

skip( ( len + 1 ) & ~1 );
}

Expand All @@ -203,6 +210,7 @@ bool SmfImport::readRIFF( TrackContainer* tc )
{
goto invalid_format;
}

return readSMF( tc );
}

Expand All @@ -216,11 +224,11 @@ extern "C"
{

// necessary for getting instance out of shared lib
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model *, void * _data )
{
return new SmfImport( QString::fromUtf8(
static_cast<const char *>( _data ) ) );
}
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model *, void * _data )
{
return new SmfImport( QString::fromUtf8(
static_cast<const char *>( _data ) ) );
}


}
Loading

0 comments on commit a9d5653

Please sign in to comment.