sample :: sample(const float* fData, int ln, int rt, int ch): data(0), info(ln,rt,ch) { data = new audioSample[audioSize()]; for (int i = audioSize() - 1; i >= 0; i--) data[i] = audioLimit((int) rint(32768.0 * fData[i])); if (parameters->debug("sample", "basic")) { cerr << "Created: "; print(); } } // sample constructor (float array)
void sample :: append(const sample& s) { if (!assertWarning(rate() == s.rate(), "append failed: different rates") || !assertWarning(channels() == s.channels(), "append failed: different channel counts")) return; audioSample* snd = new audioSample[audioSize() + s.audioSize()]; memcpy(snd, data, bytes()); memcpy(snd + audioSize(), s.data, s.bytes()); delete[] data; data = snd; info.length += s.length(); } // append()
int sample :: diff(const sample& t) const { if (!assertWarning(rate() == t.rate(),"diff: sample rates") || !assertWarning(length() == t.length(),"diff: different lengths") || !assertWarning(channels() == t.channels(), "diff: channel counts")) return 1; int diffs = 0; for (int i=0; (i<audioSize()) && (diffs<10); i++) if (data[i] != t.data[i]) { if (parameters->debug("sample", "basic")) cerr << "Data differs at " << i << " of " << audioSize() <<endl; diffs++; } if (parameters->debug("sample", "basic") && !diffs) cerr << "No diffs" << endl; return diffs; } // diffs()
// if (len < 0), fades the beginning -len seconds of the signal (fade in) // otherwise (len > 0), fades the final len seconds of the signal (fade out) void sample :: fade(int len, int offset) { int p, dir; int ch = channels(); int sz = abs(len) * rate(); // double factor = 0; double factor = 1.0 / 128.0; // double change = 1.0 / double(sz); double change = pow(2.0, 7.0 / double(sz)); if (len < 0) { if (offset < 0) p = 0; else p = offset; dir = 1; if (!assertWarning(p + sz <= audioSize(), "fade.in(): bad parameters")) return; } else if (len > 0) { if (offset < 0) p = audioSize() - 1; else p = offset - 1; dir = -1; if (!assertWarning((p - sz >= 0) && (p < audioSize()), "fade.out(): bad parameters")) return; } for (int i = 0; i < sz; i++) { for (int j = 0; j < ch; j++) { data[p] = int(rint(factor * double(data[p]))); p += dir; } // factor += change; factor *= change; } } // fade()
void TabListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QWidget *w = option.widget; const QStyle *style = w ? w->style() : m_view->style(); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); m_view->adjustStyleOption(&opt); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); painter->setRenderHint(QPainter::Antialiasing); // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(opt.rect.left() + (opt.rect.width() - iconSize) / 2, iconYPos, iconSize, iconSize); QPixmap pixmap; if (index.data(TabModel::LoadingRole).toBool()) { pixmap = m_loadingAnimator->pixmap(index); } else { pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); } painter->drawPixmap(iconRect, pixmap); // Draw audio icon const bool audioMuted = index.data(TabModel::AudioMutedRole).toBool(); const bool audioPlaying = index.data(TabModel::AudioPlayingRole).toBool(); if (audioMuted || audioPlaying) { QSize audioSize(16, 16); QPoint pos(opt.rect.right() - audioSize.width(), center - audioSize.height() / 2); QRect audioRect(pos, audioSize); QColor c = opt.palette.color(QPalette::Window); c.setAlpha(180); painter->setPen(c); painter->setBrush(c); painter->drawEllipse(audioRect); painter->drawPixmap(audioRect, audioMuted ? TabIcon::data()->audioMutedPixmap : TabIcon::data()->audioPlayingPixmap); } // Draw background activity indicator const bool backgroundActivity = index.data(TabModel::BackgroundActivityRole).toBool(); if (backgroundActivity) { QSize activitySize(7, 7); QPoint pos(iconRect.center().x() - activitySize.width() / 2 + 1, iconRect.bottom() - 2); QRect activityRect(pos, activitySize); QColor c1 = opt.palette.color(QPalette::Window); c1.setAlpha(180); painter->setPen(Qt::transparent); painter->setBrush(c1); painter->drawEllipse(activityRect); const QRect r2 = activityRect.adjusted(1, 1, -1, -1); painter->setPen(Qt::transparent); painter->setBrush(opt.palette.color(QPalette::Text)); painter->drawEllipse(r2); } }
foreach(Tag *audio, audios) { QSize audioSize(audioSpace.width() / 2, audioSpace.height() / qCeil((qreal)audios.count() / 2)); if(audio->player) audio->player->setGeometry(QRect(audioSpace.topLeft() + QPoint((index % 2) * audioSize.width(), qFloor(index / 2) * audioSize.height()), audioSize)); index++; }
sample :: sample(int len, int rt, int ch): data(0), info(len, rt, ch) { data = new audioSample[audioSize()]; clear(); if (parameters->debug("sample", "basic")) { cerr << "Created: "; print(); } } // sample constructor (blank)
sample :: sample(const sample& s) : data(0), info(s.info) { data = new audioSample[audioSize()]; memcpy(data, s.data, bytes()); if (parameters->debug("sample", "basic")) { cerr << "Created: "; print(); } } // sample copy constructor