Skip to content

Commit

Permalink
Merge pull request #1661 from teeberg/style
Browse files Browse the repository at this point in the history
Work on codestyle and readability
  • Loading branch information
lukas-w committed Jan 21, 2015
2 parents d6ff1a7 + 52ec472 commit d41d816
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 103 deletions.
2 changes: 1 addition & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected slots:

int m_oldNotesEditHeight;
int m_notesEditHeight;
int m_ppt;
int m_ppt; // pixels per tact
int m_totalKeysToScroll;

// remember these values to use them
Expand Down
10 changes: 6 additions & 4 deletions include/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class EXPORT Plugin : public Model, public JournallingObject
const Plugin::PluginTypes m_type;
} ;

SubPluginFeatures * subPluginFeatures;
SubPluginFeatures *subPluginFeatures;

} ;

Expand All @@ -148,7 +148,9 @@ class EXPORT Plugin : public Model, public JournallingObject
// returns display-name out of descriptor
virtual QString displayName() const
{
return Model::displayName().isEmpty() ? m_descriptor->displayName : Model::displayName();
return Model::displayName().isEmpty()
? m_descriptor->displayName
: Model::displayName();
}

// return plugin-type
Expand All @@ -173,13 +175,13 @@ class EXPORT Plugin : public Model, public JournallingObject

// returns an instance of a plugin whose name matches to given one
// if specified plugin couldn't be loaded, it creates a dummy-plugin
static Plugin * instantiate( const QString& pluginName, Model * parent, void * data );
static Plugin * instantiate( const QString& pluginName, Model *parent, void * data );

// fills given list with descriptors of all available plugins
static void getDescriptorsOfAvailPlugins( DescriptorList& pluginDescriptors );

// create a view for the model
PluginView * createView( QWidget* parent );
PluginView* createView( QWidget* parent );


protected:
Expand Down
10 changes: 5 additions & 5 deletions include/lmms_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ struct typeInfo
return 1;
}

static inline bool isEqual( T _x, T _y )
static inline bool isEqual( T x, T y )
{
return _x == _y;
return x == y;
}

static inline T absVal( T t )
Expand All @@ -97,13 +97,13 @@ inline float typeInfo<float>::minEps()
}

template<>
inline bool typeInfo<float>::isEqual( float _x, float _y )
inline bool typeInfo<float>::isEqual( float x, float y )
{
if( likely( _x == _y ) )
if( x == y )
{
return true;
}
return absVal( _x - _y ) < minEps();
return absVal( x - y ) < minEps();
}


Expand Down
57 changes: 26 additions & 31 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ MainWindow::MainWindow() :
vbox->setSpacing( 0 );
vbox->setMargin( 0 );


QWidget * w = new QWidget( main_widget );
QHBoxLayout * hbox = new QHBoxLayout( w );
hbox->setSpacing( 0 );
Expand All @@ -94,24 +93,25 @@ MainWindow::MainWindow() :
QSplitter * splitter = new QSplitter( Qt::Horizontal, w );
splitter->setChildrenCollapsible( false );

QString wdir = ConfigManager::inst()->workingDir();
ConfigManager* confMgr = ConfigManager::inst();

