From cd4932feff1f0aca0b49e8487950a51537937a3a Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Sun, 6 Aug 2006 21:33:29 +0000 Subject: [PATCH] frames computation based on 64th of a tact, fixes BB-pattern arbitrary positioning in song editor git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@281 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/engine.h | 8 ++++---- include/midi_time.h | 15 ++++++--------- src/core/engine.cpp | 6 +++--- src/core/note_play_handle.cpp | 10 +++++----- src/tracks/bb_track.cpp | 4 ++-- src/tracks/sample_track.cpp | 20 ++++++++------------ 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/include/engine.h b/include/engine.h index 3603c0f12d..df8301f6ce 100644 --- a/include/engine.h +++ b/include/engine.h @@ -105,16 +105,16 @@ public: void close( void ); - float framesPerTact( void ) const + float framesPerTact64th( void ) const { - return( m_frames_per_tact ); + return( m_frames_per_tact64th ); } - void updateFramesPerTact( void ); + void updateFramesPerTact64th( void ); private: bool m_hasGUI; - float m_frames_per_tact; + float m_frames_per_tact64th; mixer * m_mixer; mainWindow * m_mainWindow; diff --git a/include/midi_time.h b/include/midi_time.h index 4b58fb828b..d1c8452d61 100644 --- a/include/midi_time.h +++ b/include/midi_time.h @@ -107,24 +107,21 @@ public: } // calculate number of frame that are needed this time - inline f_cnt_t frames( const float _frames_per_tact ) const + inline f_cnt_t frames( const float _frames_per_tact64th ) const { if( m_tact >= 0 ) { - return( static_cast( m_tact * - _frames_per_tact + - m_tact64th * - _frames_per_tact / - 64.0f ) ); + return( static_cast( ( m_tact * 64 + + m_tact64th ) * _frames_per_tact64th ) ); } return( 0 ); } static inline midiTime fromFrames( const f_cnt_t _frames, - const float _frames_per_tact ) + const float _frames_per_tact64th ) { - return( midiTime( static_cast( _frames * 64.0f / - _frames_per_tact ) ) ); + return( midiTime( static_cast( _frames / + _frames_per_tact64th ) ) ); } diff --git a/src/core/engine.cpp b/src/core/engine.cpp index a630ea9caf..1f0bfefcc4 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -106,10 +106,10 @@ void engine::close( void ) -void engine::updateFramesPerTact( void ) +void engine::updateFramesPerTact64th( void ) { - m_frames_per_tact = m_mixer->sampleRate() * 60.0f * BEATS_PER_TACT - / m_songEditor->getTempo(); + m_frames_per_tact64th = m_mixer->sampleRate() * 60.0f * BEATS_PER_TACT + / 64.0f / m_songEditor->getTempo(); } diff --git a/src/core/note_play_handle.cpp b/src/core/note_play_handle.cpp index 0c64e2483b..72c8afaf55 100644 --- a/src/core/note_play_handle.cpp +++ b/src/core/note_play_handle.cpp @@ -88,8 +88,8 @@ notePlayHandle::notePlayHandle( instrumentTrack * _it, (Uint16) ( ( getVolume() / 100.0f ) * ( m_instrumentTrack->getVolume() / 100.0f ) * 127 ), 0, 127 ) ), - midiTime::fromFrames( m_framesAhead, - m_instrumentTrack->eng()->framesPerTact() ) ); + midiTime::fromFrames( m_framesAhead, m_instrumentTrack + ->eng()->framesPerTact64th() ) ); } @@ -277,9 +277,9 @@ void notePlayHandle::noteOff( const f_cnt_t _s ) m_instrumentTrack->processOutEvent( midiEvent( NOTE_OFF, m_instrumentTrack->m_midiPort->outputChannel(), key(), 0 ), - midiTime::fromFrames( - m_framesBeforeRelease, - m_instrumentTrack->eng()->framesPerTact() ) ); + midiTime::fromFrames( m_framesBeforeRelease, + m_instrumentTrack->eng() + ->framesPerTact64th() ) ); } else { diff --git a/src/tracks/bb_track.cpp b/src/tracks/bb_track.cpp index faf6cc832f..8826d42083 100644 --- a/src/tracks/bb_track.cpp +++ b/src/tracks/bb_track.cpp @@ -384,8 +384,8 @@ bool FASTCALL bbTrack::play( const midiTime & _start, } vlist tcos; - getTCOsInRange( tcos, _start, _start +static_cast( _frames * - 64 / eng()->framesPerTact() ) ); + getTCOsInRange( tcos, _start, _start + static_cast( _frames / + eng()->framesPerTact64th() ) ); if ( tcos.size() == 0 ) { diff --git a/src/tracks/sample_track.cpp b/src/tracks/sample_track.cpp index 2684b2d37c..08ff553c76 100644 --- a/src/tracks/sample_track.cpp +++ b/src/tracks/sample_track.cpp @@ -100,7 +100,7 @@ void FASTCALL sampleTCO::play( sampleFrame * _ab, f_cnt_t _start_frame, { _start_frame = static_cast( tMax( 0.0f, _start_frame - startPosition() * - eng()->framesPerTact() / 64 ) ); + eng()->framesPerTact64th() ) ); m_sampleBuffer.play( _ab, _start_frame, _frames ); } @@ -254,7 +254,7 @@ void sampleTCO::paintEvent( QPaintEvent * _pe ) midiTime sampleTCO::getSampleLength( void ) const { return( static_cast( m_sampleBuffer.frames() / - eng()->framesPerTact() * 64 ) ); + eng()->framesPerTact64th() ) ); } @@ -443,8 +443,8 @@ bool FASTCALL sampleTrack::play( const midiTime & _start, sendMidiTime( _start ); vlist tcos; - getTCOsInRange( tcos, _start, _start+static_cast( _frames * 64 / - eng()->framesPerTact() ) ); + getTCOsInRange( tcos, _start, _start+static_cast( _frames / + eng()->framesPerTact64th() ) ); if ( tcos.size() == 0 ) { @@ -458,7 +458,7 @@ bool FASTCALL sampleTrack::play( const midiTime & _start, , m_volume, m_volume #endif } ; - float fpt = eng()->framesPerTact(); + float fpt64th = eng()->framesPerTact64th(); for( vlist::iterator it = tcos.begin(); it != tcos.end(); ++it ) @@ -467,15 +467,11 @@ bool FASTCALL sampleTrack::play( const midiTime & _start, if( st != NULL && !st->muted() ) { st->play( buf, _start_frame + - static_cast( _start.getTact() * - fpt ), + static_cast( _start * fpt64th ), _frames ); eng()->getMixer()->bufferToPort( buf, _frames, - _frame_base + - static_cast( - st->startPosition().getTact64th() * - fpt / 64.0f ), v, - m_audioPort ); + _frame_base, v, + m_audioPort ); } }