diff --git a/ChangeLog b/ChangeLog index 366e93d73..af115274d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-06-30 Tobias Doerffel + + * include/automatable_model.h: + * include/combobox_model.h: + * include/piano_roll.h: + * include/mv_base.h: + * src/gui/piano_roll.cpp: + * src/gui/main_window.cpp: + * src/gui/widgets/combobox.cpp: + * src/gui/widgets/group_box.cpp: + * src/gui/automation_editor.cpp: + * src/core/instrument_functions.cpp: + * src/core/mv_base.cpp: + * src/core/fx_mixer.cpp: + fixed various leaks I found using Valgrind + 2008-06-30 Paul Giblock * plugins/ladspa_browser/ladspa_browser.cpp: diff --git a/include/automatable_model.h b/include/automatable_model.h index 752ed7f08..647a79fc6 100644 --- a/include/automatable_model.h +++ b/include/automatable_model.h @@ -295,7 +295,7 @@ public: const QString & _display_name = QString::null, bool _default_constructed = FALSE ) : automatableModel( Float, _val, _min, _max, _step, - _parent, _display_name, _default_constructed ) + _parent, _display_name, _default_constructed ) { } @@ -312,7 +312,7 @@ public: const QString & _display_name = QString::null, bool _default_constructed = FALSE ) : automatableModel( Integer, _val, _min, _max, 1, - _parent, _display_name, _default_constructed ) + _parent, _display_name, _default_constructed ) { } @@ -329,7 +329,7 @@ public: const QString & _display_name = QString::null, bool _default_constructed = FALSE ) : automatableModel( Bool, _val, FALSE, TRUE, 1, - _parent, _display_name, _default_constructed ) + _parent, _display_name, _default_constructed ) { } diff --git a/include/combobox_model.h b/include/combobox_model.h index cc284ff1a..7605ab522 100644 --- a/include/combobox_model.h +++ b/include/combobox_model.h @@ -39,11 +39,18 @@ class comboBoxModel : public intModel { Q_OBJECT public: - comboBoxModel( ::model * _parent = NULL, const QString & _display_name = QString::null ) : + comboBoxModel( ::model * _parent = NULL, + const QString & _display_name = QString::null, + bool _default_constructed = FALSE ) : intModel( 0, 0, 0, _parent, _display_name ) { } + virtual ~comboBoxModel() + { + clear(); + } + void addItem( const QString & _item, pixmapLoader * _loader = NULL ); void clear( void ); diff --git a/include/mv_base.h b/include/mv_base.h index c9e13e2df..eae16eaff 100644 --- a/include/mv_base.h +++ b/include/mv_base.h @@ -91,12 +91,15 @@ class EXPORT modelView { public: modelView( model * _model, QWidget * _this ); - virtual ~modelView() - { - } + virtual ~modelView(); virtual void setModel( model * _model, bool _old_model_valid = TRUE ); + inline model * getModel( void ) + { + return( m_model ); + } + template T * castModel( void ) { diff --git a/include/piano_roll.h b/include/piano_roll.h index ebf1105fe..18406eac5 100644 --- a/include/piano_roll.h +++ b/include/piano_roll.h @@ -29,9 +29,10 @@ #include -#include "types.h" -#include "note.h" +#include "combobox_model.h" #include "journalling_object.h" +#include "note.h" +#include "types.h" class QPainter; @@ -39,7 +40,6 @@ class QPixmap; class QScrollBar; class comboBox; -class comboBoxModel; class notePlayHandle; class pattern; class timeLine; @@ -198,9 +198,9 @@ private: comboBox * m_quantizeComboBox; comboBox * m_noteLenComboBox; - comboBoxModel * m_zoomingModel; - comboBoxModel * m_quantizeModel; - comboBoxModel * m_noteLenModel; + comboBoxModel m_zoomingModel; + comboBoxModel m_quantizeModel; + comboBoxModel m_noteLenModel; diff --git a/src/core/fx_mixer.cpp b/src/core/fx_mixer.cpp index 4e8e79388..c73aa83f6 100644 --- a/src/core/fx_mixer.cpp +++ b/src/core/fx_mixer.cpp @@ -78,6 +78,7 @@ fxMixer::fxMixer() : fxMixer::~fxMixer() { + delete[] m_out; for( int i = 0; i < NumFxChannels+1; ++i ) { delete m_fxChannels[i]; diff --git a/src/core/instrument_functions.cpp b/src/core/instrument_functions.cpp index d7e3eb38e..a0d69f25d 100644 --- a/src/core/instrument_functions.cpp +++ b/src/core/instrument_functions.cpp @@ -279,9 +279,12 @@ arpeggiator::arpeggiator( model * _parent ) : m_arpEnabledModel( FALSE ), m_arpModel( this, tr( "Arpeggio type" ) ), m_arpRangeModel( 1.0f, 1.0f, 9.0f, 1.0f, this, tr( "Arpeggio range" ) ), - m_arpTimeModel( 100.0f, 25.0f, 2000.0f, 1.0f, 1.0, this, tr( "Arpeggio time" ) ), - m_arpGateModel( 100.0f, 1.0f, 200.0f, 1.0f, this, tr( "Arpeggio gate" ) ), - m_arpDirectionModel( 0, 0, NumArpDirections, this, tr( "Arpeggio direction" ) ), + m_arpTimeModel( 100.0f, 25.0f, 2000.0f, 1.0f, 1.0, this, + tr( "Arpeggio time" ) ), + m_arpGateModel( 100.0f, 1.0f, 200.0f, 1.0f, this, + tr( "Arpeggio gate" ) ), + m_arpDirectionModel( 0, 0, NumArpDirections, this, + tr( "Arpeggio direction" ) ), m_arpModeModel( this, tr( "Arpeggio mode" ) ) { for( int i = 0; chordCreator::s_chordTable[i].interval[0] != -1; ++i ) diff --git a/src/core/mv_base.cpp b/src/core/mv_base.cpp index 440a9132b..5cff37c8b 100644 --- a/src/core/mv_base.cpp +++ b/src/core/mv_base.cpp @@ -53,6 +53,7 @@ QString model::fullDisplayName( void ) const + modelView::modelView( model * _model, QWidget * _this ) : m_widget( _this ), m_model( _model ) @@ -62,6 +63,17 @@ modelView::modelView( model * _model, QWidget * _this ) : +modelView::~modelView() +{ + if( m_model != NULL && m_model->defaultConstructed() ) + { + delete m_model; + } +} + + + + void modelView::setModel( model * _model, bool _old_model_valid ) { if( _old_model_valid && m_model != NULL ) diff --git a/src/gui/automation_editor.cpp b/src/gui/automation_editor.cpp index ee8629d44..fdc2985d8 100644 --- a/src/gui/automation_editor.cpp +++ b/src/gui/automation_editor.cpp @@ -308,6 +308,7 @@ automationEditor::automationEditor( void ) : m_quantizeComboBox = new comboBox( m_toolBar ); m_quantizeComboBox->setFixedSize( 60, 22 ); + // TODO: leak comboBoxModel * quantize_model = new comboBoxModel( /* this */ ); for( int i = 0; i < 7; ++i ) { diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp index 44400cf10..c0c36adbc 100644 --- a/src/gui/main_window.cpp +++ b/src/gui/main_window.cpp @@ -161,6 +161,13 @@ mainWindow::mainWindow( void ) : mainWindow::~mainWindow() { + for( QList::iterator it = m_tools.begin(); + it != m_tools.end(); ++it ) + { + model * m = ( *it )->getModel(); + delete *it; + delete m; + } // TODO: Close tools // destroy engine which will do further cleanups etc. engine::destroy(); diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 5ff644b90..b19a5976e 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -127,9 +127,9 @@ const int DEFAULT_PR_PPT = KEY_LINE_HEIGHT * DefaultStepsPerTact; pianoRoll::pianoRoll( void ) : - m_zoomingModel( new comboBoxModel( /* this */ ) ), - m_quantizeModel( new comboBoxModel( /* this */ ) ), - m_noteLenModel( new comboBoxModel( /* this */ ) ), + m_zoomingModel(), + m_quantizeModel(), + m_noteLenModel(), m_pattern( NULL ), m_currentPosition(), m_recording( FALSE ), @@ -359,13 +359,13 @@ pianoRoll::pianoRoll( void ) : // setup zooming-stuff for( int i = 0; i < 6; ++i ) { - m_zoomingModel->addItem( QString::number( 25 << i ) + "%" ); + m_zoomingModel.addItem( QString::number( 25 << i ) + "%" ); } - m_zoomingModel->setValue( m_zoomingModel->findText( "100%" ) ); - connect( m_zoomingModel, SIGNAL( dataChanged() ), + m_zoomingModel.setValue( m_zoomingModel.findText( "100%" ) ); + connect( &m_zoomingModel, SIGNAL( dataChanged() ), this, SLOT( zoomingChanged() ) ); m_zoomingComboBox = new comboBox( m_toolBar ); - m_zoomingComboBox->setModel( m_zoomingModel ); + m_zoomingComboBox->setModel( &m_zoomingModel ); m_zoomingComboBox->setFixedSize( 80, 22 ); @@ -375,12 +375,12 @@ pianoRoll::pianoRoll( void ) : for( int i = 0; i < 7; ++i ) { - m_quantizeModel->addItem( "1/" + QString::number( 1 << i ) ); + m_quantizeModel.addItem( "1/" + QString::number( 1 << i ) ); } - m_quantizeModel->addItem( "1/192" ); - m_quantizeModel->setValue( m_quantizeModel->findText( "1/16" ) ); + m_quantizeModel.addItem( "1/192" ); + m_quantizeModel.setValue( m_quantizeModel.findText( "1/16" ) ); m_quantizeComboBox = new comboBox( m_toolBar ); - m_quantizeComboBox->setModel( m_quantizeModel ); + m_quantizeComboBox->setModel( &m_quantizeModel ); m_quantizeComboBox->setFixedSize( 60, 22 ); @@ -388,19 +388,19 @@ pianoRoll::pianoRoll( void ) : QLabel * note_len_lbl = new QLabel( m_toolBar ); note_len_lbl->setPixmap( embed::getIconPixmap( "note" ) ); - m_noteLenModel->addItem( tr( "Last note" ), + m_noteLenModel.addItem( tr( "Last note" ), new pixmapLoader( "edit_draw" ) ); const QString pixmaps[] = { "whole", "half", "quarter", "eighth", "sixteenth", "thirtysecond" } ; for( int i = 0; i < 6; ++i ) { - m_noteLenModel->addItem( "1/" + QString::number( 1 << i ), + m_noteLenModel.addItem( "1/" + QString::number( 1 << i ), new pixmapLoader( "note_" + pixmaps[i] ) ); } - m_noteLenModel->addItem( "1/192" ); - m_noteLenModel->setValue( 0 ); + m_noteLenModel.addItem( "1/192" ); + m_noteLenModel.setValue( 0 ); m_noteLenComboBox = new comboBox( m_toolBar ); - m_noteLenComboBox->setModel( m_noteLenModel ); + m_noteLenComboBox->setModel( &m_noteLenModel ); m_noteLenComboBox->setFixedSize( 120, 22 ); @@ -2150,8 +2150,8 @@ void pianoRoll::wheelEvent( QWheelEvent * _we ) m_ppt /= 2; } // update combobox with zooming-factor - m_zoomingModel->setValue( - m_zoomingModel->findText( QString::number( + m_zoomingModel.setValue( + m_zoomingModel.findText( QString::number( static_cast( m_ppt * 100 / DEFAULT_PR_PPT ) ) +"%" ) ); // update timeline @@ -2652,7 +2652,7 @@ void pianoRoll::updatePosition( const midiTime & _t ) void pianoRoll::zoomingChanged( void ) { - const QString & zfac = m_zoomingModel->currentText(); + const QString & zfac = m_zoomingModel.currentText(); m_ppt = zfac.left( zfac.length() - 1 ).toInt() * DEFAULT_PR_PPT / 100; #ifdef LMMS_DEBUG assert( m_ppt > 0 ); @@ -2667,8 +2667,8 @@ void pianoRoll::zoomingChanged( void ) int pianoRoll::quantization( void ) const { - return( DefaultTicksPerTact / m_quantizeModel->currentText().right( - m_quantizeModel->currentText().length() - + return( DefaultTicksPerTact / m_quantizeModel.currentText().right( + m_quantizeModel.currentText().length() - 2 ).toInt() ); } @@ -2677,12 +2677,12 @@ int pianoRoll::quantization( void ) const midiTime pianoRoll::newNoteLen( void ) const { - if( m_noteLenModel->value() == 0 ) + if( m_noteLenModel.value() == 0 ) { return( m_lenOfNewNotes ); } - return( midiTime::ticksPerTact() / m_noteLenModel->currentText().right( - m_noteLenModel->currentText().length() - + return( midiTime::ticksPerTact() / m_noteLenModel.currentText().right( + m_noteLenModel.currentText().length() - 2 ).toInt() ); } diff --git a/src/gui/widgets/combobox.cpp b/src/gui/widgets/combobox.cpp index 0e9b956bd..17bfa87fc 100644 --- a/src/gui/widgets/combobox.cpp +++ b/src/gui/widgets/combobox.cpp @@ -51,7 +51,7 @@ const int CB_ARROW_BTN_WIDTH = 20; comboBox::comboBox( QWidget * _parent, const QString & _name ) : QWidget( _parent ), - intModelView( new comboBoxModel, this ), + intModelView( new comboBoxModel( NULL, QString::null, TRUE ), this ), m_menu( this ), m_pressed( FALSE ) { diff --git a/src/gui/widgets/group_box.cpp b/src/gui/widgets/group_box.cpp index e20d6cc29..a75622d7a 100644 --- a/src/gui/widgets/group_box.cpp +++ b/src/gui/widgets/group_box.cpp @@ -63,7 +63,7 @@ groupBox::groupBox( const QString & _caption, QWidget * _parent ) : m_led->setActiveGraphic( embed::getIconPixmap( "led_green" ) ); m_led->setInactiveGraphic( embed::getIconPixmap( "led_off" ) ); - setModel( new boolModel( FALSE, NULL, _caption, FALSE ) ); + setModel( new boolModel( FALSE, NULL, _caption, TRUE ) ); setAutoFillBackground( TRUE ); }