From 2c414a3fb43593ca17e900939fece4279ff916c5 Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Sun, 6 Aug 2006 21:35:14 +0000 Subject: [PATCH] - frames computation based on 64th of a tact - simplified note playing git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@283 0778d3d1-df1d-0410-868b-ea421aaaa00d --- src/tracks/instrument_track.cpp | 80 +++++++++++++-------------------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/src/tracks/instrument_track.cpp b/src/tracks/instrument_track.cpp index 32946ad66..35130e2de 100644 --- a/src/tracks/instrument_track.cpp +++ b/src/tracks/instrument_track.cpp @@ -631,7 +631,8 @@ void instrumentTrack::processInEvent( const midiEvent & _me, // create (timed) note-play-handle notePlayHandle * nph = new notePlayHandle( this, - _time.frames( eng()->framesPerTact() ), + _time.frames( + eng()->framesPerTact64th() ), valueRanges::max, n ); if( eng()->getMixer()->addPlayHandle( nph ) ) @@ -653,8 +654,8 @@ void instrumentTrack::processInEvent( const midiEvent & _me, // recording notes into a pattern note done_note( NULL, midiTime( static_cast( - n->totalFramesPlayed() * 64 / - eng()->framesPerTact() ) ), + n->totalFramesPlayed() / + eng()->framesPerTact64th() ) ), 0, n->tone(), n->octave(), n->getVolume(), n->getPanning() ); n->noteOff(); @@ -755,8 +756,8 @@ void instrumentTrack::deleteNotePluginData( notePlayHandle * _n ) if( m_notes[_n->key()] == _n ) { note done_note( NULL, midiTime( static_cast( - _n->totalFramesPlayed() * 64 / - eng()->framesPerTact() ) ), + _n->totalFramesPlayed() / + eng()->framesPerTact64th() ) ), 0, _n->tone(), _n->octave(), _n->getVolume(), _n->getPanning() ); _n->noteOff(); @@ -892,9 +893,7 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, emit sentMidiTime( _start ); } - // calculate samples per tact; need that later when calculating - // sample-pos of a note - float frames_per_tact = eng()->framesPerTact(); + float frames_per_tact64th = eng()->framesPerTact64th(); vlist tcos; if( _tco_num >= 0 ) @@ -903,9 +902,8 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, } else { - getTCOsInRange( tcos, _start, _start + - static_cast( _frames * 64 / - frames_per_tact ) ); + getTCOsInRange( tcos, _start, _start + static_cast( + _frames / frames_per_tact64th ) ); } if ( tcos.size() == 0 ) @@ -915,9 +913,6 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, bool played_a_note = FALSE; // will be return variable - // calculate the end of the current sample-frame - const f_cnt_t end_frame = _start_frame+_frames-1; - for( vlist::iterator it = tcos.begin(); it != tcos.end(); ++it ) { @@ -927,10 +922,11 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, { continue; } - midiTime cur_start = _start.getTact() * 64 - - ( ( _tco_num < 0 ) ? - p->startPosition() : - midiTime( 0 ) ); + midiTime cur_start = _start; + if( _tco_num < 0 ) + { + cur_start -= p->startPosition(); + } if( p->frozen() && eng()->getSongEditor()->exporting() == FALSE ) { @@ -944,22 +940,22 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, sampleFrame * buf = bufferAllocator::alloc( _frames ); - p->playFrozenData( buf, _start_frame + - static_cast( - cur_start.getTact() * - frames_per_tact ), + p->playFrozenData( buf, _start_frame + cur_start.frames( + frames_per_tact64th ), _frames ); eng()->getMixer()->bufferToPort( buf, _frames, - _frame_base + - static_cast( - p->startPosition().getTact64th() * - frames_per_tact / - 64.0f ), - v, m_audioPort ); + _frame_base, v, + m_audioPort ); bufferAllocator::free( buf ); continue; } + // all notes start at 0 + if( _start_frame > 0 ) + { + continue; + } + // get all notes from the given pattern... noteVector & notes = p->notes(); // ...and set our index to zero @@ -978,28 +974,15 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, } } - // skip notes before sample-frame - while( it != notes.end() && - ( *it )->pos( cur_start ).frames( frames_per_tact ) < - _start_frame ) - { - ++it; - } - note * cur_note; while( it != notes.end() && - ( ( cur_note = *it )->pos( cur_start ).frames( - frames_per_tact ) ) <= end_frame ) + ( cur_note = *it )->pos() == cur_start ) { if( cur_note->length() != 0 ) { - const f_cnt_t frames_ahead = _frame_base - - _start_frame + - cur_note->pos( cur_start ).frames( frames_per_tact ); - const f_cnt_t note_frames = cur_note->length().frames( - frames_per_tact ); + frames_per_tact64th ); /* // generate according MIDI-events processOutEvent( midiEvent( NOTE_ON, @@ -1008,20 +991,21 @@ bool FASTCALL instrumentTrack::play( const midiTime & _start, cur_note->getVolume() * 128 / 100 ), midiTime::fromFrames( - frames_ahead, - frames_per_tact ) ); + _frame_base, + frames_per_tact64th ) ); processOutEvent( midiEvent( NOTE_OFF, m_midiPort->outputChannel(), cur_note->key(), 0 ), midiTime::fromFrames( - frames_ahead + + _frame_base + note_frames, - frames_per_tact ) );*/ + frames_per_tact64th ) ); +*/ notePlayHandle * note_play_handle = new notePlayHandle( this, - frames_ahead, + _frame_base, note_frames, *cur_note ); note_play_handle->play();