sideBar->appendTab( new PluginBrowser( splitter ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userProjectsDir() + "*" +
ConfigManager::inst()->factoryProjectsDir(),
confMgr->userProjectsDir() + "*" +
confMgr->factoryProjectsDir(),
"*.mmp *.mmpz *.xml *.mid *.flp",
tr( "My Projects" ),
embed::getIconPixmap( "project_file" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userSamplesDir() + "*" +
ConfigManager::inst()->factorySamplesDir(),
confMgr->userSamplesDir() + "*" +
confMgr->factorySamplesDir(),
"*", tr( "My Samples" ),
embed::getIconPixmap( "sample_file" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userPresetsDir() + "*" +
ConfigManager::inst()->factoryPresetsDir(),
confMgr->userPresetsDir() + "*" +
confMgr->factoryPresetsDir(),
"*.xpf *.cs.xml *.xiz",
tr( "My Presets" ),
embed::getIconPixmap( "preset_file" ).transformed( QTransform().rotate( 90 ) ),
Expand All @@ -121,33 +121,30 @@ MainWindow::MainWindow() :
embed::getIconPixmap( "home" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );


QStringList root_paths;
QString title = tr( "Root directory" );
bool dirs_as_items = false;

#ifdef LMMS_BUILD_APPLE
title = tr( "Volumes" );
root_paths += "/Volumes";
#else
#elif defined(LMMS_BUILD_WIN32)
title = tr( "My Computer" );
dirs_as_items = true;
#endif

#if ! defined(LMMS_BUILD_APPLE)
QFileInfoList drives = QDir::drives();
foreach( const QFileInfo & drive, drives )
{
root_paths += drive.absolutePath();
}
#endif
sideBar->appendTab( new FileBrowser( root_paths.join( "*" ), "*",
#ifdef LMMS_BUILD_WIN32
tr( "My Computer" ),
#elif defined(LMMS_BUILD_APPLE)
tr( "Volumes" ),
#else
tr( "Root Directory" ),
#endif

sideBar->appendTab( new FileBrowser( root_paths.join( "*" ), "*", title,
embed::getIconPixmap( "computer" ).transformed( QTransform().rotate( 90 ) ),
splitter,
#ifdef LMMS_BUILD_WIN32
true
#else
false
#endif
) );
splitter, dirs_as_items) );

m_workspace = new QMdiArea( splitter );

Expand Down Expand Up @@ -190,13 +187,13 @@ MainWindow::MainWindow() :
vbox->addWidget( w );
setCentralWidget( main_widget );

m_updateTimer.start( 1000 / 20, this ); // 20 fps
m_updateTimer.start( 1000 / 20, this ); // 20 fps

if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() )
{
// connect auto save
connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
m_autoSaveTimer.start(1000 * 60); // 1 minute
m_autoSaveTimer.start(1000 * 60); // 1 minute
}

connect( Engine::getSong(), SIGNAL( playbackStateChanged() ),
Expand All @@ -208,12 +205,10 @@ MainWindow::MainWindow() :

MainWindow::~MainWindow()
{
for( QList<PluginView *>::iterator it = m_tools.begin();
it != m_tools.end(); ++it )
for( PluginView *view : m_tools )
{
Model * m = ( *it )->model();
delete *it;
delete m;
delete view->model();
delete view;
}
// TODO: Close tools
// destroy engine which will do further cleanups etc.
Expand Down
7 changes: 1 addition & 6 deletions src/gui/PluginBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ PluginBrowser::~PluginBrowser()





PluginDescList::PluginDescList(QWidget *parent) :
QWidget(parent)
{
Expand All @@ -98,7 +96,6 @@ PluginDescList::PluginDescList(QWidget *parent) :
Plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
std::sort(m_pluginDescriptors.begin(), m_pluginDescriptors.end(), pluginBefore);


for( Plugin::DescriptorList::const_iterator it = m_pluginDescriptors.constBegin();
it != m_pluginDescriptors.constEnd(); ++it )
{
Expand All @@ -117,8 +114,6 @@ PluginDescList::PluginDescList(QWidget *parent) :





PluginDescWidget::PluginDescWidget( const Plugin::Descriptor & _pd,
QWidget * _parent ) :
QWidget( _parent ),
Expand Down Expand Up @@ -181,7 +176,6 @@ void PluginDescWidget::paintEvent( QPaintEvent * )
m_targetHeight = qMax( 60, 25 + br.height() );
}
}

}


Expand Down Expand Up @@ -237,6 +231,7 @@ void PluginDescWidget::updateHeight()
m_updateTimer.stop();
return;
}

if( !m_updateTimer.isActive() )
{
m_updateTimer.start( 15 );
Expand Down
6 changes: 4 additions & 2 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ PianoRoll::PianoRoll() :
this, SLOT( quantizeChanged() ) );

// Set up scale model
const auto& chord_table = InstrumentFunctionNoteStacking::ChordTable::getInstance();
const InstrumentFunctionNoteStacking::ChordTable& chord_table =
InstrumentFunctionNoteStacking::ChordTable::getInstance();

m_scaleModel.addItem( tr("No scale") );
for( const InstrumentFunctionNoteStacking::Chord& chord : chord_table )
Expand Down Expand Up @@ -3814,7 +3815,8 @@ int PianoRoll::quantization() const

void PianoRoll::updateSemiToneMarkerMenu()
{
const auto& chord_table = InstrumentFunctionNoteStacking::ChordTable::getInstance();
const InstrumentFunctionNoteStacking::ChordTable& chord_table =
InstrumentFunctionNoteStacking::ChordTable::getInstance();
const InstrumentFunctionNoteStacking::Chord& scale =
chord_table.getScaleByName( m_scaleModel.currentText() );
const InstrumentFunctionNoteStacking::Chord& chord =
Expand Down
49 changes: 23 additions & 26 deletions src/gui/embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,70 @@ namespace
#include "embedded_resources.h"


QPixmap getIconPixmap( const char * _name, int _w, int _h )
QPixmap getIconPixmap( const char * pixmapName, int width, int height )
{
if( _w == -1 || _h == -1 )
if( width == -1 || height == -1 )
{
// Return cached pixmap
QPixmap cached = s_pixmapCache.value( _name );
// Return cached pixmap
QPixmap cached = s_pixmapCache.value( pixmapName );
if( !cached.isNull() )
{
return cached;
}

// Or try to load it
QList<QByteArray> formats =
QImageReader::supportedImageFormats();
QList<QByteArray> formats = QImageReader::supportedImageFormats();
QList<QString> candidates;
QPixmap p;
QPixmap pixmap;
QString name;
int i;

for ( i = 0; i < formats.size() && p.isNull(); ++i )
for ( i = 0; i < formats.size() && pixmap.isNull(); ++i )
{
candidates << QString( _name ) + "." + formats.at( i ).data();
candidates << QString( pixmapName ) + "." + formats.at( i ).data();
}

#ifdef PLUGIN_NAME
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->artworkDir() + "plugins/" +
pixmap = QPixmap( ConfigManager::inst()->artworkDir() + "plugins/" +
STRINGIFY( PLUGIN_NAME ) + "_" + name );
}
#endif
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->artworkDir() + name );
pixmap = QPixmap( ConfigManager::inst()->artworkDir() + name );
}

// nothing found, so look in default-artwork-dir
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->defaultArtworkDir()
+ name );
pixmap = QPixmap( ConfigManager::inst()->defaultArtworkDir() + name );
}

for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
const embed::descriptor & e =
findEmbeddedData( name.toUtf8().constData() );
// found?
if( QString( e.name ) == name )
if( name == e.name )
{
p.loadFromData( e.data, e.size );
pixmap.loadFromData( e.data, e.size );
}
}

// Fallback
if(p.isNull())
if( pixmap.isNull() )
{
p = QPixmap( 1, 1 );
pixmap = QPixmap( 1, 1 );
}
// Save to cache and return
s_pixmapCache.insert( _name, p );
return p;

s_pixmapCache.insert( pixmapName, pixmap );
return pixmap;
}

return getIconPixmap( _name ).
scaled( _w, _h, Qt::IgnoreAspectRatio,
return getIconPixmap( pixmapName ).
scaled( width, height, Qt::IgnoreAspectRatio,
Qt::SmoothTransformation );
}

Expand Down
Loading

0 comments on commit d41d816

Please sign in to comment.