void FileBrowserTreeWidget::mouseReleaseEvent(QMouseEvent * me ) { m_mousePressed = false; m_pphMutex.lock(); if( m_previewPlayHandle != NULL ) { // if there're samples shorter than 3 seconds, we don't // stop them if the user releases mouse-button... if( m_previewPlayHandle->type() == PlayHandle::TypeSamplePlayHandle ) { SamplePlayHandle * s = dynamic_cast<SamplePlayHandle *>( m_previewPlayHandle ); if( s && s->totalFrames() - s->framesDone() <= static_cast<f_cnt_t>( Engine::mixer()-> processingSampleRate() * 3 ) ) { s->setDoneMayReturnTrue( true ); m_previewPlayHandle = NULL; m_pphMutex.unlock(); return; } } Engine::mixer()->removePlayHandle( m_previewPlayHandle ); m_previewPlayHandle = NULL; } m_pphMutex.unlock(); }
bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, const f_cnt_t _offset, int /*_tco_num*/ ) { m_audioPort.effects()->startRunning(); bool played_a_note = false; // will be return variable for( int i = 0; i < numOfTCOs(); ++i ) { TrackContentObject * tco = getTCO( i ); if( tco->startPosition() != _start ) { continue; } SampleTCO * st = dynamic_cast<SampleTCO *>( tco ); if( !st->isMuted() ) { PlayHandle* handle; if( st->isRecord() ) { if( !Engine::getSong()->isRecording() ) { return played_a_note; } SampleRecordHandle* smpHandle = new SampleRecordHandle( st ); handle = smpHandle; } else { SamplePlayHandle* smpHandle = new SamplePlayHandle( st ); smpHandle->setVolumeModel( &m_volumeModel ); handle = smpHandle; } //TODO: check whether this works // handle->setBBTrack( _tco_num ); handle->setOffset( _offset ); // send it to the mixer Engine::mixer()->addPlayHandle( handle ); played_a_note = true; } } return played_a_note; }
void FileBrowserTreeWidget::mousePressEvent(QMouseEvent * me ) { QTreeWidget::mousePressEvent( me ); if( me->button() != Qt::LeftButton ) { return; } QTreeWidgetItem * i = itemAt( me->pos() ); if ( i ) { // TODO: Restrict to visible selection // if ( _me->x() > header()->cellPos( header()->mapToActual( 0 ) ) // + treeStepSize() * ( i->depth() + ( rootIsDecorated() ? // 1 : 0 ) ) + itemMargin() || // _me->x() < header()->cellPos( // header()->mapToActual( 0 ) ) ) // { m_pressPos = me->pos(); m_mousePressed = true; // } } FileItem * f = dynamic_cast<FileItem *>( i ); if( f != NULL ) { m_pphMutex.lock(); if( m_previewPlayHandle != NULL ) { Engine::mixer()->removePlayHandle( m_previewPlayHandle ); m_previewPlayHandle = NULL; } // in special case of sample-files we do not care about // handling() rather than directly creating a SamplePlayHandle if( f->type() == FileItem::SampleFile ) { TextFloat * tf = TextFloat::displayMessage( tr( "Loading sample" ), tr( "Please wait, loading sample for " "preview..." ), embed::getIconPixmap( "sample_file", 24, 24 ), 0 ); qApp->processEvents( QEventLoop::ExcludeUserInputEvents ); SamplePlayHandle * s = new SamplePlayHandle( f->fullName() ); s->setDoneMayReturnTrue( false ); m_previewPlayHandle = s; delete tf; } else if( f->type() != FileItem::VstPluginFile && ( f->handling() == FileItem::LoadAsPreset || f->handling() == FileItem::LoadByPlugin ) ) { m_previewPlayHandle = new PresetPreviewPlayHandle( f->fullName(), f->handling() == FileItem::LoadByPlugin ); } if( m_previewPlayHandle != NULL ) { if( !Engine::mixer()->addPlayHandle( m_previewPlayHandle ) ) { m_previewPlayHandle = NULL; } } m_pphMutex.unlock(); } }
bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, const f_cnt_t _offset, int _tco_num ) { m_audioPort.effects()->startRunning(); bool played_a_note = false; // will be return variable tcoVector tcos; ::BBTrack * bb_track = NULL; if( _tco_num >= 0 ) { if( _start != 0 ) { return false; } tcos.push_back( getTCO( _tco_num ) ); if (trackContainer() == (TrackContainer*)Engine::getBBTrackContainer()) { bb_track = BBTrack::findBBTrack( _tco_num ); } } else { for( int i = 0; i < numOfTCOs(); ++i ) { TrackContentObject * tco = getTCO( i ); SampleTCO * sTco = dynamic_cast<SampleTCO*>( tco ); float framesPerTick = Engine::framesPerTick(); if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) { f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames(); //if the Tco smaller than the sample length we play only until Tco end //else we play the sample to the end but nothing more f_cnt_t samplePlayLength = tcoFrameLength > sampleBufferLength ? sampleBufferLength : tcoFrameLength; //we only play within the sampleBuffer limits if( sampleStart < sampleBufferLength ) { sTco->setSampleStartFrame( sampleStart ); sTco->setSamplePlayLength( samplePlayLength ); tcos.push_back( sTco ); sTco->setIsPlaying( true ); } } } else { sTco->setIsPlaying( false ); } } } for( tcoVector::Iterator it = tcos.begin(); it != tcos.end(); ++it ) { SampleTCO * st = dynamic_cast<SampleTCO *>( *it ); if( !st->isMuted() ) { PlayHandle* handle; if( st->isRecord() ) { if( !Engine::getSong()->isRecording() ) { return played_a_note; } SampleRecordHandle* smpHandle = new SampleRecordHandle( st ); handle = smpHandle; } else { SamplePlayHandle* smpHandle = new SamplePlayHandle( st ); smpHandle->setVolumeModel( &m_volumeModel ); smpHandle->setBBTrack( bb_track ); handle = smpHandle; } handle->setOffset( _offset ); // send it to the mixer Engine::mixer()->addPlayHandle( handle ); played_a_note = true; } } return played_a_note; }