<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>waveform.h Example File | Qt Multimedia 5.9</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.9</td><td ><a href="qtmultimedia-index.html">Qt Multimedia</a></td><td ><a href="qtmultimedia-multimedia-spectrum-example.html">Spectrum Example</a></td><td >waveform.h Example File</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">waveform.h Example File</h1> <span class="subtitle">multimedia/spectrum/app/waveform.h</span> <!-- $$$multimedia/spectrum/app/waveform.h-description --> <div class="descr"> <a name="details"></a> <pre class="cpp"> <span class="comment">/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/</span> <span class="preprocessor">#ifndef WAVEFORM_H</span> <span class="preprocessor">#define WAVEFORM_H</span> <span class="preprocessor">#include <QAudioFormat></span> <span class="preprocessor">#include <QPixmap></span> <span class="preprocessor">#include <QScopedPointer></span> <span class="preprocessor">#include <QWidget></span> <span class="comment">/** * Widget which displays a section of the audio waveform. * * The waveform is rendered on a set of QPixmaps which form a group of tiles * whose extent covers the widget. As the audio position is updated, these * tiles are scrolled from left to right; when the left-most tile scrolls * outside the widget, it is moved to the right end of the tile array and * painted with the next section of the waveform. */</span> <span class="keyword">class</span> Waveform : <span class="keyword">public</span> <span class="type">QWidget</span> { Q_OBJECT <span class="keyword">public</span>: <span class="keyword">explicit</span> Waveform(<span class="type">QWidget</span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>); <span class="operator">~</span>Waveform(); <span class="comment">// QWidget</span> <span class="type">void</span> paintEvent(<span class="type">QPaintEvent</span> <span class="operator">*</span>event) override; <span class="type">void</span> resizeEvent(<span class="type">QResizeEvent</span> <span class="operator">*</span>event) override; <span class="type">void</span> initialize(<span class="keyword">const</span> <span class="type"><a href="qaudioformat.html">QAudioFormat</a></span> <span class="operator">&</span>format<span class="operator">,</span> <span class="type">qint64</span> audioBufferSize<span class="operator">,</span> <span class="type">qint64</span> windowDurationUs); <span class="type">void</span> reset(); <span class="type">void</span> setAutoUpdatePosition(bool enabled); <span class="keyword">public</span> <span class="keyword">slots</span>: <span class="type">void</span> bufferChanged(<span class="type">qint64</span> position<span class="operator">,</span> <span class="type">qint64</span> length<span class="operator">,</span> <span class="keyword">const</span> <span class="type">QByteArray</span> <span class="operator">&</span>buffer); <span class="type">void</span> audioPositionChanged(<span class="type">qint64</span> position); <span class="keyword">private</span>: <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">int</span> NullIndex <span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>; <span class="type">void</span> deletePixmaps(); <span class="comment">/* * (Re)create all pixmaps, repaint and update the display. * Triggers an update(); */</span> <span class="type">void</span> createPixmaps(<span class="keyword">const</span> <span class="type">QSize</span> <span class="operator">&</span>newSize); <span class="comment">/* * Update window position. * Triggers an update(). */</span> <span class="type">void</span> setWindowPosition(<span class="type">qint64</span> position); <span class="comment">/* * Base position of tile */</span> <span class="type">qint64</span> tilePosition(<span class="type">int</span> index) <span class="keyword">const</span>; <span class="comment">/* * Structure which identifies a point within a given * tile. */</span> <span class="keyword">struct</span> TilePoint { TilePoint(<span class="type">int</span> idx <span class="operator">=</span> <span class="number">0</span><span class="operator">,</span> <span class="type">qint64</span> pos <span class="operator">=</span> <span class="number">0</span><span class="operator">,</span> <span class="type">qint64</span> pix <span class="operator">=</span> <span class="number">0</span>) : index(idx)<span class="operator">,</span> positionOffset(pos)<span class="operator">,</span> pixelOffset(pix) { } <span class="comment">// Index of tile</span> <span class="type">int</span> index; <span class="comment">// Number of bytes from start of tile</span> <span class="type">qint64</span> positionOffset; <span class="comment">// Number of pixels from left of corresponding pixmap</span> <span class="type">int</span> pixelOffset; }; <span class="comment">/* * Convert position in m_buffer into a tile index and an offset in pixels * into the corresponding pixmap. * * \param position Offset into m_buffer, in bytes * If position is outside the tile array, index is NullIndex and * offset is zero. */</span> TilePoint tilePoint(<span class="type">qint64</span> position) <span class="keyword">const</span>; <span class="comment">/* * Convert offset in bytes into a tile into an offset in pixels * within that tile. */</span> <span class="type">int</span> tilePixelOffset(<span class="type">qint64</span> positionOffset) <span class="keyword">const</span>; <span class="comment">/* * Convert offset in bytes into the window into an offset in pixels * within the widget rect(). */</span> <span class="type">int</span> windowPixelOffset(<span class="type">qint64</span> positionOffset) <span class="keyword">const</span>; <span class="comment">/* * Paint all tiles which can be painted. * \return true iff update() was called */</span> bool paintTiles(); <span class="comment">/* * Paint the specified tile * * \pre Sufficient data is available to completely paint the tile, i.e. * m_dataLength is greater than the upper bound of the tile. */</span> <span class="type">void</span> paintTile(<span class="type">int</span> index); <span class="comment">/* * Move the first n tiles to the end of the array, and mark them as not * painted. */</span> <span class="type">void</span> shuffleTiles(<span class="type">int</span> n); <span class="comment">/* * Reset tile array */</span> <span class="type">void</span> resetTiles(<span class="type">qint64</span> newStartPos); <span class="keyword">private</span>: <span class="type">qint64</span> m_bufferPosition; <span class="type">qint64</span> m_bufferLength; <span class="type">QByteArray</span> m_buffer; <span class="type">qint64</span> m_audioPosition; <span class="type"><a href="qaudioformat.html">QAudioFormat</a></span> m_format; bool m_active; <span class="type">QSize</span> m_pixmapSize; <span class="type">QVector</span><span class="operator"><</span><span class="type">QPixmap</span><span class="operator">*</span><span class="operator">></span> m_pixmaps; <span class="keyword">struct</span> Tile { <span class="comment">// Pointer into parent m_pixmaps array</span> <span class="type">QPixmap</span><span class="operator">*</span> pixmap; <span class="comment">// Flag indicating whether this tile has been painted</span> bool painted; }; <span class="type">QVector</span><span class="operator"><</span>Tile<span class="operator">></span> m_tiles; <span class="comment">// Length of audio data in bytes depicted by each tile</span> <span class="type">qint64</span> m_tileLength; <span class="comment">// Position in bytes of the first tile, relative to m_buffer</span> <span class="type">qint64</span> m_tileArrayStart; <span class="type">qint64</span> m_windowPosition; <span class="type">qint64</span> m_windowLength; }; <span class="preprocessor">#endif // WAVEFORM_H</span> </pre> </div> <!-- @@@multimedia/spectrum/app/waveform.h --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>