def _draw_spectrogram(self, painter, _event):
width = painter.viewport().width()
height = (1 << DERIVATION_SIZE) + 1
pixels = np.zeros([width, height], dtype='byte')
horizontal_res = (
self._api.opt.general['audio']['spectrogram_resolution'])
# since the task queue is a LIFO queue, in order to render the columns
# left-to-right, they need to be iterated backwards (hence reversed()).
for x in reversed(range(width)):
pts = self._pts_from_x(x)
pts = (pts // horizontal_res) * horizontal_res
column = self._spectrum_cache.get(pts, NOT_CACHED)
if column is NOT_CACHED:
self._spectrum_provider.schedule_task(pts)
self._spectrum_cache[pts] = CACHING
continue
if column is CACHING:
continue
pixels[x] = column
pixels = pixels.transpose().copy()
image = QtGui.QImage(
pixels.data,
pixels.shape[1],
pixels.shape[0],
pixels.strides[0],
QtGui.QImage.Format_Indexed8)
image.setColorTable(self._color_table)
painter.save()
painter.scale(1, painter.viewport().height() / (height - 1))
painter.drawPixmap(0, 0, QtGui.QPixmap.fromImage(image))
painter.restore()
评论列表
文章目录