void deref() { if( d ) { bool ref = d->refCount.deref(); qcDebugMsg(2,QString("SafePtr: -refcount = %1").arg(d->refCount)); if( !ref ) { qcDebugMsg(2,"SafePtr: unreferenced!"); delete d; } } }
int QcTreeWidget::Item::finalize( VMGlobals *g, PyrObject *obj ) { qcDebugMsg(1,"finalizing QTreeViewItem!"); if( IsPtr( obj->slots+0 ) ) { QcTreeWidget::ItemPtr *ptr = static_cast<QcTreeWidget::ItemPtr*>( slotRawPtr(obj->slots+0) ); delete ptr; } return errNone; }
void QtCollider::lockLang() { qcDebugMsg(2,"locking lang!"); #ifdef QC_DEBUG QString msg; #endif while( pthread_mutex_trylock (&gLangMutex) ) { #ifdef QC_DEBUG msg += QChar('.'); #endif /* FIXME Dangerous! This sends to all QObjects. no matter what thread they live in */ QApplication::sendPostedEvents( 0, QtCollider::Event_Sync ); QThread::yieldCurrentThread(); } #ifdef QC_DEBUG msg += "locked"; #endif qcDebugMsg(2,msg); }
void QcWaveform::load( const QString& filename ) { qcDebugMsg( 1, "QcWaveform::load( filename )" ); SF_INFO new_info; memset( &new_info, 0, sizeof(SF_INFO) ); SNDFILE *new_sf = sf_open( filename.toStdString().c_str(), SFM_READ, &new_info ); if( !new_sf ) { qcErrorMsg(QString("Could not open soundfile: ") + filename); return; } doLoad( new_sf, new_info, 0, new_info.frames ); }
void QcWaveform::load( const QVector<double> & data, int offset, int ch, int sr ) { qcDebugMsg( 1, "QcWaveform::load( data, offset, channels )" ); if( ch < 1 ) { qcWarningMsg( "QSoundFileView: invalid number of channels!" ); return; } int ns = data.count(); int nf = ns / ch; if( nf * ch != ns ) { qcWarningMsg( "QSoundFileView: size of data not a multiple of channel count!" ); return; } if( offset < 0 || nf - offset < 1 ) { qcWarningMsg( "QSoundFileView: invalid range of data!" ); return; } delete _cache; if( sf ) sf_close( sf ); sf = 0; SF_INFO new_info; memset( &new_info, 0, sizeof(SF_INFO) ); new_info.channels = ch; new_info.samplerate = sr; sfInfo = new_info; _beg = _rangeBeg = 0; _dur = _rangeDur = _rangeEnd = nf - offset; updateFPP(); _cache = new SoundCacheStream(); connect( _cache, SIGNAL(loadingDone()), this, SIGNAL(loadingDone()) ); connect( _cache, SIGNAL(loadingDone()), this, SLOT(redraw()) ); _cache->load( data, _rangeDur, offset, ch ); }
void QcWaveform::draw( QPixmap *pix, int x, int width, double f_beg, double f_dur ) { // FIXME anomaly: when _fpp reaching 1.0 rms can go outside min-max! pix->fill( QColor( 0, 0, 0, 0 ) ); QPainter p( pix ); if( !_cache || !_cache->ready() ) return; // check for sane situation: if( f_beg < _rangeBeg || f_beg + f_dur > _rangeEnd ) return; // data indexes sf_count_t i_beg = floor(f_beg); // data beginning; sf_count_t i_count = ceil( f_beg + f_dur ) - i_beg; // data count; bool haveOneMore; if( i_beg + i_count < _rangeEnd ) { ++i_count; haveOneMore = true; } else { haveOneMore = false; } // data source - choose according to horiz. zoom (data-display resolution) bool canUseCache = _fpp < 1.0 ? _cache->fpu() == 1.0 : _fpp >= _cache->fpu(); SoundStream *soundStream; SoundFileStream sfStream; if( canUseCache ) { qcDebugMsg( 2, QString("using cache") ); soundStream = _cache; } else if( sf ) { qcDebugMsg( 2, QString("using file") ); soundStream = &sfStream; sfStream.load( sf, sfInfo, i_beg, i_count ); } else { qcWarningMsg( "QSoundFileView: can't paint waveform: view resolution exceeds data cache resolution," " and soundfile is not given." ); return; } // geometry float spacing = pix->height() * 0.15f / (sfInfo.channels + 1); float chHeight = pix->height() * 0.85f / (float) sfInfo.channels; float yScale = -chHeight / 65535.f * _yZoom; //spacing /= yscale; // initial painter setup QPen minMaxPen; QPen rmsPen; float halfChH = chHeight * 0.5; p.translate( 0.f, halfChH + spacing ); int waveColorN = _waveColors.count(); int ch; for( ch = 0; ch < soundStream->channels(); ++ch ) { if( ch < waveColorN && _waveColors[ch].isValid() ) { QColor clr( _waveColors[ch] ); rmsPen.setColor( clr ); minMaxPen.setColor( clr.darker( 140 ) ); } else { rmsPen.setColor( _rmsColor ); minMaxPen.setColor( _peakColor ); } // draw center line p.setPen( QColor(90,90,90) ); p.drawLine( x, 0, x + width, 0 ); // draw bounding lines p.setPen( QColor(100,100,100) ); p.drawLine( x, halfChH, x+width, halfChH ); p.drawLine( x, -halfChH, x+width, -halfChH ); p.save(); p.setClipping(true); p.setClipRect( x, -halfChH, x+width, chHeight ); p.scale( 1.f, yScale ); if( _fpp > 1.0 ) { // draw min-max regions and RMS short minBuffer[width]; short maxBuffer[width]; short minRMS[width]; short maxRMS[width]; bool ok = soundStream->displayData( ch, f_beg, f_dur, minBuffer, maxBuffer, minRMS, maxRMS, width ); // printf("integration ok: %i\n", ok); Q_ASSERT( ok ); int i; for( i = 0; i < width; ++i ) { short min = minBuffer[i]; short max = maxBuffer[i]; if( max != min ) { p.setPen( minMaxPen ); p.drawLine( x + i, min, x + i, max ); } else { p.setPen( minMaxPen ); p.drawPoint( x + i, min ); } p.setPen( rmsPen ); p.drawLine( x + i, minRMS[i], x + i, maxRMS[i] ); } } else { // draw lines between actual values qreal ppf = 1.0 / _fpp; qreal dx = (i_beg - f_beg) * ppf; bool interleaved = false; short *data = soundStream->rawFrames( ch, i_beg, i_count, &interleaved ); //printf("got raw frames ok: %i\n", data != 0 ); Q_ASSERT( data != 0 ); int step = interleaved ? soundStream->channels() : 1; QPainterPath path; if( i_count ) { QPointF pt( dx, (qreal) *data ); path.moveTo( pt ); } int f; // frame for( f = 1; f < i_count; ++f ) { data += step; QPointF pt( f * ppf + dx, (qreal) *data ); path.lineTo( pt ); } if( i_count && !haveOneMore ) { path.lineTo( QPointF( f * ppf + dx, (qreal)*data ) ); } p.setPen( rmsPen ); p.drawPath( path ); } p.restore(); p.translate( 0.f, chHeight + spacing ); } }
void ref() { if( d ) { d->refCount.ref(); qcDebugMsg(2,QString("SafePtr: +refcount = %1").arg(d->refCount)); } }
void invalidate() { qcDebugMsg(2,"SafePtr: invalidating"); if(d) d->ptr = 0; }