From e6ff4b1c4bc32fd99fa9ae7ef06e1c40a69b705d Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Tue, 1 Aug 2006 21:27:06 +0000 Subject: [PATCH] - moved framesPerTact() from songEditor to engine - update frames per tact only when changes happen git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@275 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/song_editor.h | 6 ++++-- src/core/engine.cpp | 10 ++++++++++ src/core/song_editor.cpp | 30 ++++++++++++++++-------------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/song_editor.h b/include/song_editor.h index 1ad54054df..aad33ce238 100644 --- a/include/song_editor.h +++ b/include/song_editor.h @@ -139,8 +139,6 @@ public: bool mayChangeProject( void ); - float framesPerTact( void ) const; - // file management void createNewProject( void ); void FASTCALL createNewProjectFromTemplate( const QString & _template ); @@ -311,6 +309,10 @@ private: friend class engine; +private slots: + void updateFramesPerTact( void ); + + signals: void tempoChanged( bpm_t _new_bpm ); diff --git a/src/core/engine.cpp b/src/core/engine.cpp index dc1e2dd02f..a630ea9caf 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -31,6 +31,7 @@ #include "engine.h" #include "main_window.h" #include "mixer.h" +#include "pattern.h" #include "piano_roll.h" #include "preset_preview_play_handle.h" #include "project_notes.h" @@ -105,6 +106,15 @@ void engine::close( void ) +void engine::updateFramesPerTact( void ) +{ + m_frames_per_tact = m_mixer->sampleRate() * 60.0f * BEATS_PER_TACT + / m_songEditor->getTempo(); +} + + + + engineObject::engineObject( engine * _engine ) : m_engine( _engine ) diff --git a/src/core/song_editor.cpp b/src/core/song_editor.cpp index c530f392c4..ab79aa29af 100644 --- a/src/core/song_editor.cpp +++ b/src/core/song_editor.cpp @@ -204,6 +204,9 @@ songEditor::songEditor( engine * _engine ) : eng()->getMainWindow()->addSpacingToToolBar( 10 ); + connect( eng()->getMixer(), SIGNAL( sampleRateChanged() ), this, + SLOT( updateFramesPerTact() ) ); + QLabel * master_vol_lbl = new QLabel( tb ); @@ -755,6 +758,7 @@ void songEditor::setTempo( int _new_bpm ) m_bpmSpinBox->setInitValue( tLimit( _new_bpm, MIN_BPM, MAX_BPM ) ); setModified(); + eng()->updateFramesPerTact(); emit tempoChanged( _new_bpm ); } @@ -976,7 +980,8 @@ void songEditor::processNextBuffer( void ) } f_cnt_t total_frames_played = 0; - f_cnt_t frames_per_tact = static_cast( framesPerTact() ); + f_cnt_t frames_per_tact = static_cast( + eng()->framesPerTact() ); if( m_playPos[m_playMode].currentFrame() == 0 && m_playPos[m_playMode].getTact64th() > 0 ) { @@ -1175,7 +1180,7 @@ void songEditor::setPlayPos( tact _tact_num, tact64th _t_64th, playModes m_playPos[_play_mode].setTact( _tact_num ); m_playPos[_play_mode].setTact64th( _t_64th ); m_playPos[_play_mode].setCurrentFrame( static_cast( - _t_64th * framesPerTact() / 64.0f ) ); + _t_64th * eng()->framesPerTact() / 64.0f ) ); if( _play_mode == m_playMode ) { updateTimeLinePosition(); @@ -1316,18 +1321,6 @@ void songEditor::addSampleTrack( void ) -float songEditor::framesPerTact( void ) const -{ - // when fooling around with tempo while playing, we sometimes get - // 0 here which leads to FP-exception, so handle it separately - const int bpm = tMax( 1, m_bpmSpinBox->value() ); - return( eng()->getMixer()->sampleRate() * 60.0f * BEATS_PER_TACT / - bpm ); -} - - - - bpm_t songEditor::getTempo( void ) { return( m_bpmSpinBox->value() ); @@ -1775,6 +1768,15 @@ void songEditor::exportProject( void ) + +void songEditor::updateFramesPerTact( void ) +{ + eng()->updateFramesPerTact(); +} + + + + #include "song_editor.moc"